source: rtems/doc/user/task.t @ adee5979

4.104.114.84.95
Last change on this file since adee5979 was adee5979, checked in by Joel Sherrill <joel.sherrill@…>, on 05/04/00 at 19:45:17

Numerous changes based on comments from Stephan Wilms <Stephan.Wilms@…>
including a new section in the Getting Started called "Where to
Go From Here", lots of index entries added, and more configuration
table information.

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