1 | /** |
---|
2 | * @file rtems/rtems/tasks.h |
---|
3 | * |
---|
4 | * This include file contains all constants and structures associated |
---|
5 | * with RTEMS tasks. This manager provides a comprehensive set of directives |
---|
6 | * to create, delete, and administer tasks. |
---|
7 | * |
---|
8 | * Directives provided are: |
---|
9 | * |
---|
10 | * - create a task |
---|
11 | * - get an ID of a task |
---|
12 | * - start a task |
---|
13 | * - restart a task |
---|
14 | * - delete a task |
---|
15 | * - suspend a task |
---|
16 | * - resume a task |
---|
17 | * - set a task's priority |
---|
18 | * - change the current task's mode |
---|
19 | * - get a task notepad entry |
---|
20 | * - set a task notepad entry |
---|
21 | * - wake up after interval |
---|
22 | * - wake up when specified |
---|
23 | */ |
---|
24 | |
---|
25 | /* |
---|
26 | * COPYRIGHT (c) 1989-2011. |
---|
27 | * On-Line Applications Research Corporation (OAR). |
---|
28 | * |
---|
29 | * The license and distribution terms for this file may be |
---|
30 | * found in the file LICENSE in this distribution or at |
---|
31 | * http://www.rtems.com/license/LICENSE. |
---|
32 | */ |
---|
33 | |
---|
34 | #ifndef _RTEMS_RTEMS_TASKS_H |
---|
35 | #define _RTEMS_RTEMS_TASKS_H |
---|
36 | |
---|
37 | #include <rtems/score/object.h> |
---|
38 | #include <rtems/score/states.h> |
---|
39 | #include <rtems/score/thread.h> |
---|
40 | #include <rtems/rtems/types.h> |
---|
41 | #include <rtems/rtems/event.h> |
---|
42 | #include <rtems/rtems/asr.h> |
---|
43 | #include <rtems/rtems/attr.h> |
---|
44 | #include <rtems/rtems/status.h> |
---|
45 | |
---|
46 | /** |
---|
47 | * This constant is defined to extern most of the time when using |
---|
48 | * this header file. However by defining it to nothing, the data |
---|
49 | * declared in this header file can be instantiated. This is done |
---|
50 | * in a single per manager file. |
---|
51 | */ |
---|
52 | #ifndef RTEMS_TASKS_EXTERN |
---|
53 | #define RTEMS_TASKS_EXTERN extern |
---|
54 | #endif |
---|
55 | |
---|
56 | /** |
---|
57 | * @defgroup ClassicTasks Tasks |
---|
58 | * |
---|
59 | * @ingroup ClassicRTEMS |
---|
60 | * |
---|
61 | * This encapsulates the functionality of the Classic API Task Manager. |
---|
62 | * This functionality includes task services such as creation, deletion, |
---|
63 | * delays, suspend/resume, and manipulation of execution mode and priority. |
---|
64 | */ |
---|
65 | /**@{*/ |
---|
66 | |
---|
67 | #ifdef __cplusplus |
---|
68 | extern "C" { |
---|
69 | #endif |
---|
70 | |
---|
71 | /** |
---|
72 | * Constant to be used as the ID of current task |
---|
73 | */ |
---|
74 | #define RTEMS_SELF OBJECTS_ID_OF_SELF |
---|
75 | |
---|
76 | /** |
---|
77 | * This constant is passed to the rtems_task_wake_after directive as the |
---|
78 | * interval when a task wishes to yield the CPU. |
---|
79 | */ |
---|
80 | #define RTEMS_YIELD_PROCESSOR WATCHDOG_NO_TIMEOUT |
---|
81 | |
---|
82 | /** |
---|
83 | * Define the type for an RTEMS API task priority. |
---|
84 | */ |
---|
85 | typedef Priority_Control rtems_task_priority; |
---|
86 | |
---|
87 | /** |
---|
88 | * This is the constant used with the rtems_task_set_priority |
---|
89 | * directive to indicate that the caller wants to obtain its |
---|
90 | * current priority rather than set it as the name of the |
---|
91 | * directive indicates. |
---|
92 | */ |
---|
93 | #define RTEMS_NO_PRIORITY RTEMS_CURRENT_PRIORITY |
---|
94 | |
---|
95 | /** |
---|
96 | * This constant is the least valid value for a Classic API |
---|
97 | * task priority. |
---|
98 | */ |
---|
99 | #define RTEMS_MINIMUM_PRIORITY (PRIORITY_MINIMUM + 1) |
---|
100 | |
---|
101 | /** |
---|
102 | * This constant is the maximum valid value for a Classic API |
---|
103 | * task priority. |
---|
104 | * |
---|
105 | * @note This is actually the priority of the IDLE thread so |
---|
106 | * using this priority will result in having a task |
---|
107 | * which never executes. This could be useful if you |
---|
108 | * want to ensure that a task does not executes during |
---|
109 | * certain operations such as a system mode change. |
---|
110 | */ |
---|
111 | #define RTEMS_MAXIMUM_PRIORITY PRIORITY_MAXIMUM |
---|
112 | |
---|
113 | /** |
---|
114 | * The following constant is passed to rtems_task_set_priority when the |
---|
115 | * caller wants to obtain the current priority. |
---|
116 | */ |
---|
117 | #define RTEMS_CURRENT_PRIORITY PRIORITY_MINIMUM |
---|
118 | |
---|
119 | /** This is used to indicate the lowest numbered notepad */ |
---|
120 | #define RTEMS_NOTEPAD_FIRST 0 |
---|
121 | /** This is used to indicate the notepad location 0. */ |
---|
122 | #define RTEMS_NOTEPAD_0 0 |
---|
123 | /** This is used to indicate the notepad location 1. */ |
---|
124 | #define RTEMS_NOTEPAD_1 1 |
---|
125 | /** This is used to indicate the notepad location 2. */ |
---|
126 | #define RTEMS_NOTEPAD_2 2 |
---|
127 | /** This is used to indicate the notepad location 3. */ |
---|
128 | #define RTEMS_NOTEPAD_3 3 |
---|
129 | /** This is used to indicate the notepad location 4. */ |
---|
130 | #define RTEMS_NOTEPAD_4 4 |
---|
131 | /** This is used to indicate the notepad location 5. */ |
---|
132 | #define RTEMS_NOTEPAD_5 5 |
---|
133 | /** This is used to indicate the notepad location 6. */ |
---|
134 | #define RTEMS_NOTEPAD_6 6 |
---|
135 | /** This is used to indicate the notepad location 7. */ |
---|
136 | #define RTEMS_NOTEPAD_7 7 |
---|
137 | /** This is used to indicate the notepad location 8. */ |
---|
138 | #define RTEMS_NOTEPAD_8 8 |
---|
139 | /** This is used to indicate the notepad location 9. */ |
---|
140 | #define RTEMS_NOTEPAD_9 9 |
---|
141 | /** This is used to indicate the notepad location 10. */ |
---|
142 | #define RTEMS_NOTEPAD_10 10 |
---|
143 | /** This is used to indicate the notepad location 11. */ |
---|
144 | #define RTEMS_NOTEPAD_11 11 |
---|
145 | /** This is used to indicate the notepad location 12. */ |
---|
146 | #define RTEMS_NOTEPAD_12 12 |
---|
147 | /** This is used to indicate the notepad location 13. */ |
---|
148 | #define RTEMS_NOTEPAD_13 13 |
---|
149 | /** This is used to indicate the notepad location 14. */ |
---|
150 | #define RTEMS_NOTEPAD_14 14 |
---|
151 | /** This is used to indicate the notepad location 15. */ |
---|
152 | #define RTEMS_NOTEPAD_15 15 |
---|
153 | /** This is used to indicate the highest numbered notepad. */ |
---|
154 | #define RTEMS_NOTEPAD_LAST RTEMS_NOTEPAD_15 |
---|
155 | |
---|
156 | /** This is used to indicate the number of notepads available. */ |
---|
157 | #define RTEMS_NUMBER_NOTEPADS (RTEMS_NOTEPAD_LAST+1) |
---|
158 | |
---|
159 | /** |
---|
160 | * External API name for Thread_Control |
---|
161 | */ |
---|
162 | typedef Thread_Control rtems_tcb; |
---|
163 | |
---|
164 | /** |
---|
165 | * The following defines the "return type" of an RTEMS task. |
---|
166 | */ |
---|
167 | typedef void rtems_task; |
---|
168 | |
---|
169 | /** |
---|
170 | * The following defines the argument to an RTEMS task. |
---|
171 | */ |
---|
172 | typedef Thread_Entry_numeric_type rtems_task_argument; |
---|
173 | |
---|
174 | /** |
---|
175 | * The following defines the type for the entry point of an RTEMS task. |
---|
176 | */ |
---|
177 | typedef rtems_task ( *rtems_task_entry )( |
---|
178 | rtems_task_argument |
---|
179 | ); |
---|
180 | |
---|
181 | /** |
---|
182 | * The following records define the Initialization Tasks Table. |
---|
183 | * Each entry contains the information required by RTEMS to |
---|
184 | * create and start a user task automatically at executive |
---|
185 | * initialization time. |
---|
186 | */ |
---|
187 | typedef struct { |
---|
188 | /** This is the Initialization Task's name. */ |
---|
189 | rtems_name name; |
---|
190 | /** This is the Initialization Task's stack size. */ |
---|
191 | size_t stack_size; |
---|
192 | /** This is the Initialization Task's priority. */ |
---|
193 | rtems_task_priority initial_priority; |
---|
194 | /** This is the Initialization Task's attributes. */ |
---|
195 | rtems_attribute attribute_set; |
---|
196 | /** This is the Initialization Task's entry point. */ |
---|
197 | rtems_task_entry entry_point; |
---|
198 | /** This is the Initialization Task's initial mode. */ |
---|
199 | rtems_mode mode_set; |
---|
200 | /** This is the Initialization Task's argument. */ |
---|
201 | rtems_task_argument argument; |
---|
202 | } rtems_initialization_tasks_table; |
---|
203 | |
---|
204 | /** |
---|
205 | * This is the API specific information required by each thread for |
---|
206 | * the RTEMS API to function correctly. |
---|
207 | * |
---|
208 | * @note Notepads must be the last entry in the structure and memory |
---|
209 | * will be taken away from this structure when allocated if |
---|
210 | * notespads are disabled by the application configuration. |
---|
211 | */ |
---|
212 | typedef struct { |
---|
213 | /** This field contains the event control for this task. */ |
---|
214 | Event_Control Event; |
---|
215 | /** This field contains the system event control for this task. */ |
---|
216 | Event_Control System_event; |
---|
217 | /** This field contains the Classic API Signal information for this task. */ |
---|
218 | ASR_Information Signal; |
---|
219 | /** |
---|
220 | * This field contains the notepads for this task. |
---|
221 | * |
---|
222 | * @note MUST BE LAST ENTRY. |
---|
223 | */ |
---|
224 | uint32_t Notepads[ RTEMS_NUMBER_NOTEPADS ]; |
---|
225 | } RTEMS_API_Control; |
---|
226 | |
---|
227 | /** |
---|
228 | * The following instantiates the information control block used to |
---|
229 | * manage this class of objects. |
---|
230 | */ |
---|
231 | RTEMS_TASKS_EXTERN Objects_Information _RTEMS_tasks_Information; |
---|
232 | |
---|
233 | /** |
---|
234 | * When the user configures a set of Classic API initialization tasks, |
---|
235 | * This variable will point to the method used to initialize them. |
---|
236 | * |
---|
237 | * @note It is instantiated and initialized by confdefs.h based upon |
---|
238 | * application requirements. |
---|
239 | */ |
---|
240 | extern void (*_RTEMS_tasks_Initialize_user_tasks_p)(void); |
---|
241 | |
---|
242 | /** |
---|
243 | * @brief RTEMS Task Manager Initialization |
---|
244 | * |
---|
245 | * This routine initializes all Task Manager related data structures. |
---|
246 | */ |
---|
247 | void _RTEMS_tasks_Manager_initialization(void); |
---|
248 | |
---|
249 | /** |
---|
250 | * @brief RTEMS Task Create |
---|
251 | * |
---|
252 | * This routine implements the rtems_task_create directive. The task |
---|
253 | * will have the name name. The attribute_set can be used to indicate |
---|
254 | * that the task will be globally accessible or utilize floating point. |
---|
255 | * The task's stack will be stack_size bytes. The task will begin |
---|
256 | * execution with initial_priority and initial_modes. It returns the |
---|
257 | * id of the created task in ID. |
---|
258 | * |
---|
259 | * @param[in] name is the user defined thread name |
---|
260 | * @param[in] initial_priority is the thread priority |
---|
261 | * @param[in] stack_size is the stack size in bytes |
---|
262 | * @param[in] initial_modes is the initial thread mode |
---|
263 | * @param[in] attribute_set is the thread attributes |
---|
264 | * @param[in] id is the pointer to thread id |
---|
265 | * |
---|
266 | * @return RTEMS_SUCCESSFUL if successful or error code if unsuccessful |
---|
267 | * and *id thread id filled in |
---|
268 | */ |
---|
269 | rtems_status_code rtems_task_create( |
---|
270 | rtems_name name, |
---|
271 | rtems_task_priority initial_priority, |
---|
272 | size_t stack_size, |
---|
273 | rtems_mode initial_modes, |
---|
274 | rtems_attribute attribute_set, |
---|
275 | rtems_id *id |
---|
276 | ); |
---|
277 | |
---|
278 | /** |
---|
279 | * @brief rtems_task_ident |
---|
280 | * |
---|
281 | * This routine implements the rtems_task_ident directive. |
---|
282 | * This directive returns the task ID associated with name. |
---|
283 | * If more than one task is named name, then the task to |
---|
284 | * which the ID belongs is arbitrary. node indicates the |
---|
285 | * extent of the search for the ID of the task named name. |
---|
286 | * The search can be limited to a particular node or allowed to |
---|
287 | * encompass all nodes. |
---|
288 | */ |
---|
289 | rtems_status_code rtems_task_ident( |
---|
290 | rtems_name name, |
---|
291 | uint32_t node, |
---|
292 | rtems_id *id |
---|
293 | ); |
---|
294 | |
---|
295 | /** |
---|
296 | * @brief rtems_task_delete |
---|
297 | * |
---|
298 | * This routine implements the rtems_task_delete directive. The |
---|
299 | * task indicated by ID is deleted. |
---|
300 | */ |
---|
301 | rtems_status_code rtems_task_delete( |
---|
302 | rtems_id id |
---|
303 | ); |
---|
304 | |
---|
305 | /** |
---|
306 | * @brief rtems_task_get_note |
---|
307 | * |
---|
308 | * This routine implements the rtems_task_get_note directive. The |
---|
309 | * value of the indicated notepad for the task associated with ID |
---|
310 | * is returned in note. |
---|
311 | */ |
---|
312 | rtems_status_code rtems_task_get_note( |
---|
313 | rtems_id id, |
---|
314 | uint32_t notepad, |
---|
315 | uint32_t *note |
---|
316 | ); |
---|
317 | |
---|
318 | /** |
---|
319 | * @brief rtems_task_set_note |
---|
320 | * |
---|
321 | * This routine implements the rtems_task_set_note directive. The |
---|
322 | * value of the indicated notepad for the task associated with ID |
---|
323 | * is returned in note. |
---|
324 | */ |
---|
325 | rtems_status_code rtems_task_set_note( |
---|
326 | rtems_id id, |
---|
327 | uint32_t notepad, |
---|
328 | uint32_t note |
---|
329 | ); |
---|
330 | |
---|
331 | /** |
---|
332 | * @brief rtems_task_mode |
---|
333 | * |
---|
334 | * This routine implements the rtems_task_mode directive. The current |
---|
335 | * values of the modes indicated by mask of the calling task are changed |
---|
336 | * to that indicated in mode_set. The former mode of the task is |
---|
337 | * returned in mode_set. |
---|
338 | */ |
---|
339 | rtems_status_code rtems_task_mode( |
---|
340 | rtems_mode mode_set, |
---|
341 | rtems_mode mask, |
---|
342 | rtems_mode *previous_mode_set |
---|
343 | ); |
---|
344 | |
---|
345 | /** |
---|
346 | * @brief rtems_task_restart |
---|
347 | * |
---|
348 | * This routine implements the rtems_task_restart directive. The |
---|
349 | * task associated with ID is restarted at its initial entry |
---|
350 | * point with the new argument. |
---|
351 | */ |
---|
352 | rtems_status_code rtems_task_restart( |
---|
353 | rtems_id id, |
---|
354 | uint32_t arg |
---|
355 | ); |
---|
356 | |
---|
357 | /** |
---|
358 | * @brief rtems_task_suspend |
---|
359 | * |
---|
360 | * This routine implements the rtems_task_suspend directive. The |
---|
361 | * SUSPENDED state is set for task associated with ID. |
---|
362 | */ |
---|
363 | rtems_status_code rtems_task_suspend( |
---|
364 | rtems_id id |
---|
365 | ); |
---|
366 | |
---|
367 | /** |
---|
368 | * @brief rtems_task_resume |
---|
369 | * |
---|
370 | * This routine implements the rtems_task_resume Directive. The |
---|
371 | * SUSPENDED state is cleared for task associated with ID. |
---|
372 | */ |
---|
373 | rtems_status_code rtems_task_resume( |
---|
374 | rtems_id id |
---|
375 | ); |
---|
376 | |
---|
377 | /** |
---|
378 | * @brief rtems_task_set_priority |
---|
379 | * |
---|
380 | * This routine implements the rtems_task_set_priority directive. The |
---|
381 | * current priority of the task associated with ID is set to |
---|
382 | * new_priority. The former priority of that task is returned |
---|
383 | * in old_priority. |
---|
384 | */ |
---|
385 | rtems_status_code rtems_task_set_priority( |
---|
386 | rtems_id id, |
---|
387 | rtems_task_priority new_priority, |
---|
388 | rtems_task_priority *old_priority |
---|
389 | ); |
---|
390 | |
---|
391 | /** |
---|
392 | * @brief rtems_task_start |
---|
393 | * |
---|
394 | * This routine implements the rtems_task_start directive. The |
---|
395 | * starting execution point of the task associated with ID is |
---|
396 | * set to entry_point with the initial argument. |
---|
397 | */ |
---|
398 | rtems_status_code rtems_task_start( |
---|
399 | rtems_id id, |
---|
400 | rtems_task_entry entry_point, |
---|
401 | rtems_task_argument argument |
---|
402 | ); |
---|
403 | |
---|
404 | /** |
---|
405 | * @brief RTEMS Task Wake When |
---|
406 | * |
---|
407 | * This routine implements the rtems_task_wake_when directive. The |
---|
408 | * calling task is blocked until the current time of day is |
---|
409 | * equal to that indicated by time_buffer. |
---|
410 | * |
---|
411 | * @param[in] time_buffer is the pointer to the time and date structure |
---|
412 | * |
---|
413 | * @return RTEMS_SUCCESSFUL if successful or error code if unsuccessful |
---|
414 | */ |
---|
415 | rtems_status_code rtems_task_wake_when( |
---|
416 | rtems_time_of_day *time_buffer |
---|
417 | ); |
---|
418 | |
---|
419 | /** |
---|
420 | * @brief RTEMS Task Wake After |
---|
421 | * |
---|
422 | * This routine implements the rtems_task_wake_after directive. The |
---|
423 | * calling task is blocked until the indicated number of clock |
---|
424 | * ticks have occurred. |
---|
425 | * |
---|
426 | * @param[in] ticks is the number of ticks to wait |
---|
427 | * @return RTEMS_SUCCESSFUL |
---|
428 | */ |
---|
429 | rtems_status_code rtems_task_wake_after( |
---|
430 | rtems_interval ticks |
---|
431 | ); |
---|
432 | |
---|
433 | /** |
---|
434 | * @brief rtems_task_is_suspended |
---|
435 | |
---|
436 | * This directive returns a status indicating whether or not |
---|
437 | * the specified task is suspended. |
---|
438 | */ |
---|
439 | rtems_status_code rtems_task_is_suspended( |
---|
440 | rtems_id id |
---|
441 | ); |
---|
442 | |
---|
443 | /** |
---|
444 | * @brief rtems_task_variable_add |
---|
445 | * |
---|
446 | * This directive adds a per task variable. |
---|
447 | */ |
---|
448 | rtems_status_code rtems_task_variable_add( |
---|
449 | rtems_id tid, |
---|
450 | void **ptr, |
---|
451 | void (*dtor)(void *) |
---|
452 | ); |
---|
453 | |
---|
454 | /** |
---|
455 | * @brief rtems_task_variable_get |
---|
456 | * |
---|
457 | * This directive gets the value of a task variable. |
---|
458 | */ |
---|
459 | rtems_status_code rtems_task_variable_get( |
---|
460 | rtems_id tid, |
---|
461 | void **ptr, |
---|
462 | void **result |
---|
463 | ); |
---|
464 | |
---|
465 | /** |
---|
466 | * @brief RTEMS Delete Task Variable |
---|
467 | * |
---|
468 | * This directive removes a per task variable. |
---|
469 | */ |
---|
470 | rtems_status_code rtems_task_variable_delete( |
---|
471 | rtems_id tid, |
---|
472 | void **ptr |
---|
473 | ); |
---|
474 | |
---|
475 | /** |
---|
476 | * @brief rtems_task_self |
---|
477 | * |
---|
478 | * This directive returns the ID of the currently executing task. |
---|
479 | */ |
---|
480 | rtems_id rtems_task_self(void); |
---|
481 | |
---|
482 | /** |
---|
483 | * @brief RTEMS User Task Initialization |
---|
484 | * |
---|
485 | * This routine creates and starts all configured user |
---|
486 | * initialization threads. |
---|
487 | */ |
---|
488 | void _RTEMS_tasks_Initialize_user_tasks( void ); |
---|
489 | |
---|
490 | /** |
---|
491 | * @brief _RTEMS_Tasks_Invoke_task_variable_dtor |
---|
492 | * |
---|
493 | * This routine invokes the optional user provided destructor on the |
---|
494 | * task variable and frees the memory for the task variable. |
---|
495 | * |
---|
496 | * Input parameters: NONE |
---|
497 | * |
---|
498 | * Output parameters: NONE |
---|
499 | */ |
---|
500 | void _RTEMS_Tasks_Invoke_task_variable_dtor( |
---|
501 | Thread_Control *the_thread, |
---|
502 | rtems_task_variable_t *tvp |
---|
503 | ); |
---|
504 | |
---|
505 | /** |
---|
506 | * @brief _RTEMS_tasks_Initialize_user_tasks_body |
---|
507 | * |
---|
508 | * This routine creates and starts all configured user |
---|
509 | * initialization threads. |
---|
510 | * |
---|
511 | * Input parameters: NONE |
---|
512 | * |
---|
513 | * Output parameters: NONE |
---|
514 | */ |
---|
515 | |
---|
516 | extern void _RTEMS_tasks_Initialize_user_tasks_body( void ); |
---|
517 | |
---|
518 | #ifndef __RTEMS_APPLICATION__ |
---|
519 | #include <rtems/rtems/tasks.inl> |
---|
520 | #endif |
---|
521 | #if defined(RTEMS_MULTIPROCESSING) |
---|
522 | #include <rtems/rtems/taskmp.h> |
---|
523 | #endif |
---|
524 | |
---|
525 | #ifdef __cplusplus |
---|
526 | } |
---|
527 | #endif |
---|
528 | |
---|
529 | /**@}*/ |
---|
530 | |
---|
531 | #endif |
---|
532 | /* end of include file */ |
---|