source: rtems-docs/c-user/task_manager.rst @ 6c56401

5
Last change on this file since 6c56401 was 6c56401, checked in by Chris Johns <chrisj@…>, on 11/12/17 at 03:34:48

c-user: Fix index locations.

Update #3229.

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