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

Last change on this file since ef842b4 was ef842b4, checked in by Joel Sherrill <joel.sherrill@…>, on 11/05/04 at 14:37:31

2004-11-05 Joel Sherrill <joel@…>

PR 706/doc

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