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

5
Last change on this file since f6c6c8b was 3079455, checked in by Joel Sherrill <joel@…>, on 12/05/17 at 16:16:11

Account for non-preemption and interrupt level not supported on SMP

Closes #3000.

  • Property mode set to 100644
File size: 66.4 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.. index:: create a task
602.. index:: rtems_task_create
603
604.. _rtems_task_create:
605
606TASK_CREATE - Create a task
607---------------------------
608
609CALLING SEQUENCE:
610    .. code-block:: c
611
612        rtems_status_code rtems_task_create(
613            rtems_name           name,
614            rtems_task_priority  initial_priority,
615            size_t               stack_size,
616            rtems_mode           initial_modes,
617            rtems_attribute      attribute_set,
618            rtems_id            *id
619        );
620
621DIRECTIVE STATUS CODES:
622    .. list-table::
623      :class: rtems-table
624
625      * - ``RTEMS_SUCCESSFUL``
626        - task created successfully
627      * - ``RTEMS_INVALID_ADDRESS``
628        - ``id`` is NULL
629      * - ``RTEMS_INVALID_NAME``
630        - invalid task name
631      * - ``RTEMS_INVALID_PRIORITY``
632        - invalid task priority
633      * - ``RTEMS_MP_NOT_CONFIGURED``
634        - multiprocessing not configured
635      * - ``RTEMS_TOO_MANY``
636        - too many tasks created
637      * - ``RTEMS_UNSATISFIED``
638        - not enough memory for stack/FP context
639      * - ``RTEMS_UNSATISFIED``
640        - non-preemption mode not supported on SMP system
641      * - ``RTEMS_UNSATISFIED``
642        - interrupt level mode not supported on SMP system
643      * - ``RTEMS_TOO_MANY``
644        - too many global objects
645
646DESCRIPTION:
647    This directive creates a task which resides on the local node.  It
648    allocates and initializes a TCB, a stack, and an optional floating point
649    context area.  The mode parameter contains values which sets the task's
650    initial execution mode.  The ``RTEMS_FLOATING_POINT`` attribute should be
651    specified if the created task is to use a numeric coprocessor.  For
652    performance reasons, it is recommended that tasks not using the numeric
653    coprocessor should specify the ``RTEMS_NO_FLOATING_POINT`` attribute.  If
654    the ``RTEMS_GLOBAL`` attribute is specified, the task can be accessed from
655    remote nodes.  The task id, returned in id, is used in other task related
656    directives to access the task.  When created, a task is placed in the
657    dormant state and can only be made ready to execute using the directive
658    ``rtems_task_start``.
659
660NOTES:
661    This directive may cause the calling task to be preempted.
662
663    The scheduler of the new task is the scheduler of the executing task at
664    some point during the task creation.  The specified task priority must be
665    valid for the selected scheduler.
666
667    The task processor affinity is initialized to the set of online processors.
668
669    If the requested stack size is less than the configured minimum stack size,
670    then RTEMS will use the configured minimum as the stack size for this task.
671    In addition to being able to specify the task stack size as a integer,
672    there are two constants which may be specified:
673
674    ``RTEMS_MINIMUM_STACK_SIZE``
675      The minimum stack size *RECOMMENDED* for use on this processor.  This
676      value is selected by the RTEMS developers conservatively to minimize the
677      risk of blown stacks for most user applications.  Using this constant
678      when specifying the task stack size, indicates that the stack size will
679      be at least ``RTEMS_MINIMUM_STACK_SIZE`` bytes in size.  If the user
680      configured minimum stack size is larger than the recommended minimum,
681      then it will be used.
682
683    ``RTEMS_CONFIGURED_MINIMUM_STACK_SIZE``
684      Indicates this task is to be created with a stack size of the minimum
685      stack size that was configured by the application.  If not explicitly
686      configured by the application, the default configured minimum stack size
687      is the processor dependent value ``RTEMS_MINIMUM_STACK_SIZE``.  Since
688      this uses the configured minimum stack size value, you may get a stack
689      size that is smaller or larger than the recommended minimum.  This can be
690      used to provide large stacks for all tasks on complex applications or
691      small stacks on applications that are trying to conserve memory.
692
693    Application developers should consider the stack usage of the device
694    drivers when calculating the stack size required for tasks which utilize
695    the driver.
696
697    The following task attribute constants are defined by RTEMS:
698
699    .. list-table::
700      :class: rtems-table
701
702      * - ``RTEMS_NO_FLOATING_POINT``
703        - does not use coprocessor (default)
704      * - ``RTEMS_FLOATING_POINT``
705        - uses numeric coprocessor
706      * - ``RTEMS_LOCAL``
707        - local task (default)
708      * - ``RTEMS_GLOBAL``
709        - global task
710
711    The following task mode constants are defined by RTEMS:
712
713    .. list-table::
714      :class: rtems-table
715
716      * - ``RTEMS_PREEMPT``
717        - enable preemption (default)
718      * - ``RTEMS_NO_PREEMPT``
719        - disable preemption
720      * - ``RTEMS_NO_TIMESLICE``
721        - disable timeslicing (default)
722      * - ``RTEMS_TIMESLICE``
723        - enable timeslicing
724      * - ``RTEMS_ASR``
725        - enable ASR processing (default)
726      * - ``RTEMS_NO_ASR``
727        - disable ASR processing
728      * - ``RTEMS_INTERRUPT_LEVEL(0)``
729        - enable all interrupts (default)
730      * - ``RTEMS_INTERRUPT_LEVEL(n)``
731        - execute at interrupt level ``n``
732
733    The interrupt level portion of the task execution mode supports a maximum
734    of 256 interrupt levels.  These levels are mapped onto the interrupt
735    levels actually supported by the target processor in a processor dependent
736    fashion.
737
738    Tasks should not be made global unless remote tasks must interact with
739    them.  This avoids the system overhead incurred by the creation of a
740    global task.  When a global task is created, the task's name and id must
741    be transmitted to every node in the system for insertion in the local copy
742    of the global object table.
743
744    The total number of global objects, including tasks, is limited by the
745    maximum_global_objects field in the Configuration Table.
746
747.. raw:: latex
748
749   \clearpage
750
751.. index:: get ID of a task
752.. index:: rtems_task_ident
753
754.. _rtems_task_ident:
755
756TASK_IDENT - Get ID of a task
757-----------------------------
758
759CALLING SEQUENCE:
760    .. code-block:: c
761
762        rtems_status_code rtems_task_ident(
763            rtems_name  name,
764            uint32_t    node,
765            rtems_id   *id
766        );
767
768DIRECTIVE STATUS CODES:
769    .. list-table::
770      :class: rtems-table
771
772      * - ``RTEMS_SUCCESSFUL``
773        - task identified successfully
774      * - ``RTEMS_INVALID_ADDRESS``
775        - ``id`` is NULL
776      * - ``RTEMS_INVALID_NAME``
777        - invalid task name
778      * - ``RTEMS_INVALID_NODE``
779        - invalid node id
780
781DESCRIPTION:
782    This directive obtains the task id associated with the task name specified
783    in name.  A task may obtain its own id by specifying ``RTEMS_SELF`` or its
784    own task name in name.  If the task name is not unique, then the task id
785    returned will match one of the tasks with that name.  However, this task id
786    is not guaranteed to correspond to the desired task.  The task id, returned
787    in id, is used in other task related directives to access the task.
788
789NOTES:
790    This directive will not cause the running task to be preempted.
791
792    If node is ``RTEMS_SEARCH_ALL_NODES``, all nodes are searched with the
793    local node being searched first.  All other nodes are searched with the
794    lowest numbered node searched first.
795
796    If node is a valid node number which does not represent the local node,
797    then only the tasks exported by the designated node are searched.
798
799    This directive does not generate activity on remote nodes.  It accesses
800    only the local copy of the global object table.
801
802.. raw:: latex
803
804   \clearpage
805
806.. index:: obtain ID of caller
807.. index:: rtems_task_self
808
809.. _rtems_task_self:
810
811TASK_SELF - Obtain ID of caller
812-------------------------------
813
814CALLING SEQUENCE:
815    .. code-block:: c
816
817        rtems_id rtems_task_self(void);
818
819DIRECTIVE STATUS CODES:
820    Returns the object Id of the calling task.
821
822DESCRIPTION:
823    This directive returns the Id of the calling task.
824
825NOTES:
826    If called from an interrupt service routine, this directive will return the
827    Id of the interrupted task.
828
829.. raw:: latex
830
831   \clearpage
832
833.. index:: starting a task
834.. index:: rtems_task_start
835
836.. _rtems_task_start:
837
838TASK_START - Start a task
839-------------------------
840
841CALLING SEQUENCE:
842    .. code-block:: c
843
844        rtems_status_code rtems_task_start(
845            rtems_id            id,
846            rtems_task_entry    entry_point,
847            rtems_task_argument argument
848        );
849
850DIRECTIVE STATUS CODES:
851    .. list-table::
852      :class: rtems-table
853
854      * - ``RTEMS_SUCCESSFUL``
855        - ask started successfully
856      * - ``RTEMS_INVALID_ADDRESS``
857        - invalid task entry point
858      * - ``RTEMS_INVALID_ID``
859        - invalid task id
860      * - ``RTEMS_INCORRECT_STATE``
861        - task not in the dormant state
862      * - ``RTEMS_ILLEGAL_ON_REMOTE_OBJECT``
863        - cannot start remote task
864
865DESCRIPTION:
866    This directive readies the task, specified by ``id``, for execution based
867    on the priority and execution mode specified when the task was created.
868    The starting address of the task is given in ``entry_point``.  The task's
869    starting argument is contained in argument.  This argument can be a single
870    value or used as an index into an array of parameter blocks.  The type of
871    this numeric argument is an unsigned integer type with the property that
872    any valid pointer to void can be converted to this type and then converted
873    back to a pointer to void.  The result will compare equal to the original
874    pointer.
875
876NOTES:
877    The calling task will be preempted if its preemption mode is enabled and
878    the task being started has a higher priority.
879
880    Any actions performed on a dormant task such as suspension or change of
881    priority are nullified when the task is initiated via the
882    ``rtems_task_start`` directive.
883
884.. raw:: latex
885
886   \clearpage
887
888.. index:: restarting a task
889.. index:: rtems_task_restart
890
891.. _rtems_task_restart:
892
893TASK_RESTART - Restart a task
894-----------------------------
895
896CALLING SEQUENCE:
897    .. code-block:: c
898
899        rtems_status_code rtems_task_restart(
900           rtems_id            id,
901           rtems_task_argument argument
902        );
903
904DIRECTIVE STATUS CODES:
905    .. list-table::
906      :class: rtems-table
907
908      * - ``RTEMS_SUCCESSFUL``
909        - task restarted successfully
910      * - ``RTEMS_INVALID_ID``
911        - task id invalid
912      * - ``RTEMS_INCORRECT_STATE``
913        - task never started
914      * - ``RTEMS_ILLEGAL_ON_REMOTE_OBJECT``
915        - cannot restart remote task
916
917DESCRIPTION:
918    This directive resets the task specified by id to begin execution at its
919    original starting address.  The task's priority and execution mode are set
920    to the original creation values.  If the task is currently blocked, RTEMS
921    automatically makes the task ready.  A task can be restarted from any
922    state, except the dormant state.
923
924    The task's starting argument is contained in argument.  This argument can
925    be a single value or an index into an array of parameter blocks.  The type
926    of this numeric argument is an unsigned integer type with the property that
927    any valid pointer to void can be converted to this type and then converted
928    back to a pointer to void.  The result will compare equal to the original
929    pointer.  This new argument may be used to distinguish between the initial
930    ``rtems_task_start`` of the task and any ensuing calls to
931    ``rtems_task_restart`` of the task.  This can be beneficial in deleting a
932    task.  Instead of deleting a task using the ``rtems_task_delete``
933    directive, a task can delete another task by restarting that task, and
934    allowing that task to release resources back to RTEMS and then delete
935    itself.
936
937NOTES:
938    If id is ``RTEMS_SELF``, the calling task will be restarted and will not
939    return from this directive.
940
941    The calling task will be preempted if its preemption mode is enabled and
942    the task being restarted has a higher priority.
943
944    The task must reside on the local node, even if the task was created with
945    the ``RTEMS_GLOBAL`` option.
946
947.. raw:: latex
948
949   \clearpage
950
951.. index:: deleting a task
952.. index:: rtems_task_delete
953
954.. _rtems_task_delete:
955
956TASK_DELETE - Delete a task
957---------------------------
958
959CALLING SEQUENCE:
960    .. code-block:: c
961
962        rtems_status_code rtems_task_delete(
963            rtems_id id
964        );
965
966DIRECTIVE STATUS CODES:
967    .. list-table::
968      :class: rtems-table
969
970      * - ``RTEMS_SUCCESSFUL``
971        - task deleted successfully
972      * - ``RTEMS_INVALID_ID``
973        - task id invalid
974      * - ``RTEMS_ILLEGAL_ON_REMOTE_OBJECT``
975        - cannot restart remote task
976
977DESCRIPTION:
978    This directive deletes a task, either the calling task or another task, as
979    specified by id.  RTEMS stops the execution of the task and reclaims the
980    stack memory, any allocated delay or timeout timers, the TCB, and, if the
981    task is ``RTEMS_FLOATING_POINT``, its floating point context area.  RTEMS
982    does not reclaim the following resources: region segments, partition
983    buffers, semaphores, timers, or rate monotonic periods.
984
985NOTES:
986    A task is responsible for releasing its resources back to RTEMS before
987    deletion.  To insure proper deallocation of resources, a task should not be
988    deleted unless it is unable to execute or does not hold any RTEMS
989    resources.  If a task holds RTEMS resources, the task should be allowed to
990    deallocate its resources before deletion.  A task can be directed to
991    release its resources and delete itself by restarting it with a special
992    argument or by sending it a message, an event, or a signal.
993
994    Deletion of the current task (``RTEMS_SELF``) will force RTEMS to select
995    another task to execute.
996
997    When a global task is deleted, the task id must be transmitted to every
998    node in the system for deletion from the local copy of the global object
999    table.
1000
1001    The task must reside on the local node, even if the task was created with
1002    the ``RTEMS_GLOBAL`` option.
1003
1004.. raw:: latex
1005
1006   \clearpage
1007
1008.. index:: suspending a task
1009.. index:: rtems_task_suspend
1010
1011.. _rtems_task_suspend:
1012
1013TASK_SUSPEND - Suspend a task
1014-----------------------------
1015
1016CALLING SEQUENCE:
1017    .. code-block:: c
1018
1019        rtems_status_code rtems_task_suspend(
1020            rtems_id id
1021        );
1022
1023DIRECTIVE STATUS CODES:
1024    .. list-table::
1025      :class: rtems-table
1026
1027      * - ``RTEMS_SUCCESSFUL``
1028        - task suspended successfully
1029      * - ``RTEMS_INVALID_ID``
1030        - task id invalid
1031      * - ``RTEMS_ALREADY_SUSPENDED``
1032        - task already suspended
1033
1034DESCRIPTION:
1035    This directive suspends the task specified by id from further execution by
1036    placing it in the suspended state.  This state is additive to any other
1037    blocked state that the task may already be in.  The task will not execute
1038    again until another task issues the ``rtems_task_resume`` directive for
1039    this task and any blocked state has been removed.
1040
1041NOTES:
1042    The requesting task can suspend itself by specifying ``RTEMS_SELF`` as id.
1043    In this case, the task will be suspended and a successful return code will
1044    be returned when the task is resumed.
1045
1046    Suspending a global task which does not reside on the local node will
1047    generate a request to the remote node to suspend the specified task.
1048
1049    If the task specified by id is already suspended, then the
1050    ``RTEMS_ALREADY_SUSPENDED`` status code is returned.
1051
1052.. raw:: latex
1053
1054   \clearpage
1055
1056.. index:: resuming a task
1057.. index:: rtems_task_resume
1058
1059.. _rtems_task_resume:
1060
1061TASK_RESUME - Resume a task
1062---------------------------
1063
1064CALLING SEQUENCE:
1065    .. code-block:: c
1066
1067        rtems_status_code rtems_task_resume(
1068            rtems_id id
1069        );
1070
1071DIRECTIVE STATUS CODES:
1072    .. list-table::
1073      :class: rtems-table
1074
1075      * - ``RTEMS_SUCCESSFUL``
1076        - task resumed successfully
1077      * - ``RTEMS_INVALID_ID``
1078        - task id invalid
1079      * - ``RTEMS_INCORRECT_STATE``
1080        - task not suspended
1081
1082DESCRIPTION:
1083    This directive removes the task specified by id from the suspended state.
1084    If the task is in the ready state after the suspension is removed, then it
1085    will be scheduled to run.  If the task is still in a blocked state after
1086    the suspension is removed, then it will remain in that blocked state.
1087
1088NOTES:
1089    The running task may be preempted if its preemption mode is enabled and the
1090    local task being resumed has a higher priority.
1091
1092    Resuming a global task which does not reside on the local node will
1093    generate a request to the remote node to resume the specified task.
1094
1095    If the task specified by id is not suspended, then the
1096    ``RTEMS_INCORRECT_STATE`` status code is returned.
1097
1098.. raw:: latex
1099
1100   \clearpage
1101
1102.. index:: is task suspended
1103.. index:: rtems_task_is_suspended
1104
1105.. _rtems_task_is_suspended:
1106
1107TASK_IS_SUSPENDED - Determine if a task is Suspended
1108----------------------------------------------------
1109
1110CALLING SEQUENCE:
1111    .. code-block:: c
1112
1113        rtems_status_code rtems_task_is_suspended(
1114            rtems_id id
1115        );
1116
1117DIRECTIVE STATUS CODES:
1118    .. list-table::
1119      :class: rtems-table
1120
1121      * - ``RTEMS_SUCCESSFUL``
1122        - task is NOT suspended
1123      * - ``RTEMS_ALREADY_SUSPENDED``
1124        - task is currently suspended
1125      * - ``RTEMS_INVALID_ID``
1126        - task id invalid
1127      * - ``RTEMS_ILLEGAL_ON_REMOTE_OBJECT``
1128        - not supported on remote tasks
1129
1130DESCRIPTION:
1131    This directive returns a status code indicating whether or not the
1132    specified task is currently suspended.
1133
1134NOTES:
1135    This operation is not currently supported on remote tasks.
1136
1137.. raw:: latex
1138
1139   \clearpage
1140
1141.. index:: rtems_task_set_priority
1142.. index:: current task priority
1143.. index:: set task priority
1144.. index:: get task priority
1145.. index:: obtain task priority
1146
1147.. _rtems_task_set_priority:
1148
1149TASK_SET_PRIORITY - Set task priority
1150-------------------------------------
1151
1152CALLING SEQUENCE:
1153    .. code-block:: c
1154
1155        rtems_status_code rtems_task_set_priority(
1156            rtems_id             id,
1157            rtems_task_priority  new_priority,
1158            rtems_task_priority *old_priority
1159        );
1160
1161DIRECTIVE STATUS CODES:
1162    .. list-table::
1163      :class: rtems-table
1164
1165      * - ``RTEMS_SUCCESSFUL``
1166        - task priority set successfully
1167      * - ``RTEMS_INVALID_ID``
1168        - invalid task id
1169      * - ``RTEMS_INVALID_ADDRESS``
1170        - invalid return argument pointer
1171      * - ``RTEMS_INVALID_PRIORITY``
1172        - invalid task priority
1173
1174DESCRIPTION:
1175    This directive manipulates the priority of the task specified by id.  An id
1176    of ``RTEMS_SELF`` is used to indicate the calling task.  When new_priority
1177    is not equal to ``RTEMS_CURRENT_PRIORITY``, the specified task's previous
1178    priority is returned in old_priority.  When new_priority is
1179    ``RTEMS_CURRENT_PRIORITY``, the specified task's current priority is
1180    returned in old_priority.  Valid priorities range from a high of 1 to a low
1181    of 255.
1182
1183NOTES:
1184    The calling task may be preempted if its preemption mode is enabled and it
1185    lowers its own priority or raises another task's priority.
1186
1187    In case the new priority equals the current priority of the task, then
1188    nothing happens.
1189
1190    Setting the priority of a global task which does not reside on the local
1191    node will generate a request to the remote node to change the priority of
1192    the specified task.
1193
1194    If the task specified by id is currently holding any binary semaphores
1195    which use the priority inheritance algorithm, then the task's priority
1196    cannot be lowered immediately.  If the task's priority were lowered
1197    immediately, then priority inversion results.  The requested lowering of
1198    the task's priority will occur when the task has released all priority
1199    inheritance binary semaphores.  The task's priority can be increased
1200    regardless of the task's use of priority inheritance binary semaphores.
1201
1202.. raw:: latex
1203
1204   \clearpage
1205
1206.. index:: rtems_task_get_priority
1207.. index:: current task priority
1208.. index:: get task priority
1209.. index:: obtain task priority
1210
1211.. _rtems_task_get_priority:
1212
1213TASK_GET_PRIORITY - Get task priority
1214-------------------------------------
1215
1216CALLING SEQUENCE:
1217    .. code-block:: c
1218
1219        rtems_status_code rtems_task_get_priority(
1220            rtems_id             task_id,
1221            rtems_id             scheduler_id,
1222            rtems_task_priority *priority
1223        );
1224
1225DIRECTIVE STATUS CODES:
1226    .. list-table::
1227      :class: rtems-table
1228
1229      * - ``RTEMS_SUCCESSFUL``
1230        - Successful operation.
1231      * - ``RTEMS_ILLEGAL_ON_REMOTE_OBJECT``
1232        - Directive is illegal on remote tasks.
1233      * - ``RTEMS_INVALID_ADDRESS``
1234        - The priority parameter is NULL.
1235      * - ``RTEMS_INVALID_ID``
1236        - Invalid task or scheduler identifier.
1237      * - ``RTEMS_NOT_DEFINED``
1238        - The task has no priority within the specified scheduler instance.
1239          This error is only possible in SMP configurations.
1240
1241DESCRIPTION:
1242    This directive returns the current priority of the task specified by
1243    :c:data:`task_id` with respect to the scheduler instance specified by
1244    :c:data:`scheduler_id`.  A task id of :c:macro:`RTEMS_SELF` is used to
1245    indicate the calling task.
1246
1247NOTES:
1248    The current priority reflects temporary priority adjustments due to locking
1249    protocols, the rate-monotonic period objects on some schedulers and other
1250    mechanisms.
1251
1252.. raw:: latex
1253
1254   \clearpage
1255
1256.. index:: current task mode
1257.. index:: set task mode
1258.. index:: get task mode
1259.. index:: set task preemption mode
1260.. index:: get task preemption mode
1261.. index:: obtain task mode
1262.. index:: rtems_task_mode
1263
1264.. _rtems_task_mode:
1265
1266TASK_MODE - Change the current task mode
1267----------------------------------------
1268
1269CALLING SEQUENCE:
1270    .. code-block:: c
1271
1272        rtems_status_code rtems_task_mode(
1273            rtems_mode  mode_set,
1274            rtems_mode  mask,
1275            rtems_mode *previous_mode_set
1276        );
1277
1278DIRECTIVE STATUS CODES:
1279    .. list-table::
1280      :class: rtems-table
1281
1282      * - ``RTEMS_SUCCESSFUL``
1283        - task mode set successfully
1284      * - ``RTEMS_INVALID_ADDRESS``
1285        - ``previous_mode_set`` is NULL
1286        - not enough memory for stack/FP context
1287      * - ``RTEMS_NOT_IMPLEMENTED``
1288        - non-preemption mode not supported on SMP system
1289      * - ``RTEMS_NOT_IMPLEMENTED``
1290
1291DESCRIPTION:
1292    This directive manipulates the execution mode of the calling task.  A
1293    task's execution mode enables and disables preemption, timeslicing,
1294    asynchronous signal processing, as well as specifying the current interrupt
1295    level.  To modify an execution mode, the mode class(es) to be changed must
1296    be specified in the mask parameter and the desired mode(s) must be
1297    specified in the mode parameter.
1298
1299NOTES:
1300    The calling task will be preempted if it enables preemption and a higher
1301    priority task is ready to run.
1302
1303    Enabling timeslicing has no effect if preemption is disabled.  For a task
1304    to be timesliced, that task must have both preemption and timeslicing
1305    enabled.
1306
1307    A task can obtain its current execution mode, without modifying it, by
1308    calling this directive with a mask value of ``RTEMS_CURRENT_MODE``.
1309
1310    To temporarily disable the processing of a valid ASR, a task should call
1311    this directive with the ``RTEMS_NO_ASR`` indicator specified in mode.
1312
1313    The set of task mode constants and each mode's corresponding mask constant
1314    is provided in the following table:
1315
1316    .. list-table::
1317      :class: rtems-table
1318
1319      * - ``RTEMS_PREEMPT``
1320        - is masked by ``RTEMS_PREEMPT_MASK`` and enables preemption
1321      * - ``RTEMS_NO_PREEMPT``
1322        - is masked by ``RTEMS_PREEMPT_MASK`` and disables preemption
1323      * - ``RTEMS_NO_TIMESLICE``
1324        - is masked by ``RTEMS_TIMESLICE_MASK`` and disables timeslicing
1325      * - ``RTEMS_TIMESLICE``
1326        - is masked by ``RTEMS_TIMESLICE_MASK`` and enables timeslicing
1327      * - ``RTEMS_ASR``
1328        - is masked by ``RTEMS_ASR_MASK`` and enables ASR processing
1329      * - ``RTEMS_NO_ASR``
1330        - is masked by ``RTEMS_ASR_MASK`` and disables ASR processing
1331      * - ``RTEMS_INTERRUPT_LEVEL(0)``
1332        - is masked by ``RTEMS_INTERRUPT_MASK`` and enables all interrupts
1333      * - ``RTEMS_INTERRUPT_LEVEL(n)``
1334        - is masked by ``RTEMS_INTERRUPT_MASK`` and sets interrupts level n
1335
1336.. raw:: latex
1337
1338   \clearpage
1339
1340.. index:: delay a task for an interval
1341.. index:: wake up after an interval
1342.. index:: rtems_task_wake_after
1343
1344.. _rtems_task_wake_after:
1345
1346TASK_WAKE_AFTER - Wake up after interval
1347----------------------------------------
1348
1349CALLING SEQUENCE:
1350    .. code-block:: c
1351
1352        rtems_status_code rtems_task_wake_after(
1353            rtems_interval ticks
1354        );
1355
1356DIRECTIVE STATUS CODES:
1357    .. list-table::
1358      :class: rtems-table
1359
1360      * - ``RTEMS_SUCCESSFUL``
1361        - always successful
1362
1363DESCRIPTION:
1364    This directive blocks the calling task for the specified number of system
1365    clock ticks.  When the requested interval has elapsed, the task is made
1366    ready.  The clock tick directives automatically updates the delay period.
1367
1368NOTES:
1369    Setting the system date and time with the ``rtems_clock_set`` directive has
1370    no effect on a ``rtems_task_wake_after`` blocked task.
1371
1372    A task may give up the processor and remain in the ready state by
1373    specifying a value of ``RTEMS_YIELD_PROCESSOR`` in ticks.
1374
1375    The maximum timer interval that can be specified is the maximum value which
1376    can be represented by the uint32_t type.
1377
1378    A clock tick is required to support the functionality of this directive.
1379
1380.. raw:: latex
1381
1382   \clearpage
1383
1384.. index:: delay a task until a wall time
1385.. index:: wake up at a wall time
1386.. index:: rtems_task_wake_when
1387
1388.. _rtems_task_wake_when:
1389
1390TASK_WAKE_WHEN - Wake up when specified
1391---------------------------------------
1392
1393CALLING SEQUENCE:
1394    .. code-block:: c
1395
1396        rtems_status_code rtems_task_wake_when(
1397            rtems_time_of_day *time_buffer
1398        );
1399
1400DIRECTIVE STATUS CODES:
1401    .. list-table::
1402      :class: rtems-table
1403
1404      * - ``RTEMS_SUCCESSFUL``
1405        - awakened at date/time successfully
1406      * - ``RTEMS_INVALID_ADDRESS``
1407        - ``time_buffer`` is NULL
1408      * - ``RTEMS_INVALID_TIME_OF_DAY``
1409        - invalid time buffer
1410      * - ``RTEMS_NOT_DEFINED``
1411        - system date and time is not set
1412
1413DESCRIPTION:
1414    This directive blocks a task until the date and time specified in
1415    time_buffer.  At the requested date and time, the calling task will be
1416    unblocked and made ready to execute.
1417
1418NOTES:
1419    The ticks portion of time_buffer structure is ignored.  The timing
1420    granularity of this directive is a second.
1421
1422    A clock tick is required to support the functionality of this directive.
1423
1424.. raw:: latex
1425
1426   \clearpage
1427
1428.. _rtems_task_get_scheduler:
1429
1430TASK_GET_SCHEDULER - Get scheduler of a task
1431--------------------------------------------
1432
1433CALLING SEQUENCE:
1434    .. code-block:: c
1435
1436        rtems_status_code rtems_task_get_scheduler(
1437            rtems_id  task_id,
1438            rtems_id *scheduler_id
1439        );
1440
1441DIRECTIVE STATUS CODES:
1442    .. list-table::
1443     :class: rtems-table
1444
1445     * - ``RTEMS_SUCCESSFUL``
1446       - successful operation
1447     * - ``RTEMS_INVALID_ADDRESS``
1448       - ``scheduler_id`` is NULL
1449     * - ``RTEMS_INVALID_ID``
1450       - invalid task id
1451
1452DESCRIPTION:
1453    Returns the scheduler identifier of a task identified by ``task_id`` in
1454    ``scheduler_id``.
1455
1456NOTES:
1457    None.
1458
1459.. raw:: latex
1460
1461   \clearpage
1462
1463.. _rtems_task_set_scheduler:
1464.. _TASK_SET_SCHEDULER - Set scheduler of a task:
1465
1466TASK_SET_SCHEDULER - Set scheduler of a task
1467--------------------------------------------
1468
1469CALLING SEQUENCE:
1470    .. code-block:: c
1471
1472        rtems_status_code rtems_task_set_scheduler(
1473          rtems_id            task_id,
1474          rtems_id            scheduler_id,
1475          rtems_task_priority priority
1476        );
1477
1478DIRECTIVE STATUS CODES:
1479    .. list-table::
1480     :class: rtems-table
1481
1482     * - ``RTEMS_SUCCESSFUL``
1483       - successful operation
1484     * - ``RTEMS_INVALID_ID``
1485       - invalid task or scheduler id
1486     * - ``RTEMS_INVALID_PRIORITY``
1487       - invalid task priority
1488     * - ``RTEMS_RESOURCE_IN_USE``
1489       - the task is in the wrong state to perform a scheduler change
1490     * - ``RTEMS_UNSATISFIED``
1491       - the processor set of the scheduler is empty
1492     * - ``RTEMS_ILLEGAL_ON_REMOTE_OBJECT``
1493       - not supported on remote tasks
1494
1495DESCRIPTION:
1496    Sets the scheduler of a task identified by ``task_id`` to the scheduler
1497    identified by ``scheduler_id``.  The scheduler of a task is initialized to
1498    the scheduler of the task that created it.  The priority of the task is set
1499    to ``priority``.
1500
1501NOTES:
1502    It is recommended to set the scheduler of a task before it is started or in
1503    case it is guaranteed that the task owns no resources.  Otherwise, sporadic
1504    ``RTEMS_RESOURCE_IN_USE`` errors may occur.
1505
1506EXAMPLE:
1507    .. code-block:: c
1508        :linenos:
1509
1510        #include <rtems.h>
1511        #include <assert.h>
1512
1513        void task( rtems_task_argument arg );
1514
1515        void example( void )
1516        {
1517          rtems_status_code sc;
1518          rtems_id          task_id;
1519          rtems_id          scheduler_id;
1520          rtems_name        scheduler_name;
1521
1522          scheduler_name = rtems_build_name( 'W', 'O', 'R', 'K' );
1523
1524          sc = rtems_scheduler_ident( scheduler_name, &scheduler_id );
1525          assert( sc == RTEMS_SUCCESSFUL );
1526
1527          sc = rtems_task_create(
1528            rtems_build_name( 'T', 'A', 'S', 'K' ),
1529            1,
1530            RTEMS_MINIMUM_STACK_SIZE,
1531            RTEMS_DEFAULT_MODES,
1532            RTEMS_DEFAULT_ATTRIBUTES,
1533            &task_id
1534          );
1535          assert( sc == RTEMS_SUCCESSFUL );
1536
1537          sc = rtems_task_set_scheduler( task_id, scheduler_id, 2 );
1538          assert( sc == RTEMS_SUCCESSFUL );
1539
1540          sc = rtems_task_start( task_id, task, 0 );
1541          assert( sc == RTEMS_SUCCESSFUL );
1542        }
1543
1544.. raw:: latex
1545
1546   \clearpage
1547
1548.. _rtems_task_get_affinity:
1549
1550TASK_GET_AFFINITY - Get task processor affinity
1551-----------------------------------------------
1552
1553CALLING SEQUENCE:
1554    .. code-block:: c
1555
1556        rtems_status_code rtems_task_get_affinity(
1557            rtems_id   id,
1558            size_t     cpusetsize,
1559            cpu_set_t *cpuset
1560        );
1561
1562DIRECTIVE STATUS CODES:
1563    .. list-table::
1564     :class: rtems-table
1565
1566     * - ``RTEMS_SUCCESSFUL``
1567       - successful operation
1568     * - ``RTEMS_INVALID_ADDRESS``
1569       - ``cpuset`` is NULL
1570     * - ``RTEMS_INVALID_ID``
1571       - invalid task id
1572     * - ``RTEMS_INVALID_NUMBER``
1573       - the affinity set buffer is too small for the current processor affinity
1574         set of the task
1575
1576DESCRIPTION:
1577    Returns the current processor affinity set of the task in ``cpuset``.  A
1578    set bit in the affinity set means that the task can execute on this
1579    processor and a cleared bit means the opposite.
1580
1581NOTES:
1582    The task processor affinity is initialized to the set of online processors.
1583
1584.. raw:: latex
1585
1586   \clearpage
1587
1588.. _rtems_task_set_affinity:
1589
1590TASK_SET_AFFINITY - Set task processor affinity
1591-----------------------------------------------
1592
1593CALLING SEQUENCE:
1594    .. code-block:: c
1595
1596        rtems_status_code rtems_task_set_affinity(
1597            rtems_id         id,
1598            size_t           cpusetsize,
1599            const cpu_set_t *cpuset
1600        );
1601
1602DIRECTIVE STATUS CODES:
1603    .. list-table::
1604     :class: rtems-table
1605
1606     * - ``RTEMS_SUCCESSFUL``
1607       - successful operation
1608     * - ``RTEMS_INVALID_ADDRESS``
1609       - ``cpuset`` is NULL
1610     * - ``RTEMS_INVALID_ID``
1611       - invalid task id
1612     * - ``RTEMS_INVALID_NUMBER``
1613       - invalid processor affinity set
1614
1615DESCRIPTION:
1616    Sets the processor affinity set for the task specified by ``cpuset``.  A
1617    set bit in the affinity set means that the task can execute on this
1618    processor and a cleared bit means the opposite.
1619
1620NOTES:
1621    This function will not change the scheduler of the task.  The intersection
1622    of the processor affinity set and the set of processors owned by the
1623    scheduler of the task must be non-empty.  It is not an error if the
1624    processor affinity set contains processors that are not part of the set of
1625    processors owned by the scheduler instance of the task.  A task will simply
1626    not run under normal circumstances on these processors since the scheduler
1627    ignores them.  Some locking protocols may temporarily use processors that
1628    are not included in the processor affinity set of the task.  It is also not
1629    an error if the processor affinity set contains processors that are not
1630    part of the system.
1631
1632    In case a scheduler without support for task affinites is used for the
1633    task, then the task processor affinity set must contain all online
1634    processors of the system.  This prevents odd corner cases if processors are
1635    added/removed at run-time to/from scheduler instances.
1636
1637.. raw:: latex
1638
1639   \clearpage
1640
1641.. index:: iterate over all threads
1642.. index:: rtems_task_iterate
1643
1644.. _rtems_task_iterate:
1645
1646TASK_ITERATE - Iterate Over Tasks
1647---------------------------------
1648
1649CALLING SEQUENCE:
1650    .. code-block:: c
1651
1652        typedef bool ( *rtems_task_visitor )( rtems_tcb *tcb, void *arg );
1653
1654        void rtems_task_iterate(
1655            rtems_task_visitor  visitor,
1656            void               *arg
1657        );
1658
1659DIRECTIVE STATUS CODES:
1660    NONE
1661
1662DESCRIPTION:
1663    Iterates over all tasks in the system.  This operation covers all tasks of
1664    all APIs.  The user should be careful in accessing the contents of the
1665    thread control block :c:data:`tcb`.  The visitor argument :c:data:`arg` is
1666    passed to all invocations of :c:data:`visitor` in addition to the thread
1667    control block.  The iteration stops immediately in case the visitor
1668    function returns true.
1669
1670NOTES:
1671    Must be called from task context.  This operation obtains and releases the
1672    objects allocator lock.  The task visitor is called while owning the objects
1673    allocator lock.  It is possible to perform blocking operations in the task
1674    visitor, however, take care that no deadlocks via the object allocator lock
1675    can occur.
1676
1677Deprecated and Removed Directives
1678=================================
1679
1680.. raw:: latex
1681
1682   \clearpage
1683
1684.. index:: rtems_iterate_over_all_threads
1685
1686.. _rtems_iterate_over_all_threads:
1687
1688ITERATE_OVER_ALL_THREADS - Iterate Over Tasks
1689---------------------------------------------
1690
1691.. warning::
1692
1693    This directive is deprecated.  Its use is unsafe.  Use
1694    :ref:`rtems_task_iterate` instead.
1695
1696CALLING SEQUENCE:
1697    .. code-block:: c
1698
1699        typedef void (*rtems_per_thread_routine)(Thread_Control *the_thread);
1700        void rtems_iterate_over_all_threads(
1701            rtems_per_thread_routine routine
1702        );
1703
1704DIRECTIVE STATUS CODES:
1705    NONE
1706
1707DESCRIPTION:
1708    This directive iterates over all of the existant threads in the system and
1709    invokes ``routine`` on each of them.  The user should be careful in
1710    accessing the contents of ``the_thread``.
1711
1712    This routine is intended for use in diagnostic utilities and is not
1713    intented for routine use in an operational system.
1714
1715NOTES:
1716    There is **no protection** while this routine is called.  The thread
1717    control block may be in an inconsistent state or may change due to
1718    interrupts or activity on other processors.
1719
1720.. raw:: latex
1721
1722   \clearpage
1723
1724.. index:: get task notepad entry
1725.. index:: rtems_task_get_note
1726
1727.. _rtems_task_get_note:
1728
1729TASK_GET_NOTE - Get task notepad entry
1730--------------------------------------
1731
1732.. warning::
1733
1734    This directive was removed in RTEMS 5.1.
1735
1736CALLING SEQUENCE:
1737    .. code-block:: c
1738
1739        rtems_status_code rtems_task_get_note(
1740          rtems_id  id,
1741          uint32_t  notepad,
1742          uint32_t *note
1743        );
1744
1745DIRECTIVE STATUS CODES:
1746    .. list-table::
1747      :class: rtems-table
1748
1749      * - ``RTEMS_SUCCESSFUL``
1750        - note value obtained successfully
1751      * - ``RTEMS_INVALID_ADDRESS``
1752        - ``note`` parameter is NULL
1753      * - ``RTEMS_INVALID_ID``
1754        - invalid task id
1755      * - ``RTEMS_INVALID_NUMBER``
1756        - invalid notepad location
1757
1758DESCRIPTION:
1759    This directive returns the note contained in the notepad location of the
1760    task specified by id.
1761
1762NOTES:
1763    This directive will not cause the running task to be preempted.
1764
1765    If id is set to ``RTEMS_SELF``, the calling task accesses its own notepad.
1766
1767    The sixteen notepad locations can be accessed using the constants
1768    ``RTEMS_NOTEPAD_0`` through ``RTEMS_NOTEPAD_15``.
1769
1770    Getting a note of a global task which does not reside on the local node
1771    will generate a request to the remote node to obtain the notepad entry of
1772    the specified task.
1773
1774.. raw:: latex
1775
1776   \clearpage
1777
1778.. index:: set task notepad entry
1779.. index:: rtems_task_set_note
1780
1781.. _rtems_task_set_note:
1782
1783TASK_SET_NOTE - Set task notepad entry
1784--------------------------------------
1785
1786.. warning::
1787
1788    This directive was removed in RTEMS 5.1.
1789
1790CALLING SEQUENCE:
1791    .. code-block:: c
1792
1793        rtems_status_code rtems_task_set_note(
1794          rtems_id  id,
1795          uint32_t  notepad,
1796          uint32_t  note
1797        );
1798
1799DIRECTIVE STATUS CODES:
1800    .. list-table::
1801      :class: rtems-table
1802
1803      * - ``RTEMS_SUCCESSFUL``
1804        - note set successfully
1805      * - ``RTEMS_INVALID_ID``
1806        - invalid task id
1807      * - ``RTEMS_INVALID_NUMBER``
1808        - invalid notepad location
1809
1810DESCRIPTION:
1811    This directive sets the notepad entry for the task specified by id to the
1812    value note.
1813
1814NOTES:
1815    If ``id`` is set to ``RTEMS_SELF``, the calling task accesses its own
1816    notepad.
1817
1818    This directive will not cause the running task to be preempted.
1819
1820    The sixteen notepad locations can be accessed using the constants
1821    ``RTEMS_NOTEPAD_0`` through ``RTEMS_NOTEPAD_15``.
1822
1823    Setting a note of a global task which does not reside on the local node
1824    will generate a request to the remote node to set the notepad entry of the
1825    specified task.
1826
1827.. raw:: latex
1828
1829   \clearpage
1830
1831.. index:: per-task variable
1832.. index:: task private variable
1833.. index:: task private data
1834.. index:: rtems_task_variable_add
1835
1836.. _rtems_task_variable_add:
1837
1838TASK_VARIABLE_ADD - Associate per task variable
1839-----------------------------------------------
1840
1841.. warning::
1842
1843    This directive was removed in RTEMS 5.1.
1844
1845CALLING SEQUENCE:
1846    .. code-block:: c
1847
1848        rtems_status_code rtems_task_variable_add(
1849            rtems_id  tid,
1850            void    **task_variable,
1851            void    (*dtor)(void *)
1852        );
1853
1854DIRECTIVE STATUS CODES:
1855     .. list-table::
1856      :class: rtems-table
1857
1858      * - ``RTEMS_SUCCESSFUL``
1859        - per task variable added successfully
1860      * - ``RTEMS_INVALID_ADDRESS``
1861        - ``task_variable`` is NULL
1862      * - ``RTEMS_INVALID_ID``
1863        - invalid task id
1864      * - ``RTEMS_NO_MEMORY``
1865        - invalid task id
1866      * - ``RTEMS_ILLEGAL_ON_REMOTE_OBJECT``
1867        - not supported on remote tasks
1868
1869DESCRIPTION:
1870    This directive adds the memory location specified by the ptr argument to
1871    the context of the given task.  The variable will then be private to the
1872    task.  The task can access and modify the variable, but the modifications
1873    will not appear to other tasks, and other tasks' modifications to that
1874    variable will not affect the value seen by the task.  This is accomplished
1875    by saving and restoring the variable's value each time a task switch occurs
1876    to or from the calling task.  If the dtor argument is non-NULL it specifies
1877    the address of a 'destructor' function which will be called when the task
1878    is deleted.  The argument passed to the destructor function is the task's
1879    value of the variable.
1880
1881NOTES:
1882    Task variables increase the context switch time to and from the tasks that
1883    own them so it is desirable to minimize the number of task variables.  One
1884    efficient method is to have a single task variable that is a pointer to a
1885    dynamically allocated structure containing the task's private 'global'
1886    data.  In this case the destructor function could be 'free'.
1887
1888    Per-task variables are disabled in SMP configurations and this service is
1889    not available.
1890
1891.. raw:: latex
1892
1893   \clearpage
1894
1895.. index:: get per-task variable
1896.. index:: obtain per-task variable
1897.. index:: rtems_task_variable_get
1898
1899.. _rtems_task_variable_get:
1900
1901TASK_VARIABLE_GET - Obtain value of a per task variable
1902-------------------------------------------------------
1903
1904.. warning::
1905
1906    This directive was removed in RTEMS 5.1.
1907
1908CALLING SEQUENCE:
1909    .. code-block:: c
1910
1911        rtems_status_code rtems_task_variable_get(
1912            rtems_id  tid,
1913            void    **task_variable,
1914            void    **task_variable_value
1915        );
1916
1917DIRECTIVE STATUS CODES:
1918    .. list-table::
1919      :class: rtems-table
1920
1921      * - ``RTEMS_SUCCESSFUL``
1922        - per task variable obtained successfully
1923      * - ``RTEMS_INVALID_ADDRESS``
1924        - ``task_variable`` is NULL
1925      * - ``RTEMS_INVALID_ADDRESS``
1926        - ``task_variable_value`` is NULL
1927      * - ``RTEMS_INVALID_ADDRESS``
1928        - ``task_variable`` is not found
1929      * - ``RTEMS_NO_MEMORY``
1930        - invalid task id
1931      * - ``RTEMS_ILLEGAL_ON_REMOTE_OBJECT``
1932        - not supported on remote tasks
1933
1934DESCRIPTION:
1935    This directive looks up the private value of a task variable for a
1936    specified task and stores that value in the location pointed to by the
1937    result argument.  The specified task is usually not the calling task, which
1938    can get its private value by directly accessing the variable.
1939
1940NOTES:
1941    If you change memory which ``task_variable_value`` points to, remember to
1942    declare that memory as volatile, so that the compiler will optimize it
1943    correctly.  In this case both the pointer ``task_variable_value`` and data
1944    referenced by ``task_variable_value`` should be considered volatile.
1945
1946    Per-task variables are disabled in SMP configurations and this service is
1947    not available.
1948
1949.. raw:: latex
1950
1951   \clearpage
1952
1953.. index:: per-task variable
1954.. index:: task private variable
1955.. index:: task private data
1956.. index:: rtems_task_variable_delete
1957
1958.. _rtems_task_variable_delete:
1959
1960TASK_VARIABLE_DELETE - Remove per task variable
1961-----------------------------------------------
1962
1963.. warning::
1964
1965    This directive was removed in RTEMS 5.1.
1966
1967CALLING SEQUENCE:
1968    .. code-block:: c
1969
1970        rtems_status_code rtems_task_variable_delete(
1971            rtems_id  id,
1972            void    **task_variable
1973        );
1974
1975DIRECTIVE STATUS CODES:
1976    .. list-table::
1977      :class: rtems-table
1978
1979      * - ``RTEMS_SUCCESSFUL``
1980        - per task variable deleted successfully
1981      * - ``RTEMS_INVALID_ID``
1982        - invalid task id
1983      * - ``RTEMS_NO_MEMORY``
1984        - invalid task id
1985      * - ``RTEMS_INVALID_ADDRESS``
1986        - ``task_variable`` is NULL
1987      * - ``RTEMS_ILLEGAL_ON_REMOTE_OBJECT``
1988        - not supported on remote tasks
1989
1990DESCRIPTION:
1991    This directive removes the given location from a task's context.
1992
1993NOTES:
1994    Per-task variables are disabled in SMP configurations and this service is
1995    not available.
Note: See TracBrowser for help on using the repository browser.