[fd6dc8c8] | 1 | Task Manager |
---|
| 2 | ############ |
---|
| 3 | |
---|
| 4 | .. index:: tasks |
---|
| 5 | |
---|
| 6 | Introduction |
---|
| 7 | ============ |
---|
| 8 | |
---|
| 9 | The task manager provides a comprehensive set of directives to |
---|
| 10 | create, delete, and administer tasks. The directives provided |
---|
| 11 | by the task manager are: |
---|
| 12 | |
---|
| 13 | - ``rtems_task_create`` - Create a task |
---|
| 14 | |
---|
| 15 | - ``rtems_task_ident`` - Get ID of a task |
---|
| 16 | |
---|
| 17 | - ``rtems_task_self`` - Obtain ID of caller |
---|
| 18 | |
---|
| 19 | - ``rtems_task_start`` - Start a task |
---|
| 20 | |
---|
| 21 | - ``rtems_task_restart`` - Restart a task |
---|
| 22 | |
---|
| 23 | - ``rtems_task_delete`` - Delete a task |
---|
| 24 | |
---|
| 25 | - ``rtems_task_suspend`` - Suspend a task |
---|
| 26 | |
---|
| 27 | - ``rtems_task_resume`` - Resume a task |
---|
| 28 | |
---|
| 29 | - ``rtems_task_is_suspended`` - Determine if a task is suspended |
---|
| 30 | |
---|
| 31 | - ``rtems_task_set_priority`` - Set task priority |
---|
| 32 | |
---|
[d389819] | 33 | - ``rtems_task_mode`` - Change current task's mode |
---|
[fd6dc8c8] | 34 | |
---|
| 35 | - ``rtems_task_wake_after`` - Wake up after interval |
---|
| 36 | |
---|
| 37 | - ``rtems_task_wake_when`` - Wake up when specified |
---|
| 38 | |
---|
| 39 | - ``rtems_iterate_over_all_threads`` - Iterate Over Tasks |
---|
| 40 | |
---|
| 41 | - ``rtems_task_variable_add`` - Associate per task variable |
---|
| 42 | |
---|
| 43 | - ``rtems_task_variable_get`` - Obtain value of a a per task variable |
---|
| 44 | |
---|
| 45 | - ``rtems_task_variable_delete`` - Remove per task variable |
---|
| 46 | |
---|
| 47 | Background |
---|
| 48 | ========== |
---|
| 49 | |
---|
| 50 | Task Definition |
---|
| 51 | --------------- |
---|
| 52 | .. index:: task, definition |
---|
| 53 | |
---|
| 54 | Many definitions of a task have been proposed in computer literature. |
---|
| 55 | Unfortunately, none of these definitions encompasses all facets of the |
---|
| 56 | concept in a manner which is operating system independent. Several of the |
---|
| 57 | more common definitions are provided to enable each user to select a |
---|
| 58 | definition which best matches their own experience and understanding of the |
---|
| 59 | task concept: |
---|
| 60 | |
---|
| 61 | - a "dispatchable" unit. |
---|
| 62 | |
---|
| 63 | - an entity to which the processor is allocated. |
---|
| 64 | |
---|
| 65 | - an atomic unit of a real-time, multiprocessor system. |
---|
| 66 | |
---|
| 67 | - single threads of execution which concurrently compete for resources. |
---|
| 68 | |
---|
| 69 | - a sequence of closely related computations which can execute |
---|
| 70 | concurrently with other computational sequences. |
---|
| 71 | |
---|
[d389819] | 72 | From RTEMS' perspective, a task is the smallest thread of |
---|
[fd6dc8c8] | 73 | execution which can compete on its own for system resources. A |
---|
| 74 | task is manifested by the existence of a task control block |
---|
| 75 | (TCB). |
---|
| 76 | |
---|
| 77 | Task Control Block |
---|
| 78 | ------------------ |
---|
| 79 | |
---|
| 80 | The Task Control Block (TCB) is an RTEMS defined data structure |
---|
| 81 | which contains all the information that is pertinent to the |
---|
| 82 | execution of a task. During system initialization, RTEMS |
---|
| 83 | reserves a TCB for each task configured. A TCB is allocated |
---|
| 84 | upon creation of the task and is returned to the TCB free list |
---|
| 85 | upon deletion of the task. |
---|
| 86 | |
---|
[d389819] | 87 | The TCB's elements are modified as a result of system calls made |
---|
[fd6dc8c8] | 88 | by the application in response to external and internal stimuli. |
---|
| 89 | TCBs are the only RTEMS internal data structure that can be |
---|
| 90 | accessed by an application via user extension routines. The TCB |
---|
[d389819] | 91 | contains a task's name, ID, current priority, current and |
---|
[fd6dc8c8] | 92 | starting states, execution mode, TCB user extension pointer, |
---|
| 93 | scheduling control structures, as well as data required by a |
---|
| 94 | blocked task. |
---|
| 95 | |
---|
[d389819] | 96 | A task's context is stored in the TCB when a task switch occurs. |
---|
[fd6dc8c8] | 97 | When the task regains control of the processor, its context is |
---|
| 98 | restored from the TCB. When a task is restarted, the initial |
---|
| 99 | state of the task is restored from the starting context area in |
---|
[d389819] | 100 | the task's TCB. |
---|
[fd6dc8c8] | 101 | |
---|
| 102 | Task States |
---|
| 103 | ----------- |
---|
| 104 | .. index:: task states |
---|
| 105 | |
---|
| 106 | A task may exist in one of the following five states: |
---|
| 107 | |
---|
| 108 | - *executing* - Currently scheduled to the CPU |
---|
| 109 | |
---|
| 110 | - *ready* - May be scheduled to the CPU |
---|
| 111 | |
---|
| 112 | - *blocked* - Unable to be scheduled to the CPU |
---|
| 113 | |
---|
| 114 | - *dormant* - Created task that is not started |
---|
| 115 | |
---|
| 116 | - *non-existent* - Uncreated or deleted task |
---|
| 117 | |
---|
| 118 | An active task may occupy the executing, ready, blocked or |
---|
| 119 | dormant state, otherwise the task is considered non-existent. |
---|
| 120 | One or more tasks may be active in the system simultaneously. |
---|
| 121 | Multiple tasks communicate, synchronize, and compete for system |
---|
| 122 | resources with each other via system calls. The multiple tasks |
---|
| 123 | appear to execute in parallel, but actually each is dispatched |
---|
| 124 | to the CPU for periods of time determined by the RTEMS |
---|
| 125 | scheduling algorithm. The scheduling of a task is based on its |
---|
| 126 | current state and priority. |
---|
| 127 | |
---|
| 128 | Task Priority |
---|
| 129 | ------------- |
---|
| 130 | .. index:: task priority |
---|
| 131 | .. index:: priority, task |
---|
| 132 | .. index:: rtems_task_priority |
---|
| 133 | |
---|
[d389819] | 134 | A task's priority determines its importance in relation to the |
---|
[fd6dc8c8] | 135 | other tasks executing on the same processor. RTEMS supports 255 |
---|
| 136 | levels of priority ranging from 1 to 255. The data type``rtems_task_priority`` is used to store task |
---|
| 137 | priorities. |
---|
| 138 | |
---|
| 139 | Tasks of numerically |
---|
| 140 | smaller priority values are more important tasks than tasks of |
---|
| 141 | numerically larger priority values. For example, a task at |
---|
| 142 | priority level 5 is of higher privilege than a task at priority |
---|
| 143 | level 10. There is no limit to the number of tasks assigned to |
---|
| 144 | the same priority. |
---|
| 145 | |
---|
| 146 | Each task has a priority associated with it at all times. The |
---|
| 147 | initial value of this priority is assigned at task creation |
---|
| 148 | time. The priority of a task may be changed at any subsequent |
---|
| 149 | time. |
---|
| 150 | |
---|
| 151 | Priorities are used by the scheduler to determine which ready |
---|
| 152 | task will be allowed to execute. In general, the higher the |
---|
| 153 | logical priority of a task, the more likely it is to receive |
---|
| 154 | processor execution time. |
---|
| 155 | |
---|
| 156 | Task Mode |
---|
| 157 | --------- |
---|
| 158 | .. index:: task mode |
---|
| 159 | .. index:: rtems_task_mode |
---|
| 160 | |
---|
[d389819] | 161 | A task's execution mode is a combination of the following |
---|
[fd6dc8c8] | 162 | four components: |
---|
| 163 | |
---|
| 164 | - preemption |
---|
| 165 | |
---|
| 166 | - ASR processing |
---|
| 167 | |
---|
| 168 | - timeslicing |
---|
| 169 | |
---|
| 170 | - interrupt level |
---|
| 171 | |
---|
[d389819] | 172 | It is used to modify RTEMS' scheduling process and to alter the |
---|
[fd6dc8c8] | 173 | execution environment of the task. The data type``rtems_task_mode`` is used to manage the task |
---|
| 174 | execution mode... index:: preemption |
---|
| 175 | |
---|
| 176 | The preemption component allows a task to determine when control of the |
---|
| 177 | processor is relinquished. If preemption is disabled |
---|
| 178 | (``RTEMS_NO_PREEMPT``), the task will retain control of the |
---|
[d389819] | 179 | processor as long as it is in the executing state - even if a higher |
---|
[fd6dc8c8] | 180 | priority task is made ready. If preemption is enabled |
---|
| 181 | (``RTEMS_PREEMPT``) and a higher priority task is made ready, |
---|
| 182 | then the processor will be taken away from the current task immediately and |
---|
| 183 | given to the higher priority task... index:: timeslicing |
---|
| 184 | |
---|
| 185 | The timeslicing component is used by the RTEMS scheduler to determine how |
---|
| 186 | the processor is allocated to tasks of equal priority. If timeslicing is |
---|
| 187 | enabled (``RTEMS_TIMESLICE``), then RTEMS will limit the amount |
---|
| 188 | of time the task can execute before the processor is allocated to another |
---|
| 189 | ready task of equal priority. The length of the timeslice is application |
---|
| 190 | dependent and specified in the Configuration Table. If timeslicing is |
---|
| 191 | disabled (``RTEMS_NO_TIMESLICE``), then the task will be |
---|
| 192 | allowed to execute until a task of higher priority is made ready. If``RTEMS_NO_PREEMPT`` is selected, then the timeslicing |
---|
| 193 | component is ignored by the scheduler. |
---|
| 194 | |
---|
| 195 | The asynchronous signal processing component is used to determine when |
---|
| 196 | received signals are to be processed by the task. |
---|
| 197 | If signal processing is enabled (``RTEMS_ASR``), then signals |
---|
| 198 | sent to the task will be processed the next time the task executes. If |
---|
| 199 | signal processing is disabled (``RTEMS_NO_ASR``), then all |
---|
| 200 | signals received by the task will remain posted until signal processing is |
---|
| 201 | enabled. This component affects only tasks which have established a |
---|
| 202 | routine to process asynchronous signals... index:: interrupt level, task |
---|
| 203 | |
---|
| 204 | The interrupt level component is used to determine which |
---|
| 205 | interrupts will be enabled when the task is executing.``RTEMS_INTERRUPT_LEVEL(n)`` |
---|
| 206 | specifies that the task will execute at interrupt level n. |
---|
| 207 | |
---|
| 208 | - ``RTEMS_PREEMPT`` - enable preemption (default) |
---|
| 209 | |
---|
| 210 | - ``RTEMS_NO_PREEMPT`` - disable preemption |
---|
| 211 | |
---|
| 212 | - ``RTEMS_NO_TIMESLICE`` - disable timeslicing (default) |
---|
| 213 | |
---|
| 214 | - ``RTEMS_TIMESLICE`` - enable timeslicing |
---|
| 215 | |
---|
| 216 | - ``RTEMS_ASR`` - enable ASR processing (default) |
---|
| 217 | |
---|
| 218 | - ``RTEMS_NO_ASR`` - disable ASR processing |
---|
| 219 | |
---|
| 220 | - ``RTEMS_INTERRUPT_LEVEL(0)`` - enable all interrupts (default) |
---|
| 221 | |
---|
| 222 | - ``RTEMS_INTERRUPT_LEVEL(n)`` - execute at interrupt level n |
---|
| 223 | |
---|
| 224 | The set of default modes may be selected by specifying the``RTEMS_DEFAULT_MODES`` constant. |
---|
| 225 | |
---|
| 226 | Accessing Task Arguments |
---|
| 227 | ------------------------ |
---|
| 228 | .. index:: task arguments |
---|
| 229 | .. index:: task prototype |
---|
| 230 | |
---|
| 231 | All RTEMS tasks are invoked with a single argument which is |
---|
| 232 | specified when they are started or restarted. The argument is |
---|
| 233 | commonly used to communicate startup information to the task. |
---|
| 234 | The simplest manner in which to define a task which accesses it |
---|
| 235 | argument is:.. index:: rtems_task |
---|
| 236 | |
---|
| 237 | .. code:: c |
---|
| 238 | |
---|
| 239 | rtems_task user_task( |
---|
| 240 | rtems_task_argument argument |
---|
| 241 | ); |
---|
| 242 | |
---|
| 243 | Application tasks requiring more information may view this |
---|
| 244 | single argument as an index into an array of parameter blocks. |
---|
| 245 | |
---|
| 246 | Floating Point Considerations |
---|
| 247 | ----------------------------- |
---|
| 248 | .. index:: floating point |
---|
| 249 | |
---|
| 250 | Creating a task with the ``RTEMS_FLOATING_POINT`` attribute |
---|
| 251 | flag results |
---|
| 252 | in additional memory being allocated for the TCB to store the state of the |
---|
| 253 | numeric coprocessor during task switches. This additional memory is*NOT* allocated for ``RTEMS_NO_FLOATING_POINT`` tasks. Saving |
---|
| 254 | and restoring the context of a ``RTEMS_FLOATING_POINT`` task |
---|
| 255 | takes longer than that of a ``RTEMS_NO_FLOATING_POINT`` task |
---|
| 256 | because of the relatively large amount of time required for the numeric |
---|
| 257 | coprocessor to save or restore its computational state. |
---|
| 258 | |
---|
| 259 | Since RTEMS was designed specifically for embedded military applications |
---|
| 260 | which are floating point intensive, the executive is optimized to avoid |
---|
| 261 | unnecessarily saving and restoring the state of the numeric coprocessor. |
---|
| 262 | The state of the numeric coprocessor is only saved when a``RTEMS_FLOATING_POINT`` task is dispatched and that task was |
---|
| 263 | not the last task to utilize the coprocessor. In a system with only one``RTEMS_FLOATING_POINT`` task, the state of the numeric |
---|
| 264 | coprocessor will never be saved or restored. |
---|
| 265 | |
---|
| 266 | Although the overhead imposed by ``RTEMS_FLOATING_POINT`` tasks |
---|
| 267 | is minimal, some applications may wish to completely avoid the overhead |
---|
| 268 | associated with ``RTEMS_FLOATING_POINT`` tasks and still |
---|
| 269 | utilize a numeric coprocessor. By preventing a task from being preempted |
---|
| 270 | while performing a sequence of floating point operations, a``RTEMS_NO_FLOATING_POINT`` task can utilize the numeric |
---|
| 271 | coprocessor without incurring the overhead of a``RTEMS_FLOATING_POINT`` context switch. This approach also |
---|
| 272 | avoids the allocation of a floating point context area. However, if this |
---|
| 273 | approach is taken by the application designer, NO tasks should be created |
---|
| 274 | as ``RTEMS_FLOATING_POINT`` tasks. Otherwise, the floating |
---|
| 275 | point context will not be correctly maintained because RTEMS assumes that |
---|
| 276 | the state of the numeric coprocessor will not be altered by``RTEMS_NO_FLOATING_POINT`` tasks. |
---|
| 277 | |
---|
| 278 | If the supported processor type does not have hardware floating |
---|
| 279 | capabilities or a standard numeric coprocessor, RTEMS will not provide |
---|
| 280 | built-in support for hardware floating point on that processor. In this |
---|
| 281 | case, all tasks are considered ``RTEMS_NO_FLOATING_POINT`` |
---|
| 282 | whether created as ``RTEMS_FLOATING_POINT`` or``RTEMS_NO_FLOATING_POINT`` tasks. A floating point emulation |
---|
| 283 | software library must be utilized for floating point operations. |
---|
| 284 | |
---|
| 285 | On some processors, it is possible to disable the floating point unit |
---|
| 286 | dynamically. If this capability is supported by the target processor, then |
---|
| 287 | RTEMS will utilize this capability to enable the floating point unit only |
---|
| 288 | for tasks which are created with the ``RTEMS_FLOATING_POINT`` |
---|
| 289 | attribute. The consequence of a ``RTEMS_NO_FLOATING_POINT`` |
---|
| 290 | task attempting to access the floating point unit is CPU dependent but will |
---|
| 291 | generally result in an exception condition. |
---|
| 292 | |
---|
| 293 | Per Task Variables |
---|
| 294 | ------------------ |
---|
| 295 | .. index:: per task variables |
---|
| 296 | |
---|
| 297 | Per task variables are deprecated, see the warning below. |
---|
| 298 | |
---|
| 299 | Per task variables are used to support global variables whose value |
---|
| 300 | may be unique to a task. After indicating that a variable should be |
---|
| 301 | treated as private (i.e. per-task) the task can access and modify the |
---|
| 302 | variable, but the modifications will not appear to other tasks, and |
---|
[d389819] | 303 | other tasks' modifications to that variable will not affect the value |
---|
[fd6dc8c8] | 304 | seen by the task. This is accomplished by saving and restoring the |
---|
[d389819] | 305 | variable's value each time a task switch occurs to or from the calling task. |
---|
[fd6dc8c8] | 306 | |
---|
| 307 | The value seen by other tasks, including those which have not added the |
---|
| 308 | variable to their set and are thus accessing the variable as a common |
---|
| 309 | location shared among tasks, cannot be affected by a task once it has |
---|
| 310 | added a variable to its local set. Changes made to the variable by |
---|
| 311 | other tasks will not affect the value seen by a task which has added the |
---|
| 312 | variable to its private set. |
---|
| 313 | |
---|
| 314 | This feature can be used when a routine is to be spawned repeatedly as |
---|
| 315 | several independent tasks. Although each task will have its own stack, |
---|
| 316 | and thus separate stack variables, they will all share the same static and |
---|
| 317 | global variables. To make a variable not shareable (i.e. a "global" variable |
---|
| 318 | that is specific to a single task), the tasks can call``rtems_task_variable_add`` to make a separate copy of the variable |
---|
| 319 | for each task, but all at the same physical address. |
---|
| 320 | |
---|
| 321 | Task variables increase the context switch time to and from the |
---|
| 322 | tasks that own them so it is desirable to minimize the number of |
---|
| 323 | task variables. One efficient method is to have a single task |
---|
| 324 | variable that is a pointer to a dynamically allocated structure |
---|
[d389819] | 325 | containing the task's private "global" data. |
---|
[fd6dc8c8] | 326 | |
---|
| 327 | A critical point with per-task variables is that each task must separately |
---|
| 328 | request that the same global variable is per-task private. |
---|
| 329 | |
---|
| 330 | *WARNING*: Per-Task variables are inherently broken on SMP systems. They |
---|
| 331 | only work correctly when there is one task executing in the system and |
---|
[d389819] | 332 | that task is the logical owner of the value in the per-task variable's |
---|
[fd6dc8c8] | 333 | location. There is no way for a single memory image to contain the |
---|
| 334 | correct value for each task executing on each core. Consequently, |
---|
| 335 | per-task variables are disabled in SMP configurations of RTEMS. |
---|
| 336 | Instead the application developer should |
---|
| 337 | consider the use of POSIX Keys or Thread Local Storage (TLS). POSIX Keys |
---|
| 338 | are not enabled in all RTEMS configurations. |
---|
| 339 | |
---|
| 340 | Building a Task Attribute Set |
---|
| 341 | ----------------------------- |
---|
| 342 | .. index:: task attributes, building |
---|
| 343 | |
---|
| 344 | In general, an attribute set is built by a bitwise OR of the |
---|
| 345 | desired components. The set of valid task attribute components |
---|
| 346 | is listed below: |
---|
| 347 | |
---|
| 348 | - ``RTEMS_NO_FLOATING_POINT`` - does not use coprocessor (default) |
---|
| 349 | |
---|
| 350 | - ``RTEMS_FLOATING_POINT`` - uses numeric coprocessor |
---|
| 351 | |
---|
| 352 | - ``RTEMS_LOCAL`` - local task (default) |
---|
| 353 | |
---|
| 354 | - ``RTEMS_GLOBAL`` - global task |
---|
| 355 | |
---|
| 356 | Attribute values are specifically designed to be mutually |
---|
| 357 | exclusive, therefore bitwise OR and addition operations are |
---|
| 358 | equivalent as long as each attribute appears exactly once in the |
---|
| 359 | component list. A component listed as a default is not required |
---|
| 360 | to appear in the component list, although it is a good |
---|
| 361 | programming practice to specify default components. If all |
---|
| 362 | defaults are desired, then ``RTEMS_DEFAULT_ATTRIBUTES`` should be used. |
---|
| 363 | |
---|
| 364 | This example demonstrates the attribute_set parameter needed to |
---|
| 365 | create a local task which utilizes the numeric coprocessor. The |
---|
| 366 | attribute_set parameter could be ``RTEMS_FLOATING_POINT`` or``RTEMS_LOCAL | RTEMS_FLOATING_POINT``. |
---|
| 367 | The attribute_set parameter can be set to``RTEMS_FLOATING_POINT`` because ``RTEMS_LOCAL`` is the default for all created |
---|
| 368 | tasks. If the task were global and used the numeric |
---|
| 369 | coprocessor, then the attribute_set parameter would be``RTEMS_GLOBAL | RTEMS_FLOATING_POINT``. |
---|
| 370 | |
---|
| 371 | Building a Mode and Mask |
---|
| 372 | ------------------------ |
---|
| 373 | .. index:: task mode, building |
---|
| 374 | |
---|
| 375 | In general, a mode and its corresponding mask is built by a |
---|
| 376 | bitwise OR of the desired components. The set of valid mode |
---|
[d389819] | 377 | constants and each mode's corresponding mask constant is |
---|
[fd6dc8c8] | 378 | listed below: |
---|
| 379 | |
---|
| 380 | - ``RTEMS_PREEMPT`` is masked by``RTEMS_PREEMPT_MASK`` and enables preemption |
---|
| 381 | |
---|
| 382 | - ``RTEMS_NO_PREEMPT`` is masked by``RTEMS_PREEMPT_MASK`` and disables preemption |
---|
| 383 | |
---|
| 384 | - ``RTEMS_NO_TIMESLICE`` is masked by``RTEMS_TIMESLICE_MASK`` and disables timeslicing |
---|
| 385 | |
---|
| 386 | - ``RTEMS_TIMESLICE`` is masked by``RTEMS_TIMESLICE_MASK`` and enables timeslicing |
---|
| 387 | |
---|
| 388 | - ``RTEMS_ASR`` is masked by``RTEMS_ASR_MASK`` and enables ASR processing |
---|
| 389 | |
---|
| 390 | - ``RTEMS_NO_ASR`` is masked by``RTEMS_ASR_MASK`` and disables ASR processing |
---|
| 391 | |
---|
| 392 | - ``RTEMS_INTERRUPT_LEVEL(0)`` is masked by``RTEMS_INTERRUPT_MASK`` and enables all interrupts |
---|
| 393 | |
---|
| 394 | - ``RTEMS_INTERRUPT_LEVEL(n)`` is masked by``RTEMS_INTERRUPT_MASK`` and sets interrupts level n |
---|
| 395 | |
---|
| 396 | Mode values are specifically designed to be mutually exclusive, therefore |
---|
| 397 | bitwise OR and addition operations are equivalent as long as each mode |
---|
| 398 | appears exactly once in the component list. A mode component listed as a |
---|
| 399 | default is not required to appear in the mode component list, although it |
---|
| 400 | is a good programming practice to specify default components. If all |
---|
| 401 | defaults are desired, the mode ``RTEMS_DEFAULT_MODES`` and the |
---|
| 402 | mask ``RTEMS_ALL_MODE_MASKS`` should be used. |
---|
| 403 | |
---|
| 404 | The following example demonstrates the mode and mask parameters used with |
---|
| 405 | the ``rtems_task_mode`` |
---|
| 406 | directive to place a task at interrupt level 3 and make it |
---|
| 407 | non-preemptible. The mode should be set to``RTEMS_INTERRUPT_LEVEL(3) | |
---|
| 408 | RTEMS_NO_PREEMPT`` to indicate the desired preemption mode and |
---|
| 409 | interrupt level, while the mask parameter should be set to``RTEMS_INTERRUPT_MASK | |
---|
[d389819] | 410 | RTEMS_NO_PREEMPT_MASK`` to indicate that the calling task's |
---|
[fd6dc8c8] | 411 | interrupt level and preemption mode are being altered. |
---|
| 412 | |
---|
| 413 | Operations |
---|
| 414 | ========== |
---|
| 415 | |
---|
| 416 | Creating Tasks |
---|
| 417 | -------------- |
---|
| 418 | |
---|
| 419 | The ``rtems_task_create`` |
---|
| 420 | directive creates a task by allocating a task |
---|
| 421 | control block, assigning the task a user-specified name, |
---|
| 422 | allocating it a stack and floating point context area, setting a |
---|
| 423 | user-specified initial priority, setting a user-specified |
---|
| 424 | initial mode, and assigning it a task ID. Newly created tasks |
---|
| 425 | are initially placed in the dormant state. All RTEMS tasks |
---|
| 426 | execute in the most privileged mode of the processor. |
---|
| 427 | |
---|
| 428 | Obtaining Task IDs |
---|
| 429 | ------------------ |
---|
| 430 | |
---|
| 431 | When a task is created, RTEMS generates a unique task ID and |
---|
| 432 | assigns it to the created task until it is deleted. The task ID |
---|
| 433 | may be obtained by either of two methods. First, as the result |
---|
| 434 | of an invocation of the ``rtems_task_create`` |
---|
| 435 | directive, the task ID is |
---|
| 436 | stored in a user provided location. Second, the task ID may be |
---|
| 437 | obtained later using the ``rtems_task_ident`` |
---|
| 438 | directive. The task ID is |
---|
| 439 | used by other directives to manipulate this task. |
---|
| 440 | |
---|
| 441 | Starting and Restarting Tasks |
---|
| 442 | ----------------------------- |
---|
| 443 | |
---|
| 444 | The ``rtems_task_start`` |
---|
| 445 | directive is used to place a dormant task in the |
---|
| 446 | ready state. This enables the task to compete, based on its |
---|
| 447 | current priority, for the processor and other system resources. |
---|
| 448 | Any actions, such as suspension or change of priority, performed |
---|
| 449 | on a task prior to starting it are nullified when the task is |
---|
| 450 | started. |
---|
| 451 | |
---|
| 452 | With the ``rtems_task_start`` |
---|
[d389819] | 453 | directive the user specifies the task's |
---|
[fd6dc8c8] | 454 | starting address and argument. The argument is used to |
---|
| 455 | communicate some startup information to the task. As part of |
---|
[d389819] | 456 | this directive, RTEMS initializes the task's stack based upon |
---|
| 457 | the task's initial execution mode and start address. The |
---|
[fd6dc8c8] | 458 | starting argument is passed to the task in accordance with the |
---|
[d389819] | 459 | target processor's calling convention. |
---|
[fd6dc8c8] | 460 | |
---|
| 461 | The ``rtems_task_restart`` |
---|
| 462 | directive restarts a task at its initial |
---|
| 463 | starting address with its original priority and execution mode, |
---|
| 464 | but with a possibly different argument. The new argument may be |
---|
| 465 | used to distinguish between the original invocation of the task |
---|
[d389819] | 466 | and subsequent invocations. The task's stack and control block |
---|
[fd6dc8c8] | 467 | are modified to reflect their original creation values. |
---|
| 468 | Although references to resources that have been requested are |
---|
| 469 | cleared, resources allocated by the task are NOT automatically |
---|
| 470 | returned to RTEMS. A task cannot be restarted unless it has |
---|
| 471 | previously been started (i.e. dormant tasks cannot be |
---|
| 472 | restarted). All restarted tasks are placed in the ready state. |
---|
| 473 | |
---|
| 474 | Suspending and Resuming Tasks |
---|
| 475 | ----------------------------- |
---|
| 476 | |
---|
| 477 | The ``rtems_task_suspend`` |
---|
| 478 | directive is used to place either the caller or |
---|
| 479 | another task into a suspended state. The task remains suspended |
---|
| 480 | until a ``rtems_task_resume`` |
---|
| 481 | directive is issued. This implies that a |
---|
| 482 | task may be suspended as well as blocked waiting either to |
---|
| 483 | acquire a resource or for the expiration of a timer. |
---|
| 484 | |
---|
| 485 | The ``rtems_task_resume`` |
---|
| 486 | directive is used to remove another task from |
---|
| 487 | the suspended state. If the task is not also blocked, resuming |
---|
| 488 | it will place it in the ready state, allowing it to once again |
---|
| 489 | compete for the processor and resources. If the task was |
---|
| 490 | blocked as well as suspended, this directive clears the |
---|
| 491 | suspension and leaves the task in the blocked state. |
---|
| 492 | |
---|
| 493 | Suspending a task which is already suspended or resuming a |
---|
| 494 | task which is not suspended is considered an error. |
---|
| 495 | The ``rtems_task_is_suspended`` can be used to |
---|
| 496 | determine if a task is currently suspended. |
---|
| 497 | |
---|
| 498 | Delaying the Currently Executing Task |
---|
| 499 | ------------------------------------- |
---|
| 500 | |
---|
| 501 | The ``rtems_task_wake_after`` directive creates a sleep timer |
---|
| 502 | which allows a task to go to sleep for a specified interval. The task is |
---|
| 503 | blocked until the delay interval has elapsed, at which time the task is |
---|
| 504 | unblocked. A task calling the ``rtems_task_wake_after`` |
---|
| 505 | directive with a delay |
---|
| 506 | interval of ``RTEMS_YIELD_PROCESSOR`` ticks will yield the |
---|
| 507 | processor to any other ready task of equal or greater priority and remain |
---|
| 508 | ready to execute. |
---|
| 509 | |
---|
| 510 | The ``rtems_task_wake_when`` |
---|
| 511 | directive creates a sleep timer which allows |
---|
| 512 | a task to go to sleep until a specified date and time. The |
---|
| 513 | calling task is blocked until the specified date and time has |
---|
| 514 | occurred, at which time the task is unblocked. |
---|
| 515 | |
---|
| 516 | Changing Task Priority |
---|
| 517 | ---------------------- |
---|
| 518 | |
---|
| 519 | The ``rtems_task_set_priority`` |
---|
| 520 | directive is used to obtain or change the |
---|
| 521 | current priority of either the calling task or another task. If |
---|
[d389819] | 522 | the new priority requested is``RTEMS_CURRENT_PRIORITY`` or the task's |
---|
[fd6dc8c8] | 523 | actual priority, then the current priority will be returned and |
---|
[d389819] | 524 | the task's priority will remain unchanged. If the task's |
---|
[fd6dc8c8] | 525 | priority is altered, then the task will be scheduled according |
---|
| 526 | to its new priority. |
---|
| 527 | |
---|
| 528 | The ``rtems_task_restart`` |
---|
| 529 | directive resets the priority of a task to its |
---|
| 530 | original value. |
---|
| 531 | |
---|
| 532 | Changing Task Mode |
---|
| 533 | ------------------ |
---|
| 534 | |
---|
| 535 | The ``rtems_task_mode`` |
---|
| 536 | directive is used to obtain or change the current |
---|
[d389819] | 537 | execution mode of the calling task. A task's execution mode is |
---|
[fd6dc8c8] | 538 | used to enable preemption, timeslicing, ASR processing, and to |
---|
[d389819] | 539 | set the task's interrupt level. |
---|
[fd6dc8c8] | 540 | |
---|
| 541 | The ``rtems_task_restart`` |
---|
| 542 | directive resets the mode of a task to its |
---|
| 543 | original value. |
---|
| 544 | |
---|
| 545 | Task Deletion |
---|
| 546 | ------------- |
---|
| 547 | |
---|
| 548 | RTEMS provides the ``rtems_task_delete`` |
---|
| 549 | directive to allow a task to |
---|
| 550 | delete itself or any other task. This directive removes all |
---|
[d389819] | 551 | RTEMS references to the task, frees the task's control block, |
---|
[fd6dc8c8] | 552 | removes it from resource wait queues, and deallocates its stack |
---|
[d389819] | 553 | as well as the optional floating point context. The task's name |
---|
[fd6dc8c8] | 554 | and ID become inactive at this time, and any subsequent |
---|
| 555 | references to either of them is invalid. In fact, RTEMS may |
---|
| 556 | reuse the task ID for another task which is created later in the |
---|
| 557 | application. |
---|
| 558 | |
---|
| 559 | Unexpired delay timers (i.e. those used by``rtems_task_wake_after`` and``rtems_task_wake_when``) and |
---|
| 560 | timeout timers associated with the task are |
---|
| 561 | automatically deleted, however, other resources dynamically |
---|
| 562 | allocated by the task are NOT automatically returned to RTEMS. |
---|
| 563 | Therefore, before a task is deleted, all of its dynamically |
---|
| 564 | allocated resources should be deallocated by the user. This may |
---|
| 565 | be accomplished by instructing the task to delete itself rather |
---|
| 566 | than directly deleting the task. Other tasks may instruct a |
---|
| 567 | task to delete itself by sending a "delete self" message, event, |
---|
| 568 | or signal, or by restarting the task with special arguments |
---|
| 569 | which instruct the task to delete itself. |
---|
| 570 | |
---|
| 571 | Transition Advice for Obsolete Directives |
---|
| 572 | ----------------------------------------- |
---|
| 573 | |
---|
| 574 | Notepads |
---|
| 575 | ~~~~~~~~.. index:: rtems_task_get_note |
---|
| 576 | .. index:: rtems_task_set_note |
---|
| 577 | |
---|
| 578 | Task notepads and the associated directives``rtems_task_get_note`` and``rtems_task_set_note`` were removed after the 4.11 Release |
---|
| 579 | Series. These were never thread-safe to access and subject to conflicting |
---|
| 580 | use of the notepad index by libraries which were designed independently. |
---|
| 581 | |
---|
| 582 | It is recommended that applications be modified to use services |
---|
| 583 | which are thread safe and not subject to issues with multiple applications |
---|
| 584 | conflicting over the key (e.g. notepad index) selection. For most |
---|
| 585 | applications, POSIX Keys should be used. These are available in all RTEMS |
---|
| 586 | build configurations. It is also possible that Thread Local Storage is |
---|
| 587 | an option for some use cases. |
---|
| 588 | |
---|
| 589 | Directives |
---|
| 590 | ========== |
---|
| 591 | |
---|
[d389819] | 592 | This section details the task manager's directives. A |
---|
| 593 | subsection is dedicated to each of this manager's directives and |
---|
[fd6dc8c8] | 594 | describes the calling sequence, related constants, usage, and |
---|
| 595 | status codes. |
---|
| 596 | |
---|
| 597 | TASK_CREATE - Create a task |
---|
| 598 | --------------------------- |
---|
| 599 | .. index:: create a task |
---|
| 600 | |
---|
| 601 | **CALLING SEQUENCE:** |
---|
| 602 | |
---|
| 603 | .. index:: rtems_task_create |
---|
| 604 | |
---|
| 605 | .. code:: c |
---|
| 606 | |
---|
| 607 | rtems_status_code rtems_task_create( |
---|
| 608 | rtems_name name, |
---|
| 609 | rtems_task_priority initial_priority, |
---|
| 610 | size_t stack_size, |
---|
| 611 | rtems_mode initial_modes, |
---|
| 612 | rtems_attribute attribute_set, |
---|
| 613 | rtems_id \*id |
---|
| 614 | ); |
---|
| 615 | |
---|
| 616 | **DIRECTIVE STATUS CODES:** |
---|
| 617 | |
---|
| 618 | ``RTEMS_SUCCESSFUL`` - task created successfully |
---|
| 619 | ``RTEMS_INVALID_ADDRESS`` - ``id`` is NULL |
---|
| 620 | ``RTEMS_INVALID_NAME`` - invalid task name |
---|
| 621 | ``RTEMS_INVALID_PRIORITY`` - invalid task priority |
---|
| 622 | ``RTEMS_MP_NOT_CONFIGURED`` - multiprocessing not configured |
---|
| 623 | ``RTEMS_TOO_MANY`` - too many tasks created |
---|
| 624 | ``RTEMS_UNSATISFIED`` - not enough memory for stack/FP context |
---|
| 625 | ``RTEMS_TOO_MANY`` - too many global objects |
---|
| 626 | |
---|
| 627 | **DESCRIPTION:** |
---|
| 628 | |
---|
| 629 | This directive creates a task which resides on the local node. |
---|
| 630 | It allocates and initializes a TCB, a stack, and an optional |
---|
| 631 | floating point context area. The mode parameter contains values |
---|
[d389819] | 632 | which sets the task's initial execution mode. The``RTEMS_FLOATING_POINT`` attribute should be |
---|
[fd6dc8c8] | 633 | specified if the created task |
---|
| 634 | is to use a numeric coprocessor. For performance reasons, it is |
---|
| 635 | recommended that tasks not using the numeric coprocessor should |
---|
| 636 | specify the ``RTEMS_NO_FLOATING_POINT`` attribute. |
---|
| 637 | If the ``RTEMS_GLOBAL`` |
---|
| 638 | attribute is specified, the task can be accessed from remote |
---|
| 639 | nodes. The task id, returned in id, is used in other task |
---|
| 640 | related directives to access the task. When created, a task is |
---|
| 641 | placed in the dormant state and can only be made ready to |
---|
| 642 | execute using the directive ``rtems_task_start``. |
---|
| 643 | |
---|
| 644 | **NOTES:** |
---|
| 645 | |
---|
| 646 | This directive will not cause the calling task to be preempted. |
---|
| 647 | |
---|
| 648 | Valid task priorities range from a high of 1 to a low of 255. |
---|
| 649 | |
---|
| 650 | If the requested stack size is less than the configured |
---|
| 651 | minimum stack size, then RTEMS will use the configured |
---|
| 652 | minimum as the stack size for this task. In addition |
---|
| 653 | to being able to specify the task stack size as a integer, |
---|
| 654 | there are two constants which may be specified: |
---|
| 655 | |
---|
| 656 | - ``RTEMS_MINIMUM_STACK_SIZE`` |
---|
| 657 | is the minimum stack size *RECOMMENDED* for use on this processor. |
---|
| 658 | This value is selected by the RTEMS developers conservatively to |
---|
| 659 | minimize the risk of blown stacks for most user applications. |
---|
| 660 | Using this constant when specifying the task stack size, indicates |
---|
| 661 | that the stack size will be at least``RTEMS_MINIMUM_STACK_SIZE`` bytes in size. If the |
---|
| 662 | user configured minimum stack size is larger than the recommended |
---|
| 663 | minimum, then it will be used. |
---|
| 664 | |
---|
| 665 | - ``RTEMS_CONFIGURED_MINIMUM_STACK_SIZE`` |
---|
| 666 | indicates that this task is to be created with a stack size |
---|
| 667 | of the minimum stack size that was configured by the application. |
---|
| 668 | If not explicitly configured by the application, the default |
---|
| 669 | configured minimum stack size is the processor dependent value``RTEMS_MINIMUM_STACK_SIZE``. Since this uses |
---|
| 670 | the configured minimum stack size value, you may get a stack |
---|
| 671 | size that is smaller or larger than the recommended minimum. This |
---|
| 672 | can be used to provide large stacks for all tasks on complex |
---|
| 673 | applications or small stacks on applications that are trying |
---|
| 674 | to conserve memory. |
---|
| 675 | |
---|
| 676 | Application developers should consider the stack usage of the |
---|
| 677 | device drivers when calculating the stack size required for |
---|
| 678 | tasks which utilize the driver. |
---|
| 679 | |
---|
| 680 | The following task attribute constants are defined by RTEMS: |
---|
| 681 | |
---|
| 682 | - ``RTEMS_NO_FLOATING_POINT`` - does not use coprocessor (default) |
---|
| 683 | |
---|
| 684 | - ``RTEMS_FLOATING_POINT`` - uses numeric coprocessor |
---|
| 685 | |
---|
| 686 | - ``RTEMS_LOCAL`` - local task (default) |
---|
| 687 | |
---|
| 688 | - ``RTEMS_GLOBAL`` - global task |
---|
| 689 | |
---|
| 690 | The following task mode constants are defined by RTEMS: |
---|
| 691 | |
---|
| 692 | - ``RTEMS_PREEMPT`` - enable preemption (default) |
---|
| 693 | |
---|
| 694 | - ``RTEMS_NO_PREEMPT`` - disable preemption |
---|
| 695 | |
---|
| 696 | - ``RTEMS_NO_TIMESLICE`` - disable timeslicing (default) |
---|
| 697 | |
---|
| 698 | - ``RTEMS_TIMESLICE`` - enable timeslicing |
---|
| 699 | |
---|
| 700 | - ``RTEMS_ASR`` - enable ASR processing (default) |
---|
| 701 | |
---|
| 702 | - ``RTEMS_NO_ASR`` - disable ASR processing |
---|
| 703 | |
---|
| 704 | - ``RTEMS_INTERRUPT_LEVEL(0)`` - enable all interrupts (default) |
---|
| 705 | |
---|
| 706 | - ``RTEMS_INTERRUPT_LEVEL(n)`` - execute at interrupt level n |
---|
| 707 | |
---|
| 708 | The interrupt level portion of the task execution mode |
---|
| 709 | supports a maximum of 256 interrupt levels. These levels are |
---|
| 710 | mapped onto the interrupt levels actually supported by the |
---|
| 711 | target processor in a processor dependent fashion. |
---|
| 712 | |
---|
| 713 | Tasks should not be made global unless remote tasks must |
---|
| 714 | interact with them. This avoids the system overhead incurred by |
---|
| 715 | the creation of a global task. When a global task is created, |
---|
[d389819] | 716 | the task's name and id must be transmitted to every node in the |
---|
[fd6dc8c8] | 717 | system for insertion in the local copy of the global object |
---|
| 718 | table. |
---|
| 719 | |
---|
| 720 | The total number of global objects, including tasks, is limited |
---|
| 721 | by the maximum_global_objects field in the Configuration Table. |
---|
| 722 | |
---|
| 723 | TASK_IDENT - Get ID of a task |
---|
| 724 | ----------------------------- |
---|
| 725 | .. index:: get ID of a task |
---|
| 726 | |
---|
| 727 | **CALLING SEQUENCE:** |
---|
| 728 | |
---|
| 729 | .. index:: rtems_task_ident |
---|
| 730 | |
---|
| 731 | .. code:: c |
---|
| 732 | |
---|
| 733 | rtems_status_code rtems_task_ident( |
---|
| 734 | rtems_name name, |
---|
| 735 | uint32_t node, |
---|
| 736 | rtems_id \*id |
---|
| 737 | ); |
---|
| 738 | |
---|
| 739 | **DIRECTIVE STATUS CODES:** |
---|
| 740 | |
---|
| 741 | ``RTEMS_SUCCESSFUL`` - task identified successfully |
---|
| 742 | ``RTEMS_INVALID_ADDRESS`` - ``id`` is NULL |
---|
| 743 | ``RTEMS_INVALID_NAME`` - invalid task name |
---|
| 744 | ``RTEMS_INVALID_NODE`` - invalid node id |
---|
| 745 | |
---|
| 746 | **DESCRIPTION:** |
---|
| 747 | |
---|
| 748 | This directive obtains the task id associated with the task name |
---|
| 749 | specified in name. A task may obtain its own id by specifying``RTEMS_SELF`` or its own task name in name. If the task name is not |
---|
| 750 | unique, then the task id returned will match one of the tasks |
---|
| 751 | with that name. However, this task id is not guaranteed to |
---|
| 752 | correspond to the desired task. The task id, returned in id, is |
---|
| 753 | used in other task related directives to access the task. |
---|
| 754 | |
---|
| 755 | **NOTES:** |
---|
| 756 | |
---|
| 757 | This directive will not cause the running task to be preempted. |
---|
| 758 | |
---|
| 759 | If node is ``RTEMS_SEARCH_ALL_NODES``, all nodes are searched with the |
---|
| 760 | local node being searched first. All other nodes are searched |
---|
| 761 | with the lowest numbered node searched first. |
---|
| 762 | |
---|
| 763 | If node is a valid node number which does not represent the |
---|
| 764 | local node, then only the tasks exported by the designated node |
---|
| 765 | are searched. |
---|
| 766 | |
---|
| 767 | This directive does not generate activity on remote nodes. It |
---|
| 768 | accesses only the local copy of the global object table. |
---|
| 769 | |
---|
| 770 | TASK_SELF - Obtain ID of caller |
---|
| 771 | ------------------------------- |
---|
| 772 | .. index:: obtain ID of caller |
---|
| 773 | |
---|
| 774 | **CALLING SEQUENCE:** |
---|
| 775 | |
---|
| 776 | .. index:: rtems_task_self |
---|
| 777 | |
---|
| 778 | .. code:: c |
---|
| 779 | |
---|
| 780 | rtems_id rtems_task_self(void); |
---|
| 781 | |
---|
| 782 | **DIRECTIVE STATUS CODES:** |
---|
| 783 | |
---|
| 784 | Returns the object Id of the calling task. |
---|
| 785 | |
---|
| 786 | **DESCRIPTION:** |
---|
| 787 | |
---|
| 788 | This directive returns the Id of the calling task. |
---|
| 789 | |
---|
| 790 | **NOTES:** |
---|
| 791 | |
---|
| 792 | If called from an interrupt service routine, this directive |
---|
| 793 | will return the Id of the interrupted task. |
---|
| 794 | |
---|
| 795 | TASK_START - Start a task |
---|
| 796 | ------------------------- |
---|
| 797 | .. index:: starting a task |
---|
| 798 | |
---|
| 799 | **CALLING SEQUENCE:** |
---|
| 800 | |
---|
| 801 | .. index:: rtems_task_start |
---|
| 802 | |
---|
| 803 | .. code:: c |
---|
| 804 | |
---|
| 805 | rtems_status_code rtems_task_start( |
---|
| 806 | rtems_id id, |
---|
| 807 | rtems_task_entry entry_point, |
---|
| 808 | rtems_task_argument argument |
---|
| 809 | ); |
---|
| 810 | |
---|
| 811 | **DIRECTIVE STATUS CODES:** |
---|
| 812 | |
---|
| 813 | ``RTEMS_SUCCESSFUL`` - ask started successfully |
---|
| 814 | ``RTEMS_INVALID_ADDRESS`` - invalid task entry point |
---|
| 815 | ``RTEMS_INVALID_ID`` - invalid task id |
---|
| 816 | ``RTEMS_INCORRECT_STATE`` - task not in the dormant state |
---|
| 817 | ``RTEMS_ILLEGAL_ON_REMOTE_OBJECT`` - cannot start remote task |
---|
| 818 | |
---|
| 819 | **DESCRIPTION:** |
---|
| 820 | |
---|
| 821 | This directive readies the task, specified by ``id``, for execution |
---|
| 822 | based on the priority and execution mode specified when the task |
---|
[d389819] | 823 | was created. The starting address of the task is given in``entry_point``. The task's starting argument is contained in |
---|
[fd6dc8c8] | 824 | argument. This argument can be a single value or used as an index into an |
---|
| 825 | array of parameter blocks. The type of this numeric argument is an unsigned |
---|
| 826 | integer type with the property that any valid pointer to void can be converted |
---|
| 827 | to this type and then converted back to a pointer to void. The result will |
---|
| 828 | compare equal to the original pointer. |
---|
| 829 | |
---|
| 830 | **NOTES:** |
---|
| 831 | |
---|
| 832 | The calling task will be preempted if its preemption mode is |
---|
| 833 | enabled and the task being started has a higher priority. |
---|
| 834 | |
---|
| 835 | Any actions performed on a dormant task such as suspension or |
---|
| 836 | change of priority are nullified when the task is initiated via |
---|
| 837 | the ``rtems_task_start`` directive. |
---|
| 838 | |
---|
| 839 | TASK_RESTART - Restart a task |
---|
| 840 | ----------------------------- |
---|
| 841 | .. index:: restarting a task |
---|
| 842 | |
---|
| 843 | **CALLING SEQUENCE:** |
---|
| 844 | |
---|
| 845 | .. index:: rtems_task_restart |
---|
| 846 | |
---|
| 847 | .. code:: c |
---|
| 848 | |
---|
| 849 | rtems_status_code rtems_task_restart( |
---|
| 850 | rtems_id id, |
---|
| 851 | rtems_task_argument argument |
---|
| 852 | ); |
---|
| 853 | |
---|
| 854 | **DIRECTIVE STATUS CODES:** |
---|
| 855 | |
---|
| 856 | ``RTEMS_SUCCESSFUL`` - task restarted successfully |
---|
| 857 | ``RTEMS_INVALID_ID`` - task id invalid |
---|
| 858 | ``RTEMS_INCORRECT_STATE`` - task never started |
---|
| 859 | ``RTEMS_ILLEGAL_ON_REMOTE_OBJECT`` - cannot restart remote task |
---|
| 860 | |
---|
| 861 | **DESCRIPTION:** |
---|
| 862 | |
---|
| 863 | This directive resets the task specified by id to begin |
---|
[d389819] | 864 | execution at its original starting address. The task's priority |
---|
[fd6dc8c8] | 865 | and execution mode are set to the original creation values. If |
---|
| 866 | the task is currently blocked, RTEMS automatically makes the |
---|
| 867 | task ready. A task can be restarted from any state, except the |
---|
| 868 | dormant state. |
---|
| 869 | |
---|
[d389819] | 870 | The task's starting argument is contained in argument. This argument can be a |
---|
[fd6dc8c8] | 871 | single value or an index into an array of parameter blocks. The type of this |
---|
| 872 | numeric argument is an unsigned integer type with the property that any valid |
---|
| 873 | pointer to void can be converted to this type and then converted back to a |
---|
| 874 | pointer to void. The result will compare equal to the original pointer. This |
---|
| 875 | new argument may be used to distinguish |
---|
| 876 | between the initial ``rtems_task_start`` |
---|
| 877 | of the task and any ensuing calls |
---|
| 878 | to ``rtems_task_restart`` |
---|
| 879 | of the task. This can be beneficial in deleting |
---|
| 880 | a task. Instead of deleting a task using |
---|
| 881 | the ``rtems_task_delete`` |
---|
| 882 | directive, a task can delete another task by restarting that |
---|
| 883 | task, and allowing that task to release resources back to RTEMS |
---|
| 884 | and then delete itself. |
---|
| 885 | |
---|
| 886 | **NOTES:** |
---|
| 887 | |
---|
| 888 | If id is ``RTEMS_SELF``, the calling task will be restarted and will not |
---|
| 889 | return from this directive. |
---|
| 890 | |
---|
| 891 | The calling task will be preempted if its preemption mode is |
---|
| 892 | enabled and the task being restarted has a higher priority. |
---|
| 893 | |
---|
| 894 | The task must reside on the local node, even if the task was |
---|
| 895 | created with the ``RTEMS_GLOBAL`` option. |
---|
| 896 | |
---|
| 897 | TASK_DELETE - Delete a task |
---|
| 898 | --------------------------- |
---|
| 899 | .. index:: deleting a task |
---|
| 900 | |
---|
| 901 | **CALLING SEQUENCE:** |
---|
| 902 | |
---|
| 903 | .. index:: rtems_task_delete |
---|
| 904 | |
---|
| 905 | .. code:: c |
---|
| 906 | |
---|
| 907 | rtems_status_code rtems_task_delete( |
---|
| 908 | rtems_id id |
---|
| 909 | ); |
---|
| 910 | |
---|
| 911 | **DIRECTIVE STATUS CODES:** |
---|
| 912 | |
---|
| 913 | ``RTEMS_SUCCESSFUL`` - task deleted successfully |
---|
| 914 | ``RTEMS_INVALID_ID`` - task id invalid |
---|
| 915 | ``RTEMS_ILLEGAL_ON_REMOTE_OBJECT`` - cannot restart remote task |
---|
| 916 | |
---|
| 917 | **DESCRIPTION:** |
---|
| 918 | |
---|
| 919 | This directive deletes a task, either the calling task or |
---|
| 920 | another task, as specified by id. RTEMS stops the execution of |
---|
| 921 | the task and reclaims the stack memory, any allocated delay or |
---|
| 922 | timeout timers, the TCB, and, if the task is ``RTEMS_FLOATING_POINT``, its |
---|
| 923 | floating point context area. RTEMS does not reclaim the |
---|
| 924 | following resources: region segments, partition buffers, |
---|
| 925 | semaphores, timers, or rate monotonic periods. |
---|
| 926 | |
---|
| 927 | **NOTES:** |
---|
| 928 | |
---|
| 929 | A task is responsible for releasing its resources back to RTEMS |
---|
| 930 | before deletion. To insure proper deallocation of resources, a |
---|
| 931 | task should not be deleted unless it is unable to execute or |
---|
| 932 | does not hold any RTEMS resources. If a task holds RTEMS |
---|
| 933 | resources, the task should be allowed to deallocate its |
---|
| 934 | resources before deletion. A task can be directed to release |
---|
| 935 | its resources and delete itself by restarting it with a special |
---|
| 936 | argument or by sending it a message, an event, or a signal. |
---|
| 937 | |
---|
| 938 | Deletion of the current task (``RTEMS_SELF``) will force RTEMS to select |
---|
| 939 | another task to execute. |
---|
| 940 | |
---|
| 941 | When a global task is deleted, the task id must be transmitted |
---|
| 942 | to every node in the system for deletion from the local copy of |
---|
| 943 | the global object table. |
---|
| 944 | |
---|
| 945 | The task must reside on the local node, even if the task was |
---|
| 946 | created with the ``RTEMS_GLOBAL`` option. |
---|
| 947 | |
---|
| 948 | TASK_SUSPEND - Suspend a task |
---|
| 949 | ----------------------------- |
---|
| 950 | .. index:: suspending a task |
---|
| 951 | |
---|
| 952 | **CALLING SEQUENCE:** |
---|
| 953 | |
---|
| 954 | .. index:: rtems_task_suspend |
---|
| 955 | |
---|
| 956 | .. code:: c |
---|
| 957 | |
---|
| 958 | rtems_status_code rtems_task_suspend( |
---|
| 959 | rtems_id id |
---|
| 960 | ); |
---|
| 961 | |
---|
| 962 | **DIRECTIVE STATUS CODES:** |
---|
| 963 | |
---|
| 964 | ``RTEMS_SUCCESSFUL`` - task suspended successfully |
---|
| 965 | ``RTEMS_INVALID_ID`` - task id invalid |
---|
| 966 | ``RTEMS_ALREADY_SUSPENDED`` - task already suspended |
---|
| 967 | |
---|
| 968 | **DESCRIPTION:** |
---|
| 969 | |
---|
| 970 | This directive suspends the task specified by id from further |
---|
| 971 | execution by placing it in the suspended state. This state is |
---|
| 972 | additive to any other blocked state that the task may already be |
---|
| 973 | in. The task will not execute again until another task issues |
---|
| 974 | the ``rtems_task_resume`` |
---|
| 975 | directive for this task and any blocked state |
---|
| 976 | has been removed. |
---|
| 977 | |
---|
| 978 | **NOTES:** |
---|
| 979 | |
---|
| 980 | The requesting task can suspend itself by specifying ``RTEMS_SELF`` as id. |
---|
| 981 | In this case, the task will be suspended and a successful |
---|
| 982 | return code will be returned when the task is resumed. |
---|
| 983 | |
---|
| 984 | Suspending a global task which does not reside on the local node |
---|
| 985 | will generate a request to the remote node to suspend the |
---|
| 986 | specified task. |
---|
| 987 | |
---|
| 988 | If the task specified by id is already suspended, then the``RTEMS_ALREADY_SUSPENDED`` status code is returned. |
---|
| 989 | |
---|
| 990 | TASK_RESUME - Resume a task |
---|
| 991 | --------------------------- |
---|
| 992 | .. index:: resuming a task |
---|
| 993 | |
---|
| 994 | **CALLING SEQUENCE:** |
---|
| 995 | |
---|
| 996 | .. index:: rtems_task_resume |
---|
| 997 | |
---|
| 998 | .. code:: c |
---|
| 999 | |
---|
| 1000 | rtems_status_code rtems_task_resume( |
---|
| 1001 | rtems_id id |
---|
| 1002 | ); |
---|
| 1003 | |
---|
| 1004 | **DIRECTIVE STATUS CODES:** |
---|
| 1005 | |
---|
| 1006 | ``RTEMS_SUCCESSFUL`` - task resumed successfully |
---|
| 1007 | ``RTEMS_INVALID_ID`` - task id invalid |
---|
| 1008 | ``RTEMS_INCORRECT_STATE`` - task not suspended |
---|
| 1009 | |
---|
| 1010 | **DESCRIPTION:** |
---|
| 1011 | |
---|
| 1012 | This directive removes the task specified by id from the |
---|
| 1013 | suspended state. If the task is in the ready state after the |
---|
| 1014 | suspension is removed, then it will be scheduled to run. If the |
---|
| 1015 | task is still in a blocked state after the suspension is |
---|
| 1016 | removed, then it will remain in that blocked state. |
---|
| 1017 | |
---|
| 1018 | **NOTES:** |
---|
| 1019 | |
---|
| 1020 | The running task may be preempted if its preemption mode is |
---|
| 1021 | enabled and the local task being resumed has a higher priority. |
---|
| 1022 | |
---|
| 1023 | Resuming a global task which does not reside on the local node |
---|
| 1024 | will generate a request to the remote node to resume the |
---|
| 1025 | specified task. |
---|
| 1026 | |
---|
| 1027 | If the task specified by id is not suspended, then the``RTEMS_INCORRECT_STATE`` status code is returned. |
---|
| 1028 | |
---|
| 1029 | TASK_IS_SUSPENDED - Determine if a task is Suspended |
---|
| 1030 | ---------------------------------------------------- |
---|
| 1031 | .. index:: is task suspended |
---|
| 1032 | |
---|
| 1033 | **CALLING SEQUENCE:** |
---|
| 1034 | |
---|
| 1035 | .. index:: rtems_task_is_suspended |
---|
| 1036 | |
---|
| 1037 | .. code:: c |
---|
| 1038 | |
---|
| 1039 | rtems_status_code rtems_task_is_suspended( |
---|
| 1040 | rtems_id id |
---|
| 1041 | ); |
---|
| 1042 | |
---|
| 1043 | **DIRECTIVE STATUS CODES:** |
---|
| 1044 | |
---|
| 1045 | ``RTEMS_SUCCESSFUL`` - task is NOT suspended |
---|
| 1046 | ``RTEMS_ALREADY_SUSPENDED`` - task is currently suspended |
---|
| 1047 | ``RTEMS_INVALID_ID`` - task id invalid |
---|
| 1048 | ``RTEMS_ILLEGAL_ON_REMOTE_OBJECT`` - not supported on remote tasks |
---|
| 1049 | |
---|
| 1050 | **DESCRIPTION:** |
---|
| 1051 | |
---|
| 1052 | This directive returns a status code indicating whether or |
---|
| 1053 | not the specified task is currently suspended. |
---|
| 1054 | |
---|
| 1055 | **NOTES:** |
---|
| 1056 | |
---|
| 1057 | This operation is not currently supported on remote tasks. |
---|
| 1058 | |
---|
| 1059 | TASK_SET_PRIORITY - Set task priority |
---|
| 1060 | ------------------------------------- |
---|
| 1061 | .. index:: rtems_task_set_priority |
---|
| 1062 | .. index:: current task priority |
---|
| 1063 | .. index:: set task priority |
---|
| 1064 | .. index:: get task priority |
---|
| 1065 | .. index:: obtain task priority |
---|
| 1066 | |
---|
| 1067 | **CALLING SEQUENCE:** |
---|
| 1068 | |
---|
| 1069 | .. code:: c |
---|
| 1070 | |
---|
| 1071 | rtems_status_code rtems_task_set_priority( |
---|
| 1072 | rtems_id id, |
---|
| 1073 | rtems_task_priority new_priority, |
---|
| 1074 | rtems_task_priority \*old_priority |
---|
| 1075 | ); |
---|
| 1076 | |
---|
| 1077 | **DIRECTIVE STATUS CODES:** |
---|
| 1078 | |
---|
| 1079 | ``RTEMS_SUCCESSFUL`` - task priority set successfully |
---|
| 1080 | ``RTEMS_INVALID_ID`` - invalid task id |
---|
| 1081 | ``RTEMS_INVALID_ADDRESS`` - invalid return argument pointer |
---|
| 1082 | ``RTEMS_INVALID_PRIORITY`` - invalid task priority |
---|
| 1083 | |
---|
| 1084 | **DESCRIPTION:** |
---|
| 1085 | |
---|
| 1086 | This directive manipulates the priority of the task specified by |
---|
| 1087 | id. An id of ``RTEMS_SELF`` is used to indicate |
---|
| 1088 | the calling task. When new_priority is not equal to``RTEMS_CURRENT_PRIORITY``, the specified |
---|
[d389819] | 1089 | task's previous priority is returned in old_priority. When |
---|
[fd6dc8c8] | 1090 | new_priority is ``RTEMS_CURRENT_PRIORITY``, |
---|
[d389819] | 1091 | the specified task's current |
---|
[fd6dc8c8] | 1092 | priority is returned in old_priority. Valid priorities range |
---|
| 1093 | from a high of 1 to a low of 255. |
---|
| 1094 | |
---|
| 1095 | **NOTES:** |
---|
| 1096 | |
---|
| 1097 | The calling task may be preempted if its preemption mode is |
---|
[d389819] | 1098 | enabled and it lowers its own priority or raises another task's |
---|
[fd6dc8c8] | 1099 | priority. |
---|
| 1100 | |
---|
| 1101 | In case the new priority equals the current priority of the task, then nothing |
---|
| 1102 | happens. |
---|
| 1103 | |
---|
| 1104 | Setting the priority of a global task which does not reside on |
---|
| 1105 | the local node will generate a request to the remote node to |
---|
| 1106 | change the priority of the specified task. |
---|
| 1107 | |
---|
| 1108 | If the task specified by id is currently holding any binary |
---|
| 1109 | semaphores which use the priority inheritance algorithm, then |
---|
[d389819] | 1110 | the task's priority cannot be lowered immediately. If the |
---|
| 1111 | task's priority were lowered immediately, then priority |
---|
| 1112 | inversion results. The requested lowering of the task's |
---|
[fd6dc8c8] | 1113 | priority will occur when the task has released all priority |
---|
[d389819] | 1114 | inheritance binary semaphores. The task's priority can be |
---|
| 1115 | increased regardless of the task's use of priority inheritance |
---|
[fd6dc8c8] | 1116 | binary semaphores. |
---|
| 1117 | |
---|
| 1118 | TASK_MODE - Change the current task mode |
---|
| 1119 | ---------------------------------------- |
---|
| 1120 | .. index:: current task mode |
---|
| 1121 | .. index:: set task mode |
---|
| 1122 | .. index:: get task mode |
---|
| 1123 | .. index:: set task preemption mode |
---|
| 1124 | .. index:: get task preemption mode |
---|
| 1125 | .. index:: obtain task mode |
---|
| 1126 | |
---|
| 1127 | **CALLING SEQUENCE:** |
---|
| 1128 | |
---|
| 1129 | .. index:: rtems_task_mode |
---|
| 1130 | |
---|
| 1131 | .. code:: c |
---|
| 1132 | |
---|
| 1133 | rtems_status_code rtems_task_mode( |
---|
| 1134 | rtems_mode mode_set, |
---|
| 1135 | rtems_mode mask, |
---|
| 1136 | rtems_mode \*previous_mode_set |
---|
| 1137 | ); |
---|
| 1138 | |
---|
| 1139 | **DIRECTIVE STATUS CODES:** |
---|
| 1140 | |
---|
| 1141 | ``RTEMS_SUCCESSFUL`` - task mode set successfully |
---|
| 1142 | ``RTEMS_INVALID_ADDRESS`` - ``previous_mode_set`` is NULL |
---|
| 1143 | |
---|
| 1144 | **DESCRIPTION:** |
---|
| 1145 | |
---|
| 1146 | This directive manipulates the execution mode of the calling |
---|
[d389819] | 1147 | task. A task's execution mode enables and disables preemption, |
---|
[fd6dc8c8] | 1148 | timeslicing, asynchronous signal processing, as well as |
---|
| 1149 | specifying the current interrupt level. To modify an execution |
---|
| 1150 | mode, the mode class(es) to be changed must be specified in the |
---|
| 1151 | mask parameter and the desired mode(s) must be specified in the |
---|
| 1152 | mode parameter. |
---|
| 1153 | |
---|
| 1154 | **NOTES:** |
---|
| 1155 | |
---|
| 1156 | The calling task will be preempted if it enables preemption and |
---|
| 1157 | a higher priority task is ready to run. |
---|
| 1158 | |
---|
| 1159 | Enabling timeslicing has no effect if preemption is disabled. For |
---|
| 1160 | a task to be timesliced, that task must have both preemption and |
---|
| 1161 | timeslicing enabled. |
---|
| 1162 | |
---|
| 1163 | A task can obtain its current execution mode, without modifying |
---|
| 1164 | it, by calling this directive with a mask value of``RTEMS_CURRENT_MODE``. |
---|
| 1165 | |
---|
| 1166 | To temporarily disable the processing of a valid ASR, a task |
---|
| 1167 | should call this directive with the ``RTEMS_NO_ASR`` |
---|
| 1168 | indicator specified in mode. |
---|
| 1169 | |
---|
[d389819] | 1170 | The set of task mode constants and each mode's corresponding |
---|
[fd6dc8c8] | 1171 | mask constant is provided in the following table: |
---|
| 1172 | |
---|
| 1173 | - ``RTEMS_PREEMPT`` is masked by``RTEMS_PREEMPT_MASK`` and enables preemption |
---|
| 1174 | |
---|
| 1175 | - ``RTEMS_NO_PREEMPT`` is masked by``RTEMS_PREEMPT_MASK`` and disables preemption |
---|
| 1176 | |
---|
| 1177 | - ``RTEMS_NO_TIMESLICE`` is masked by``RTEMS_TIMESLICE_MASK`` and disables timeslicing |
---|
| 1178 | |
---|
| 1179 | - ``RTEMS_TIMESLICE`` is masked by``RTEMS_TIMESLICE_MASK`` and enables timeslicing |
---|
| 1180 | |
---|
| 1181 | - ``RTEMS_ASR`` is masked by``RTEMS_ASR_MASK`` and enables ASR processing |
---|
| 1182 | |
---|
| 1183 | - ``RTEMS_NO_ASR`` is masked by``RTEMS_ASR_MASK`` and disables ASR processing |
---|
| 1184 | |
---|
| 1185 | - ``RTEMS_INTERRUPT_LEVEL(0)`` is masked by``RTEMS_INTERRUPT_MASK`` and enables all interrupts |
---|
| 1186 | |
---|
| 1187 | - ``RTEMS_INTERRUPT_LEVEL(n)`` is masked by``RTEMS_INTERRUPT_MASK`` and sets interrupts level n |
---|
| 1188 | |
---|
| 1189 | TASK_WAKE_AFTER - Wake up after interval |
---|
| 1190 | ---------------------------------------- |
---|
| 1191 | .. index:: delay a task for an interval |
---|
| 1192 | .. index:: wake up after an interval |
---|
| 1193 | |
---|
| 1194 | **CALLING SEQUENCE:** |
---|
| 1195 | |
---|
| 1196 | .. index:: rtems_task_wake_after |
---|
| 1197 | |
---|
| 1198 | .. code:: c |
---|
| 1199 | |
---|
| 1200 | rtems_status_code rtems_task_wake_after( |
---|
| 1201 | rtems_interval ticks |
---|
| 1202 | ); |
---|
| 1203 | |
---|
| 1204 | **DIRECTIVE STATUS CODES:** |
---|
| 1205 | |
---|
| 1206 | ``RTEMS_SUCCESSFUL`` - always successful |
---|
| 1207 | |
---|
| 1208 | **DESCRIPTION:** |
---|
| 1209 | |
---|
| 1210 | This directive blocks the calling task for the specified number |
---|
| 1211 | of system clock ticks. When the requested interval has elapsed, |
---|
| 1212 | the task is made ready. The ``rtems_clock_tick`` |
---|
| 1213 | directive automatically updates the delay period. |
---|
| 1214 | |
---|
| 1215 | **NOTES:** |
---|
| 1216 | |
---|
| 1217 | Setting the system date and time with the``rtems_clock_set`` directive |
---|
| 1218 | has no effect on a ``rtems_task_wake_after`` blocked task. |
---|
| 1219 | |
---|
| 1220 | A task may give up the processor and remain in the ready state |
---|
| 1221 | by specifying a value of ``RTEMS_YIELD_PROCESSOR`` in ticks. |
---|
| 1222 | |
---|
| 1223 | The maximum timer interval that can be specified is the maximum |
---|
| 1224 | value which can be represented by the uint32_t type. |
---|
| 1225 | |
---|
| 1226 | A clock tick is required to support the functionality of this directive. |
---|
| 1227 | |
---|
| 1228 | TASK_WAKE_WHEN - Wake up when specified |
---|
| 1229 | --------------------------------------- |
---|
| 1230 | .. index:: delay a task until a wall time |
---|
| 1231 | .. index:: wake up at a wall time |
---|
| 1232 | |
---|
| 1233 | **CALLING SEQUENCE:** |
---|
| 1234 | |
---|
| 1235 | .. index:: rtems_task_wake_when |
---|
| 1236 | |
---|
| 1237 | .. code:: c |
---|
| 1238 | |
---|
| 1239 | rtems_status_code rtems_task_wake_when( |
---|
| 1240 | rtems_time_of_day \*time_buffer |
---|
| 1241 | ); |
---|
| 1242 | |
---|
| 1243 | **DIRECTIVE STATUS CODES:** |
---|
| 1244 | |
---|
| 1245 | ``RTEMS_SUCCESSFUL`` - awakened at date/time successfully |
---|
| 1246 | ``RTEMS_INVALID_ADDRESS`` - ``time_buffer`` is NULL |
---|
| 1247 | ``RTEMS_INVALID_TIME_OF_DAY`` - invalid time buffer |
---|
| 1248 | ``RTEMS_NOT_DEFINED`` - system date and time is not set |
---|
| 1249 | |
---|
| 1250 | **DESCRIPTION:** |
---|
| 1251 | |
---|
| 1252 | This directive blocks a task until the date and time specified |
---|
| 1253 | in time_buffer. At the requested date and time, the calling |
---|
| 1254 | task will be unblocked and made ready to execute. |
---|
| 1255 | |
---|
| 1256 | **NOTES:** |
---|
| 1257 | |
---|
| 1258 | The ticks portion of time_buffer structure is ignored. The |
---|
| 1259 | timing granularity of this directive is a second. |
---|
| 1260 | |
---|
| 1261 | A clock tick is required to support the functionality of this directive. |
---|
| 1262 | |
---|
| 1263 | ITERATE_OVER_ALL_THREADS - Iterate Over Tasks |
---|
| 1264 | --------------------------------------------- |
---|
| 1265 | .. index:: iterate over all threads |
---|
| 1266 | |
---|
| 1267 | **CALLING SEQUENCE:** |
---|
| 1268 | |
---|
| 1269 | .. index:: rtems_iterate_over_all_threads |
---|
| 1270 | |
---|
| 1271 | .. code:: c |
---|
| 1272 | |
---|
| 1273 | typedef void (\*rtems_per_thread_routine)( |
---|
| 1274 | Thread_Control \*the_thread |
---|
| 1275 | ); |
---|
| 1276 | void rtems_iterate_over_all_threads( |
---|
| 1277 | rtems_per_thread_routine routine |
---|
| 1278 | ); |
---|
| 1279 | |
---|
| 1280 | **DIRECTIVE STATUS CODES: NONE** |
---|
| 1281 | |
---|
| 1282 | **DESCRIPTION:** |
---|
| 1283 | |
---|
| 1284 | This directive iterates over all of the existant threads in the |
---|
| 1285 | system and invokes ``routine`` on each of them. The user should |
---|
| 1286 | be careful in accessing the contents of ``the_thread``. |
---|
| 1287 | |
---|
| 1288 | This routine is intended for use in diagnostic utilities and is |
---|
| 1289 | not intented for routine use in an operational system. |
---|
| 1290 | |
---|
| 1291 | **NOTES:** |
---|
| 1292 | |
---|
| 1293 | There is NO protection while this routine is called. Thus it is |
---|
| 1294 | possible that ``the_thread`` could be deleted while this is operating. |
---|
| 1295 | By not having protection, the user is free to invoke support routines |
---|
| 1296 | from the C Library which require semaphores for data structures. |
---|
| 1297 | |
---|
| 1298 | TASK_VARIABLE_ADD - Associate per task variable |
---|
| 1299 | ----------------------------------------------- |
---|
| 1300 | .. index:: per-task variable |
---|
| 1301 | .. index:: task private variable |
---|
| 1302 | .. index:: task private data |
---|
| 1303 | |
---|
| 1304 | **CALLING SEQUENCE:** |
---|
| 1305 | |
---|
| 1306 | .. index:: rtems_task_variable_add |
---|
| 1307 | |
---|
| 1308 | .. code:: c |
---|
| 1309 | |
---|
| 1310 | rtems_status_code rtems_task_variable_add( |
---|
| 1311 | rtems_id tid, |
---|
| 1312 | void \**task_variable, |
---|
| 1313 | void (\*dtor)(void \*) |
---|
| 1314 | ); |
---|
| 1315 | |
---|
| 1316 | **DIRECTIVE STATUS CODES:** |
---|
| 1317 | |
---|
| 1318 | ``RTEMS_SUCCESSFUL`` - per task variable added successfully |
---|
| 1319 | ``RTEMS_INVALID_ADDRESS`` - ``task_variable`` is NULL |
---|
| 1320 | ``RTEMS_INVALID_ID`` - invalid task id |
---|
| 1321 | ``RTEMS_NO_MEMORY`` - invalid task id |
---|
| 1322 | ``RTEMS_ILLEGAL_ON_REMOTE_OBJECT`` - not supported on remote tasks |
---|
| 1323 | |
---|
| 1324 | **DESCRIPTION:** |
---|
| 1325 | |
---|
| 1326 | This directive adds the memory location specified by the |
---|
| 1327 | ptr argument to the context of the given task. The variable will |
---|
| 1328 | then be private to the task. The task can access and modify the |
---|
| 1329 | variable, but the modifications will not appear to other tasks, and |
---|
[d389819] | 1330 | other tasks' modifications to that variable will not affect the value |
---|
[fd6dc8c8] | 1331 | seen by the task. This is accomplished by saving and restoring the |
---|
[d389819] | 1332 | variable's value each time a task switch occurs to or from the calling task. |
---|
| 1333 | If the dtor argument is non-NULL it specifies the address of a 'destructor' |
---|
[fd6dc8c8] | 1334 | function which will be called when the task is deleted. The argument |
---|
[d389819] | 1335 | passed to the destructor function is the task's value of the variable. |
---|
[fd6dc8c8] | 1336 | |
---|
| 1337 | **NOTES:** |
---|
| 1338 | |
---|
| 1339 | This directive is deprecated and task variables will be removed. |
---|
| 1340 | |
---|
| 1341 | Task variables increase the context switch time to and from the |
---|
| 1342 | tasks that own them so it is desirable to minimize the number of |
---|
| 1343 | task variables. One efficient method |
---|
| 1344 | is to have a single task variable that is a pointer to a dynamically |
---|
[d389819] | 1345 | allocated structure containing the task's private 'global' data. |
---|
| 1346 | In this case the destructor function could be 'free'. |
---|
[fd6dc8c8] | 1347 | |
---|
| 1348 | Per-task variables are disabled in SMP configurations and this service |
---|
| 1349 | is not available. |
---|
| 1350 | |
---|
| 1351 | TASK_VARIABLE_GET - Obtain value of a per task variable |
---|
| 1352 | ------------------------------------------------------- |
---|
| 1353 | .. index:: get per-task variable |
---|
| 1354 | .. index:: obtain per-task variable |
---|
| 1355 | |
---|
| 1356 | **CALLING SEQUENCE:** |
---|
| 1357 | |
---|
| 1358 | .. index:: rtems_task_variable_get |
---|
| 1359 | |
---|
| 1360 | .. code:: c |
---|
| 1361 | |
---|
| 1362 | rtems_status_code rtems_task_variable_get( |
---|
| 1363 | rtems_id tid, |
---|
| 1364 | void \**task_variable, |
---|
| 1365 | void \**task_variable_value |
---|
| 1366 | ); |
---|
| 1367 | |
---|
| 1368 | **DIRECTIVE STATUS CODES:** |
---|
| 1369 | |
---|
| 1370 | ``RTEMS_SUCCESSFUL`` - per task variable obtained successfully |
---|
| 1371 | ``RTEMS_INVALID_ADDRESS`` - ``task_variable`` is NULL |
---|
| 1372 | ``RTEMS_INVALID_ADDRESS`` - ``task_variable_value`` is NULL |
---|
| 1373 | ``RTEMS_INVALID_ADDRESS`` - ``task_variable`` is not found |
---|
| 1374 | ``RTEMS_NO_MEMORY`` - invalid task id |
---|
| 1375 | ``RTEMS_ILLEGAL_ON_REMOTE_OBJECT`` - not supported on remote tasks |
---|
| 1376 | |
---|
| 1377 | **DESCRIPTION:** |
---|
| 1378 | |
---|
| 1379 | This directive looks up the private value of a task variable for a |
---|
| 1380 | specified task and stores that value in the location pointed to by |
---|
| 1381 | the result argument. The specified task is usually not the calling |
---|
| 1382 | task, which can get its private value by directly accessing the variable. |
---|
| 1383 | |
---|
| 1384 | **NOTES:** |
---|
| 1385 | |
---|
| 1386 | This directive is deprecated and task variables will be removed. |
---|
| 1387 | |
---|
| 1388 | If you change memory which ``task_variable_value`` points to, |
---|
| 1389 | remember to declare that memory as volatile, so that the compiler |
---|
| 1390 | will optimize it correctly. In this case both the pointer``task_variable_value`` and data referenced by ``task_variable_value`` |
---|
| 1391 | should be considered volatile. |
---|
| 1392 | |
---|
| 1393 | Per-task variables are disabled in SMP configurations and this service |
---|
| 1394 | is not available. |
---|
| 1395 | |
---|
| 1396 | TASK_VARIABLE_DELETE - Remove per task variable |
---|
| 1397 | ----------------------------------------------- |
---|
| 1398 | .. index:: per-task variable |
---|
| 1399 | .. index:: task private variable |
---|
| 1400 | .. index:: task private data |
---|
| 1401 | |
---|
| 1402 | **CALLING SEQUENCE:** |
---|
| 1403 | |
---|
| 1404 | .. index:: rtems_task_variable_delete |
---|
| 1405 | |
---|
| 1406 | .. code:: c |
---|
| 1407 | |
---|
| 1408 | rtems_status_code rtems_task_variable_delete( |
---|
| 1409 | rtems_id id, |
---|
| 1410 | void \**task_variable |
---|
| 1411 | ); |
---|
| 1412 | |
---|
| 1413 | **DIRECTIVE STATUS CODES:** |
---|
| 1414 | |
---|
| 1415 | ``RTEMS_SUCCESSFUL`` - per task variable deleted successfully |
---|
| 1416 | ``RTEMS_INVALID_ID`` - invalid task id |
---|
| 1417 | ``RTEMS_NO_MEMORY`` - invalid task id |
---|
| 1418 | ``RTEMS_INVALID_ADDRESS`` - ``task_variable`` is NULL |
---|
| 1419 | ``RTEMS_ILLEGAL_ON_REMOTE_OBJECT`` - not supported on remote tasks |
---|
| 1420 | |
---|
| 1421 | **DESCRIPTION:** |
---|
| 1422 | |
---|
[d389819] | 1423 | This directive removes the given location from a task's context. |
---|
[fd6dc8c8] | 1424 | |
---|
| 1425 | **NOTES:** |
---|
| 1426 | |
---|
| 1427 | This directive is deprecated and task variables will be removed. |
---|
| 1428 | |
---|
| 1429 | Per-task variables are disabled in SMP configurations and this service |
---|
| 1430 | is not available. |
---|
| 1431 | |
---|
| 1432 | .. COMMENT: COPYRIGHT (c) 1988-2008. |
---|
| 1433 | |
---|
| 1434 | .. COMMENT: On-Line Applications Research Corporation (OAR). |
---|
| 1435 | |
---|
| 1436 | .. COMMENT: All rights reserved. |
---|
| 1437 | |
---|