source: rtems-docs/c-user/task_manager.rst @ 56cccd6

5
Last change on this file since 56cccd6 was 56cccd6, checked in by Sebastian Huber <sebastian.huber@…>, on 09/14/17 at 08:52:44

c-user: Fix task create notes

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