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