1 | .. comment SPDX-License-Identifier: CC-BY-SA-4.0 |
---|
2 | |
---|
3 | .. COMMENT: COPYRIGHT (c) 1988-2008. |
---|
4 | .. COMMENT: On-Line Applications Research Corporation (OAR). |
---|
5 | .. COMMENT: All rights reserved. |
---|
6 | |
---|
7 | .. index:: tasks |
---|
8 | |
---|
9 | Task Manager |
---|
10 | ************ |
---|
11 | |
---|
12 | Introduction |
---|
13 | ============ |
---|
14 | |
---|
15 | The task manager provides a comprehensive set of directives to create, delete, |
---|
16 | and administer tasks. The directives provided by the task manager are: |
---|
17 | |
---|
18 | - rtems_task_create_ - Create a task |
---|
19 | |
---|
20 | - rtems_task_ident_ - Get ID of a task |
---|
21 | |
---|
22 | - rtems_task_self_ - Obtain ID of caller |
---|
23 | |
---|
24 | - rtems_task_start_ - Start a task |
---|
25 | |
---|
26 | - rtems_task_restart_ - Restart a task |
---|
27 | |
---|
28 | - rtems_task_delete_ - Delete a task |
---|
29 | |
---|
30 | - rtems_task_suspend_ - Suspend a task |
---|
31 | |
---|
32 | - rtems_task_resume_ - Resume a task |
---|
33 | |
---|
34 | - rtems_task_is_suspended_ - Determine if a task is suspended |
---|
35 | |
---|
36 | - rtems_task_set_priority_ - Set task priority |
---|
37 | |
---|
38 | - rtems_task_get_priority_ - Get task priority |
---|
39 | |
---|
40 | - rtems_task_mode_ - Change current task's mode |
---|
41 | |
---|
42 | - rtems_task_wake_after_ - Wake up after interval |
---|
43 | |
---|
44 | - rtems_task_wake_when_ - Wake up when specified |
---|
45 | |
---|
46 | - rtems_task_get_scheduler_ - Get scheduler of a task |
---|
47 | |
---|
48 | - rtems_task_set_scheduler_ - Set scheduler of a task |
---|
49 | |
---|
50 | - rtems_task_get_affinity_ - Get task processor affinity |
---|
51 | |
---|
52 | - rtems_task_set_affinity_ - Set task processor affinity |
---|
53 | |
---|
54 | - rtems_task_iterate_ - Iterate Over Tasks |
---|
55 | |
---|
56 | Background |
---|
57 | ========== |
---|
58 | |
---|
59 | .. index:: task, definition |
---|
60 | |
---|
61 | Task Definition |
---|
62 | --------------- |
---|
63 | |
---|
64 | Many definitions of a task have been proposed in computer literature. |
---|
65 | Unfortunately, none of these definitions encompasses all facets of the concept |
---|
66 | in a manner which is operating system independent. Several of the more common |
---|
67 | definitions are provided to enable each user to select a definition which best |
---|
68 | matches their own experience and understanding of the task concept: |
---|
69 | |
---|
70 | - a "dispatchable" unit. |
---|
71 | |
---|
72 | - an entity to which the processor is allocated. |
---|
73 | |
---|
74 | - an atomic unit of a real-time, multiprocessor system. |
---|
75 | |
---|
76 | - single threads of execution which concurrently compete for resources. |
---|
77 | |
---|
78 | - a sequence of closely related computations which can execute concurrently |
---|
79 | with other computational sequences. |
---|
80 | |
---|
81 | From RTEMS' perspective, a task is the smallest thread of execution which can |
---|
82 | compete on its own for system resources. A task is manifested by the existence |
---|
83 | of a task control block (TCB). |
---|
84 | |
---|
85 | Task Control Block |
---|
86 | ------------------ |
---|
87 | |
---|
88 | The Task Control Block (TCB) is an RTEMS defined data structure which contains |
---|
89 | all the information that is pertinent to the execution of a task. During |
---|
90 | system initialization, RTEMS reserves a TCB for each task configured. A TCB is |
---|
91 | allocated upon creation of the task and is returned to the TCB free list upon |
---|
92 | deletion of the task. |
---|
93 | |
---|
94 | The TCB's elements are modified as a result of system calls made by the |
---|
95 | application in response to external and internal stimuli. TCBs are the only |
---|
96 | RTEMS internal data structure that can be accessed by an application via user |
---|
97 | extension routines. The TCB contains a task's name, ID, current priority, |
---|
98 | current and starting states, execution mode, TCB user extension pointer, |
---|
99 | scheduling control structures, as well as data required by a blocked task. |
---|
100 | |
---|
101 | A task's context is stored in the TCB when a task switch occurs. When the task |
---|
102 | regains control of the processor, its context is restored from the TCB. When a |
---|
103 | task is restarted, the initial state of the task is restored from the starting |
---|
104 | context area in the task's TCB. |
---|
105 | |
---|
106 | .. index:: task name |
---|
107 | |
---|
108 | Task Name |
---|
109 | --------- |
---|
110 | |
---|
111 | By default, the task name is defined by the task object name given to |
---|
112 | :ref:`rtems_task_create() <rtems_task_create>`. The task name can be obtained |
---|
113 | with the `pthread_getname_np() |
---|
114 | <http://man7.org/linux/man-pages/man3/pthread_setname_np.3.html>`_ function. |
---|
115 | Optionally, a new task name may be set with the `pthread_setname_np() |
---|
116 | <http://man7.org/linux/man-pages/man3/pthread_setname_np.3.html>`_ function. |
---|
117 | The maximum size of a task name is defined by the application configuration |
---|
118 | option :ref:`CONFIGURE_MAXIMUM_THREAD_NAME_SIZE |
---|
119 | <CONFIGURE_MAXIMUM_THREAD_NAME_SIZE>`. |
---|
120 | |
---|
121 | .. index:: task states |
---|
122 | |
---|
123 | Task States |
---|
124 | ----------- |
---|
125 | |
---|
126 | A task may exist in one of the following five states: |
---|
127 | |
---|
128 | - *executing* - Currently scheduled to the CPU |
---|
129 | |
---|
130 | - *ready* - May be scheduled to the CPU |
---|
131 | |
---|
132 | - *blocked* - Unable to be scheduled to the CPU |
---|
133 | |
---|
134 | - *dormant* - Created task that is not started |
---|
135 | |
---|
136 | - *non-existent* - Uncreated or deleted task |
---|
137 | |
---|
138 | An active task may occupy the executing, ready, blocked or dormant state, |
---|
139 | otherwise the task is considered non-existent. One or more tasks may be active |
---|
140 | in the system simultaneously. Multiple tasks communicate, synchronize, and |
---|
141 | compete for system resources with each other via system calls. The multiple |
---|
142 | tasks appear to execute in parallel, but actually each is dispatched to the CPU |
---|
143 | for periods of time determined by the RTEMS scheduling algorithm. The |
---|
144 | scheduling of a task is based on its current state and priority. |
---|
145 | |
---|
146 | .. index:: task priority |
---|
147 | .. index:: priority, task |
---|
148 | .. index:: rtems_task_priority |
---|
149 | |
---|
150 | Task Priority |
---|
151 | ------------- |
---|
152 | |
---|
153 | A task's priority determines its importance in relation to the other tasks |
---|
154 | executing on the same processor. RTEMS supports 255 levels of priority ranging |
---|
155 | from 1 to 255. The data type ``rtems_task_priority`` is used to store task |
---|
156 | priorities. |
---|
157 | |
---|
158 | Tasks of numerically smaller priority values are more important tasks than |
---|
159 | tasks of numerically larger priority values. For example, a task at priority |
---|
160 | level 5 is of higher privilege than a task at priority level 10. There is no |
---|
161 | limit to the number of tasks assigned to the same priority. |
---|
162 | |
---|
163 | Each task has a priority associated with it at all times. The initial value of |
---|
164 | this priority is assigned at task creation time. The priority of a task may be |
---|
165 | changed at any subsequent time. |
---|
166 | |
---|
167 | Priorities are used by the scheduler to determine which ready task will be |
---|
168 | allowed to execute. In general, the higher the logical priority of a task, the |
---|
169 | more likely it is to receive processor execution time. |
---|
170 | |
---|
171 | .. index:: task mode |
---|
172 | .. index:: rtems_task_mode |
---|
173 | |
---|
174 | Task Mode |
---|
175 | --------- |
---|
176 | |
---|
177 | A task's execution mode is a combination of the following four components: |
---|
178 | |
---|
179 | - preemption |
---|
180 | |
---|
181 | - ASR processing |
---|
182 | |
---|
183 | - timeslicing |
---|
184 | |
---|
185 | - interrupt level |
---|
186 | |
---|
187 | It is used to modify RTEMS' scheduling process and to alter the execution |
---|
188 | environment of the task. The data type ``rtems_task_mode`` is used to manage |
---|
189 | the task execution mode. |
---|
190 | |
---|
191 | .. index:: preemption |
---|
192 | |
---|
193 | The preemption component allows a task to determine when control of the |
---|
194 | processor is relinquished. If preemption is disabled (``RTEMS_NO_PREEMPT``), |
---|
195 | the task will retain control of the processor as long as it is in the executing |
---|
196 | state - even if a higher priority task is made ready. If preemption is enabled |
---|
197 | (``RTEMS_PREEMPT``) and a higher priority task is made ready, then the |
---|
198 | processor will be taken away from the current task immediately and given to the |
---|
199 | higher priority task. |
---|
200 | |
---|
201 | .. index:: timeslicing |
---|
202 | |
---|
203 | The timeslicing component is used by the RTEMS scheduler to determine how the |
---|
204 | processor is allocated to tasks of equal priority. If timeslicing is enabled |
---|
205 | (``RTEMS_TIMESLICE``), then RTEMS will limit the amount of time the task can |
---|
206 | execute before the processor is allocated to another ready task of equal |
---|
207 | priority. The length of the timeslice is application dependent and specified in |
---|
208 | the Configuration Table. If timeslicing is disabled (``RTEMS_NO_TIMESLICE``), |
---|
209 | then the task will be allowed to execute until a task of higher priority is |
---|
210 | made ready. If ``RTEMS_NO_PREEMPT`` is selected, then the timeslicing component |
---|
211 | is ignored by the scheduler. |
---|
212 | |
---|
213 | The asynchronous signal processing component is used to determine when received |
---|
214 | signals are to be processed by the task. If signal processing is enabled |
---|
215 | (``RTEMS_ASR``), then signals sent to the task will be processed the next time |
---|
216 | the task executes. If signal processing is disabled (``RTEMS_NO_ASR``), then |
---|
217 | all signals received by the task will remain posted until signal processing is |
---|
218 | enabled. This component affects only tasks which have established a routine to |
---|
219 | process asynchronous signals. |
---|
220 | |
---|
221 | .. index:: interrupt level, task |
---|
222 | |
---|
223 | The interrupt level component is used to determine which interrupts will be |
---|
224 | enabled when the task is executing. ``RTEMS_INTERRUPT_LEVEL(n)`` specifies that |
---|
225 | the task will execute at interrupt level n. |
---|
226 | |
---|
227 | .. list-table:: |
---|
228 | :class: rtems-table |
---|
229 | |
---|
230 | * - ``RTEMS_PREEMPT`` |
---|
231 | - enable preemption (default) |
---|
232 | * - ``RTEMS_NO_PREEMPT`` |
---|
233 | - disable preemption |
---|
234 | * - ``RTEMS_NO_TIMESLICE`` |
---|
235 | - disable timeslicing (default) |
---|
236 | * - ``RTEMS_TIMESLICE`` |
---|
237 | - enable timeslicing |
---|
238 | * - ``RTEMS_ASR`` |
---|
239 | - enable ASR processing (default) |
---|
240 | * - ``RTEMS_NO_ASR`` |
---|
241 | - disable ASR processing |
---|
242 | * - ``RTEMS_INTERRUPT_LEVEL(0)`` |
---|
243 | - enable all interrupts (default) |
---|
244 | * - ``RTEMS_INTERRUPT_LEVEL(n)`` |
---|
245 | - execute at interrupt level n |
---|
246 | |
---|
247 | The set of default modes may be selected by specifying the |
---|
248 | ``RTEMS_DEFAULT_MODES`` constant. |
---|
249 | |
---|
250 | .. index:: task arguments |
---|
251 | .. index:: task prototype |
---|
252 | |
---|
253 | Accessing Task Arguments |
---|
254 | ------------------------ |
---|
255 | |
---|
256 | All RTEMS tasks are invoked with a single argument which is specified when they |
---|
257 | are started or restarted. The argument is commonly used to communicate startup |
---|
258 | information to the task. The simplest manner in which to define a task which |
---|
259 | accesses it argument is: |
---|
260 | |
---|
261 | .. index:: rtems_task |
---|
262 | |
---|
263 | .. code-block:: c |
---|
264 | |
---|
265 | rtems_task user_task( |
---|
266 | rtems_task_argument argument |
---|
267 | ); |
---|
268 | |
---|
269 | Application tasks requiring more information may view this single argument as |
---|
270 | an index into an array of parameter blocks. |
---|
271 | |
---|
272 | .. index:: floating point |
---|
273 | |
---|
274 | Floating Point Considerations |
---|
275 | ----------------------------- |
---|
276 | |
---|
277 | Creating a task with the ``RTEMS_FLOATING_POINT`` attribute flag results in |
---|
278 | additional memory being allocated for the TCB to store the state of the numeric |
---|
279 | coprocessor during task switches. This additional memory is *NOT* allocated for |
---|
280 | ``RTEMS_NO_FLOATING_POINT`` tasks. Saving and restoring the context of a |
---|
281 | ``RTEMS_FLOATING_POINT`` task takes longer than that of a |
---|
282 | ``RTEMS_NO_FLOATING_POINT`` task because of the relatively large amount of time |
---|
283 | required for the numeric coprocessor to save or restore its computational |
---|
284 | state. |
---|
285 | |
---|
286 | Since RTEMS was designed specifically for embedded military applications which |
---|
287 | are floating point intensive, the executive is optimized to avoid unnecessarily |
---|
288 | saving and restoring the state of the numeric coprocessor. The state of the |
---|
289 | numeric coprocessor is only saved when a ``RTEMS_FLOATING_POINT`` task is |
---|
290 | dispatched and that task was not the last task to utilize the coprocessor. In |
---|
291 | a system with only one ``RTEMS_FLOATING_POINT`` task, the state of the numeric |
---|
292 | coprocessor will never be saved or restored. |
---|
293 | |
---|
294 | Although the overhead imposed by ``RTEMS_FLOATING_POINT`` tasks is minimal, |
---|
295 | some applications may wish to completely avoid the overhead associated with |
---|
296 | ``RTEMS_FLOATING_POINT`` tasks and still utilize a numeric coprocessor. By |
---|
297 | preventing a task from being preempted while performing a sequence of floating |
---|
298 | point operations, a ``RTEMS_NO_FLOATING_POINT`` task can utilize the numeric |
---|
299 | coprocessor without incurring the overhead of a ``RTEMS_FLOATING_POINT`` |
---|
300 | context switch. This approach also avoids the allocation of a floating point |
---|
301 | context area. However, if this approach is taken by the application designer, |
---|
302 | NO tasks should be created as ``RTEMS_FLOATING_POINT`` tasks. Otherwise, the |
---|
303 | floating point context will not be correctly maintained because RTEMS assumes |
---|
304 | that the state of the numeric coprocessor will not be altered by |
---|
305 | ``RTEMS_NO_FLOATING_POINT`` tasks. |
---|
306 | |
---|
307 | If the supported processor type does not have hardware floating capabilities or |
---|
308 | a standard numeric coprocessor, RTEMS will not provide built-in support for |
---|
309 | hardware floating point on that processor. In this case, all tasks are |
---|
310 | considered ``RTEMS_NO_FLOATING_POINT`` whether created as |
---|
311 | ``RTEMS_FLOATING_POINT`` or ``RTEMS_NO_FLOATING_POINT`` tasks. A floating |
---|
312 | point emulation software library must be utilized for floating point |
---|
313 | operations. |
---|
314 | |
---|
315 | On some processors, it is possible to disable the floating point unit |
---|
316 | dynamically. If this capability is supported by the target processor, then |
---|
317 | RTEMS will utilize this capability to enable the floating point unit only for |
---|
318 | tasks which are created with the ``RTEMS_FLOATING_POINT`` attribute. The |
---|
319 | consequence of a ``RTEMS_NO_FLOATING_POINT`` task attempting to access the |
---|
320 | floating point unit is CPU dependent but will generally result in an exception |
---|
321 | condition. |
---|
322 | |
---|
323 | .. index:: task attributes, building |
---|
324 | |
---|
325 | Building a Task Attribute Set |
---|
326 | ----------------------------- |
---|
327 | |
---|
328 | In general, an attribute set is built by a bitwise OR of the desired |
---|
329 | components. The set of valid task attribute components is listed below: |
---|
330 | |
---|
331 | .. list-table:: |
---|
332 | :class: rtems-table |
---|
333 | |
---|
334 | * - ``RTEMS_NO_FLOATING_POINT`` |
---|
335 | - does not use coprocessor (default) |
---|
336 | * - ``RTEMS_FLOATING_POINT`` |
---|
337 | - uses numeric coprocessor |
---|
338 | * - ``RTEMS_LOCAL`` |
---|
339 | - local task (default) |
---|
340 | * - ``RTEMS_GLOBAL`` |
---|
341 | - global task |
---|
342 | |
---|
343 | Attribute values are specifically designed to be mutually exclusive, therefore |
---|
344 | bitwise OR and addition operations are equivalent as long as each attribute |
---|
345 | appears exactly once in the component list. A component listed as a default is |
---|
346 | not required to appear in the component list, although it is a good programming |
---|
347 | practice to specify default components. If all defaults are desired, then |
---|
348 | ``RTEMS_DEFAULT_ATTRIBUTES`` should be used. |
---|
349 | |
---|
350 | This example demonstrates the attribute_set parameter needed to create a local |
---|
351 | task which utilizes the numeric coprocessor. The attribute_set parameter could |
---|
352 | be ``RTEMS_FLOATING_POINT`` or ``RTEMS_LOCAL | RTEMS_FLOATING_POINT``. The |
---|
353 | attribute_set parameter can be set to ``RTEMS_FLOATING_POINT`` because |
---|
354 | ``RTEMS_LOCAL`` is the default for all created tasks. If the task were global |
---|
355 | and used the numeric coprocessor, then the attribute_set parameter would be |
---|
356 | ``RTEMS_GLOBAL | RTEMS_FLOATING_POINT``. |
---|
357 | |
---|
358 | .. index:: task mode, building |
---|
359 | |
---|
360 | Building a Mode and Mask |
---|
361 | ------------------------ |
---|
362 | |
---|
363 | In general, a mode and its corresponding mask is built by a bitwise OR of the |
---|
364 | desired components. The set of valid mode constants and each mode's |
---|
365 | corresponding mask constant is listed below: |
---|
366 | |
---|
367 | .. list-table:: |
---|
368 | :class: rtems-table |
---|
369 | |
---|
370 | * - ``RTEMS_PREEMPT`` |
---|
371 | - is masked by ``RTEMS_PREEMPT_MASK`` and enables preemption |
---|
372 | * - ``RTEMS_NO_PREEMPT`` |
---|
373 | - is masked by ``RTEMS_PREEMPT_MASK`` and disables preemption |
---|
374 | * - ``RTEMS_NO_TIMESLICE`` |
---|
375 | - is masked by ``RTEMS_TIMESLICE_MASK`` and disables timeslicing |
---|
376 | * - ``RTEMS_TIMESLICE`` |
---|
377 | - is masked by ``RTEMS_TIMESLICE_MASK`` and enables timeslicing |
---|
378 | * - ``RTEMS_ASR`` |
---|
379 | - is masked by ``RTEMS_ASR_MASK`` and enables ASR processing |
---|
380 | * - ``RTEMS_NO_ASR`` |
---|
381 | - is masked by ``RTEMS_ASR_MASK`` and disables ASR processing |
---|
382 | * - ``RTEMS_INTERRUPT_LEVEL(0)`` |
---|
383 | - is masked by ``RTEMS_INTERRUPT_MASK`` and enables all interrupts |
---|
384 | * - ``RTEMS_INTERRUPT_LEVEL(n)`` |
---|
385 | - is masked by ``RTEMS_INTERRUPT_MASK`` and sets interrupts level n |
---|
386 | |
---|
387 | Mode values are specifically designed to be mutually exclusive, therefore |
---|
388 | bitwise OR and addition operations are equivalent as long as each mode appears |
---|
389 | exactly once in the component list. A mode component listed as a default is |
---|
390 | not required to appear in the mode component list, although it is a good |
---|
391 | programming practice to specify default components. If all defaults are |
---|
392 | desired, the mode ``RTEMS_DEFAULT_MODES`` and the mask ``RTEMS_ALL_MODE_MASKS`` |
---|
393 | should be used. |
---|
394 | |
---|
395 | The following example demonstrates the mode and mask parameters used with the |
---|
396 | ``rtems_task_mode`` directive to place a task at interrupt level 3 and make it |
---|
397 | non-preemptible. The mode should be set to ``RTEMS_INTERRUPT_LEVEL(3) | |
---|
398 | RTEMS_NO_PREEMPT`` to indicate the desired preemption mode and interrupt level, |
---|
399 | while the mask parameter should be set to ``RTEMS_INTERRUPT_MASK | |
---|
400 | RTEMS_NO_PREEMPT_MASK`` to indicate that the calling task's interrupt level and |
---|
401 | preemption mode are being altered. |
---|
402 | |
---|
403 | Operations |
---|
404 | ========== |
---|
405 | |
---|
406 | Creating Tasks |
---|
407 | -------------- |
---|
408 | |
---|
409 | The ``rtems_task_create`` directive creates a task by allocating a task control |
---|
410 | block, assigning the task a user-specified name, allocating it a stack and |
---|
411 | floating point context area, setting a user-specified initial priority, setting |
---|
412 | a user-specified initial mode, and assigning it a task ID. Newly created tasks |
---|
413 | are initially placed in the dormant state. All RTEMS tasks execute in the most |
---|
414 | privileged mode of the processor. |
---|
415 | |
---|
416 | Obtaining Task IDs |
---|
417 | ------------------ |
---|
418 | |
---|
419 | When a task is created, RTEMS generates a unique task ID and assigns it to the |
---|
420 | created task until it is deleted. The task ID may be obtained by either of two |
---|
421 | methods. First, as the result of an invocation of the ``rtems_task_create`` |
---|
422 | directive, the task ID is stored in a user provided location. Second, the task |
---|
423 | ID may be obtained later using the ``rtems_task_ident`` directive. The task ID |
---|
424 | is used by other directives to manipulate this task. |
---|
425 | |
---|
426 | Starting and Restarting Tasks |
---|
427 | ----------------------------- |
---|
428 | |
---|
429 | The ``rtems_task_start`` directive is used to place a dormant task in the ready |
---|
430 | state. This enables the task to compete, based on its current priority, for |
---|
431 | the processor and other system resources. Any actions, such as suspension or |
---|
432 | change of priority, performed on a task prior to starting it are nullified when |
---|
433 | the task is started. |
---|
434 | |
---|
435 | With the ``rtems_task_start`` directive the user specifies the task's starting |
---|
436 | address and argument. The argument is used to communicate some startup |
---|
437 | information to the task. As part of this directive, RTEMS initializes the |
---|
438 | task's stack based upon the task's initial execution mode and start address. |
---|
439 | The starting argument is passed to the task in accordance with the target |
---|
440 | processor's calling convention. |
---|
441 | |
---|
442 | The ``rtems_task_restart`` directive restarts a task at its initial starting |
---|
443 | address with its original priority and execution mode, but with a possibly |
---|
444 | different argument. The new argument may be used to distinguish between the |
---|
445 | original invocation of the task and subsequent invocations. The task's stack |
---|
446 | and control block are modified to reflect their original creation values. |
---|
447 | Although references to resources that have been requested are cleared, |
---|
448 | resources allocated by the task are NOT automatically returned to RTEMS. A |
---|
449 | task cannot be restarted unless it has previously been started (i.e. dormant |
---|
450 | tasks cannot be restarted). All restarted tasks are placed in the ready state. |
---|
451 | |
---|
452 | Suspending and Resuming Tasks |
---|
453 | ----------------------------- |
---|
454 | |
---|
455 | The ``rtems_task_suspend`` directive is used to place either the caller or |
---|
456 | another task into a suspended state. The task remains suspended until a |
---|
457 | ``rtems_task_resume`` directive is issued. This implies that a task may be |
---|
458 | suspended as well as blocked waiting either to acquire a resource or for the |
---|
459 | expiration of a timer. |
---|
460 | |
---|
461 | The ``rtems_task_resume`` directive is used to remove another task from the |
---|
462 | suspended state. If the task is not also blocked, resuming it will place it in |
---|
463 | the ready state, allowing it to once again compete for the processor and |
---|
464 | resources. If the task was blocked as well as suspended, this directive clears |
---|
465 | the suspension and leaves the task in the blocked state. |
---|
466 | |
---|
467 | Suspending a task which is already suspended or resuming a task which is not |
---|
468 | suspended is considered an error. The ``rtems_task_is_suspended`` can be used |
---|
469 | to determine if a task is currently suspended. |
---|
470 | |
---|
471 | Delaying the Currently Executing Task |
---|
472 | ------------------------------------- |
---|
473 | |
---|
474 | The ``rtems_task_wake_after`` directive creates a sleep timer which allows a |
---|
475 | task to go to sleep for a specified interval. The task is blocked until the |
---|
476 | delay interval has elapsed, at which time the task is unblocked. A task |
---|
477 | calling the ``rtems_task_wake_after`` directive with a delay interval of |
---|
478 | ``RTEMS_YIELD_PROCESSOR`` ticks will yield the processor to any other ready |
---|
479 | task of equal or greater priority and remain ready to execute. |
---|
480 | |
---|
481 | The ``rtems_task_wake_when`` directive creates a sleep timer which allows a |
---|
482 | task to go to sleep until a specified date and time. The calling task is |
---|
483 | blocked until the specified date and time has occurred, at which time the task |
---|
484 | is unblocked. |
---|
485 | |
---|
486 | Changing Task Priority |
---|
487 | ---------------------- |
---|
488 | |
---|
489 | The ``rtems_task_set_priority`` directive is used to obtain or change the |
---|
490 | current priority of either the calling task or another task. If the new |
---|
491 | priority requested is ``RTEMS_CURRENT_PRIORITY`` or the task's actual priority, |
---|
492 | then the current priority will be returned and the task's priority will remain |
---|
493 | unchanged. If the task's priority is altered, then the task will be scheduled |
---|
494 | according to its new priority. |
---|
495 | |
---|
496 | The ``rtems_task_restart`` directive resets the priority of a task to its |
---|
497 | original value. |
---|
498 | |
---|
499 | Changing Task Mode |
---|
500 | ------------------ |
---|
501 | |
---|
502 | The ``rtems_task_mode`` directive is used to obtain or change the current |
---|
503 | execution mode of the calling task. A task's execution mode is used to enable |
---|
504 | preemption, timeslicing, ASR processing, and to set the task's interrupt level. |
---|
505 | |
---|
506 | The ``rtems_task_restart`` directive resets the mode of a task to its original |
---|
507 | value. |
---|
508 | |
---|
509 | Task Deletion |
---|
510 | ------------- |
---|
511 | |
---|
512 | RTEMS provides the ``rtems_task_delete`` directive to allow a task to delete |
---|
513 | itself or any other task. This directive removes all RTEMS references to the |
---|
514 | task, frees the task's control block, removes it from resource wait queues, and |
---|
515 | deallocates its stack as well as the optional floating point context. The |
---|
516 | task's name and ID become inactive at this time, and any subsequent references |
---|
517 | to either of them is invalid. In fact, RTEMS may reuse the task ID for another |
---|
518 | task which is created later in the application. |
---|
519 | |
---|
520 | Unexpired delay timers (i.e. those used by ``rtems_task_wake_after`` and |
---|
521 | ``rtems_task_wake_when``) and timeout timers associated with the task are |
---|
522 | automatically deleted, however, other resources dynamically allocated by the |
---|
523 | task are NOT automatically returned to RTEMS. Therefore, before a task is |
---|
524 | deleted, all of its dynamically allocated resources should be deallocated by |
---|
525 | the user. This may be accomplished by instructing the task to delete itself |
---|
526 | rather than directly deleting the task. Other tasks may instruct a task to |
---|
527 | delete itself by sending a "delete self" message, event, or signal, or by |
---|
528 | restarting the task with special arguments which instruct the task to delete |
---|
529 | itself. |
---|
530 | |
---|
531 | Setting Affinity to a Single Processor |
---|
532 | -------------------------------------- |
---|
533 | |
---|
534 | On some embedded applications targeting SMP systems, it may be beneficial to |
---|
535 | lock individual tasks to specific processors. In this way, one can designate a |
---|
536 | processor for I/O tasks, another for computation, etc.. The following |
---|
537 | illustrates the code sequence necessary to assign a task an affinity for |
---|
538 | processor with index ``processor_index``. |
---|
539 | |
---|
540 | .. code-block:: c |
---|
541 | |
---|
542 | #include <rtems.h> |
---|
543 | #include <assert.h> |
---|
544 | |
---|
545 | void pin_to_processor(rtems_id task_id, int processor_index) |
---|
546 | { |
---|
547 | rtems_status_code sc; |
---|
548 | cpu_set_t cpuset; |
---|
549 | CPU_ZERO(&cpuset); |
---|
550 | CPU_SET(processor_index, &cpuset); |
---|
551 | sc = rtems_task_set_affinity(task_id, sizeof(cpuset), &cpuset); |
---|
552 | assert(sc == RTEMS_SUCCESSFUL); |
---|
553 | } |
---|
554 | |
---|
555 | It is important to note that the ``cpuset`` is not validated until the |
---|
556 | ``rtems_task_set_affinity`` call is made. At that point, it is validated |
---|
557 | against the current system configuration. |
---|
558 | |
---|
559 | .. index:: rtems_task_get_note |
---|
560 | .. index:: rtems_task_set_note |
---|
561 | |
---|
562 | Transition Advice for Obsolete Notepads |
---|
563 | --------------------------------------- |
---|
564 | |
---|
565 | Task notepads and the associated directives :ref:`rtems_task_get_note` and |
---|
566 | :ref:`rtems_task_set_note` were removed in RTEMS 5.1. These were never |
---|
567 | thread-safe to access and subject to conflicting use of the notepad index by |
---|
568 | libraries which were designed independently. |
---|
569 | |
---|
570 | It is recommended that applications be modified to use services which are |
---|
571 | thread safe and not subject to issues with multiple applications conflicting |
---|
572 | over the key (e.g. notepad index) selection. For most applications, POSIX Keys |
---|
573 | should be used. These are available in all RTEMS build configurations. It is |
---|
574 | also possible that thread-local storage (TLS) is an option for some use cases. |
---|
575 | |
---|
576 | .. index:: rtems_task_variable_add |
---|
577 | .. index:: rtems_task_variable_get |
---|
578 | .. index:: rtems_task_variable_delete |
---|
579 | |
---|
580 | Transition Advice for Obsolete Task Variables |
---|
581 | --------------------------------------------- |
---|
582 | |
---|
583 | Task notepads and the associated directives :ref:`rtems_task_variable_add`, |
---|
584 | :ref:`rtems_task_variable_get` and :ref:`rtems_task_variable_delete` were |
---|
585 | removed in RTEMS 5.1. Task variables must be replaced by POSIX Keys or |
---|
586 | thread-local storage (TLS). POSIX Keys are available in all configurations and |
---|
587 | support value destructors. For the TLS support consult the :title:`RTEMS CPU |
---|
588 | Architecture Supplement`. |
---|
589 | |
---|
590 | Directives |
---|
591 | ========== |
---|
592 | |
---|
593 | This section details the task manager's directives. A subsection is dedicated |
---|
594 | to each of this manager's directives and describes the calling sequence, |
---|
595 | related constants, usage, and status codes. |
---|
596 | |
---|
597 | .. raw:: latex |
---|
598 | |
---|
599 | \clearpage |
---|
600 | |
---|
601 | .. _rtems_task_create: |
---|
602 | .. index:: create a task |
---|
603 | .. index:: rtems_task_create |
---|
604 | |
---|
605 | TASK_CREATE - Create a task |
---|
606 | --------------------------- |
---|
607 | |
---|
608 | CALLING SEQUENCE: |
---|
609 | .. code-block:: c |
---|
610 | |
---|
611 | rtems_status_code rtems_task_create( |
---|
612 | rtems_name name, |
---|
613 | rtems_task_priority initial_priority, |
---|
614 | size_t stack_size, |
---|
615 | rtems_mode initial_modes, |
---|
616 | rtems_attribute attribute_set, |
---|
617 | rtems_id *id |
---|
618 | ); |
---|
619 | |
---|
620 | DIRECTIVE STATUS CODES: |
---|
621 | .. list-table:: |
---|
622 | :class: rtems-table |
---|
623 | |
---|
624 | * - ``RTEMS_SUCCESSFUL`` |
---|
625 | - task created successfully |
---|
626 | * - ``RTEMS_INVALID_ADDRESS`` |
---|
627 | - ``id`` is NULL |
---|
628 | * - ``RTEMS_INVALID_NAME`` |
---|
629 | - invalid task name |
---|
630 | * - ``RTEMS_INVALID_PRIORITY`` |
---|
631 | - invalid task priority |
---|
632 | * - ``RTEMS_MP_NOT_CONFIGURED`` |
---|
633 | - multiprocessing not configured |
---|
634 | * - ``RTEMS_TOO_MANY`` |
---|
635 | - too many tasks created |
---|
636 | * - ``RTEMS_UNSATISFIED`` |
---|
637 | - not enough memory for stack/FP context |
---|
638 | * - ``RTEMS_TOO_MANY`` |
---|
639 | - too many global objects |
---|
640 | |
---|
641 | DESCRIPTION: |
---|
642 | This directive creates a task which resides on the local node. It |
---|
643 | allocates and initializes a TCB, a stack, and an optional floating point |
---|
644 | context area. The mode parameter contains values which sets the task's |
---|
645 | initial execution mode. The ``RTEMS_FLOATING_POINT`` attribute should be |
---|
646 | specified if the created task is to use a numeric coprocessor. For |
---|
647 | performance reasons, it is recommended that tasks not using the numeric |
---|
648 | coprocessor should specify the ``RTEMS_NO_FLOATING_POINT`` attribute. If |
---|
649 | the ``RTEMS_GLOBAL`` attribute is specified, the task can be accessed from |
---|
650 | remote nodes. The task id, returned in id, is used in other task related |
---|
651 | directives to access the task. When created, a task is placed in the |
---|
652 | dormant state and can only be made ready to execute using the directive |
---|
653 | ``rtems_task_start``. |
---|
654 | |
---|
655 | NOTES: |
---|
656 | This directive may cause the calling task to be preempted. |
---|
657 | |
---|
658 | The scheduler of the new task is the scheduler of the executing task at |
---|
659 | some point during the task creation. The specified task priority must be |
---|
660 | valid for the selected scheduler. |
---|
661 | |
---|
662 | The task processor affinity is initialized to the set of online processors. |
---|
663 | |
---|
664 | If the requested stack size is less than the configured minimum stack size, |
---|
665 | then RTEMS will use the configured minimum as the stack size for this task. |
---|
666 | In addition to being able to specify the task stack size as a integer, |
---|
667 | there are two constants which may be specified: |
---|
668 | |
---|
669 | ``RTEMS_MINIMUM_STACK_SIZE`` |
---|
670 | The minimum stack size *RECOMMENDED* for use on this processor. This |
---|
671 | value is selected by the RTEMS developers conservatively to minimize the |
---|
672 | risk of blown stacks for most user applications. Using this constant |
---|
673 | when specifying the task stack size, indicates that the stack size will |
---|
674 | be at least ``RTEMS_MINIMUM_STACK_SIZE`` bytes in size. If the user |
---|
675 | configured minimum stack size is larger than the recommended minimum, |
---|
676 | then it will be used. |
---|
677 | |
---|
678 | ``RTEMS_CONFIGURED_MINIMUM_STACK_SIZE`` |
---|
679 | Indicates this task is to be created with a stack size of the minimum |
---|
680 | stack size that was configured by the application. If not explicitly |
---|
681 | configured by the application, the default configured minimum stack size |
---|
682 | is the processor dependent value ``RTEMS_MINIMUM_STACK_SIZE``. Since |
---|
683 | this uses the configured minimum stack size value, you may get a stack |
---|
684 | size that is smaller or larger than the recommended minimum. This can be |
---|
685 | used to provide large stacks for all tasks on complex applications or |
---|
686 | small stacks on applications that are trying to conserve memory. |
---|
687 | |
---|
688 | Application developers should consider the stack usage of the device |
---|
689 | drivers when calculating the stack size required for tasks which utilize |
---|
690 | the driver. |
---|
691 | |
---|
692 | The following task attribute constants are defined by RTEMS: |
---|
693 | |
---|
694 | .. list-table:: |
---|
695 | :class: rtems-table |
---|
696 | |
---|
697 | * - ``RTEMS_NO_FLOATING_POINT`` |
---|
698 | - does not use coprocessor (default) |
---|
699 | * - ``RTEMS_FLOATING_POINT`` |
---|
700 | - uses numeric coprocessor |
---|
701 | * - ``RTEMS_LOCAL`` |
---|
702 | - local task (default) |
---|
703 | * - ``RTEMS_GLOBAL`` |
---|
704 | - global task |
---|
705 | |
---|
706 | The following task mode constants are defined by RTEMS: |
---|
707 | |
---|
708 | .. list-table:: |
---|
709 | :class: rtems-table |
---|
710 | |
---|
711 | * - ``RTEMS_PREEMPT`` |
---|
712 | - enable preemption (default) |
---|
713 | * - ``RTEMS_NO_PREEMPT`` |
---|
714 | - disable preemption |
---|
715 | * - ``RTEMS_NO_TIMESLICE`` |
---|
716 | - disable timeslicing (default) |
---|
717 | * - ``RTEMS_TIMESLICE`` |
---|
718 | - enable timeslicing |
---|
719 | * - ``RTEMS_ASR`` |
---|
720 | - enable ASR processing (default) |
---|
721 | * - ``RTEMS_NO_ASR`` |
---|
722 | - disable ASR processing |
---|
723 | * - ``RTEMS_INTERRUPT_LEVEL(0)`` |
---|
724 | - enable all interrupts (default) |
---|
725 | * - ``RTEMS_INTERRUPT_LEVEL(n)`` |
---|
726 | - execute at interrupt level ``n`` |
---|
727 | |
---|
728 | The interrupt level portion of the task execution mode supports a maximum |
---|
729 | of 256 interrupt levels. These levels are mapped onto the interrupt |
---|
730 | levels actually supported by the target processor in a processor dependent |
---|
731 | fashion. |
---|
732 | |
---|
733 | Tasks should not be made global unless remote tasks must interact with |
---|
734 | them. This avoids the system overhead incurred by the creation of a |
---|
735 | global task. When a global task is created, the task's name and id must |
---|
736 | be transmitted to every node in the system for insertion in the local copy |
---|
737 | of the global object table. |
---|
738 | |
---|
739 | The total number of global objects, including tasks, is limited by the |
---|
740 | maximum_global_objects field in the Configuration Table. |
---|
741 | |
---|
742 | .. raw:: latex |
---|
743 | |
---|
744 | \clearpage |
---|
745 | |
---|
746 | .. _rtems_task_ident: |
---|
747 | .. index:: get ID of a task |
---|
748 | .. index:: rtems_task_ident |
---|
749 | |
---|
750 | TASK_IDENT - Get ID of a task |
---|
751 | ----------------------------- |
---|
752 | |
---|
753 | CALLING SEQUENCE: |
---|
754 | .. code-block:: c |
---|
755 | |
---|
756 | rtems_status_code rtems_task_ident( |
---|
757 | rtems_name name, |
---|
758 | uint32_t node, |
---|
759 | rtems_id *id |
---|
760 | ); |
---|
761 | |
---|
762 | DIRECTIVE STATUS CODES: |
---|
763 | .. list-table:: |
---|
764 | :class: rtems-table |
---|
765 | |
---|
766 | * - ``RTEMS_SUCCESSFUL`` |
---|
767 | - task identified successfully |
---|
768 | * - ``RTEMS_INVALID_ADDRESS`` |
---|
769 | - ``id`` is NULL |
---|
770 | * - ``RTEMS_INVALID_NAME`` |
---|
771 | - invalid task name |
---|
772 | * - ``RTEMS_INVALID_NODE`` |
---|
773 | - invalid node id |
---|
774 | |
---|
775 | DESCRIPTION: |
---|
776 | This directive obtains the task id associated with the task name specified |
---|
777 | in name. A task may obtain its own id by specifying ``RTEMS_SELF`` or its |
---|
778 | own task name in name. If the task name is not unique, then the task id |
---|
779 | returned will match one of the tasks with that name. However, this task id |
---|
780 | is not guaranteed to correspond to the desired task. The task id, returned |
---|
781 | in id, is used in other task related directives to access the task. |
---|
782 | |
---|
783 | NOTES: |
---|
784 | This directive will not cause the running task to be preempted. |
---|
785 | |
---|
786 | If node is ``RTEMS_SEARCH_ALL_NODES``, all nodes are searched with the |
---|
787 | local node being searched first. All other nodes are searched with the |
---|
788 | lowest numbered node searched first. |
---|
789 | |
---|
790 | If node is a valid node number which does not represent the local node, |
---|
791 | then only the tasks exported by the designated node are searched. |
---|
792 | |
---|
793 | This directive does not generate activity on remote nodes. It accesses |
---|
794 | only the local copy of the global object table. |
---|
795 | |
---|
796 | .. raw:: latex |
---|
797 | |
---|
798 | \clearpage |
---|
799 | |
---|
800 | .. _rtems_task_self: |
---|
801 | .. index:: obtain ID of caller |
---|
802 | .. index:: rtems_task_self |
---|
803 | |
---|
804 | TASK_SELF - Obtain ID of caller |
---|
805 | ------------------------------- |
---|
806 | |
---|
807 | CALLING SEQUENCE: |
---|
808 | .. code-block:: c |
---|
809 | |
---|
810 | rtems_id rtems_task_self(void); |
---|
811 | |
---|
812 | DIRECTIVE STATUS CODES: |
---|
813 | Returns the object Id of the calling task. |
---|
814 | |
---|
815 | DESCRIPTION: |
---|
816 | This directive returns the Id of the calling task. |
---|
817 | |
---|
818 | NOTES: |
---|
819 | If called from an interrupt service routine, this directive will return the |
---|
820 | Id of the interrupted task. |
---|
821 | |
---|
822 | .. raw:: latex |
---|
823 | |
---|
824 | \clearpage |
---|
825 | |
---|
826 | .. _rtems_task_start: |
---|
827 | .. index:: starting a task |
---|
828 | .. index:: rtems_task_start |
---|
829 | |
---|
830 | TASK_START - Start a task |
---|
831 | ------------------------- |
---|
832 | |
---|
833 | CALLING SEQUENCE: |
---|
834 | .. code-block:: c |
---|
835 | |
---|
836 | rtems_status_code rtems_task_start( |
---|
837 | rtems_id id, |
---|
838 | rtems_task_entry entry_point, |
---|
839 | rtems_task_argument argument |
---|
840 | ); |
---|
841 | |
---|
842 | DIRECTIVE STATUS CODES: |
---|
843 | .. list-table:: |
---|
844 | :class: rtems-table |
---|
845 | |
---|
846 | * - ``RTEMS_SUCCESSFUL`` |
---|
847 | - ask started successfully |
---|
848 | * - ``RTEMS_INVALID_ADDRESS`` |
---|
849 | - invalid task entry point |
---|
850 | * - ``RTEMS_INVALID_ID`` |
---|
851 | - invalid task id |
---|
852 | * - ``RTEMS_INCORRECT_STATE`` |
---|
853 | - task not in the dormant state |
---|
854 | * - ``RTEMS_ILLEGAL_ON_REMOTE_OBJECT`` |
---|
855 | - cannot start remote task |
---|
856 | |
---|
857 | DESCRIPTION: |
---|
858 | This directive readies the task, specified by ``id``, for execution based |
---|
859 | on the priority and execution mode specified when the task was created. |
---|
860 | The starting address of the task is given in ``entry_point``. The task's |
---|
861 | starting argument is contained in argument. This argument can be a single |
---|
862 | value or used as an index into an array of parameter blocks. The type of |
---|
863 | this numeric argument is an unsigned integer type with the property that |
---|
864 | any valid pointer to void can be converted to this type and then converted |
---|
865 | back to a pointer to void. The result will compare equal to the original |
---|
866 | pointer. |
---|
867 | |
---|
868 | NOTES: |
---|
869 | The calling task will be preempted if its preemption mode is enabled and |
---|
870 | the task being started has a higher priority. |
---|
871 | |
---|
872 | Any actions performed on a dormant task such as suspension or change of |
---|
873 | priority are nullified when the task is initiated via the |
---|
874 | ``rtems_task_start`` directive. |
---|
875 | |
---|
876 | .. raw:: latex |
---|
877 | |
---|
878 | \clearpage |
---|
879 | |
---|
880 | .. _rtems_task_restart: |
---|
881 | .. index:: restarting a task |
---|
882 | .. index:: rtems_task_restart |
---|
883 | |
---|
884 | TASK_RESTART - Restart a task |
---|
885 | ----------------------------- |
---|
886 | |
---|
887 | CALLING SEQUENCE: |
---|
888 | .. code-block:: c |
---|
889 | |
---|
890 | rtems_status_code rtems_task_restart( |
---|
891 | rtems_id id, |
---|
892 | rtems_task_argument argument |
---|
893 | ); |
---|
894 | |
---|
895 | DIRECTIVE STATUS CODES: |
---|
896 | .. list-table:: |
---|
897 | :class: rtems-table |
---|
898 | |
---|
899 | * - ``RTEMS_SUCCESSFUL`` |
---|
900 | - task restarted successfully |
---|
901 | * - ``RTEMS_INVALID_ID`` |
---|
902 | - task id invalid |
---|
903 | * - ``RTEMS_INCORRECT_STATE`` |
---|
904 | - task never started |
---|
905 | * - ``RTEMS_ILLEGAL_ON_REMOTE_OBJECT`` |
---|
906 | - cannot restart remote task |
---|
907 | |
---|
908 | DESCRIPTION: |
---|
909 | This directive resets the task specified by id to begin execution at its |
---|
910 | original starting address. The task's priority and execution mode are set |
---|
911 | to the original creation values. If the task is currently blocked, RTEMS |
---|
912 | automatically makes the task ready. A task can be restarted from any |
---|
913 | state, except the dormant state. |
---|
914 | |
---|
915 | The task's starting argument is contained in argument. This argument can |
---|
916 | be a single value or an index into an array of parameter blocks. The type |
---|
917 | of this numeric argument is an unsigned integer type with the property that |
---|
918 | any valid pointer to void can be converted to this type and then converted |
---|
919 | back to a pointer to void. The result will compare equal to the original |
---|
920 | pointer. This new argument may be used to distinguish between the initial |
---|
921 | ``rtems_task_start`` of the task and any ensuing calls to |
---|
922 | ``rtems_task_restart`` of the task. This can be beneficial in deleting a |
---|
923 | task. Instead of deleting a task using the ``rtems_task_delete`` |
---|
924 | directive, a task can delete another task by restarting that task, and |
---|
925 | allowing that task to release resources back to RTEMS and then delete |
---|
926 | itself. |
---|
927 | |
---|
928 | NOTES: |
---|
929 | If id is ``RTEMS_SELF``, the calling task will be restarted and will not |
---|
930 | return from this directive. |
---|
931 | |
---|
932 | The calling task will be preempted if its preemption mode is enabled and |
---|
933 | the task being restarted has a higher priority. |
---|
934 | |
---|
935 | The task must reside on the local node, even if the task was created with |
---|
936 | the ``RTEMS_GLOBAL`` option. |
---|
937 | |
---|
938 | .. raw:: latex |
---|
939 | |
---|
940 | \clearpage |
---|
941 | |
---|
942 | .. _rtems_task_delete: |
---|
943 | .. index:: deleting a task |
---|
944 | .. index:: rtems_task_delete |
---|
945 | |
---|
946 | TASK_DELETE - Delete a task |
---|
947 | --------------------------- |
---|
948 | |
---|
949 | CALLING SEQUENCE: |
---|
950 | .. code-block:: c |
---|
951 | |
---|
952 | rtems_status_code rtems_task_delete( |
---|
953 | rtems_id id |
---|
954 | ); |
---|
955 | |
---|
956 | DIRECTIVE STATUS CODES: |
---|
957 | .. list-table:: |
---|
958 | :class: rtems-table |
---|
959 | |
---|
960 | * - ``RTEMS_SUCCESSFUL`` |
---|
961 | - task deleted successfully |
---|
962 | * - ``RTEMS_INVALID_ID`` |
---|
963 | - task id invalid |
---|
964 | * - ``RTEMS_ILLEGAL_ON_REMOTE_OBJECT`` |
---|
965 | - cannot restart remote task |
---|
966 | |
---|
967 | DESCRIPTION: |
---|
968 | This directive deletes a task, either the calling task or another task, as |
---|
969 | specified by id. RTEMS stops the execution of the task and reclaims the |
---|
970 | stack memory, any allocated delay or timeout timers, the TCB, and, if the |
---|
971 | task is ``RTEMS_FLOATING_POINT``, its floating point context area. RTEMS |
---|
972 | does not reclaim the following resources: region segments, partition |
---|
973 | buffers, semaphores, timers, or rate monotonic periods. |
---|
974 | |
---|
975 | NOTES: |
---|
976 | A task is responsible for releasing its resources back to RTEMS before |
---|
977 | deletion. To insure proper deallocation of resources, a task should not be |
---|
978 | deleted unless it is unable to execute or does not hold any RTEMS |
---|
979 | resources. If a task holds RTEMS resources, the task should be allowed to |
---|
980 | deallocate its resources before deletion. A task can be directed to |
---|
981 | release its resources and delete itself by restarting it with a special |
---|
982 | argument or by sending it a message, an event, or a signal. |
---|
983 | |
---|
984 | Deletion of the current task (``RTEMS_SELF``) will force RTEMS to select |
---|
985 | another task to execute. |
---|
986 | |
---|
987 | When a global task is deleted, the task id must be transmitted to every |
---|
988 | node in the system for deletion from the local copy of the global object |
---|
989 | table. |
---|
990 | |
---|
991 | The task must reside on the local node, even if the task was created with |
---|
992 | the ``RTEMS_GLOBAL`` option. |
---|
993 | |
---|
994 | .. raw:: latex |
---|
995 | |
---|
996 | \clearpage |
---|
997 | |
---|
998 | .. _rtems_task_suspend: |
---|
999 | .. index:: suspending a task |
---|
1000 | .. index:: rtems_task_suspend |
---|
1001 | |
---|
1002 | TASK_SUSPEND - Suspend a task |
---|
1003 | ----------------------------- |
---|
1004 | |
---|
1005 | CALLING SEQUENCE: |
---|
1006 | .. code-block:: c |
---|
1007 | |
---|
1008 | rtems_status_code rtems_task_suspend( |
---|
1009 | rtems_id id |
---|
1010 | ); |
---|
1011 | |
---|
1012 | DIRECTIVE STATUS CODES: |
---|
1013 | .. list-table:: |
---|
1014 | :class: rtems-table |
---|
1015 | |
---|
1016 | * - ``RTEMS_SUCCESSFUL`` |
---|
1017 | - task suspended successfully |
---|
1018 | * - ``RTEMS_INVALID_ID`` |
---|
1019 | - task id invalid |
---|
1020 | * - ``RTEMS_ALREADY_SUSPENDED`` |
---|
1021 | - task already suspended |
---|
1022 | |
---|
1023 | DESCRIPTION: |
---|
1024 | This directive suspends the task specified by id from further execution by |
---|
1025 | placing it in the suspended state. This state is additive to any other |
---|
1026 | blocked state that the task may already be in. The task will not execute |
---|
1027 | again until another task issues the ``rtems_task_resume`` directive for |
---|
1028 | this task and any blocked state has been removed. |
---|
1029 | |
---|
1030 | NOTES: |
---|
1031 | The requesting task can suspend itself by specifying ``RTEMS_SELF`` as id. |
---|
1032 | In this case, the task will be suspended and a successful return code will |
---|
1033 | be returned when the task is resumed. |
---|
1034 | |
---|
1035 | Suspending a global task which does not reside on the local node will |
---|
1036 | generate a request to the remote node to suspend the specified task. |
---|
1037 | |
---|
1038 | If the task specified by id is already suspended, then the |
---|
1039 | ``RTEMS_ALREADY_SUSPENDED`` status code is returned. |
---|
1040 | |
---|
1041 | .. raw:: latex |
---|
1042 | |
---|
1043 | \clearpage |
---|
1044 | |
---|
1045 | .. _rtems_task_resume: |
---|
1046 | .. index:: resuming a task |
---|
1047 | .. index:: rtems_task_resume |
---|
1048 | |
---|
1049 | TASK_RESUME - Resume a task |
---|
1050 | --------------------------- |
---|
1051 | |
---|
1052 | CALLING SEQUENCE: |
---|
1053 | .. code-block:: c |
---|
1054 | |
---|
1055 | rtems_status_code rtems_task_resume( |
---|
1056 | rtems_id id |
---|
1057 | ); |
---|
1058 | |
---|
1059 | DIRECTIVE STATUS CODES: |
---|
1060 | .. list-table:: |
---|
1061 | :class: rtems-table |
---|
1062 | |
---|
1063 | * - ``RTEMS_SUCCESSFUL`` |
---|
1064 | - task resumed successfully |
---|
1065 | * - ``RTEMS_INVALID_ID`` |
---|
1066 | - task id invalid |
---|
1067 | * - ``RTEMS_INCORRECT_STATE`` |
---|
1068 | - task not suspended |
---|
1069 | |
---|
1070 | DESCRIPTION: |
---|
1071 | This directive removes the task specified by id from the suspended state. |
---|
1072 | If the task is in the ready state after the suspension is removed, then it |
---|
1073 | will be scheduled to run. If the task is still in a blocked state after |
---|
1074 | the suspension is removed, then it will remain in that blocked state. |
---|
1075 | |
---|
1076 | NOTES: |
---|
1077 | The running task may be preempted if its preemption mode is enabled and the |
---|
1078 | local task being resumed has a higher priority. |
---|
1079 | |
---|
1080 | Resuming a global task which does not reside on the local node will |
---|
1081 | generate a request to the remote node to resume the specified task. |
---|
1082 | |
---|
1083 | If the task specified by id is not suspended, then the |
---|
1084 | ``RTEMS_INCORRECT_STATE`` status code is returned. |
---|
1085 | |
---|
1086 | .. raw:: latex |
---|
1087 | |
---|
1088 | \clearpage |
---|
1089 | |
---|
1090 | .. _rtems_task_is_suspended: |
---|
1091 | .. index:: is task suspended |
---|
1092 | .. index:: rtems_task_is_suspended |
---|
1093 | |
---|
1094 | TASK_IS_SUSPENDED - Determine if a task is Suspended |
---|
1095 | ---------------------------------------------------- |
---|
1096 | |
---|
1097 | CALLING SEQUENCE: |
---|
1098 | .. code-block:: c |
---|
1099 | |
---|
1100 | rtems_status_code rtems_task_is_suspended( |
---|
1101 | rtems_id id |
---|
1102 | ); |
---|
1103 | |
---|
1104 | DIRECTIVE STATUS CODES: |
---|
1105 | .. list-table:: |
---|
1106 | :class: rtems-table |
---|
1107 | |
---|
1108 | * - ``RTEMS_SUCCESSFUL`` |
---|
1109 | - task is NOT suspended |
---|
1110 | * - ``RTEMS_ALREADY_SUSPENDED`` |
---|
1111 | - task is currently suspended |
---|
1112 | * - ``RTEMS_INVALID_ID`` |
---|
1113 | - task id invalid |
---|
1114 | * - ``RTEMS_ILLEGAL_ON_REMOTE_OBJECT`` |
---|
1115 | - not supported on remote tasks |
---|
1116 | |
---|
1117 | DESCRIPTION: |
---|
1118 | This directive returns a status code indicating whether or not the |
---|
1119 | specified task is currently suspended. |
---|
1120 | |
---|
1121 | NOTES: |
---|
1122 | This operation is not currently supported on remote tasks. |
---|
1123 | |
---|
1124 | .. raw:: latex |
---|
1125 | |
---|
1126 | \clearpage |
---|
1127 | |
---|
1128 | .. _rtems_task_set_priority: |
---|
1129 | .. index:: rtems_task_set_priority |
---|
1130 | .. index:: current task priority |
---|
1131 | .. index:: set task priority |
---|
1132 | .. index:: get task priority |
---|
1133 | .. index:: obtain task priority |
---|
1134 | |
---|
1135 | TASK_SET_PRIORITY - Set task priority |
---|
1136 | ------------------------------------- |
---|
1137 | |
---|
1138 | CALLING SEQUENCE: |
---|
1139 | .. code-block:: c |
---|
1140 | |
---|
1141 | rtems_status_code rtems_task_set_priority( |
---|
1142 | rtems_id id, |
---|
1143 | rtems_task_priority new_priority, |
---|
1144 | rtems_task_priority *old_priority |
---|
1145 | ); |
---|
1146 | |
---|
1147 | DIRECTIVE STATUS CODES: |
---|
1148 | .. list-table:: |
---|
1149 | :class: rtems-table |
---|
1150 | |
---|
1151 | * - ``RTEMS_SUCCESSFUL`` |
---|
1152 | - task priority set successfully |
---|
1153 | * - ``RTEMS_INVALID_ID`` |
---|
1154 | - invalid task id |
---|
1155 | * - ``RTEMS_INVALID_ADDRESS`` |
---|
1156 | - invalid return argument pointer |
---|
1157 | * - ``RTEMS_INVALID_PRIORITY`` |
---|
1158 | - invalid task priority |
---|
1159 | |
---|
1160 | DESCRIPTION: |
---|
1161 | This directive manipulates the priority of the task specified by id. An id |
---|
1162 | of ``RTEMS_SELF`` is used to indicate the calling task. When new_priority |
---|
1163 | is not equal to ``RTEMS_CURRENT_PRIORITY``, the specified task's previous |
---|
1164 | priority is returned in old_priority. When new_priority is |
---|
1165 | ``RTEMS_CURRENT_PRIORITY``, the specified task's current priority is |
---|
1166 | returned in old_priority. Valid priorities range from a high of 1 to a low |
---|
1167 | of 255. |
---|
1168 | |
---|
1169 | NOTES: |
---|
1170 | The calling task may be preempted if its preemption mode is enabled and it |
---|
1171 | lowers its own priority or raises another task's priority. |
---|
1172 | |
---|
1173 | In case the new priority equals the current priority of the task, then |
---|
1174 | nothing happens. |
---|
1175 | |
---|
1176 | Setting the priority of a global task which does not reside on the local |
---|
1177 | node will generate a request to the remote node to change the priority of |
---|
1178 | the specified task. |
---|
1179 | |
---|
1180 | If the task specified by id is currently holding any binary semaphores |
---|
1181 | which use the priority inheritance algorithm, then the task's priority |
---|
1182 | cannot be lowered immediately. If the task's priority were lowered |
---|
1183 | immediately, then priority inversion results. The requested lowering of |
---|
1184 | the task's priority will occur when the task has released all priority |
---|
1185 | inheritance binary semaphores. The task's priority can be increased |
---|
1186 | regardless of the task's use of priority inheritance binary semaphores. |
---|
1187 | |
---|
1188 | .. raw:: latex |
---|
1189 | |
---|
1190 | \clearpage |
---|
1191 | |
---|
1192 | .. _rtems_task_get_priority: |
---|
1193 | .. index:: rtems_task_get_priority |
---|
1194 | .. index:: current task priority |
---|
1195 | .. index:: get task priority |
---|
1196 | .. index:: obtain task priority |
---|
1197 | |
---|
1198 | TASK_GET_PRIORITY - Get task priority |
---|
1199 | ------------------------------------- |
---|
1200 | |
---|
1201 | CALLING SEQUENCE: |
---|
1202 | .. code-block:: c |
---|
1203 | |
---|
1204 | rtems_status_code rtems_task_get_priority( |
---|
1205 | rtems_id task_id, |
---|
1206 | rtems_id scheduler_id, |
---|
1207 | rtems_task_priority *priority |
---|
1208 | ); |
---|
1209 | |
---|
1210 | DIRECTIVE STATUS CODES: |
---|
1211 | .. list-table:: |
---|
1212 | :class: rtems-table |
---|
1213 | |
---|
1214 | * - ``RTEMS_SUCCESSFUL`` |
---|
1215 | - Successful operation. |
---|
1216 | * - ``RTEMS_ILLEGAL_ON_REMOTE_OBJECT`` |
---|
1217 | - Directive is illegal on remote tasks. |
---|
1218 | * - ``RTEMS_INVALID_ADDRESS`` |
---|
1219 | - The priority parameter is NULL. |
---|
1220 | * - ``RTEMS_INVALID_ID`` |
---|
1221 | - Invalid task or scheduler identifier. |
---|
1222 | * - ``RTEMS_NOT_DEFINED`` |
---|
1223 | - The task has no priority within the specified scheduler instance. |
---|
1224 | This error is only possible in SMP configurations. |
---|
1225 | |
---|
1226 | DESCRIPTION: |
---|
1227 | This directive returns the current priority of the task specified by |
---|
1228 | :c:data:`task_id` with respect to the scheduler instance specified by |
---|
1229 | :c:data:`scheduler_id`. A task id of :c:macro:`RTEMS_SELF` is used to |
---|
1230 | indicate the calling task. |
---|
1231 | |
---|
1232 | NOTES: |
---|
1233 | The current priority reflects temporary priority adjustments due to locking |
---|
1234 | protocols, the rate-monotonic period objects on some schedulers and other |
---|
1235 | mechanisms. |
---|
1236 | |
---|
1237 | .. raw:: latex |
---|
1238 | |
---|
1239 | \clearpage |
---|
1240 | |
---|
1241 | .. _rtems_task_mode: |
---|
1242 | .. index:: current task mode |
---|
1243 | .. index:: set task mode |
---|
1244 | .. index:: get task mode |
---|
1245 | .. index:: set task preemption mode |
---|
1246 | .. index:: get task preemption mode |
---|
1247 | .. index:: obtain task mode |
---|
1248 | .. index:: rtems_task_mode |
---|
1249 | |
---|
1250 | TASK_MODE - Change the current task mode |
---|
1251 | ---------------------------------------- |
---|
1252 | |
---|
1253 | CALLING SEQUENCE: |
---|
1254 | .. code-block:: c |
---|
1255 | |
---|
1256 | rtems_status_code rtems_task_mode( |
---|
1257 | rtems_mode mode_set, |
---|
1258 | rtems_mode mask, |
---|
1259 | rtems_mode *previous_mode_set |
---|
1260 | ); |
---|
1261 | |
---|
1262 | DIRECTIVE STATUS CODES: |
---|
1263 | .. list-table:: |
---|
1264 | :class: rtems-table |
---|
1265 | |
---|
1266 | * - ``RTEMS_SUCCESSFUL`` |
---|
1267 | - task mode set successfully |
---|
1268 | * - ``RTEMS_INVALID_ADDRESS`` |
---|
1269 | - ``previous_mode_set`` is NULL |
---|
1270 | |
---|
1271 | DESCRIPTION: |
---|
1272 | This directive manipulates the execution mode of the calling task. A |
---|
1273 | task's execution mode enables and disables preemption, timeslicing, |
---|
1274 | asynchronous signal processing, as well as specifying the current interrupt |
---|
1275 | level. To modify an execution mode, the mode class(es) to be changed must |
---|
1276 | be specified in the mask parameter and the desired mode(s) must be |
---|
1277 | specified in the mode parameter. |
---|
1278 | |
---|
1279 | NOTES: |
---|
1280 | The calling task will be preempted if it enables preemption and a higher |
---|
1281 | priority task is ready to run. |
---|
1282 | |
---|
1283 | Enabling timeslicing has no effect if preemption is disabled. For a task |
---|
1284 | to be timesliced, that task must have both preemption and timeslicing |
---|
1285 | enabled. |
---|
1286 | |
---|
1287 | A task can obtain its current execution mode, without modifying it, by |
---|
1288 | calling this directive with a mask value of ``RTEMS_CURRENT_MODE``. |
---|
1289 | |
---|
1290 | To temporarily disable the processing of a valid ASR, a task should call |
---|
1291 | this directive with the ``RTEMS_NO_ASR`` indicator specified in mode. |
---|
1292 | |
---|
1293 | The set of task mode constants and each mode's corresponding mask constant |
---|
1294 | is provided in the following table: |
---|
1295 | |
---|
1296 | .. list-table:: |
---|
1297 | :class: rtems-table |
---|
1298 | |
---|
1299 | * - ``RTEMS_PREEMPT`` |
---|
1300 | - is masked by ``RTEMS_PREEMPT_MASK`` and enables preemption |
---|
1301 | * - ``RTEMS_NO_PREEMPT`` |
---|
1302 | - is masked by ``RTEMS_PREEMPT_MASK`` and disables preemption |
---|
1303 | * - ``RTEMS_NO_TIMESLICE`` |
---|
1304 | - is masked by ``RTEMS_TIMESLICE_MASK`` and disables timeslicing |
---|
1305 | * - ``RTEMS_TIMESLICE`` |
---|
1306 | - is masked by ``RTEMS_TIMESLICE_MASK`` and enables timeslicing |
---|
1307 | * - ``RTEMS_ASR`` |
---|
1308 | - is masked by ``RTEMS_ASR_MASK`` and enables ASR processing |
---|
1309 | * - ``RTEMS_NO_ASR`` |
---|
1310 | - is masked by ``RTEMS_ASR_MASK`` and disables ASR processing |
---|
1311 | * - ``RTEMS_INTERRUPT_LEVEL(0)`` |
---|
1312 | - is masked by ``RTEMS_INTERRUPT_MASK`` and enables all interrupts |
---|
1313 | * - ``RTEMS_INTERRUPT_LEVEL(n)`` |
---|
1314 | - is masked by ``RTEMS_INTERRUPT_MASK`` and sets interrupts level n |
---|
1315 | |
---|
1316 | .. raw:: latex |
---|
1317 | |
---|
1318 | \clearpage |
---|
1319 | |
---|
1320 | .. _rtems_task_wake_after: |
---|
1321 | .. index:: delay a task for an interval |
---|
1322 | .. index:: wake up after an interval |
---|
1323 | .. index:: rtems_task_wake_after |
---|
1324 | |
---|
1325 | TASK_WAKE_AFTER - Wake up after interval |
---|
1326 | ---------------------------------------- |
---|
1327 | |
---|
1328 | CALLING SEQUENCE: |
---|
1329 | .. code-block:: c |
---|
1330 | |
---|
1331 | rtems_status_code rtems_task_wake_after( |
---|
1332 | rtems_interval ticks |
---|
1333 | ); |
---|
1334 | |
---|
1335 | DIRECTIVE STATUS CODES: |
---|
1336 | .. list-table:: |
---|
1337 | :class: rtems-table |
---|
1338 | |
---|
1339 | * - ``RTEMS_SUCCESSFUL`` |
---|
1340 | - always successful |
---|
1341 | |
---|
1342 | DESCRIPTION: |
---|
1343 | This directive blocks the calling task for the specified number of system |
---|
1344 | clock ticks. When the requested interval has elapsed, the task is made |
---|
1345 | ready. The clock tick directives automatically updates the delay period. |
---|
1346 | |
---|
1347 | NOTES: |
---|
1348 | Setting the system date and time with the ``rtems_clock_set`` directive has |
---|
1349 | no effect on a ``rtems_task_wake_after`` blocked task. |
---|
1350 | |
---|
1351 | A task may give up the processor and remain in the ready state by |
---|
1352 | specifying a value of ``RTEMS_YIELD_PROCESSOR`` in ticks. |
---|
1353 | |
---|
1354 | The maximum timer interval that can be specified is the maximum value which |
---|
1355 | can be represented by the uint32_t type. |
---|
1356 | |
---|
1357 | A clock tick is required to support the functionality of this directive. |
---|
1358 | |
---|
1359 | .. raw:: latex |
---|
1360 | |
---|
1361 | \clearpage |
---|
1362 | |
---|
1363 | .. _rtems_task_wake_when: |
---|
1364 | .. index:: delay a task until a wall time |
---|
1365 | .. index:: wake up at a wall time |
---|
1366 | .. index:: rtems_task_wake_when |
---|
1367 | |
---|
1368 | TASK_WAKE_WHEN - Wake up when specified |
---|
1369 | --------------------------------------- |
---|
1370 | |
---|
1371 | CALLING SEQUENCE: |
---|
1372 | .. code-block:: c |
---|
1373 | |
---|
1374 | rtems_status_code rtems_task_wake_when( |
---|
1375 | rtems_time_of_day *time_buffer |
---|
1376 | ); |
---|
1377 | |
---|
1378 | DIRECTIVE STATUS CODES: |
---|
1379 | .. list-table:: |
---|
1380 | :class: rtems-table |
---|
1381 | |
---|
1382 | * - ``RTEMS_SUCCESSFUL`` |
---|
1383 | - awakened at date/time successfully |
---|
1384 | * - ``RTEMS_INVALID_ADDRESS`` |
---|
1385 | - ``time_buffer`` is NULL |
---|
1386 | * - ``RTEMS_INVALID_TIME_OF_DAY`` |
---|
1387 | - invalid time buffer |
---|
1388 | * - ``RTEMS_NOT_DEFINED`` |
---|
1389 | - system date and time is not set |
---|
1390 | |
---|
1391 | DESCRIPTION: |
---|
1392 | This directive blocks a task until the date and time specified in |
---|
1393 | time_buffer. At the requested date and time, the calling task will be |
---|
1394 | unblocked and made ready to execute. |
---|
1395 | |
---|
1396 | NOTES: |
---|
1397 | The ticks portion of time_buffer structure is ignored. The timing |
---|
1398 | granularity of this directive is a second. |
---|
1399 | |
---|
1400 | A clock tick is required to support the functionality of this directive. |
---|
1401 | |
---|
1402 | .. raw:: latex |
---|
1403 | |
---|
1404 | \clearpage |
---|
1405 | |
---|
1406 | .. _rtems_task_get_scheduler: |
---|
1407 | |
---|
1408 | TASK_GET_SCHEDULER - Get scheduler of a task |
---|
1409 | -------------------------------------------- |
---|
1410 | |
---|
1411 | CALLING SEQUENCE: |
---|
1412 | .. code-block:: c |
---|
1413 | |
---|
1414 | rtems_status_code rtems_task_get_scheduler( |
---|
1415 | rtems_id task_id, |
---|
1416 | rtems_id *scheduler_id |
---|
1417 | ); |
---|
1418 | |
---|
1419 | DIRECTIVE STATUS CODES: |
---|
1420 | .. list-table:: |
---|
1421 | :class: rtems-table |
---|
1422 | |
---|
1423 | * - ``RTEMS_SUCCESSFUL`` |
---|
1424 | - successful operation |
---|
1425 | * - ``RTEMS_INVALID_ADDRESS`` |
---|
1426 | - ``scheduler_id`` is NULL |
---|
1427 | * - ``RTEMS_INVALID_ID`` |
---|
1428 | - invalid task id |
---|
1429 | |
---|
1430 | DESCRIPTION: |
---|
1431 | Returns the scheduler identifier of a task identified by ``task_id`` in |
---|
1432 | ``scheduler_id``. |
---|
1433 | |
---|
1434 | NOTES: |
---|
1435 | None. |
---|
1436 | |
---|
1437 | .. raw:: latex |
---|
1438 | |
---|
1439 | \clearpage |
---|
1440 | |
---|
1441 | .. _rtems_task_set_scheduler: |
---|
1442 | .. _TASK_SET_SCHEDULER - Set scheduler of a task: |
---|
1443 | |
---|
1444 | TASK_SET_SCHEDULER - Set scheduler of a task |
---|
1445 | -------------------------------------------- |
---|
1446 | |
---|
1447 | CALLING SEQUENCE: |
---|
1448 | .. code-block:: c |
---|
1449 | |
---|
1450 | rtems_status_code rtems_task_set_scheduler( |
---|
1451 | rtems_id task_id, |
---|
1452 | rtems_id scheduler_id, |
---|
1453 | rtems_task_priority priority |
---|
1454 | ); |
---|
1455 | |
---|
1456 | DIRECTIVE STATUS CODES: |
---|
1457 | .. list-table:: |
---|
1458 | :class: rtems-table |
---|
1459 | |
---|
1460 | * - ``RTEMS_SUCCESSFUL`` |
---|
1461 | - successful operation |
---|
1462 | * - ``RTEMS_INVALID_ID`` |
---|
1463 | - invalid task or scheduler id |
---|
1464 | * - ``RTEMS_INVALID_PRIORITY`` |
---|
1465 | - invalid task priority |
---|
1466 | * - ``RTEMS_RESOURCE_IN_USE`` |
---|
1467 | - the task is in the wrong state to perform a scheduler change |
---|
1468 | * - ``RTEMS_UNSATISFIED`` |
---|
1469 | - the processor set of the scheduler is empty |
---|
1470 | * - ``RTEMS_ILLEGAL_ON_REMOTE_OBJECT`` |
---|
1471 | - not supported on remote tasks |
---|
1472 | |
---|
1473 | DESCRIPTION: |
---|
1474 | Sets the scheduler of a task identified by ``task_id`` to the scheduler |
---|
1475 | identified by ``scheduler_id``. The scheduler of a task is initialized to |
---|
1476 | the scheduler of the task that created it. The priority of the task is set |
---|
1477 | to ``priority``. |
---|
1478 | |
---|
1479 | NOTES: |
---|
1480 | It is recommended to set the scheduler of a task before it is started or in |
---|
1481 | case it is guaranteed that the task owns no resources. Otherwise, sporadic |
---|
1482 | ``RTEMS_RESOURCE_IN_USE`` errors may occur. |
---|
1483 | |
---|
1484 | EXAMPLE: |
---|
1485 | .. code-block:: c |
---|
1486 | :linenos: |
---|
1487 | |
---|
1488 | #include <rtems.h> |
---|
1489 | #include <assert.h> |
---|
1490 | |
---|
1491 | void task( rtems_task_argument arg ); |
---|
1492 | |
---|
1493 | void example( void ) |
---|
1494 | { |
---|
1495 | rtems_status_code sc; |
---|
1496 | rtems_id task_id; |
---|
1497 | rtems_id scheduler_id; |
---|
1498 | rtems_name scheduler_name; |
---|
1499 | |
---|
1500 | scheduler_name = rtems_build_name( 'W', 'O', 'R', 'K' ); |
---|
1501 | |
---|
1502 | sc = rtems_scheduler_ident( scheduler_name, &scheduler_id ); |
---|
1503 | assert( sc == RTEMS_SUCCESSFUL ); |
---|
1504 | |
---|
1505 | sc = rtems_task_create( |
---|
1506 | rtems_build_name( 'T', 'A', 'S', 'K' ), |
---|
1507 | 1, |
---|
1508 | RTEMS_MINIMUM_STACK_SIZE, |
---|
1509 | RTEMS_DEFAULT_MODES, |
---|
1510 | RTEMS_DEFAULT_ATTRIBUTES, |
---|
1511 | &task_id |
---|
1512 | ); |
---|
1513 | assert( sc == RTEMS_SUCCESSFUL ); |
---|
1514 | |
---|
1515 | sc = rtems_task_set_scheduler( task_id, scheduler_id, 2 ); |
---|
1516 | assert( sc == RTEMS_SUCCESSFUL ); |
---|
1517 | |
---|
1518 | sc = rtems_task_start( task_id, task, 0 ); |
---|
1519 | assert( sc == RTEMS_SUCCESSFUL ); |
---|
1520 | } |
---|
1521 | |
---|
1522 | .. raw:: latex |
---|
1523 | |
---|
1524 | \clearpage |
---|
1525 | |
---|
1526 | .. _rtems_task_get_affinity: |
---|
1527 | |
---|
1528 | TASK_GET_AFFINITY - Get task processor affinity |
---|
1529 | ----------------------------------------------- |
---|
1530 | |
---|
1531 | CALLING SEQUENCE: |
---|
1532 | .. code-block:: c |
---|
1533 | |
---|
1534 | rtems_status_code rtems_task_get_affinity( |
---|
1535 | rtems_id id, |
---|
1536 | size_t cpusetsize, |
---|
1537 | cpu_set_t *cpuset |
---|
1538 | ); |
---|
1539 | |
---|
1540 | DIRECTIVE STATUS CODES: |
---|
1541 | .. list-table:: |
---|
1542 | :class: rtems-table |
---|
1543 | |
---|
1544 | * - ``RTEMS_SUCCESSFUL`` |
---|
1545 | - successful operation |
---|
1546 | * - ``RTEMS_INVALID_ADDRESS`` |
---|
1547 | - ``cpuset`` is NULL |
---|
1548 | * - ``RTEMS_INVALID_ID`` |
---|
1549 | - invalid task id |
---|
1550 | * - ``RTEMS_INVALID_NUMBER`` |
---|
1551 | - the affinity set buffer is too small for the current processor affinity |
---|
1552 | set of the task |
---|
1553 | |
---|
1554 | DESCRIPTION: |
---|
1555 | Returns the current processor affinity set of the task in ``cpuset``. A |
---|
1556 | set bit in the affinity set means that the task can execute on this |
---|
1557 | processor and a cleared bit means the opposite. |
---|
1558 | |
---|
1559 | NOTES: |
---|
1560 | The task processor affinity is initialized to the set of online processors. |
---|
1561 | |
---|
1562 | .. raw:: latex |
---|
1563 | |
---|
1564 | \clearpage |
---|
1565 | |
---|
1566 | .. _rtems_task_set_affinity: |
---|
1567 | |
---|
1568 | TASK_SET_AFFINITY - Set task processor affinity |
---|
1569 | ----------------------------------------------- |
---|
1570 | |
---|
1571 | CALLING SEQUENCE: |
---|
1572 | .. code-block:: c |
---|
1573 | |
---|
1574 | rtems_status_code rtems_task_set_affinity( |
---|
1575 | rtems_id id, |
---|
1576 | size_t cpusetsize, |
---|
1577 | const cpu_set_t *cpuset |
---|
1578 | ); |
---|
1579 | |
---|
1580 | DIRECTIVE STATUS CODES: |
---|
1581 | .. list-table:: |
---|
1582 | :class: rtems-table |
---|
1583 | |
---|
1584 | * - ``RTEMS_SUCCESSFUL`` |
---|
1585 | - successful operation |
---|
1586 | * - ``RTEMS_INVALID_ADDRESS`` |
---|
1587 | - ``cpuset`` is NULL |
---|
1588 | * - ``RTEMS_INVALID_ID`` |
---|
1589 | - invalid task id |
---|
1590 | * - ``RTEMS_INVALID_NUMBER`` |
---|
1591 | - invalid processor affinity set |
---|
1592 | |
---|
1593 | DESCRIPTION: |
---|
1594 | Sets the processor affinity set for the task specified by ``cpuset``. A |
---|
1595 | set bit in the affinity set means that the task can execute on this |
---|
1596 | processor and a cleared bit means the opposite. |
---|
1597 | |
---|
1598 | NOTES: |
---|
1599 | This function will not change the scheduler of the task. The intersection |
---|
1600 | of the processor affinity set and the set of processors owned by the |
---|
1601 | scheduler of the task must be non-empty. It is not an error if the |
---|
1602 | processor affinity set contains processors that are not part of the set of |
---|
1603 | processors owned by the scheduler instance of the task. A task will simply |
---|
1604 | not run under normal circumstances on these processors since the scheduler |
---|
1605 | ignores them. Some locking protocols may temporarily use processors that |
---|
1606 | are not included in the processor affinity set of the task. It is also not |
---|
1607 | an error if the processor affinity set contains processors that are not |
---|
1608 | part of the system. |
---|
1609 | |
---|
1610 | In case a scheduler without support for task affinites is used for the |
---|
1611 | task, then the task processor affinity set must contain all online |
---|
1612 | processors of the system. This prevents odd corner cases if processors are |
---|
1613 | added/removed at run-time to/from scheduler instances. |
---|
1614 | |
---|
1615 | .. raw:: latex |
---|
1616 | |
---|
1617 | \clearpage |
---|
1618 | |
---|
1619 | .. _rtems_task_iterate: |
---|
1620 | .. index:: iterate over all threads |
---|
1621 | .. index:: rtems_task_iterate |
---|
1622 | |
---|
1623 | TASK_ITERATE - Iterate Over Tasks |
---|
1624 | --------------------------------- |
---|
1625 | |
---|
1626 | CALLING SEQUENCE: |
---|
1627 | .. code-block:: c |
---|
1628 | |
---|
1629 | typedef bool ( *rtems_task_visitor )( rtems_tcb *tcb, void *arg ); |
---|
1630 | |
---|
1631 | void rtems_task_iterate( |
---|
1632 | rtems_task_visitor visitor, |
---|
1633 | void *arg |
---|
1634 | ); |
---|
1635 | |
---|
1636 | DIRECTIVE STATUS CODES: |
---|
1637 | NONE |
---|
1638 | |
---|
1639 | DESCRIPTION: |
---|
1640 | Iterates over all tasks in the system. This operation covers all tasks of |
---|
1641 | all APIs. The user should be careful in accessing the contents of the |
---|
1642 | thread control block :c:data:`tcb`. The visitor argument :c:data:`arg` is |
---|
1643 | passed to all invocations of :c:data:`visitor` in addition to the thread |
---|
1644 | control block. The iteration stops immediately in case the visitor |
---|
1645 | function returns true. |
---|
1646 | |
---|
1647 | NOTES: |
---|
1648 | Must be called from task context. This operation obtains and releases the |
---|
1649 | objects allocator lock. The task visitor is called while owning the objects |
---|
1650 | allocator lock. It is possible to perform blocking operations in the task |
---|
1651 | visitor, however, take care that no deadlocks via the object allocator lock |
---|
1652 | can occur. |
---|
1653 | |
---|
1654 | Deprecated and Removed Directives |
---|
1655 | ================================= |
---|
1656 | |
---|
1657 | .. raw:: latex |
---|
1658 | |
---|
1659 | \clearpage |
---|
1660 | |
---|
1661 | .. _rtems_iterate_over_all_threads: |
---|
1662 | .. index:: rtems_iterate_over_all_threads |
---|
1663 | |
---|
1664 | ITERATE_OVER_ALL_THREADS - Iterate Over Tasks |
---|
1665 | --------------------------------------------- |
---|
1666 | |
---|
1667 | .. warning:: |
---|
1668 | |
---|
1669 | This directive is deprecated. Its use is unsafe. Use |
---|
1670 | :ref:`rtems_task_iterate` instead. |
---|
1671 | |
---|
1672 | CALLING SEQUENCE: |
---|
1673 | .. code-block:: c |
---|
1674 | |
---|
1675 | typedef void (*rtems_per_thread_routine)(Thread_Control *the_thread); |
---|
1676 | void rtems_iterate_over_all_threads( |
---|
1677 | rtems_per_thread_routine routine |
---|
1678 | ); |
---|
1679 | |
---|
1680 | DIRECTIVE STATUS CODES: |
---|
1681 | NONE |
---|
1682 | |
---|
1683 | DESCRIPTION: |
---|
1684 | This directive iterates over all of the existant threads in the system and |
---|
1685 | invokes ``routine`` on each of them. The user should be careful in |
---|
1686 | accessing the contents of ``the_thread``. |
---|
1687 | |
---|
1688 | This routine is intended for use in diagnostic utilities and is not |
---|
1689 | intented for routine use in an operational system. |
---|
1690 | |
---|
1691 | NOTES: |
---|
1692 | There is **no protection** while this routine is called. The thread |
---|
1693 | control block may be in an inconsistent state or may change due to |
---|
1694 | interrupts or activity on other processors. |
---|
1695 | |
---|
1696 | .. raw:: latex |
---|
1697 | |
---|
1698 | \clearpage |
---|
1699 | |
---|
1700 | .. _rtems_task_get_note: |
---|
1701 | .. index:: get task notepad entry |
---|
1702 | .. index:: rtems_task_get_note |
---|
1703 | |
---|
1704 | TASK_GET_NOTE - Get task notepad entry |
---|
1705 | -------------------------------------- |
---|
1706 | |
---|
1707 | .. warning:: |
---|
1708 | |
---|
1709 | This directive was removed in RTEMS 5.1. |
---|
1710 | |
---|
1711 | CALLING SEQUENCE: |
---|
1712 | .. code-block:: c |
---|
1713 | |
---|
1714 | rtems_status_code rtems_task_get_note( |
---|
1715 | rtems_id id, |
---|
1716 | uint32_t notepad, |
---|
1717 | uint32_t *note |
---|
1718 | ); |
---|
1719 | |
---|
1720 | DIRECTIVE STATUS CODES: |
---|
1721 | .. list-table:: |
---|
1722 | :class: rtems-table |
---|
1723 | |
---|
1724 | * - ``RTEMS_SUCCESSFUL`` |
---|
1725 | - note value obtained successfully |
---|
1726 | * - ``RTEMS_INVALID_ADDRESS`` |
---|
1727 | - ``note`` parameter is NULL |
---|
1728 | * - ``RTEMS_INVALID_ID`` |
---|
1729 | - invalid task id |
---|
1730 | * - ``RTEMS_INVALID_NUMBER`` |
---|
1731 | - invalid notepad location |
---|
1732 | |
---|
1733 | DESCRIPTION: |
---|
1734 | This directive returns the note contained in the notepad location of the |
---|
1735 | task specified by id. |
---|
1736 | |
---|
1737 | NOTES: |
---|
1738 | This directive will not cause the running task to be preempted. |
---|
1739 | |
---|
1740 | If id is set to ``RTEMS_SELF``, the calling task accesses its own notepad. |
---|
1741 | |
---|
1742 | The sixteen notepad locations can be accessed using the constants |
---|
1743 | ``RTEMS_NOTEPAD_0`` through ``RTEMS_NOTEPAD_15``. |
---|
1744 | |
---|
1745 | Getting a note of a global task which does not reside on the local node |
---|
1746 | will generate a request to the remote node to obtain the notepad entry of |
---|
1747 | the specified task. |
---|
1748 | |
---|
1749 | .. raw:: latex |
---|
1750 | |
---|
1751 | \clearpage |
---|
1752 | |
---|
1753 | .. _rtems_task_set_note: |
---|
1754 | .. index:: set task notepad entry |
---|
1755 | .. index:: rtems_task_set_note |
---|
1756 | |
---|
1757 | TASK_SET_NOTE - Set task notepad entry |
---|
1758 | -------------------------------------- |
---|
1759 | |
---|
1760 | .. warning:: |
---|
1761 | |
---|
1762 | This directive was removed in RTEMS 5.1. |
---|
1763 | |
---|
1764 | CALLING SEQUENCE: |
---|
1765 | .. code-block:: c |
---|
1766 | |
---|
1767 | rtems_status_code rtems_task_set_note( |
---|
1768 | rtems_id id, |
---|
1769 | uint32_t notepad, |
---|
1770 | uint32_t note |
---|
1771 | ); |
---|
1772 | |
---|
1773 | DIRECTIVE STATUS CODES: |
---|
1774 | .. list-table:: |
---|
1775 | :class: rtems-table |
---|
1776 | |
---|
1777 | * - ``RTEMS_SUCCESSFUL`` |
---|
1778 | - note set successfully |
---|
1779 | * - ``RTEMS_INVALID_ID`` |
---|
1780 | - invalid task id |
---|
1781 | * - ``RTEMS_INVALID_NUMBER`` |
---|
1782 | - invalid notepad location |
---|
1783 | |
---|
1784 | DESCRIPTION: |
---|
1785 | This directive sets the notepad entry for the task specified by id to the |
---|
1786 | value note. |
---|
1787 | |
---|
1788 | NOTES: |
---|
1789 | If ``id`` is set to ``RTEMS_SELF``, the calling task accesses its own |
---|
1790 | notepad. |
---|
1791 | |
---|
1792 | This directive will not cause the running task to be preempted. |
---|
1793 | |
---|
1794 | The sixteen notepad locations can be accessed using the constants |
---|
1795 | ``RTEMS_NOTEPAD_0`` through ``RTEMS_NOTEPAD_15``. |
---|
1796 | |
---|
1797 | Setting a note of a global task which does not reside on the local node |
---|
1798 | will generate a request to the remote node to set the notepad entry of the |
---|
1799 | specified task. |
---|
1800 | |
---|
1801 | .. raw:: latex |
---|
1802 | |
---|
1803 | \clearpage |
---|
1804 | |
---|
1805 | .. _rtems_task_variable_add: |
---|
1806 | .. index:: per-task variable |
---|
1807 | .. index:: task private variable |
---|
1808 | .. index:: task private data |
---|
1809 | .. index:: rtems_task_variable_add |
---|
1810 | |
---|
1811 | TASK_VARIABLE_ADD - Associate per task variable |
---|
1812 | ----------------------------------------------- |
---|
1813 | |
---|
1814 | .. warning:: |
---|
1815 | |
---|
1816 | This directive was removed in RTEMS 5.1. |
---|
1817 | |
---|
1818 | CALLING SEQUENCE: |
---|
1819 | .. code-block:: c |
---|
1820 | |
---|
1821 | rtems_status_code rtems_task_variable_add( |
---|
1822 | rtems_id tid, |
---|
1823 | void **task_variable, |
---|
1824 | void (*dtor)(void *) |
---|
1825 | ); |
---|
1826 | |
---|
1827 | DIRECTIVE STATUS CODES: |
---|
1828 | .. list-table:: |
---|
1829 | :class: rtems-table |
---|
1830 | |
---|
1831 | * - ``RTEMS_SUCCESSFUL`` |
---|
1832 | - per task variable added successfully |
---|
1833 | * - ``RTEMS_INVALID_ADDRESS`` |
---|
1834 | - ``task_variable`` is NULL |
---|
1835 | * - ``RTEMS_INVALID_ID`` |
---|
1836 | - invalid task id |
---|
1837 | * - ``RTEMS_NO_MEMORY`` |
---|
1838 | - invalid task id |
---|
1839 | * - ``RTEMS_ILLEGAL_ON_REMOTE_OBJECT`` |
---|
1840 | - not supported on remote tasks |
---|
1841 | |
---|
1842 | DESCRIPTION: |
---|
1843 | This directive adds the memory location specified by the ptr argument to |
---|
1844 | the context of the given task. The variable will then be private to the |
---|
1845 | task. The task can access and modify the variable, but the modifications |
---|
1846 | will not appear to other tasks, and other tasks' modifications to that |
---|
1847 | variable will not affect the value seen by the task. This is accomplished |
---|
1848 | by saving and restoring the variable's value each time a task switch occurs |
---|
1849 | to or from the calling task. If the dtor argument is non-NULL it specifies |
---|
1850 | the address of a 'destructor' function which will be called when the task |
---|
1851 | is deleted. The argument passed to the destructor function is the task's |
---|
1852 | value of the variable. |
---|
1853 | |
---|
1854 | NOTES: |
---|
1855 | Task variables increase the context switch time to and from the tasks that |
---|
1856 | own them so it is desirable to minimize the number of task variables. One |
---|
1857 | efficient method is to have a single task variable that is a pointer to a |
---|
1858 | dynamically allocated structure containing the task's private 'global' |
---|
1859 | data. In this case the destructor function could be 'free'. |
---|
1860 | |
---|
1861 | Per-task variables are disabled in SMP configurations and this service is |
---|
1862 | not available. |
---|
1863 | |
---|
1864 | .. raw:: latex |
---|
1865 | |
---|
1866 | \clearpage |
---|
1867 | |
---|
1868 | .. _rtems_task_variable_get: |
---|
1869 | .. index:: get per-task variable |
---|
1870 | .. index:: obtain per-task variable |
---|
1871 | .. index:: rtems_task_variable_get |
---|
1872 | |
---|
1873 | TASK_VARIABLE_GET - Obtain value of a per task variable |
---|
1874 | ------------------------------------------------------- |
---|
1875 | |
---|
1876 | .. warning:: |
---|
1877 | |
---|
1878 | This directive was removed in RTEMS 5.1. |
---|
1879 | |
---|
1880 | CALLING SEQUENCE: |
---|
1881 | .. code-block:: c |
---|
1882 | |
---|
1883 | rtems_status_code rtems_task_variable_get( |
---|
1884 | rtems_id tid, |
---|
1885 | void **task_variable, |
---|
1886 | void **task_variable_value |
---|
1887 | ); |
---|
1888 | |
---|
1889 | DIRECTIVE STATUS CODES: |
---|
1890 | .. list-table:: |
---|
1891 | :class: rtems-table |
---|
1892 | |
---|
1893 | * - ``RTEMS_SUCCESSFUL`` |
---|
1894 | - per task variable obtained successfully |
---|
1895 | * - ``RTEMS_INVALID_ADDRESS`` |
---|
1896 | - ``task_variable`` is NULL |
---|
1897 | * - ``RTEMS_INVALID_ADDRESS`` |
---|
1898 | - ``task_variable_value`` is NULL |
---|
1899 | * - ``RTEMS_INVALID_ADDRESS`` |
---|
1900 | - ``task_variable`` is not found |
---|
1901 | * - ``RTEMS_NO_MEMORY`` |
---|
1902 | - invalid task id |
---|
1903 | * - ``RTEMS_ILLEGAL_ON_REMOTE_OBJECT`` |
---|
1904 | - not supported on remote tasks |
---|
1905 | |
---|
1906 | DESCRIPTION: |
---|
1907 | This directive looks up the private value of a task variable for a |
---|
1908 | specified task and stores that value in the location pointed to by the |
---|
1909 | result argument. The specified task is usually not the calling task, which |
---|
1910 | can get its private value by directly accessing the variable. |
---|
1911 | |
---|
1912 | NOTES: |
---|
1913 | If you change memory which ``task_variable_value`` points to, remember to |
---|
1914 | declare that memory as volatile, so that the compiler will optimize it |
---|
1915 | correctly. In this case both the pointer ``task_variable_value`` and data |
---|
1916 | referenced by ``task_variable_value`` should be considered volatile. |
---|
1917 | |
---|
1918 | Per-task variables are disabled in SMP configurations and this service is |
---|
1919 | not available. |
---|
1920 | |
---|
1921 | .. raw:: latex |
---|
1922 | |
---|
1923 | \clearpage |
---|
1924 | |
---|
1925 | .. _rtems_task_variable_delete: |
---|
1926 | .. index:: per-task variable |
---|
1927 | .. index:: task private variable |
---|
1928 | .. index:: task private data |
---|
1929 | .. index:: rtems_task_variable_delete |
---|
1930 | |
---|
1931 | TASK_VARIABLE_DELETE - Remove per task variable |
---|
1932 | ----------------------------------------------- |
---|
1933 | |
---|
1934 | .. warning:: |
---|
1935 | |
---|
1936 | This directive was removed in RTEMS 5.1. |
---|
1937 | |
---|
1938 | CALLING SEQUENCE: |
---|
1939 | .. code-block:: c |
---|
1940 | |
---|
1941 | rtems_status_code rtems_task_variable_delete( |
---|
1942 | rtems_id id, |
---|
1943 | void **task_variable |
---|
1944 | ); |
---|
1945 | |
---|
1946 | DIRECTIVE STATUS CODES: |
---|
1947 | .. list-table:: |
---|
1948 | :class: rtems-table |
---|
1949 | |
---|
1950 | * - ``RTEMS_SUCCESSFUL`` |
---|
1951 | - per task variable deleted successfully |
---|
1952 | * - ``RTEMS_INVALID_ID`` |
---|
1953 | - invalid task id |
---|
1954 | * - ``RTEMS_NO_MEMORY`` |
---|
1955 | - invalid task id |
---|
1956 | * - ``RTEMS_INVALID_ADDRESS`` |
---|
1957 | - ``task_variable`` is NULL |
---|
1958 | * - ``RTEMS_ILLEGAL_ON_REMOTE_OBJECT`` |
---|
1959 | - not supported on remote tasks |
---|
1960 | |
---|
1961 | DESCRIPTION: |
---|
1962 | This directive removes the given location from a task's context. |
---|
1963 | |
---|
1964 | NOTES: |
---|
1965 | Per-task variables are disabled in SMP configurations and this service is |
---|
1966 | not available. |
---|