source: rtems/cpukit/rtems/include/rtems/rtems/tasks.h @ 1ff8eca

5
Last change on this file since 1ff8eca was 1ff8eca, checked in by Sebastian Huber <sebastian.huber@…>, on 01/26/16 at 10:10:43

Use linker set for Classic User Tasks init

Update #2408.

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