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