source: rtems/cpukit/rtems/include/rtems/rtems/tasks.h @ d271c3bb

5
Last change on this file since d271c3bb was d271c3bb, checked in by Sebastian Huber <sebastian.huber@…>, on 10/31/16 at 12:37:59

rtems: Add rtems_task_iterate()

Update #2423.

  • Property mode set to 100644
File size: 19.5 KB
Line 
1/**
2 * @file rtems/rtems/tasks.h
3 *
4 * @defgroup ClassicTasks Tasks
5 *
6 * @ingroup ClassicRTEMS
7 * @brief RTEMS Tasks
8 *
9 * This include file contains all constants and structures associated
10 * with RTEMS tasks. This manager provides a comprehensive set of directives
11 * to create, delete, and administer tasks.
12 *
13 * Directives provided are:
14 *
15 * - create a task
16 * - get an ID of a task
17 * - start a task
18 * - restart a task
19 * - delete a task
20 * - suspend a task
21 * - resume a task
22 * - set a task's priority
23 * - change the current task's mode
24 * - wake up after interval
25 * - wake up when specified
26 */
27
28/*
29 * COPYRIGHT (c) 1989-2014.
30 * On-Line Applications Research Corporation (OAR).
31 *
32 * The license and distribution terms for this file may be
33 * found in the file LICENSE in this distribution or at
34 * http://www.rtems.org/license/LICENSE.
35 */
36
37#ifndef _RTEMS_RTEMS_TASKS_H
38#define _RTEMS_RTEMS_TASKS_H
39
40#include <rtems/score/object.h>
41#include <rtems/score/scheduler.h>
42#include <rtems/score/thread.h>
43#include <rtems/rtems/types.h>
44#include <rtems/rtems/event.h>
45#include <rtems/rtems/asr.h>
46#include <rtems/rtems/attr.h>
47#include <rtems/rtems/status.h>
48
49#ifdef __cplusplus
50extern "C" {
51#endif
52
53/**
54 *  @defgroup ClassicTasks Tasks
55 *
56 *  @ingroup ClassicRTEMS
57 *
58 *  This encapsulates the functionality of the Classic API Task Manager.
59 *  This functionality includes task services such as creation, deletion,
60 *  delays, suspend/resume, and manipulation of execution mode and priority.
61 */
62/**@{*/
63
64/**
65 *  Constant to be used as the ID of current task
66 */
67#define RTEMS_SELF                OBJECTS_ID_OF_SELF
68
69/**
70 *  This constant is passed to the rtems_task_wake_after directive as the
71 *  interval when a task wishes to yield the CPU.
72 */
73#define RTEMS_YIELD_PROCESSOR WATCHDOG_NO_TIMEOUT
74
75/**
76 *  Define the type for an RTEMS API task priority.
77 */
78typedef uint32_t rtems_task_priority;
79
80/**
81 *  This is the constant used with the rtems_task_set_priority
82 *  directive to indicate that the caller wants to obtain its
83 *  current priority rather than set it as the name of the
84 *  directive indicates.
85 */
86#define RTEMS_NO_PRIORITY           RTEMS_CURRENT_PRIORITY
87
88/**
89 *  This constant is the least valid value for a Classic API
90 *  task priority.
91 */
92#define RTEMS_MINIMUM_PRIORITY      (PRIORITY_MINIMUM + 1)
93
94/**
95 *  This constant is the maximum valid value for a Classic API
96 *  task priority.
97 *
98 *  @note This is actually the priority of the IDLE thread so
99 *        using this priority will result in having a task
100 *        which never executes.  This could be useful if you
101 *        want to ensure that a task does not executes during
102 *        certain operations such as a system mode change.
103 */
104#define RTEMS_MAXIMUM_PRIORITY      PRIORITY_MAXIMUM
105
106/**
107 *  The following constant is passed to rtems_task_set_priority when the
108 *  caller wants to obtain the current priority.
109 */
110#define RTEMS_CURRENT_PRIORITY      PRIORITY_MINIMUM
111
112/**
113 *  External API name for Thread_Control
114 */
115typedef Thread_Control rtems_tcb;
116
117/**
118 *  The following defines the "return type" of an RTEMS task.
119 */
120typedef void rtems_task;
121
122/**
123 *  The following defines the argument to an RTEMS task.
124 */
125typedef Thread_Entry_numeric_type rtems_task_argument;
126
127/**
128 *  The following defines the type for the entry point of an RTEMS task.
129 */
130typedef rtems_task ( *rtems_task_entry )(
131                      rtems_task_argument
132                   );
133
134/**
135 *  The following records define the Initialization Tasks Table.
136 *  Each entry contains the information required by RTEMS to
137 *  create and start a user task automatically at executive
138 *  initialization time.
139 */
140typedef struct {
141  /** This is the Initialization Task's name. */
142  rtems_name            name;
143  /** This is the Initialization Task's stack size. */
144  size_t                stack_size;
145  /** This is the Initialization Task's priority. */
146  rtems_task_priority   initial_priority;
147  /** This is the Initialization Task's attributes. */
148  rtems_attribute       attribute_set;
149  /** This is the Initialization Task's entry point. */
150  rtems_task_entry      entry_point;
151  /** This is the Initialization Task's initial mode. */
152  rtems_mode            mode_set;
153  /** This is the Initialization Task's argument. */
154  rtems_task_argument   argument;
155} rtems_initialization_tasks_table;
156
157/**
158 * @brief RTEMS Task Create
159 *
160 * This routine implements the rtems_task_create directive. The task
161 * will have the name name. The attribute_set can be used to indicate
162 * that the task will be globally accessible or utilize floating point.
163 * The task's stack will be stack_size bytes. The task will begin
164 * execution with initial_priority and initial_modes. It returns the
165 * id of the created task in ID.
166 *
167 * @param[in] name is the user defined thread name
168 * @param[in] initial_priority is the thread priority
169 * @param[in] stack_size is the stack size in bytes
170 * @param[in] initial_modes is the initial thread mode
171 * @param[in] attribute_set is the thread attributes
172 * @param[in] id is the pointer to thread id
173 *
174 * @retval RTEMS_SUCCESSFUL if successful or error code if unsuccessful
175 *              and *id thread id filled in
176 */
177rtems_status_code rtems_task_create(
178  rtems_name           name,
179  rtems_task_priority  initial_priority,
180  size_t               stack_size,
181  rtems_mode           initial_modes,
182  rtems_attribute      attribute_set,
183  rtems_id            *id
184);
185
186/**
187 * @brief RTEMS Task Name to Id
188 *
189 * This routine implements the rtems_task_ident directive.
190 * This directive returns the task ID associated with name.
191 * If more than one task is named name, then the task to
192 * which the ID belongs is arbitrary. node indicates the
193 * extent of the search for the ID of the task named name.
194 * The search can be limited to a particular node or allowed to
195 * encompass all nodes.
196 *
197 * @param[in] name is the user defined thread name
198 * @param[in] node is(are) the node(s) to be searched
199 * @param[in] id is the pointer to thread id
200 *
201 * @retval This method returns RTEMS_SUCCESSFUL if there was not an
202 *         error. Otherwise, a status code is returned indicating the
203 *         source of the error. If successful, the id will
204 *         be filled in with the thread id.
205 */
206rtems_status_code rtems_task_ident(
207  rtems_name    name,
208  uint32_t      node,
209  rtems_id     *id
210);
211
212/**
213 * @brief RTEMS Delete Task
214 *
215 * This routine implements the rtems_task_delete directive. The
216 * task indicated by ID is deleted. The executive halts execution
217 * of the thread and frees the thread control block.
218 *
219 * @param[in] id is the thread id
220 *
221 * @retval This method returns RTEMS_SUCCESSFUL if there was not an
222 *         error and id is not the requesting thread. Status code is
223 *         returned indicating the source of the error. Nothing
224 *         is returned if id is the requesting thread (always succeeds).
225 */
226rtems_status_code rtems_task_delete(
227  rtems_id   id
228);
229
230/**
231 * @brief RTEMS Task Mode
232 *
233 * This routine implements the rtems_task_mode directive. The current
234 * values of the modes indicated by mask of the calling task are changed
235 * to that indicated in mode_set. The former mode of the task is
236 * returned in mode_set.
237 *
238 * @param[in] mode_set is the new mode
239 * @param[in] mask is the mask
240 * @param[in] previous_mode_set is the address of previous mode set
241 *
242 * @retval RTEMS_SUCCESSFUL and previous_mode_set filled in with the
243 * previous mode set
244 */
245rtems_status_code rtems_task_mode(
246  rtems_mode  mode_set,
247  rtems_mode  mask,
248  rtems_mode *previous_mode_set
249);
250
251/**
252 * @brief RTEMS Task Restart
253 *
254 * This routine implements the rtems_task_restart directive. The
255 * task associated with ID is restarted at its initial entry
256 * point with the new argument.
257 *
258 * @param[in] id is the thread id
259 * @param[in] arg is the thread argument
260 *
261 * @retval RTEMS_SUCCESSFUL if successful or error code if unsuccessful
262 */
263rtems_status_code rtems_task_restart(
264  rtems_id   id,
265  uint32_t   arg
266);
267
268/**
269 * @brief RTEMS Suspend Task
270 *
271 * This routine implements the rtems_task_suspend directive. The
272 * SUSPENDED state is set for task associated with ID. Note that the
273 * suspended state can be in addition to other waiting states.
274 *
275 * @param[in] id is the thread id
276 *
277 * @retval This method returns RTEMS_SUCCESSFUL if there was not an
278 *         error. Otherwise, a status code is returned indicating the
279 *         source of the error.
280 */
281rtems_status_code rtems_task_suspend(
282  rtems_id   id
283);
284
285/**
286 * @brief RTEMS Resume Task
287 *
288 * This routine implements the rtems_task_resume Directive. The
289 * SUSPENDED state is cleared for task associated with ID.
290 *
291 * @param[in] id is the thread id
292 *
293 * @retval This method returns RTEMS_SUCCESSFUL if there was not an
294 *         error. Otherwise, a status code is returned indicating the
295 *         source of the error.
296 */
297rtems_status_code rtems_task_resume(
298  rtems_id   id
299);
300
301/**
302 * @brief RTEMS Set Task Priority
303 *
304 * This routine implements the rtems_task_set_priority directive. The
305 * current priority of the task associated with ID is set to
306 * new_priority. The former priority of that task is returned
307 * in old_priority.
308 *
309 * @param[in] id is the thread to extract
310 * @param[in] new_priority is the thread to extract
311 * @param[in] old_priority is the thread to extract
312 *
313 * @retval RTEMS_SUCCESSFUL if successful or error code if unsuccessful and
314 * and *old_priority filled in with the previous previous priority
315 */
316rtems_status_code rtems_task_set_priority(
317  rtems_id             id,
318  rtems_task_priority  new_priority,
319  rtems_task_priority *old_priority
320);
321
322/**
323 * @brief Gets the current priority of the specified task with respect to the
324 * specified scheduler instance.
325 *
326 * The current priority reflects temporary priority adjustments due to locking
327 * protocols, the rate-monotonic period objects on some schedulers and other
328 * mechanisms.
329 *
330 * @param[in] task_id Identifier of the task.  Use @ref RTEMS_SELF to select
331 *   the executing task.
332 * @param[in] scheduler_id Identifier of the scheduler instance.
333 * @param[out] priority Returns the current priority of the specified task with
334 *   respect to the specified scheduler instance.
335 *
336 * @retval RTEMS_SUCCESSFUL Successful operation.
337 * @retval RTEMS_ILLEGAL_ON_REMOTE_OBJECT Directive is illegal on remote tasks.
338 * @retval RTEMS_INVALID_ADDRESS The priority parameter is @c NULL.
339 * @retval RTEMS_INVALID_ID Invalid task or scheduler identifier.
340 * @retval RTEMS_NOT_DEFINED The task has no priority within the specified
341 *   scheduler instance.  This error is only possible on SMP configurations.
342 *
343 * @see rtems_scheduler_ident().
344 */
345rtems_status_code rtems_task_get_priority(
346  rtems_id             task_id,
347  rtems_id             scheduler_id,
348  rtems_task_priority *priority
349);
350
351/**
352 *  @brief RTEMS Start Task
353 *
354 *  RTEMS Task Manager
355 *
356 *  This routine implements the rtems_task_start directive.  The
357 *  starting execution point of the task associated with ID is
358 *  set to entry_point with the initial argument.
359 */
360rtems_status_code rtems_task_start(
361  rtems_id             id,
362  rtems_task_entry     entry_point,
363  rtems_task_argument  argument
364);
365
366/**
367 * @brief RTEMS Task Wake When
368 *
369 * This routine implements the rtems_task_wake_when directive. The
370 * calling task is blocked until the current time of day is
371 * equal to that indicated by time_buffer.
372 *
373 * @param[in] time_buffer is the pointer to the time and date structure
374 *
375 * @retval RTEMS_SUCCESSFUL if successful or error code if unsuccessful
376 */
377rtems_status_code rtems_task_wake_when(
378  rtems_time_of_day *time_buffer
379);
380
381/**
382 * @brief RTEMS Task Wake After
383 *
384 * This routine implements the rtems_task_wake_after directive. The
385 * calling task is blocked until the indicated number of clock
386 * ticks have occurred.
387 *
388 * @param[in] ticks is the number of ticks to wait
389 * @retval RTEMS_SUCCESSFUL
390 */
391rtems_status_code rtems_task_wake_after(
392  rtems_interval  ticks
393);
394
395/**
396 *  @brief rtems_task_is_suspended
397 *
398 *  This directive returns a status indicating whether or not
399 *  the specified task is suspended.
400 */
401rtems_status_code rtems_task_is_suspended(
402  rtems_id   id
403);
404
405#if defined(__RTEMS_HAVE_SYS_CPUSET_H__)
406/**
407 * @brief Gets the processor affinity set of a task.
408 *
409 * @param[in] id Identifier of the task.  Use @ref RTEMS_SELF to select the
410 * executing task.
411 * @param[in] cpusetsize Size of the specified affinity set buffer in
412 * bytes.  This value must be positive.
413 * @param[out] cpuset The current processor affinity set of the task.  A set
414 * bit in the affinity set means that the task can execute on this processor
415 * and a cleared bit means the opposite.
416 *
417 * @retval RTEMS_SUCCESSFUL Successful operation.
418 * @retval RTEMS_INVALID_ADDRESS The @a cpuset parameter is @c NULL.
419 * @retval RTEMS_INVALID_ID Invalid task identifier.
420 * @retval RTEMS_INVALID_NUMBER The affinity set buffer is too small for the
421 * current processor affinity set of the task.
422 */
423rtems_status_code rtems_task_get_affinity(
424  rtems_id             id,
425  size_t               cpusetsize,
426  cpu_set_t           *cpuset
427);
428
429/**
430 * @brief Sets the processor affinity set of a task.
431 *
432 * This function will not change the scheduler of the task.  The intersection
433 * of the processor affinity set and the set of processors owned by the
434 * scheduler of the task must be non-empty.  It is not an error if the
435 * processor affinity set contains processors that are not part of the set of
436 * processors owned by the scheduler instance of the task.  A task will simply
437 * not run under normal circumstances on these processors since the scheduler
438 * ignores them.  Some locking protocols may temporarily use processors that
439 * are not included in the processor affinity set of the task.  It is also not
440 * an error if the processor affinity set contains processors that are not part
441 * of the system.
442 *
443 * @param[in] id Identifier of the task.  Use @ref RTEMS_SELF to select the
444 * executing task.
445 * @param[in] cpusetsize Size of the specified affinity set buffer in
446 * bytes.  This value must be positive.
447 * @param[in] cpuset The new processor affinity set for the task.  A set bit in
448 * the affinity set means that the task can execute on this processor and a
449 * cleared bit means the opposite.
450 *
451 * @retval RTEMS_SUCCESSFUL Successful operation.
452 * @retval RTEMS_INVALID_ADDRESS The @a cpuset parameter is @c NULL.
453 * @retval RTEMS_INVALID_ID Invalid task identifier.
454 * @retval RTEMS_INVALID_NUMBER Invalid processor affinity set.
455 */
456rtems_status_code rtems_task_set_affinity(
457  rtems_id         id,
458  size_t           cpusetsize,
459  const cpu_set_t *cpuset
460);
461#endif
462
463/**
464 * @brief Gets the scheduler of a task.
465 *
466 * @param[in] task_id Identifier of the task.  Use @ref RTEMS_SELF to select
467 * the executing task.
468 * @param[out] scheduler_id Identifier of the scheduler.
469 *
470 * @retval RTEMS_SUCCESSFUL Successful operation.
471 * @retval RTEMS_INVALID_ADDRESS The @a scheduler_id parameter is @c NULL.
472 * @retval RTEMS_INVALID_ID Invalid task identifier.
473 */
474rtems_status_code rtems_task_get_scheduler(
475  rtems_id  task_id,
476  rtems_id *scheduler_id
477);
478
479/**
480 * @brief Sets the scheduler instance of a task.
481 *
482 * Initially, the scheduler instance of a task is set to the scheduler instance
483 * of the task that created it.  This directive allows to move a task from its
484 * current scheduler instance to another specified by the scheduler identifier.
485 *
486 * @param[in] task_id Identifier of the task.  Use @ref RTEMS_SELF to select
487 *   the executing task.
488 * @param[in] scheduler_id Identifier of the scheduler instance.
489 * @param[in] priority The task priority with respect to the new scheduler
490 *   instance.  The real and initial priority of the task is set to this value.
491 *   The initial priority is used by rtems_task_restart() for example.
492 *
493 * @retval RTEMS_SUCCESSFUL Successful operation.
494 * @retval RTEMS_ILLEGAL_ON_REMOTE_OBJECT Directive is illegal on remote tasks.
495 * @retval RTEMS_INVALID_ID Invalid task or scheduler identifier.
496 * @retval RTEMS_INVALID_PRIORITY Invalid priority.
497 * @retval RTEMS_RESOURCE_IN_USE The task owns resources which deny a scheduler
498 *   change.
499 *
500 * @see rtems_scheduler_ident().
501 */
502rtems_status_code rtems_task_set_scheduler(
503  rtems_id            task_id,
504  rtems_id            scheduler_id,
505  rtems_task_priority priority
506);
507
508/**
509 *  @brief RTEMS Get Self Task Id
510 *
511 *  This directive returns the ID of the currently executing task.
512 */
513rtems_id rtems_task_self(void);
514
515/**
516 * @brief Task visitor.
517 *
518 * @param[in] tcb The task control block.
519 * @param[in] arg The visitor argument.
520 *
521 * @retval true Stop the iteration.
522 * @retval false Otherwise.
523 *
524 * @see rtems_task_iterate().
525 */
526typedef bool ( *rtems_task_visitor )( rtems_tcb *tcb, void *arg );
527
528/**
529 * @brief Iterates over all tasks in the system.
530 *
531 * This operation covers all tasks of all APIs.
532 *
533 * Must be called from task context.  This operation obtains and releases the
534 * objects allocator lock.  The task visitor is called while owning the objects
535 * allocator lock.  It is possible to perform blocking operations in the task
536 * visitor, however, take care that no deadlocks via the object allocator lock
537 * can occur.
538 *
539 * @param[in] visitor The task visitor.
540 * @param[in] arg The visitor argument.
541 */
542void rtems_task_iterate(
543  rtems_task_visitor  visitor,
544  void               *arg
545);
546
547/**
548 * @brief Identifies a scheduler by its name.
549 *
550 * The scheduler name is determined by the scheduler configuration.
551 *
552 * @param[in] name The scheduler name.
553 * @param[out] id The scheduler identifier associated with the name.
554 *
555 * @retval RTEMS_SUCCESSFUL Successful operation.
556 * @retval RTEMS_INVALID_ADDRESS The @a id parameter is @c NULL.
557 * @retval RTEMS_INVALID_NAME Invalid scheduler name.
558 * @retval RTEMS_UNSATISFIED A scheduler with this name exists, but the
559 * processor set of this scheduler is empty.
560 */
561rtems_status_code rtems_scheduler_ident(
562  rtems_name  name,
563  rtems_id   *id
564);
565
566#if defined(__RTEMS_HAVE_SYS_CPUSET_H__)
567/**
568 * @brief Gets the set of processors owned by the scheduler.
569 *
570 * @param[in] scheduler_id Identifier of the scheduler.
571 * @param[in] cpusetsize Size of the specified processor set buffer in
572 * bytes.  This value must be positive.
573 * @param[out] cpuset The processor set owned by the scheduler.  A set bit in
574 * the processor set means that this processor is owned by the scheduler and a
575 * cleared bit means the opposite.
576 *
577 * @retval RTEMS_SUCCESSFUL Successful operation.
578 * @retval RTEMS_INVALID_ADDRESS The @a cpuset parameter is @c NULL.
579 * @retval RTEMS_INVALID_ID Invalid scheduler identifier.
580 * @retval RTEMS_INVALID_NUMBER The processor set buffer is too small for the
581 * set of processors owned by the scheduler.
582 */
583rtems_status_code rtems_scheduler_get_processor_set(
584  rtems_id   scheduler_id,
585  size_t     cpusetsize,
586  cpu_set_t *cpuset
587);
588#endif
589
590/**@}*/
591
592/**
593 *  This is the API specific information required by each thread for
594 *  the RTEMS API to function correctly.
595 *
596 */
597typedef struct {
598  /** This field contains the event control for this task. */
599  Event_Control            Event;
600  /** This field contains the system event control for this task. */
601  Event_Control            System_event;
602  /** This field contains the Classic API Signal information for this task. */
603  ASR_Information          Signal;
604
605  /**
606   * @brief Signal post-switch action in case signals are pending.
607   */
608  Thread_Action            Signal_action;
609}  RTEMS_API_Control;
610
611/**
612 *  @brief _RTEMS_tasks_Initialize_user_tasks_body
613 *
614 *  This routine creates and starts all configured user
615 *  initialization threads.
616 *
617 *  Input parameters: NONE
618 *
619 *  Output parameters:  NONE
620 *
621 *  RTEMS Task Manager
622 */
623
624extern void _RTEMS_tasks_Initialize_user_tasks_body( void );
625
626#ifdef __cplusplus
627}
628#endif
629
630#endif
631/* end of include file */
Note: See TracBrowser for help on using the repository browser.