1 | Task Manager |
---|
2 | ############ |
---|
3 | |
---|
4 | .. index:: tasks |
---|
5 | |
---|
6 | Introduction |
---|
7 | ============ |
---|
8 | |
---|
9 | The task manager provides a comprehensive set of directives to |
---|
10 | create, delete, and administer tasks. The directives provided |
---|
11 | by the task manager are: |
---|
12 | |
---|
13 | - ``rtems.task_create`` - Create a task |
---|
14 | |
---|
15 | - ``rtems.task_ident`` - Get ID of a task |
---|
16 | |
---|
17 | - ``rtems.task_self`` - Obtain ID of caller |
---|
18 | |
---|
19 | - ``rtems.task_start`` - Start a task |
---|
20 | |
---|
21 | - ``rtems.task_restart`` - Restart a task |
---|
22 | |
---|
23 | - ``rtems.task_delete`` - Delete a task |
---|
24 | |
---|
25 | - ``rtems.task_suspend`` - Suspend a task |
---|
26 | |
---|
27 | - ``rtems.task_resume`` - Resume a task |
---|
28 | |
---|
29 | - ``rtems.task_is_suspended`` - Determine if a task is suspended |
---|
30 | |
---|
31 | - ``rtems.task_set_priority`` - Set task priority |
---|
32 | |
---|
33 | - ``rtems.task_mode`` - Change current taskâs mode |
---|
34 | |
---|
35 | - ``rtems.task_wake_after`` - Wake up after interval |
---|
36 | |
---|
37 | - ``rtems.task_wake_when`` - Wake up when specified |
---|
38 | |
---|
39 | - ``rtems.iterate_over_all_threads`` - Iterate Over Tasks |
---|
40 | |
---|
41 | - ``rtems.task_variable_add`` - Associate per task variable |
---|
42 | |
---|
43 | - ``rtems.task_variable_get`` - Obtain value of a a per task variable |
---|
44 | |
---|
45 | - ``rtems.task_variable_delete`` - Remove per task variable |
---|
46 | |
---|
47 | Background |
---|
48 | ========== |
---|
49 | |
---|
50 | Task Definition |
---|
51 | --------------- |
---|
52 | .. index:: task, definition |
---|
53 | |
---|
54 | Many definitions of a task have been proposed in computer literature. |
---|
55 | Unfortunately, none of these definitions encompasses all facets of the |
---|
56 | concept in a manner which is operating system independent. Several of the |
---|
57 | more common definitions are provided to enable each user to select a |
---|
58 | definition which best matches their own experience and understanding of the |
---|
59 | task concept: |
---|
60 | |
---|
61 | - a "dispatchable" unit. |
---|
62 | |
---|
63 | - an entity to which the processor is allocated. |
---|
64 | |
---|
65 | - an atomic unit of a real-time, multiprocessor system. |
---|
66 | |
---|
67 | - single threads of execution which concurrently compete for resources. |
---|
68 | |
---|
69 | - a sequence of closely related computations which can execute |
---|
70 | concurrently with other computational sequences. |
---|
71 | |
---|
72 | From RTEMSâ perspective, a task is the smallest thread of |
---|
73 | execution which can compete on its own for system resources. A |
---|
74 | task is manifested by the existence of a task control block |
---|
75 | (TCB). |
---|
76 | |
---|
77 | Task Control Block |
---|
78 | ------------------ |
---|
79 | |
---|
80 | The Task Control Block (TCB) is an RTEMS defined data structure |
---|
81 | which contains all the information that is pertinent to the |
---|
82 | execution of a task. During system initialization, RTEMS |
---|
83 | reserves a TCB for each task configured. A TCB is allocated |
---|
84 | upon creation of the task and is returned to the TCB free list |
---|
85 | upon deletion of the task. |
---|
86 | |
---|
87 | The TCBâs elements are modified as a result of system calls made |
---|
88 | by the application in response to external and internal stimuli. |
---|
89 | TCBs are the only RTEMS internal data structure that can be |
---|
90 | accessed by an application via user extension routines. The TCB |
---|
91 | contains a taskâs name, ID, current priority, current and |
---|
92 | starting states, execution mode, TCB user extension pointer, |
---|
93 | scheduling control structures, as well as data required by a |
---|
94 | blocked task. |
---|
95 | |
---|
96 | A taskâs context is stored in the TCB when a task switch occurs. |
---|
97 | When the task regains control of the processor, its context is |
---|
98 | restored from the TCB. When a task is restarted, the initial |
---|
99 | state of the task is restored from the starting context area in |
---|
100 | the taskâs TCB. |
---|
101 | |
---|
102 | Task States |
---|
103 | ----------- |
---|
104 | .. index:: task states |
---|
105 | |
---|
106 | A task may exist in one of the following five states: |
---|
107 | |
---|
108 | - *executing* - Currently scheduled to the CPU |
---|
109 | |
---|
110 | - *ready* - May be scheduled to the CPU |
---|
111 | |
---|
112 | - *blocked* - Unable to be scheduled to the CPU |
---|
113 | |
---|
114 | - *dormant* - Created task that is not started |
---|
115 | |
---|
116 | - *non-existent* - Uncreated or deleted task |
---|
117 | |
---|
118 | An active task may occupy the executing, ready, blocked or |
---|
119 | dormant state, otherwise the task is considered non-existent. |
---|
120 | One or more tasks may be active in the system simultaneously. |
---|
121 | Multiple tasks communicate, synchronize, and compete for system |
---|
122 | resources with each other via system calls. The multiple tasks |
---|
123 | appear to execute in parallel, but actually each is dispatched |
---|
124 | to the CPU for periods of time determined by the RTEMS |
---|
125 | scheduling algorithm. The scheduling of a task is based on its |
---|
126 | current state and priority. |
---|
127 | |
---|
128 | Task Priority |
---|
129 | ------------- |
---|
130 | .. index:: task priority |
---|
131 | .. index:: priority, task |
---|
132 | .. index:: rtems_task_priority |
---|
133 | |
---|
134 | A taskâs priority determines its importance in relation to the |
---|
135 | other tasks executing on the same processor. RTEMS supports 255 |
---|
136 | levels of priority ranging from 1 to 255. The data type``rtems.task_priority`` is used to store task |
---|
137 | priorities. |
---|
138 | |
---|
139 | Tasks of numerically |
---|
140 | smaller priority values are more important tasks than tasks of |
---|
141 | numerically larger priority values. For example, a task at |
---|
142 | priority level 5 is of higher privilege than a task at priority |
---|
143 | level 10. There is no limit to the number of tasks assigned to |
---|
144 | the same priority. |
---|
145 | |
---|
146 | Each task has a priority associated with it at all times. The |
---|
147 | initial value of this priority is assigned at task creation |
---|
148 | time. The priority of a task may be changed at any subsequent |
---|
149 | time. |
---|
150 | |
---|
151 | Priorities are used by the scheduler to determine which ready |
---|
152 | task will be allowed to execute. In general, the higher the |
---|
153 | logical priority of a task, the more likely it is to receive |
---|
154 | processor execution time. |
---|
155 | |
---|
156 | Task Mode |
---|
157 | --------- |
---|
158 | .. index:: task mode |
---|
159 | .. index:: rtems_task_mode |
---|
160 | |
---|
161 | A taskâs execution mode is a combination of the following |
---|
162 | four components: |
---|
163 | |
---|
164 | - preemption |
---|
165 | |
---|
166 | - ASR processing |
---|
167 | |
---|
168 | - timeslicing |
---|
169 | |
---|
170 | - interrupt level |
---|
171 | |
---|
172 | It is used to modify RTEMSâ scheduling process and to alter the |
---|
173 | execution environment of the task. The data type``rtems.task_mode`` is used to manage the task |
---|
174 | execution mode... index:: preemption |
---|
175 | |
---|
176 | The preemption component allows a task to determine when control of the |
---|
177 | processor is relinquished. If preemption is disabled |
---|
178 | (``RTEMS.NO_PREEMPT``), the task will retain control of the |
---|
179 | processor as long as it is in the executing state â even if a higher |
---|
180 | priority task is made ready. If preemption is enabled |
---|
181 | (``RTEMS.PREEMPT``) and a higher priority task is made ready, |
---|
182 | then the processor will be taken away from the current task immediately and |
---|
183 | given to the higher priority task... index:: timeslicing |
---|
184 | |
---|
185 | The timeslicing component is used by the RTEMS scheduler to determine how |
---|
186 | the processor is allocated to tasks of equal priority. If timeslicing is |
---|
187 | enabled (``RTEMS.TIMESLICE``), then RTEMS will limit the amount |
---|
188 | of time the task can execute before the processor is allocated to another |
---|
189 | ready task of equal priority. The length of the timeslice is application |
---|
190 | dependent and specified in the Configuration Table. If timeslicing is |
---|
191 | disabled (``RTEMS.NO_TIMESLICE``), then the task will be |
---|
192 | allowed to execute until a task of higher priority is made ready. If``RTEMS.NO_PREEMPT`` is selected, then the timeslicing |
---|
193 | component is ignored by the scheduler. |
---|
194 | |
---|
195 | The asynchronous signal processing component is used to determine when |
---|
196 | received signals are to be processed by the task. |
---|
197 | If signal processing is enabled (``RTEMS.ASR``), then signals |
---|
198 | sent to the task will be processed the next time the task executes. If |
---|
199 | signal processing is disabled (``RTEMS.NO_ASR``), then all |
---|
200 | signals received by the task will remain posted until signal processing is |
---|
201 | enabled. This component affects only tasks which have established a |
---|
202 | routine to process asynchronous signals... index:: interrupt level, task |
---|
203 | |
---|
204 | The interrupt level component is used to determine which |
---|
205 | interrupts will be enabled when the task is executing.``RTEMS.INTERRUPT_LEVEL(n)`` |
---|
206 | specifies that the task will execute at interrupt level n. |
---|
207 | |
---|
208 | - ``RTEMS.PREEMPT`` - enable preemption (default) |
---|
209 | |
---|
210 | - ``RTEMS.NO_PREEMPT`` - disable preemption |
---|
211 | |
---|
212 | - ``RTEMS.NO_TIMESLICE`` - disable timeslicing (default) |
---|
213 | |
---|
214 | - ``RTEMS.TIMESLICE`` - enable timeslicing |
---|
215 | |
---|
216 | - ``RTEMS.ASR`` - enable ASR processing (default) |
---|
217 | |
---|
218 | - ``RTEMS.NO_ASR`` - disable ASR processing |
---|
219 | |
---|
220 | - ``RTEMS.INTERRUPT_LEVEL(0)`` - enable all interrupts (default) |
---|
221 | |
---|
222 | - ``RTEMS.INTERRUPT_LEVEL(n)`` - execute at interrupt level n |
---|
223 | |
---|
224 | The set of default modes may be selected by specifying the``RTEMS.DEFAULT_MODES`` constant. |
---|
225 | |
---|
226 | Accessing Task Arguments |
---|
227 | ------------------------ |
---|
228 | .. index:: task arguments |
---|
229 | .. index:: task prototype |
---|
230 | |
---|
231 | All RTEMS tasks are invoked with a single argument which is |
---|
232 | specified when they are started or restarted. The argument is |
---|
233 | commonly used to communicate startup information to the task. |
---|
234 | The simplest manner in which to define a task which accesses it |
---|
235 | argument is: |
---|
236 | |
---|
237 | .. code:: c |
---|
238 | |
---|
239 | procedure User_Task ( |
---|
240 | Argument : in RTEMS.Task_Argument_Ptr |
---|
241 | ); |
---|
242 | |
---|
243 | Application tasks requiring more information may view this |
---|
244 | single argument as an index into an array of parameter blocks. |
---|
245 | |
---|
246 | Floating Point Considerations |
---|
247 | ----------------------------- |
---|
248 | .. index:: floating point |
---|
249 | |
---|
250 | Creating a task with the ``RTEMS.FLOATING_POINT`` attribute |
---|
251 | flag results |
---|
252 | in additional memory being allocated for the TCB to store the state of the |
---|
253 | numeric coprocessor during task switches. This additional memory is*NOT* allocated for ``RTEMS.NO_FLOATING_POINT`` tasks. Saving |
---|
254 | and restoring the context of a ``RTEMS.FLOATING_POINT`` task |
---|
255 | takes longer than that of a ``RTEMS.NO_FLOATING_POINT`` task |
---|
256 | because of the relatively large amount of time required for the numeric |
---|
257 | coprocessor to save or restore its computational state. |
---|
258 | |
---|
259 | Since RTEMS was designed specifically for embedded military applications |
---|
260 | which are floating point intensive, the executive is optimized to avoid |
---|
261 | unnecessarily saving and restoring the state of the numeric coprocessor. |
---|
262 | The state of the numeric coprocessor is only saved when a``RTEMS.FLOATING_POINT`` task is dispatched and that task was |
---|
263 | not the last task to utilize the coprocessor. In a system with only one``RTEMS.FLOATING_POINT`` task, the state of the numeric |
---|
264 | coprocessor will never be saved or restored. |
---|
265 | |
---|
266 | Although the overhead imposed by ``RTEMS.FLOATING_POINT`` tasks |
---|
267 | is minimal, some applications may wish to completely avoid the overhead |
---|
268 | associated with ``RTEMS.FLOATING_POINT`` tasks and still |
---|
269 | utilize a numeric coprocessor. By preventing a task from being preempted |
---|
270 | while performing a sequence of floating point operations, a``RTEMS.NO_FLOATING_POINT`` task can utilize the numeric |
---|
271 | coprocessor without incurring the overhead of a``RTEMS.FLOATING_POINT`` context switch. This approach also |
---|
272 | avoids the allocation of a floating point context area. However, if this |
---|
273 | approach is taken by the application designer, NO tasks should be created |
---|
274 | as ``RTEMS.FLOATING_POINT`` tasks. Otherwise, the floating |
---|
275 | point context will not be correctly maintained because RTEMS assumes that |
---|
276 | the state of the numeric coprocessor will not be altered by``RTEMS.NO_FLOATING_POINT`` tasks. |
---|
277 | |
---|
278 | If the supported processor type does not have hardware floating |
---|
279 | capabilities or a standard numeric coprocessor, RTEMS will not provide |
---|
280 | built-in support for hardware floating point on that processor. In this |
---|
281 | case, all tasks are considered ``RTEMS.NO_FLOATING_POINT`` |
---|
282 | whether created as ``RTEMS.FLOATING_POINT`` or``RTEMS.NO_FLOATING_POINT`` tasks. A floating point emulation |
---|
283 | software library must be utilized for floating point operations. |
---|
284 | |
---|
285 | On some processors, it is possible to disable the floating point unit |
---|
286 | dynamically. If this capability is supported by the target processor, then |
---|
287 | RTEMS will utilize this capability to enable the floating point unit only |
---|
288 | for tasks which are created with the ``RTEMS.FLOATING_POINT`` |
---|
289 | attribute. The consequence of a ``RTEMS.NO_FLOATING_POINT`` |
---|
290 | task attempting to access the floating point unit is CPU dependent but will |
---|
291 | generally result in an exception condition. |
---|
292 | |
---|
293 | Per Task Variables |
---|
294 | ------------------ |
---|
295 | .. index:: per task variables |
---|
296 | |
---|
297 | Per task variables are deprecated, see the warning below. |
---|
298 | |
---|
299 | Per task variables are used to support global variables whose value |
---|
300 | may be unique to a task. After indicating that a variable should be |
---|
301 | treated as private (i.e. per-task) the task can access and modify the |
---|
302 | variable, but the modifications will not appear to other tasks, and |
---|
303 | other tasksâ modifications to that variable will not affect the value |
---|
304 | seen by the task. This is accomplished by saving and restoring the |
---|
305 | variableâs value each time a task switch occurs to or from the calling task. |
---|
306 | |
---|
307 | The value seen by other tasks, including those which have not added the |
---|
308 | variable to their set and are thus accessing the variable as a common |
---|
309 | location shared among tasks, cannot be affected by a task once it has |
---|
310 | added a variable to its local set. Changes made to the variable by |
---|
311 | other tasks will not affect the value seen by a task which has added the |
---|
312 | variable to its private set. |
---|
313 | |
---|
314 | This feature can be used when a routine is to be spawned repeatedly as |
---|
315 | several independent tasks. Although each task will have its own stack, |
---|
316 | and thus separate stack variables, they will all share the same static and |
---|
317 | global variables. To make a variable not shareable (i.e. a "global" variable |
---|
318 | that is specific to a single task), the tasks can call``rtems_task_variable_add`` to make a separate copy of the variable |
---|
319 | for each task, but all at the same physical address. |
---|
320 | |
---|
321 | Task variables increase the context switch time to and from the |
---|
322 | tasks that own them so it is desirable to minimize the number of |
---|
323 | task variables. One efficient method is to have a single task |
---|
324 | variable that is a pointer to a dynamically allocated structure |
---|
325 | containing the taskâs private "global" data. |
---|
326 | |
---|
327 | A critical point with per-task variables is that each task must separately |
---|
328 | request that the same global variable is per-task private. |
---|
329 | |
---|
330 | *WARNING*: Per-Task variables are inherently broken on SMP systems. They |
---|
331 | only work correctly when there is one task executing in the system and |
---|
332 | that task is the logical owner of the value in the per-task variableâs |
---|
333 | location. There is no way for a single memory image to contain the |
---|
334 | correct value for each task executing on each core. Consequently, |
---|
335 | per-task variables are disabled in SMP configurations of RTEMS. |
---|
336 | Instead the application developer should |
---|
337 | consider the use of POSIX Keys or Thread Local Storage (TLS). POSIX Keys |
---|
338 | are not enabled in all RTEMS configurations. |
---|
339 | |
---|
340 | Building a Task Attribute Set |
---|
341 | ----------------------------- |
---|
342 | .. index:: task attributes, building |
---|
343 | |
---|
344 | In general, an attribute set is built by a bitwise OR of the |
---|
345 | desired components. The set of valid task attribute components |
---|
346 | is listed below: |
---|
347 | |
---|
348 | - ``RTEMS.NO_FLOATING_POINT`` - does not use coprocessor (default) |
---|
349 | |
---|
350 | - ``RTEMS.FLOATING_POINT`` - uses numeric coprocessor |
---|
351 | |
---|
352 | - ``RTEMS.LOCAL`` - local task (default) |
---|
353 | |
---|
354 | - ``RTEMS.GLOBAL`` - global task |
---|
355 | |
---|
356 | Attribute values are specifically designed to be mutually |
---|
357 | exclusive, therefore bitwise OR and addition operations are |
---|
358 | equivalent as long as each attribute appears exactly once in the |
---|
359 | component list. A component listed as a default is not required |
---|
360 | to appear in the component list, although it is a good |
---|
361 | programming practice to specify default components. If all |
---|
362 | defaults are desired, then ``RTEMS.DEFAULT_ATTRIBUTES`` should be used. |
---|
363 | |
---|
364 | This example demonstrates the attribute_set parameter needed to |
---|
365 | create a local task which utilizes the numeric coprocessor. The |
---|
366 | attribute_set parameter could be ``RTEMS.FLOATING_POINT`` or``RTEMS.LOCAL or RTEMS.FLOATING_POINT``. |
---|
367 | The attribute_set parameter can be set to``RTEMS.FLOATING_POINT`` because ``RTEMS.LOCAL`` is the default for all created |
---|
368 | tasks. If the task were global and used the numeric |
---|
369 | coprocessor, then the attribute_set parameter would be``RTEMS.GLOBAL or RTEMS.FLOATING_POINT``. |
---|
370 | |
---|
371 | Building a Mode and Mask |
---|
372 | ------------------------ |
---|
373 | .. index:: task mode, building |
---|
374 | |
---|
375 | In general, a mode and its corresponding mask is built by a |
---|
376 | bitwise OR of the desired components. The set of valid mode |
---|
377 | constants and each modeâs corresponding mask constant is |
---|
378 | listed below: |
---|
379 | |
---|
380 | - ``RTEMS.PREEMPT`` is masked by``RTEMS.PREEMPT_MASK`` and enables preemption |
---|
381 | |
---|
382 | - ``RTEMS.NO_PREEMPT`` is masked by``RTEMS.PREEMPT_MASK`` and disables preemption |
---|
383 | |
---|
384 | - ``RTEMS.NO_TIMESLICE`` is masked by``RTEMS.TIMESLICE_MASK`` and disables timeslicing |
---|
385 | |
---|
386 | - ``RTEMS.TIMESLICE`` is masked by``RTEMS.TIMESLICE_MASK`` and enables timeslicing |
---|
387 | |
---|
388 | - ``RTEMS.ASR`` is masked by``RTEMS.ASR_MASK`` and enables ASR processing |
---|
389 | |
---|
390 | - ``RTEMS.NO_ASR`` is masked by``RTEMS.ASR_MASK`` and disables ASR processing |
---|
391 | |
---|
392 | - ``RTEMS.INTERRUPT_LEVEL(0)`` is masked by``RTEMS.INTERRUPT_MASK`` and enables all interrupts |
---|
393 | |
---|
394 | - ``RTEMS.INTERRUPT_LEVEL(n)`` is masked by``RTEMS.INTERRUPT_MASK`` and sets interrupts level n |
---|
395 | |
---|
396 | Mode values are specifically designed to be mutually exclusive, therefore |
---|
397 | bitwise OR and addition operations are equivalent as long as each mode |
---|
398 | appears exactly once in the component list. A mode component listed as a |
---|
399 | default is not required to appear in the mode component list, although it |
---|
400 | is a good programming practice to specify default components. If all |
---|
401 | defaults are desired, the mode ``RTEMS.DEFAULT_MODES`` and the |
---|
402 | mask ``RTEMS.ALL_MODE_MASKS`` should be used. |
---|
403 | |
---|
404 | The following example demonstrates the mode and mask parameters used with |
---|
405 | the ``rtems.task_mode`` |
---|
406 | directive to place a task at interrupt level 3 and make it |
---|
407 | non-preemptible. The mode should be set to``RTEMS.INTERRUPT_LEVEL(3) or |
---|
408 | RTEMS.NO_PREEMPT`` to indicate the desired preemption mode and |
---|
409 | interrupt level, while the mask parameter should be set to``RTEMS.INTERRUPT_MASK or |
---|
410 | RTEMS.NO_PREEMPT_MASK`` to indicate that the calling taskâs |
---|
411 | interrupt level and preemption mode are being altered. |
---|
412 | |
---|
413 | Operations |
---|
414 | ========== |
---|
415 | |
---|
416 | Creating Tasks |
---|
417 | -------------- |
---|
418 | |
---|
419 | The ``rtems.task_create`` |
---|
420 | directive creates a task by allocating a task |
---|
421 | control block, assigning the task a user-specified name, |
---|
422 | allocating it a stack and floating point context area, setting a |
---|
423 | user-specified initial priority, setting a user-specified |
---|
424 | initial mode, and assigning it a task ID. Newly created tasks |
---|
425 | are initially placed in the dormant state. All RTEMS tasks |
---|
426 | execute in the most privileged mode of the processor. |
---|
427 | |
---|
428 | Obtaining Task IDs |
---|
429 | ------------------ |
---|
430 | |
---|
431 | When a task is created, RTEMS generates a unique task ID and |
---|
432 | assigns it to the created task until it is deleted. The task ID |
---|
433 | may be obtained by either of two methods. First, as the result |
---|
434 | of an invocation of the ``rtems.task_create`` |
---|
435 | directive, the task ID is |
---|
436 | stored in a user provided location. Second, the task ID may be |
---|
437 | obtained later using the ``rtems.task_ident`` |
---|
438 | directive. The task ID is |
---|
439 | used by other directives to manipulate this task. |
---|
440 | |
---|
441 | Starting and Restarting Tasks |
---|
442 | ----------------------------- |
---|
443 | |
---|
444 | The ``rtems.task_start`` |
---|
445 | directive is used to place a dormant task in the |
---|
446 | ready state. This enables the task to compete, based on its |
---|
447 | current priority, for the processor and other system resources. |
---|
448 | Any actions, such as suspension or change of priority, performed |
---|
449 | on a task prior to starting it are nullified when the task is |
---|
450 | started. |
---|
451 | |
---|
452 | With the ``rtems.task_start`` |
---|
453 | directive the user specifies the taskâs |
---|
454 | starting address and argument. The argument is used to |
---|
455 | communicate some startup information to the task. As part of |
---|
456 | this directive, RTEMS initializes the taskâs stack based upon |
---|
457 | the taskâs initial execution mode and start address. The |
---|
458 | starting argument is passed to the task in accordance with the |
---|
459 | target processorâs calling convention. |
---|
460 | |
---|
461 | The ``rtems.task_restart`` |
---|
462 | directive restarts a task at its initial |
---|
463 | starting address with its original priority and execution mode, |
---|
464 | but with a possibly different argument. The new argument may be |
---|
465 | used to distinguish between the original invocation of the task |
---|
466 | and subsequent invocations. The taskâs stack and control block |
---|
467 | are modified to reflect their original creation values. |
---|
468 | Although references to resources that have been requested are |
---|
469 | cleared, resources allocated by the task are NOT automatically |
---|
470 | returned to RTEMS. A task cannot be restarted unless it has |
---|
471 | previously been started (i.e. dormant tasks cannot be |
---|
472 | restarted). All restarted tasks are placed in the ready state. |
---|
473 | |
---|
474 | Suspending and Resuming Tasks |
---|
475 | ----------------------------- |
---|
476 | |
---|
477 | The ``rtems.task_suspend`` |
---|
478 | directive is used to place either the caller or |
---|
479 | another task into a suspended state. The task remains suspended |
---|
480 | until a ``rtems.task_resume`` |
---|
481 | directive is issued. This implies that a |
---|
482 | task may be suspended as well as blocked waiting either to |
---|
483 | acquire a resource or for the expiration of a timer. |
---|
484 | |
---|
485 | The ``rtems.task_resume`` |
---|
486 | directive is used to remove another task from |
---|
487 | the suspended state. If the task is not also blocked, resuming |
---|
488 | it will place it in the ready state, allowing it to once again |
---|
489 | compete for the processor and resources. If the task was |
---|
490 | blocked as well as suspended, this directive clears the |
---|
491 | suspension and leaves the task in the blocked state. |
---|
492 | |
---|
493 | Suspending a task which is already suspended or resuming a |
---|
494 | task which is not suspended is considered an error. |
---|
495 | The ``rtems.task_is_suspended`` can be used to |
---|
496 | determine if a task is currently suspended. |
---|
497 | |
---|
498 | Delaying the Currently Executing Task |
---|
499 | ------------------------------------- |
---|
500 | |
---|
501 | The ``rtems.task_wake_after`` directive creates a sleep timer |
---|
502 | which allows a task to go to sleep for a specified interval. The task is |
---|
503 | blocked until the delay interval has elapsed, at which time the task is |
---|
504 | unblocked. A task calling the ``rtems.task_wake_after`` |
---|
505 | directive with a delay |
---|
506 | interval of ``RTEMS.YIELD_PROCESSOR`` ticks will yield the |
---|
507 | processor to any other ready task of equal or greater priority and remain |
---|
508 | ready to execute. |
---|
509 | |
---|
510 | The ``rtems.task_wake_when`` |
---|
511 | directive creates a sleep timer which allows |
---|
512 | a task to go to sleep until a specified date and time. The |
---|
513 | calling task is blocked until the specified date and time has |
---|
514 | occurred, at which time the task is unblocked. |
---|
515 | |
---|
516 | Changing Task Priority |
---|
517 | ---------------------- |
---|
518 | |
---|
519 | The ``rtems.task_set_priority`` |
---|
520 | directive is used to obtain or change the |
---|
521 | current priority of either the calling task or another task. If |
---|
522 | the new priority requested is``RTEMS.CURRENT_PRIORITY`` or the taskâs |
---|
523 | actual priority, then the current priority will be returned and |
---|
524 | the taskâs priority will remain unchanged. If the taskâs |
---|
525 | priority is altered, then the task will be scheduled according |
---|
526 | to its new priority. |
---|
527 | |
---|
528 | The ``rtems.task_restart`` |
---|
529 | directive resets the priority of a task to its |
---|
530 | original value. |
---|
531 | |
---|
532 | Changing Task Mode |
---|
533 | ------------------ |
---|
534 | |
---|
535 | The ``rtems.task_mode`` |
---|
536 | directive is used to obtain or change the current |
---|
537 | execution mode of the calling task. A taskâs execution mode is |
---|
538 | used to enable preemption, timeslicing, ASR processing, and to |
---|
539 | set the taskâs interrupt level. |
---|
540 | |
---|
541 | The ``rtems.task_restart`` |
---|
542 | directive resets the mode of a task to its |
---|
543 | original value. |
---|
544 | |
---|
545 | Task Deletion |
---|
546 | ------------- |
---|
547 | |
---|
548 | RTEMS provides the ``rtems.task_delete`` |
---|
549 | directive to allow a task to |
---|
550 | delete itself or any other task. This directive removes all |
---|
551 | RTEMS references to the task, frees the taskâs control block, |
---|
552 | removes it from resource wait queues, and deallocates its stack |
---|
553 | as well as the optional floating point context. The taskâs name |
---|
554 | and ID become inactive at this time, and any subsequent |
---|
555 | references to either of them is invalid. In fact, RTEMS may |
---|
556 | reuse the task ID for another task which is created later in the |
---|
557 | application. |
---|
558 | |
---|
559 | Unexpired delay timers (i.e. those used by``rtems.task_wake_after`` and``rtems.task_wake_when``) and |
---|
560 | timeout timers associated with the task are |
---|
561 | automatically deleted, however, other resources dynamically |
---|
562 | allocated by the task are NOT automatically returned to RTEMS. |
---|
563 | Therefore, before a task is deleted, all of its dynamically |
---|
564 | allocated resources should be deallocated by the user. This may |
---|
565 | be accomplished by instructing the task to delete itself rather |
---|
566 | than directly deleting the task. Other tasks may instruct a |
---|
567 | task to delete itself by sending a "delete self" message, event, |
---|
568 | or signal, or by restarting the task with special arguments |
---|
569 | which instruct the task to delete itself. |
---|
570 | |
---|
571 | Transition Advice for Obsolete Directives |
---|
572 | ----------------------------------------- |
---|
573 | |
---|
574 | Notepads |
---|
575 | ~~~~~~~~ |
---|
576 | |
---|
577 | Task notepads and the associated directives``rtems.task_get_note`` and``rtems.task_set_note`` were removed after the 4.11 Release |
---|
578 | Series. These were never thread-safe to access and subject to conflicting |
---|
579 | use of the notepad index by libraries which were designed independently. |
---|
580 | |
---|
581 | It is recommended that applications be modified to use services |
---|
582 | which are thread safe and not subject to issues with multiple applications |
---|
583 | conflicting over the key (e.g. notepad index) selection. For most |
---|
584 | applications, POSIX Keys should be used. These are available in all RTEMS |
---|
585 | build configurations. It is also possible that Thread Local Storage is |
---|
586 | an option for some use cases. |
---|
587 | |
---|
588 | Directives |
---|
589 | ========== |
---|
590 | |
---|
591 | This section details the task managerâs directives. A |
---|
592 | subsection is dedicated to each of this managerâs directives and |
---|
593 | describes the calling sequence, related constants, usage, and |
---|
594 | status codes. |
---|
595 | |
---|
596 | TASK_CREATE - Create a task |
---|
597 | --------------------------- |
---|
598 | .. index:: create a task |
---|
599 | |
---|
600 | **CALLING SEQUENCE:** |
---|
601 | |
---|
602 | .. code:: c |
---|
603 | |
---|
604 | procedure Task_Create ( |
---|
605 | Name : in RTEMS.Name; |
---|
606 | Initial_Priority : in RTEMS.Task_Priority; |
---|
607 | Stack_Size : in RTEMS.Unsigned32; |
---|
608 | Initial_Modes : in RTEMS.Mode; |
---|
609 | Attribute_Set : in RTEMS.Attribute; |
---|
610 | ID : out RTEMS.ID; |
---|
611 | Result : out RTEMS.Status_Codes |
---|
612 | ); |
---|
613 | |
---|
614 | **DIRECTIVE STATUS CODES:** |
---|
615 | |
---|
616 | ``RTEMS.SUCCESSFUL`` - task created successfully |
---|
617 | ``RTEMS.INVALID_ADDRESS`` - ``id`` is NULL |
---|
618 | ``RTEMS.INVALID_NAME`` - invalid task name |
---|
619 | ``RTEMS.INVALID_PRIORITY`` - invalid task priority |
---|
620 | ``RTEMS.MP_NOT_CONFIGURED`` - multiprocessing not configured |
---|
621 | ``RTEMS.TOO_MANY`` - too many tasks created |
---|
622 | ``RTEMS.UNSATISFIED`` - not enough memory for stack/FP context |
---|
623 | ``RTEMS.TOO_MANY`` - too many global objects |
---|
624 | |
---|
625 | **DESCRIPTION:** |
---|
626 | |
---|
627 | This directive creates a task which resides on the local node. |
---|
628 | It allocates and initializes a TCB, a stack, and an optional |
---|
629 | floating point context area. The mode parameter contains values |
---|
630 | which sets the taskâs initial execution mode. The``RTEMS.FLOATING_POINT`` attribute should be |
---|
631 | specified if the created task |
---|
632 | is to use a numeric coprocessor. For performance reasons, it is |
---|
633 | recommended that tasks not using the numeric coprocessor should |
---|
634 | specify the ``RTEMS.NO_FLOATING_POINT`` attribute. |
---|
635 | If the ``RTEMS.GLOBAL`` |
---|
636 | attribute is specified, the task can be accessed from remote |
---|
637 | nodes. The task id, returned in id, is used in other task |
---|
638 | related directives to access the task. When created, a task is |
---|
639 | placed in the dormant state and can only be made ready to |
---|
640 | execute using the directive ``rtems.task_start``. |
---|
641 | |
---|
642 | **NOTES:** |
---|
643 | |
---|
644 | This directive will not cause the calling task to be preempted. |
---|
645 | |
---|
646 | Valid task priorities range from a high of 1 to a low of 255. |
---|
647 | |
---|
648 | If the requested stack size is less than the configured |
---|
649 | minimum stack size, then RTEMS will use the configured |
---|
650 | minimum as the stack size for this task. In addition |
---|
651 | to being able to specify the task stack size as a integer, |
---|
652 | there are two constants which may be specified: |
---|
653 | |
---|
654 | - ``RTEMS.MINIMUM_STACK_SIZE`` |
---|
655 | is the minimum stack size *RECOMMENDED* for use on this processor. |
---|
656 | This value is selected by the RTEMS developers conservatively to |
---|
657 | minimize the risk of blown stacks for most user applications. |
---|
658 | Using this constant when specifying the task stack size, indicates |
---|
659 | that the stack size will be at least``RTEMS.MINIMUM_STACK_SIZE`` bytes in size. If the |
---|
660 | user configured minimum stack size is larger than the recommended |
---|
661 | minimum, then it will be used. |
---|
662 | |
---|
663 | - ``RTEMS.CONFIGURED_MINIMUM_STACK_SIZE`` |
---|
664 | indicates that this task is to be created with a stack size |
---|
665 | of the minimum stack size that was configured by the application. |
---|
666 | If not explicitly configured by the application, the default |
---|
667 | configured minimum stack size is the processor dependent value``RTEMS.MINIMUM_STACK_SIZE``. Since this uses |
---|
668 | the configured minimum stack size value, you may get a stack |
---|
669 | size that is smaller or larger than the recommended minimum. This |
---|
670 | can be used to provide large stacks for all tasks on complex |
---|
671 | applications or small stacks on applications that are trying |
---|
672 | to conserve memory. |
---|
673 | |
---|
674 | Application developers should consider the stack usage of the |
---|
675 | device drivers when calculating the stack size required for |
---|
676 | tasks which utilize the driver. |
---|
677 | |
---|
678 | The following task attribute constants are defined by RTEMS: |
---|
679 | |
---|
680 | - ``RTEMS.NO_FLOATING_POINT`` - does not use coprocessor (default) |
---|
681 | |
---|
682 | - ``RTEMS.FLOATING_POINT`` - uses numeric coprocessor |
---|
683 | |
---|
684 | - ``RTEMS.LOCAL`` - local task (default) |
---|
685 | |
---|
686 | - ``RTEMS.GLOBAL`` - global task |
---|
687 | |
---|
688 | The following task mode constants are defined by RTEMS: |
---|
689 | |
---|
690 | - ``RTEMS.PREEMPT`` - enable preemption (default) |
---|
691 | |
---|
692 | - ``RTEMS.NO_PREEMPT`` - disable preemption |
---|
693 | |
---|
694 | - ``RTEMS.NO_TIMESLICE`` - disable timeslicing (default) |
---|
695 | |
---|
696 | - ``RTEMS.TIMESLICE`` - enable timeslicing |
---|
697 | |
---|
698 | - ``RTEMS.ASR`` - enable ASR processing (default) |
---|
699 | |
---|
700 | - ``RTEMS.NO_ASR`` - disable ASR processing |
---|
701 | |
---|
702 | - ``RTEMS.INTERRUPT_LEVEL(0)`` - enable all interrupts (default) |
---|
703 | |
---|
704 | - ``RTEMS.INTERRUPT_LEVEL(n)`` - execute at interrupt level n |
---|
705 | |
---|
706 | The interrupt level portion of the task execution mode |
---|
707 | supports a maximum of 256 interrupt levels. These levels are |
---|
708 | mapped onto the interrupt levels actually supported by the |
---|
709 | target processor in a processor dependent fashion. |
---|
710 | |
---|
711 | Tasks should not be made global unless remote tasks must |
---|
712 | interact with them. This avoids the system overhead incurred by |
---|
713 | the creation of a global task. When a global task is created, |
---|
714 | the taskâs name and id must be transmitted to every node in the |
---|
715 | system for insertion in the local copy of the global object |
---|
716 | table. |
---|
717 | |
---|
718 | The total number of global objects, including tasks, is limited |
---|
719 | by the maximum_global_objects field in the Configuration Table. |
---|
720 | |
---|
721 | TASK_IDENT - Get ID of a task |
---|
722 | ----------------------------- |
---|
723 | .. index:: get ID of a task |
---|
724 | |
---|
725 | **CALLING SEQUENCE:** |
---|
726 | |
---|
727 | .. code:: c |
---|
728 | |
---|
729 | procedure Task_Ident ( |
---|
730 | Name : in RTEMS.Name; |
---|
731 | Node : in RTEMS.Node; |
---|
732 | ID : out RTEMS.ID; |
---|
733 | Result : out RTEMS.Status_Codes |
---|
734 | ); |
---|
735 | |
---|
736 | **DIRECTIVE STATUS CODES:** |
---|
737 | |
---|
738 | ``RTEMS.SUCCESSFUL`` - task identified successfully |
---|
739 | ``RTEMS.INVALID_ADDRESS`` - ``id`` is NULL |
---|
740 | ``RTEMS.INVALID_NAME`` - invalid task name |
---|
741 | ``RTEMS.INVALID_NODE`` - invalid node id |
---|
742 | |
---|
743 | **DESCRIPTION:** |
---|
744 | |
---|
745 | This directive obtains the task id associated with the task name |
---|
746 | specified in name. A task may obtain its own id by specifying``RTEMS.SELF`` or its own task name in name. If the task name is not |
---|
747 | unique, then the task id returned will match one of the tasks |
---|
748 | with that name. However, this task id is not guaranteed to |
---|
749 | correspond to the desired task. The task id, returned in id, is |
---|
750 | used in other task related directives to access the task. |
---|
751 | |
---|
752 | **NOTES:** |
---|
753 | |
---|
754 | This directive will not cause the running task to be preempted. |
---|
755 | |
---|
756 | If node is ``RTEMS.SEARCH_ALL_NODES``, all nodes are searched with the |
---|
757 | local node being searched first. All other nodes are searched |
---|
758 | with the lowest numbered node searched first. |
---|
759 | |
---|
760 | If node is a valid node number which does not represent the |
---|
761 | local node, then only the tasks exported by the designated node |
---|
762 | are searched. |
---|
763 | |
---|
764 | This directive does not generate activity on remote nodes. It |
---|
765 | accesses only the local copy of the global object table. |
---|
766 | |
---|
767 | TASK_SELF - Obtain ID of caller |
---|
768 | ------------------------------- |
---|
769 | .. index:: obtain ID of caller |
---|
770 | |
---|
771 | **CALLING SEQUENCE:** |
---|
772 | |
---|
773 | .. code:: c |
---|
774 | |
---|
775 | function Task_Self return RTEMS.ID; |
---|
776 | |
---|
777 | **DIRECTIVE STATUS CODES:** |
---|
778 | |
---|
779 | Returns the object Id of the calling task. |
---|
780 | |
---|
781 | **DESCRIPTION:** |
---|
782 | |
---|
783 | This directive returns the Id of the calling task. |
---|
784 | |
---|
785 | **NOTES:** |
---|
786 | |
---|
787 | If called from an interrupt service routine, this directive |
---|
788 | will return the Id of the interrupted task. |
---|
789 | |
---|
790 | TASK_START - Start a task |
---|
791 | ------------------------- |
---|
792 | .. index:: starting a task |
---|
793 | |
---|
794 | **CALLING SEQUENCE:** |
---|
795 | |
---|
796 | .. code:: c |
---|
797 | |
---|
798 | procedure Task_Start ( |
---|
799 | ID : in RTEMS.ID; |
---|
800 | Entry_Point : in RTEMS.Task_Entry; |
---|
801 | Argument : in RTEMS.Task_Argument; |
---|
802 | Result : out RTEMS.Status_Codes |
---|
803 | ); |
---|
804 | |
---|
805 | **DIRECTIVE STATUS CODES:** |
---|
806 | |
---|
807 | ``RTEMS.SUCCESSFUL`` - ask started successfully |
---|
808 | ``RTEMS.INVALID_ADDRESS`` - invalid task entry point |
---|
809 | ``RTEMS.INVALID_ID`` - invalid task id |
---|
810 | ``RTEMS.INCORRECT_STATE`` - task not in the dormant state |
---|
811 | ``RTEMS.ILLEGAL_ON_REMOTE_OBJECT`` - cannot start remote task |
---|
812 | |
---|
813 | **DESCRIPTION:** |
---|
814 | |
---|
815 | This directive readies the task, specified by ``id``, for execution |
---|
816 | based on the priority and execution mode specified when the task |
---|
817 | was created. The starting address of the task is given in``entry_point``. The taskâs starting argument is contained in |
---|
818 | argument. This argument can be a single value or used as an index into an |
---|
819 | array of parameter blocks. The type of this numeric argument is an unsigned |
---|
820 | integer type with the property that any valid pointer to void can be converted |
---|
821 | to this type and then converted back to a pointer to void. The result will |
---|
822 | compare equal to the original pointer. |
---|
823 | |
---|
824 | **NOTES:** |
---|
825 | |
---|
826 | The calling task will be preempted if its preemption mode is |
---|
827 | enabled and the task being started has a higher priority. |
---|
828 | |
---|
829 | Any actions performed on a dormant task such as suspension or |
---|
830 | change of priority are nullified when the task is initiated via |
---|
831 | the ``rtems.task_start`` directive. |
---|
832 | |
---|
833 | TASK_RESTART - Restart a task |
---|
834 | ----------------------------- |
---|
835 | .. index:: restarting a task |
---|
836 | |
---|
837 | **CALLING SEQUENCE:** |
---|
838 | |
---|
839 | .. code:: c |
---|
840 | |
---|
841 | procedure Task_Restart ( |
---|
842 | ID : in RTEMS.ID; |
---|
843 | Argument : in RTEMS.Task_Argument; |
---|
844 | Result : out RTEMS.Status_Codes |
---|
845 | ); |
---|
846 | |
---|
847 | **DIRECTIVE STATUS CODES:** |
---|
848 | |
---|
849 | ``RTEMS.SUCCESSFUL`` - task restarted successfully |
---|
850 | ``RTEMS.INVALID_ID`` - task id invalid |
---|
851 | ``RTEMS.INCORRECT_STATE`` - task never started |
---|
852 | ``RTEMS.ILLEGAL_ON_REMOTE_OBJECT`` - cannot restart remote task |
---|
853 | |
---|
854 | **DESCRIPTION:** |
---|
855 | |
---|
856 | This directive resets the task specified by id to begin |
---|
857 | execution at its original starting address. The taskâs priority |
---|
858 | and execution mode are set to the original creation values. If |
---|
859 | the task is currently blocked, RTEMS automatically makes the |
---|
860 | task ready. A task can be restarted from any state, except the |
---|
861 | dormant state. |
---|
862 | |
---|
863 | The taskâs starting argument is contained in argument. This argument can be a |
---|
864 | single value or an index into an array of parameter blocks. The type of this |
---|
865 | numeric argument is an unsigned integer type with the property that any valid |
---|
866 | pointer to void can be converted to this type and then converted back to a |
---|
867 | pointer to void. The result will compare equal to the original pointer. This |
---|
868 | new argument may be used to distinguish |
---|
869 | between the initial ``rtems.task_start`` |
---|
870 | of the task and any ensuing calls |
---|
871 | to ``rtems.task_restart`` |
---|
872 | of the task. This can be beneficial in deleting |
---|
873 | a task. Instead of deleting a task using |
---|
874 | the ``rtems.task_delete`` |
---|
875 | directive, a task can delete another task by restarting that |
---|
876 | task, and allowing that task to release resources back to RTEMS |
---|
877 | and then delete itself. |
---|
878 | |
---|
879 | **NOTES:** |
---|
880 | |
---|
881 | If id is ``RTEMS.SELF``, the calling task will be restarted and will not |
---|
882 | return from this directive. |
---|
883 | |
---|
884 | The calling task will be preempted if its preemption mode is |
---|
885 | enabled and the task being restarted has a higher priority. |
---|
886 | |
---|
887 | The task must reside on the local node, even if the task was |
---|
888 | created with the ``RTEMS.GLOBAL`` option. |
---|
889 | |
---|
890 | TASK_DELETE - Delete a task |
---|
891 | --------------------------- |
---|
892 | .. index:: deleting a task |
---|
893 | |
---|
894 | **CALLING SEQUENCE:** |
---|
895 | |
---|
896 | .. code:: c |
---|
897 | |
---|
898 | procedure Task_Delete ( |
---|
899 | ID : in RTEMS.ID; |
---|
900 | Result : out RTEMS.Status_Codes |
---|
901 | ); |
---|
902 | |
---|
903 | **DIRECTIVE STATUS CODES:** |
---|
904 | |
---|
905 | ``RTEMS.SUCCESSFUL`` - task deleted successfully |
---|
906 | ``RTEMS.INVALID_ID`` - task id invalid |
---|
907 | ``RTEMS.ILLEGAL_ON_REMOTE_OBJECT`` - cannot restart remote task |
---|
908 | |
---|
909 | **DESCRIPTION:** |
---|
910 | |
---|
911 | This directive deletes a task, either the calling task or |
---|
912 | another task, as specified by id. RTEMS stops the execution of |
---|
913 | the task and reclaims the stack memory, any allocated delay or |
---|
914 | timeout timers, the TCB, and, if the task is ``RTEMS.FLOATING_POINT``, its |
---|
915 | floating point context area. RTEMS does not reclaim the |
---|
916 | following resources: region segments, partition buffers, |
---|
917 | semaphores, timers, or rate monotonic periods. |
---|
918 | |
---|
919 | **NOTES:** |
---|
920 | |
---|
921 | A task is responsible for releasing its resources back to RTEMS |
---|
922 | before deletion. To insure proper deallocation of resources, a |
---|
923 | task should not be deleted unless it is unable to execute or |
---|
924 | does not hold any RTEMS resources. If a task holds RTEMS |
---|
925 | resources, the task should be allowed to deallocate its |
---|
926 | resources before deletion. A task can be directed to release |
---|
927 | its resources and delete itself by restarting it with a special |
---|
928 | argument or by sending it a message, an event, or a signal. |
---|
929 | |
---|
930 | Deletion of the current task (``RTEMS.SELF``) will force RTEMS to select |
---|
931 | another task to execute. |
---|
932 | |
---|
933 | When a global task is deleted, the task id must be transmitted |
---|
934 | to every node in the system for deletion from the local copy of |
---|
935 | the global object table. |
---|
936 | |
---|
937 | The task must reside on the local node, even if the task was |
---|
938 | created with the ``RTEMS.GLOBAL`` option. |
---|
939 | |
---|
940 | TASK_SUSPEND - Suspend a task |
---|
941 | ----------------------------- |
---|
942 | .. index:: suspending a task |
---|
943 | |
---|
944 | **CALLING SEQUENCE:** |
---|
945 | |
---|
946 | .. code:: c |
---|
947 | |
---|
948 | procedure Task_Suspend ( |
---|
949 | ID : in RTEMS.ID; |
---|
950 | Result : out RTEMS.Status_Codes |
---|
951 | ); |
---|
952 | |
---|
953 | **DIRECTIVE STATUS CODES:** |
---|
954 | |
---|
955 | ``RTEMS.SUCCESSFUL`` - task suspended successfully |
---|
956 | ``RTEMS.INVALID_ID`` - task id invalid |
---|
957 | ``RTEMS.ALREADY_SUSPENDED`` - task already suspended |
---|
958 | |
---|
959 | **DESCRIPTION:** |
---|
960 | |
---|
961 | This directive suspends the task specified by id from further |
---|
962 | execution by placing it in the suspended state. This state is |
---|
963 | additive to any other blocked state that the task may already be |
---|
964 | in. The task will not execute again until another task issues |
---|
965 | the ``rtems.task_resume`` |
---|
966 | directive for this task and any blocked state |
---|
967 | has been removed. |
---|
968 | |
---|
969 | **NOTES:** |
---|
970 | |
---|
971 | The requesting task can suspend itself by specifying ``RTEMS.SELF`` as id. |
---|
972 | In this case, the task will be suspended and a successful |
---|
973 | return code will be returned when the task is resumed. |
---|
974 | |
---|
975 | Suspending a global task which does not reside on the local node |
---|
976 | will generate a request to the remote node to suspend the |
---|
977 | specified task. |
---|
978 | |
---|
979 | If the task specified by id is already suspended, then the``RTEMS.ALREADY_SUSPENDED`` status code is returned. |
---|
980 | |
---|
981 | TASK_RESUME - Resume a task |
---|
982 | --------------------------- |
---|
983 | .. index:: resuming a task |
---|
984 | |
---|
985 | **CALLING SEQUENCE:** |
---|
986 | |
---|
987 | .. code:: c |
---|
988 | |
---|
989 | procedure Task_Resume ( |
---|
990 | ID : in RTEMS.ID; |
---|
991 | Result : out RTEMS.Status_Codes |
---|
992 | ); |
---|
993 | |
---|
994 | **DIRECTIVE STATUS CODES:** |
---|
995 | |
---|
996 | ``RTEMS.SUCCESSFUL`` - task resumed successfully |
---|
997 | ``RTEMS.INVALID_ID`` - task id invalid |
---|
998 | ``RTEMS.INCORRECT_STATE`` - task not suspended |
---|
999 | |
---|
1000 | **DESCRIPTION:** |
---|
1001 | |
---|
1002 | This directive removes the task specified by id from the |
---|
1003 | suspended state. If the task is in the ready state after the |
---|
1004 | suspension is removed, then it will be scheduled to run. If the |
---|
1005 | task is still in a blocked state after the suspension is |
---|
1006 | removed, then it will remain in that blocked state. |
---|
1007 | |
---|
1008 | **NOTES:** |
---|
1009 | |
---|
1010 | The running task may be preempted if its preemption mode is |
---|
1011 | enabled and the local task being resumed has a higher priority. |
---|
1012 | |
---|
1013 | Resuming a global task which does not reside on the local node |
---|
1014 | will generate a request to the remote node to resume the |
---|
1015 | specified task. |
---|
1016 | |
---|
1017 | If the task specified by id is not suspended, then the``RTEMS.INCORRECT_STATE`` status code is returned. |
---|
1018 | |
---|
1019 | TASK_IS_SUSPENDED - Determine if a task is Suspended |
---|
1020 | ---------------------------------------------------- |
---|
1021 | .. index:: is task suspended |
---|
1022 | |
---|
1023 | **CALLING SEQUENCE:** |
---|
1024 | |
---|
1025 | .. code:: c |
---|
1026 | |
---|
1027 | procedure Task_Is_Suspended ( |
---|
1028 | ID : in RTEMS.ID; |
---|
1029 | Result : out RTEMS.Status_Codes |
---|
1030 | ); |
---|
1031 | |
---|
1032 | **DIRECTIVE STATUS CODES:** |
---|
1033 | |
---|
1034 | ``RTEMS.SUCCESSFUL`` - task is NOT suspended |
---|
1035 | ``RTEMS.ALREADY_SUSPENDED`` - task is currently suspended |
---|
1036 | ``RTEMS.INVALID_ID`` - task id invalid |
---|
1037 | ``RTEMS.ILLEGAL_ON_REMOTE_OBJECT`` - not supported on remote tasks |
---|
1038 | |
---|
1039 | **DESCRIPTION:** |
---|
1040 | |
---|
1041 | This directive returns a status code indicating whether or |
---|
1042 | not the specified task is currently suspended. |
---|
1043 | |
---|
1044 | **NOTES:** |
---|
1045 | |
---|
1046 | This operation is not currently supported on remote tasks. |
---|
1047 | |
---|
1048 | TASK_SET_PRIORITY - Set task priority |
---|
1049 | ------------------------------------- |
---|
1050 | .. index:: rtems_task_set_priority |
---|
1051 | .. index:: current task priority |
---|
1052 | .. index:: set task priority |
---|
1053 | .. index:: get task priority |
---|
1054 | .. index:: obtain task priority |
---|
1055 | |
---|
1056 | **CALLING SEQUENCE:** |
---|
1057 | |
---|
1058 | .. code:: c |
---|
1059 | |
---|
1060 | procedure Task_Set_Priority ( |
---|
1061 | ID : in RTEMS.ID; |
---|
1062 | New_Priority : in RTEMS.Task_Priority; |
---|
1063 | Old_Priority : out RTEMS.Task_Priority; |
---|
1064 | Result : out RTEMS.Status_Codes |
---|
1065 | ); |
---|
1066 | |
---|
1067 | **DIRECTIVE STATUS CODES:** |
---|
1068 | |
---|
1069 | ``RTEMS.SUCCESSFUL`` - task priority set successfully |
---|
1070 | ``RTEMS.INVALID_ID`` - invalid task id |
---|
1071 | ``RTEMS.INVALID_ADDRESS`` - invalid return argument pointer |
---|
1072 | ``RTEMS.INVALID_PRIORITY`` - invalid task priority |
---|
1073 | |
---|
1074 | **DESCRIPTION:** |
---|
1075 | |
---|
1076 | This directive manipulates the priority of the task specified by |
---|
1077 | id. An id of ``RTEMS.SELF`` is used to indicate |
---|
1078 | the calling task. When new_priority is not equal to``RTEMS.CURRENT_PRIORITY``, the specified |
---|
1079 | taskâs previous priority is returned in old_priority. When |
---|
1080 | new_priority is ``RTEMS.CURRENT_PRIORITY``, |
---|
1081 | the specified taskâs current |
---|
1082 | priority is returned in old_priority. Valid priorities range |
---|
1083 | from a high of 1 to a low of 255. |
---|
1084 | |
---|
1085 | **NOTES:** |
---|
1086 | |
---|
1087 | The calling task may be preempted if its preemption mode is |
---|
1088 | enabled and it lowers its own priority or raises another taskâs |
---|
1089 | priority. |
---|
1090 | |
---|
1091 | In case the new priority equals the current priority of the task, then nothing |
---|
1092 | happens. |
---|
1093 | |
---|
1094 | Setting the priority of a global task which does not reside on |
---|
1095 | the local node will generate a request to the remote node to |
---|
1096 | change the priority of the specified task. |
---|
1097 | |
---|
1098 | If the task specified by id is currently holding any binary |
---|
1099 | semaphores which use the priority inheritance algorithm, then |
---|
1100 | the taskâs priority cannot be lowered immediately. If the |
---|
1101 | taskâs priority were lowered immediately, then priority |
---|
1102 | inversion results. The requested lowering of the taskâs |
---|
1103 | priority will occur when the task has released all priority |
---|
1104 | inheritance binary semaphores. The taskâs priority can be |
---|
1105 | increased regardless of the taskâs use of priority inheritance |
---|
1106 | binary semaphores. |
---|
1107 | |
---|
1108 | TASK_MODE - Change the current task mode |
---|
1109 | ---------------------------------------- |
---|
1110 | .. index:: current task mode |
---|
1111 | .. index:: set task mode |
---|
1112 | .. index:: get task mode |
---|
1113 | .. index:: set task preemption mode |
---|
1114 | .. index:: get task preemption mode |
---|
1115 | .. index:: obtain task mode |
---|
1116 | |
---|
1117 | **CALLING SEQUENCE:** |
---|
1118 | |
---|
1119 | .. code:: c |
---|
1120 | |
---|
1121 | procedure Task_Mode ( |
---|
1122 | Mode_Set : in RTEMS.Mode; |
---|
1123 | Mask : in RTEMS.Mode; |
---|
1124 | Previous_Mode_Set : in RTEMS.Mode; |
---|
1125 | Result : out RTEMS.Status_Codes |
---|
1126 | ); |
---|
1127 | |
---|
1128 | **DIRECTIVE STATUS CODES:** |
---|
1129 | |
---|
1130 | ``RTEMS.SUCCESSFUL`` - task mode set successfully |
---|
1131 | ``RTEMS.INVALID_ADDRESS`` - ``previous_mode_set`` is NULL |
---|
1132 | |
---|
1133 | **DESCRIPTION:** |
---|
1134 | |
---|
1135 | This directive manipulates the execution mode of the calling |
---|
1136 | task. A taskâs execution mode enables and disables preemption, |
---|
1137 | timeslicing, asynchronous signal processing, as well as |
---|
1138 | specifying the current interrupt level. To modify an execution |
---|
1139 | mode, the mode class(es) to be changed must be specified in the |
---|
1140 | mask parameter and the desired mode(s) must be specified in the |
---|
1141 | mode parameter. |
---|
1142 | |
---|
1143 | **NOTES:** |
---|
1144 | |
---|
1145 | The calling task will be preempted if it enables preemption and |
---|
1146 | a higher priority task is ready to run. |
---|
1147 | |
---|
1148 | Enabling timeslicing has no effect if preemption is disabled. For |
---|
1149 | a task to be timesliced, that task must have both preemption and |
---|
1150 | timeslicing enabled. |
---|
1151 | |
---|
1152 | A task can obtain its current execution mode, without modifying |
---|
1153 | it, by calling this directive with a mask value of``RTEMS.CURRENT_MODE``. |
---|
1154 | |
---|
1155 | To temporarily disable the processing of a valid ASR, a task |
---|
1156 | should call this directive with the ``RTEMS.NO_ASR`` |
---|
1157 | indicator specified in mode. |
---|
1158 | |
---|
1159 | The set of task mode constants and each modeâs corresponding |
---|
1160 | mask constant is provided in the following table: |
---|
1161 | |
---|
1162 | - ``RTEMS.PREEMPT`` is masked by``RTEMS.PREEMPT_MASK`` and enables preemption |
---|
1163 | |
---|
1164 | - ``RTEMS.NO_PREEMPT`` is masked by``RTEMS.PREEMPT_MASK`` and disables preemption |
---|
1165 | |
---|
1166 | - ``RTEMS.NO_TIMESLICE`` is masked by``RTEMS.TIMESLICE_MASK`` and disables timeslicing |
---|
1167 | |
---|
1168 | - ``RTEMS.TIMESLICE`` is masked by``RTEMS.TIMESLICE_MASK`` and enables timeslicing |
---|
1169 | |
---|
1170 | - ``RTEMS.ASR`` is masked by``RTEMS.ASR_MASK`` and enables ASR processing |
---|
1171 | |
---|
1172 | - ``RTEMS.NO_ASR`` is masked by``RTEMS.ASR_MASK`` and disables ASR processing |
---|
1173 | |
---|
1174 | - ``RTEMS.INTERRUPT_LEVEL(0)`` is masked by``RTEMS.INTERRUPT_MASK`` and enables all interrupts |
---|
1175 | |
---|
1176 | - ``RTEMS.INTERRUPT_LEVEL(n)`` is masked by``RTEMS.INTERRUPT_MASK`` and sets interrupts level n |
---|
1177 | |
---|
1178 | TASK_WAKE_AFTER - Wake up after interval |
---|
1179 | ---------------------------------------- |
---|
1180 | .. index:: delay a task for an interval |
---|
1181 | .. index:: wake up after an interval |
---|
1182 | |
---|
1183 | **CALLING SEQUENCE:** |
---|
1184 | |
---|
1185 | .. code:: c |
---|
1186 | |
---|
1187 | procedure Task_Wake_After ( |
---|
1188 | Ticks : in RTEMS.Interval; |
---|
1189 | Result : out RTEMS.Status_Codes |
---|
1190 | ); |
---|
1191 | |
---|
1192 | **DIRECTIVE STATUS CODES:** |
---|
1193 | |
---|
1194 | ``RTEMS.SUCCESSFUL`` - always successful |
---|
1195 | |
---|
1196 | **DESCRIPTION:** |
---|
1197 | |
---|
1198 | This directive blocks the calling task for the specified number |
---|
1199 | of system clock ticks. When the requested interval has elapsed, |
---|
1200 | the task is made ready. The ``rtems.clock_tick`` |
---|
1201 | directive automatically updates the delay period. |
---|
1202 | |
---|
1203 | **NOTES:** |
---|
1204 | |
---|
1205 | Setting the system date and time with the``rtems.clock_set`` directive |
---|
1206 | has no effect on a ``rtems.task_wake_after`` blocked task. |
---|
1207 | |
---|
1208 | A task may give up the processor and remain in the ready state |
---|
1209 | by specifying a value of ``RTEMS.YIELD_PROCESSOR`` in ticks. |
---|
1210 | |
---|
1211 | The maximum timer interval that can be specified is the maximum |
---|
1212 | value which can be represented by the uint32_t type. |
---|
1213 | |
---|
1214 | A clock tick is required to support the functionality of this directive. |
---|
1215 | |
---|
1216 | TASK_WAKE_WHEN - Wake up when specified |
---|
1217 | --------------------------------------- |
---|
1218 | .. index:: delay a task until a wall time |
---|
1219 | .. index:: wake up at a wall time |
---|
1220 | |
---|
1221 | **CALLING SEQUENCE:** |
---|
1222 | |
---|
1223 | .. code:: c |
---|
1224 | |
---|
1225 | procedure Task_Wake_When ( |
---|
1226 | Time_Buffer : in RTEMS.Time_Of_Day; |
---|
1227 | Result : out RTEMS.Status_Codes |
---|
1228 | ); |
---|
1229 | |
---|
1230 | **DIRECTIVE STATUS CODES:** |
---|
1231 | |
---|
1232 | ``RTEMS.SUCCESSFUL`` - awakened at date/time successfully |
---|
1233 | ``RTEMS.INVALID_ADDRESS`` - ``time_buffer`` is NULL |
---|
1234 | ``RTEMS.INVALID_TIME_OF_DAY`` - invalid time buffer |
---|
1235 | ``RTEMS.NOT_DEFINED`` - system date and time is not set |
---|
1236 | |
---|
1237 | **DESCRIPTION:** |
---|
1238 | |
---|
1239 | This directive blocks a task until the date and time specified |
---|
1240 | in time_buffer. At the requested date and time, the calling |
---|
1241 | task will be unblocked and made ready to execute. |
---|
1242 | |
---|
1243 | **NOTES:** |
---|
1244 | |
---|
1245 | The ticks portion of time_buffer record is ignored. The |
---|
1246 | timing granularity of this directive is a second. |
---|
1247 | |
---|
1248 | A clock tick is required to support the functionality of this directive. |
---|
1249 | |
---|
1250 | ITERATE_OVER_ALL_THREADS - Iterate Over Tasks |
---|
1251 | --------------------------------------------- |
---|
1252 | .. index:: iterate over all threads |
---|
1253 | |
---|
1254 | **CALLING SEQUENCE:** |
---|
1255 | |
---|
1256 | .. code:: c |
---|
1257 | |
---|
1258 | NOT SUPPORTED FROM Ada BINDING |
---|
1259 | |
---|
1260 | **DIRECTIVE STATUS CODES: NONE** |
---|
1261 | |
---|
1262 | **DESCRIPTION:** |
---|
1263 | |
---|
1264 | This directive iterates over all of the existant threads in the |
---|
1265 | system and invokes ``routine`` on each of them. The user should |
---|
1266 | be careful in accessing the contents of ``the_thread``. |
---|
1267 | |
---|
1268 | This routine is intended for use in diagnostic utilities and is |
---|
1269 | not intented for routine use in an operational system. |
---|
1270 | |
---|
1271 | **NOTES:** |
---|
1272 | |
---|
1273 | There is NO protection while this routine is called. Thus it is |
---|
1274 | possible that ``the_thread`` could be deleted while this is operating. |
---|
1275 | By not having protection, the user is free to invoke support routines |
---|
1276 | from the C Library which require semaphores for data structures. |
---|
1277 | |
---|
1278 | TASK_VARIABLE_ADD - Associate per task variable |
---|
1279 | ----------------------------------------------- |
---|
1280 | .. index:: per-task variable |
---|
1281 | .. index:: task private variable |
---|
1282 | .. index:: task private data |
---|
1283 | |
---|
1284 | **CALLING SEQUENCE:** |
---|
1285 | |
---|
1286 | .. code:: c |
---|
1287 | |
---|
1288 | type Task_Variable_Dtor is access procedure ( |
---|
1289 | Argument : in RTEMS.Address; |
---|
1290 | ); |
---|
1291 | procedure Task_Variable_Add ( |
---|
1292 | ID : in RTEMS.ID; |
---|
1293 | Task_Variable : in RTEMS.Address; |
---|
1294 | Dtor : in RTEMS.Task_Variable_Dtor; |
---|
1295 | Result : out RTEMS.Status_Codes |
---|
1296 | ); |
---|
1297 | |
---|
1298 | **DIRECTIVE STATUS CODES:** |
---|
1299 | |
---|
1300 | ``RTEMS.SUCCESSFUL`` - per task variable added successfully |
---|
1301 | ``RTEMS.INVALID_ADDRESS`` - ``task_variable`` is NULL |
---|
1302 | ``RTEMS.INVALID_ID`` - invalid task id |
---|
1303 | ``RTEMS.NO_MEMORY`` - invalid task id |
---|
1304 | ``RTEMS.ILLEGAL_ON_REMOTE_OBJECT`` - not supported on remote tasks |
---|
1305 | |
---|
1306 | **DESCRIPTION:** |
---|
1307 | |
---|
1308 | This directive adds the memory location specified by the |
---|
1309 | ptr argument to the context of the given task. The variable will |
---|
1310 | then be private to the task. The task can access and modify the |
---|
1311 | variable, but the modifications will not appear to other tasks, and |
---|
1312 | other tasksâ modifications to that variable will not affect the value |
---|
1313 | seen by the task. This is accomplished by saving and restoring the |
---|
1314 | variableâs value each time a task switch occurs to or from the calling task. |
---|
1315 | If the dtor argument is non-NULL it specifies the address of a âdestructorâ |
---|
1316 | function which will be called when the task is deleted. The argument |
---|
1317 | passed to the destructor function is the taskâs value of the variable. |
---|
1318 | |
---|
1319 | **NOTES:** |
---|
1320 | |
---|
1321 | This directive is deprecated and task variables will be removed. |
---|
1322 | |
---|
1323 | Task variables increase the context switch time to and from the |
---|
1324 | tasks that own them so it is desirable to minimize the number of |
---|
1325 | task variables. One efficient method |
---|
1326 | is to have a single task variable that is a pointer to a dynamically |
---|
1327 | allocated structure containing the taskâs private âglobalâ data. |
---|
1328 | In this case the destructor function could be âfreeâ. |
---|
1329 | |
---|
1330 | Per-task variables are disabled in SMP configurations and this service |
---|
1331 | is not available. |
---|
1332 | |
---|
1333 | TASK_VARIABLE_GET - Obtain value of a per task variable |
---|
1334 | ------------------------------------------------------- |
---|
1335 | .. index:: get per-task variable |
---|
1336 | .. index:: obtain per-task variable |
---|
1337 | |
---|
1338 | **CALLING SEQUENCE:** |
---|
1339 | |
---|
1340 | .. code:: c |
---|
1341 | |
---|
1342 | procedure Task_Variable_Get ( |
---|
1343 | ID : in RTEMS.ID; |
---|
1344 | Task_Variable : out RTEMS.Address; |
---|
1345 | Task_Variable_Value : out RTEMS.Address; |
---|
1346 | Result : out RTEMS.Status_Codes |
---|
1347 | ); |
---|
1348 | |
---|
1349 | **DIRECTIVE STATUS CODES:** |
---|
1350 | |
---|
1351 | ``RTEMS.SUCCESSFUL`` - per task variable obtained successfully |
---|
1352 | ``RTEMS.INVALID_ADDRESS`` - ``task_variable`` is NULL |
---|
1353 | ``RTEMS.INVALID_ADDRESS`` - ``task_variable_value`` is NULL |
---|
1354 | ``RTEMS.INVALID_ADDRESS`` - ``task_variable`` is not found |
---|
1355 | ``RTEMS.NO_MEMORY`` - invalid task id |
---|
1356 | ``RTEMS.ILLEGAL_ON_REMOTE_OBJECT`` - not supported on remote tasks |
---|
1357 | |
---|
1358 | **DESCRIPTION:** |
---|
1359 | |
---|
1360 | This directive looks up the private value of a task variable for a |
---|
1361 | specified task and stores that value in the location pointed to by |
---|
1362 | the result argument. The specified task is usually not the calling |
---|
1363 | task, which can get its private value by directly accessing the variable. |
---|
1364 | |
---|
1365 | **NOTES:** |
---|
1366 | |
---|
1367 | This directive is deprecated and task variables will be removed. |
---|
1368 | |
---|
1369 | If you change memory which ``task_variable_value`` points to, |
---|
1370 | remember to declare that memory as volatile, so that the compiler |
---|
1371 | will optimize it correctly. In this case both the pointer``task_variable_value`` and data referenced by ``task_variable_value`` |
---|
1372 | should be considered volatile. |
---|
1373 | |
---|
1374 | Per-task variables are disabled in SMP configurations and this service |
---|
1375 | is not available. |
---|
1376 | |
---|
1377 | TASK_VARIABLE_DELETE - Remove per task variable |
---|
1378 | ----------------------------------------------- |
---|
1379 | .. index:: per-task variable |
---|
1380 | .. index:: task private variable |
---|
1381 | .. index:: task private data |
---|
1382 | |
---|
1383 | **CALLING SEQUENCE:** |
---|
1384 | |
---|
1385 | .. code:: c |
---|
1386 | |
---|
1387 | procedure Task_Variable_Delete ( |
---|
1388 | ID : in RTEMS.ID; |
---|
1389 | Task_Variable : out RTEMS.Address; |
---|
1390 | Result : out RTEMS.Status_Codes |
---|
1391 | ); |
---|
1392 | |
---|
1393 | **DIRECTIVE STATUS CODES:** |
---|
1394 | |
---|
1395 | ``RTEMS.SUCCESSFUL`` - per task variable deleted successfully |
---|
1396 | ``RTEMS.INVALID_ID`` - invalid task id |
---|
1397 | ``RTEMS.NO_MEMORY`` - invalid task id |
---|
1398 | ``RTEMS.INVALID_ADDRESS`` - ``task_variable`` is NULL |
---|
1399 | ``RTEMS.ILLEGAL_ON_REMOTE_OBJECT`` - not supported on remote tasks |
---|
1400 | |
---|
1401 | **DESCRIPTION:** |
---|
1402 | |
---|
1403 | This directive removes the given location from a taskâs context. |
---|
1404 | |
---|
1405 | **NOTES:** |
---|
1406 | |
---|
1407 | This directive is deprecated and task variables will be removed. |
---|
1408 | |
---|
1409 | Per-task variables are disabled in SMP configurations and this service |
---|
1410 | is not available. |
---|
1411 | |
---|
1412 | .. COMMENT: COPYRIGHT (c) 1988-2008. |
---|
1413 | |
---|
1414 | .. COMMENT: On-Line Applications Research Corporation (OAR). |
---|
1415 | |
---|
1416 | .. COMMENT: All rights reserved. |
---|
1417 | |
---|