]> git.sur5r.net Git - freertos/blob - FreeRTOS/Source/include/task.h
Update version number.
[freertos] / FreeRTOS / Source / include / task.h
1 /*\r
2     FreeRTOS V7.5.1 - Copyright (C) 2013 Real Time Engineers Ltd.\r
3 \r
4     VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.\r
5 \r
6     ***************************************************************************\r
7      *                                                                       *\r
8      *    FreeRTOS provides completely free yet professionally developed,    *\r
9      *    robust, strictly quality controlled, supported, and cross          *\r
10      *    platform software that has become a de facto standard.             *\r
11      *                                                                       *\r
12      *    Help yourself get started quickly and support the FreeRTOS         *\r
13      *    project by purchasing a FreeRTOS tutorial book, reference          *\r
14      *    manual, or both from: http://www.FreeRTOS.org/Documentation        *\r
15      *                                                                       *\r
16      *    Thank you!                                                         *\r
17      *                                                                       *\r
18     ***************************************************************************\r
19 \r
20     This file is part of the FreeRTOS distribution.\r
21 \r
22     FreeRTOS is free software; you can redistribute it and/or modify it under\r
23     the terms of the GNU General Public License (version 2) as published by the\r
24     Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.\r
25 \r
26     >>! NOTE: The modification to the GPL is included to allow you to distribute\r
27     >>! a combined work that includes FreeRTOS without being obliged to provide\r
28     >>! the source code for proprietary components outside of the FreeRTOS\r
29     >>! kernel.\r
30 \r
31     FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY\r
32     WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\r
33     FOR A PARTICULAR PURPOSE.  Full license text is available from the following\r
34     link: http://www.freertos.org/a00114.html\r
35 \r
36     1 tab == 4 spaces!\r
37 \r
38     ***************************************************************************\r
39      *                                                                       *\r
40      *    Having a problem?  Start by reading the FAQ "My application does   *\r
41      *    not run, what could be wrong?"                                     *\r
42      *                                                                       *\r
43      *    http://www.FreeRTOS.org/FAQHelp.html                               *\r
44      *                                                                       *\r
45     ***************************************************************************\r
46 \r
47     http://www.FreeRTOS.org - Documentation, books, training, latest versions,\r
48     license and Real Time Engineers Ltd. contact details.\r
49 \r
50     http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
51     including FreeRTOS+Trace - an indispensable productivity tool, a DOS\r
52     compatible FAT file system, and our tiny thread aware UDP/IP stack.\r
53 \r
54     http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High\r
55     Integrity Systems to sell under the OpenRTOS brand.  Low cost OpenRTOS\r
56     licenses offer ticketed support, indemnification and middleware.\r
57 \r
58     http://www.SafeRTOS.com - High Integrity Systems also provide a safety\r
59     engineered and independently SIL3 certified version for use in safety and\r
60     mission critical applications that require provable dependability.\r
61 \r
62     1 tab == 4 spaces!\r
63 */\r
64 \r
65 \r
66 #ifndef INC_TASK_H\r
67 #define INC_TASK_H\r
68 \r
69 #ifndef INC_FREERTOS_H\r
70         #error "include FreeRTOS.h must appear in source files before include task.h"\r
71 #endif\r
72 \r
73 #include "list.h"\r
74 \r
75 #ifdef __cplusplus\r
76 extern "C" {\r
77 #endif\r
78 \r
79 /*-----------------------------------------------------------\r
80  * MACROS AND DEFINITIONS\r
81  *----------------------------------------------------------*/\r
82 \r
83 #define tskKERNEL_VERSION_NUMBER "V7.5.1"\r
84 \r
85 /**\r
86  * task. h\r
87  *\r
88  * Type by which tasks are referenced.  For example, a call to xTaskCreate\r
89  * returns (via a pointer parameter) an xTaskHandle variable that can then\r
90  * be used as a parameter to vTaskDelete to delete the task.\r
91  *\r
92  * \defgroup xTaskHandle xTaskHandle\r
93  * \ingroup Tasks\r
94  */\r
95 typedef void * xTaskHandle;\r
96 \r
97 /* Task states returned by eTaskGetState. */\r
98 typedef enum\r
99 {\r
100         eRunning = 0,   /* A task is querying the state of itself, so must be running. */\r
101         eReady,                 /* The task being queried is in a read or pending ready list. */\r
102         eBlocked,               /* The task being queried is in the Blocked state. */\r
103         eSuspended,             /* The task being queried is in the Suspended state, or is in the Blocked state with an infinite time out. */\r
104         eDeleted                /* The task being queried has been deleted, but its TCB has not yet been freed. */\r
105 } eTaskState;\r
106 \r
107 /*\r
108  * Used internally only.\r
109  */\r
110 typedef struct xTIME_OUT\r
111 {\r
112         portBASE_TYPE xOverflowCount;\r
113         portTickType  xTimeOnEntering;\r
114 } xTimeOutType;\r
115 \r
116 /*\r
117  * Defines the memory ranges allocated to the task when an MPU is used.\r
118  */\r
119 typedef struct xMEMORY_REGION\r
120 {\r
121         void *pvBaseAddress;\r
122         unsigned long ulLengthInBytes;\r
123         unsigned long ulParameters;\r
124 } xMemoryRegion;\r
125 \r
126 /*\r
127  * Parameters required to create an MPU protected task.\r
128  */\r
129 typedef struct xTASK_PARAMTERS\r
130 {\r
131         pdTASK_CODE pvTaskCode;\r
132         const signed char * const pcName;\r
133         unsigned short usStackDepth;\r
134         void *pvParameters;\r
135         unsigned portBASE_TYPE uxPriority;\r
136         portSTACK_TYPE *puxStackBuffer;\r
137         xMemoryRegion xRegions[ portNUM_CONFIGURABLE_REGIONS ];\r
138 } xTaskParameters;\r
139 \r
140 /* Used with the uxTaskGetSystemState() function to return the state of each task\r
141 in the system. */\r
142 typedef struct xTASK_STATUS\r
143 {\r
144         xTaskHandle xHandle;                                            /* The handle of the task to which the rest of the information in the structure relates. */\r
145         const signed char *pcTaskName;                          /* A pointer to the task's name.  This value will be invalid if the task was deleted since the structure was populated! */\r
146         unsigned portBASE_TYPE xTaskNumber;                     /* A number unique to the task. */\r
147         eTaskState eCurrentState;                                       /* The state in which the task existed when the structure was populated. */\r
148         unsigned portBASE_TYPE uxCurrentPriority;       /* The priority at which the task was running (may be inherited) when the structure was populated. */\r
149         unsigned portBASE_TYPE uxBasePriority;          /* The priority to which the task will return if the task's current priority has been inherited to avoid unbounded priority inversion when obtaining a mutex.  Only valid if configUSE_MUTEXES is defined as 1 in FreeRTOSConfig.h. */\r
150         unsigned long ulRunTimeCounter;                         /* The total run time allocated to the task so far, as defined by the run time stats clock.  See http://www.freertos.org/rtos-run-time-stats.html.  Only valid when configGENERATE_RUN_TIME_STATS is defined as 1 in FreeRTOSConfig.h. */\r
151         unsigned short usStackHighWaterMark;            /* The minimum amount of stack space that has remained for the task since the task was created.  The closer this value is to zero the closer the task has come to overflowing its stack. */\r
152 } xTaskStatusType;\r
153 \r
154 /* Possible return values for eTaskConfirmSleepModeStatus(). */\r
155 typedef enum\r
156 {\r
157         eAbortSleep = 0,                /* A task has been made ready or a context switch pended since portSUPPORESS_TICKS_AND_SLEEP() was called - abort entering a sleep mode. */\r
158         eStandardSleep,                 /* Enter a sleep mode that will not last any longer than the expected idle time. */\r
159         eNoTasksWaitingTimeout  /* No tasks are waiting for a timeout so it is safe to enter a sleep mode that can only be exited by an external interrupt. */\r
160 } eSleepModeStatus;\r
161 \r
162 \r
163 /*\r
164  * Defines the priority used by the idle task.  This must not be modified.\r
165  *\r
166  * \ingroup TaskUtils\r
167  */\r
168 #define tskIDLE_PRIORITY                        ( ( unsigned portBASE_TYPE ) 0U )\r
169 \r
170 /**\r
171  * task. h\r
172  *\r
173  * Macro for forcing a context switch.\r
174  *\r
175  * \defgroup taskYIELD taskYIELD\r
176  * \ingroup SchedulerControl\r
177  */\r
178 #define taskYIELD()                                     portYIELD()\r
179 \r
180 /**\r
181  * task. h\r
182  *\r
183  * Macro to mark the start of a critical code region.  Preemptive context\r
184  * switches cannot occur when in a critical region.\r
185  *\r
186  * NOTE: This may alter the stack (depending on the portable implementation)\r
187  * so must be used with care!\r
188  *\r
189  * \defgroup taskENTER_CRITICAL taskENTER_CRITICAL\r
190  * \ingroup SchedulerControl\r
191  */\r
192 #define taskENTER_CRITICAL()            portENTER_CRITICAL()\r
193 \r
194 /**\r
195  * task. h\r
196  *\r
197  * Macro to mark the end of a critical code region.  Preemptive context\r
198  * switches cannot occur when in a critical region.\r
199  *\r
200  * NOTE: This may alter the stack (depending on the portable implementation)\r
201  * so must be used with care!\r
202  *\r
203  * \defgroup taskEXIT_CRITICAL taskEXIT_CRITICAL\r
204  * \ingroup SchedulerControl\r
205  */\r
206 #define taskEXIT_CRITICAL()                     portEXIT_CRITICAL()\r
207 \r
208 /**\r
209  * task. h\r
210  *\r
211  * Macro to disable all maskable interrupts.\r
212  *\r
213  * \defgroup taskDISABLE_INTERRUPTS taskDISABLE_INTERRUPTS\r
214  * \ingroup SchedulerControl\r
215  */\r
216 #define taskDISABLE_INTERRUPTS()        portDISABLE_INTERRUPTS()\r
217 \r
218 /**\r
219  * task. h\r
220  *\r
221  * Macro to enable microcontroller interrupts.\r
222  *\r
223  * \defgroup taskENABLE_INTERRUPTS taskENABLE_INTERRUPTS\r
224  * \ingroup SchedulerControl\r
225  */\r
226 #define taskENABLE_INTERRUPTS()         portENABLE_INTERRUPTS()\r
227 \r
228 /* Definitions returned by xTaskGetSchedulerState(). */\r
229 #define taskSCHEDULER_NOT_STARTED       ( ( portBASE_TYPE ) 0 )\r
230 #define taskSCHEDULER_RUNNING           ( ( portBASE_TYPE ) 1 )\r
231 #define taskSCHEDULER_SUSPENDED         ( ( portBASE_TYPE ) 2 )\r
232 \r
233 /*-----------------------------------------------------------\r
234  * TASK CREATION API\r
235  *----------------------------------------------------------*/\r
236 \r
237 /**\r
238  * task. h\r
239  *<pre>\r
240  portBASE_TYPE xTaskCreate(\r
241                                                           pdTASK_CODE pvTaskCode,\r
242                                                           const char * const pcName,\r
243                                                           unsigned short usStackDepth,\r
244                                                           void *pvParameters,\r
245                                                           unsigned portBASE_TYPE uxPriority,\r
246                                                           xTaskHandle *pvCreatedTask\r
247                                                   );</pre>\r
248  *\r
249  * Create a new task and add it to the list of tasks that are ready to run.\r
250  *\r
251  * xTaskCreate() can only be used to create a task that has unrestricted\r
252  * access to the entire microcontroller memory map.  Systems that include MPU\r
253  * support can alternatively create an MPU constrained task using\r
254  * xTaskCreateRestricted().\r
255  *\r
256  * @param pvTaskCode Pointer to the task entry function.  Tasks\r
257  * must be implemented to never return (i.e. continuous loop).\r
258  *\r
259  * @param pcName A descriptive name for the task.  This is mainly used to\r
260  * facilitate debugging.  Max length defined by tskMAX_TASK_NAME_LEN - default\r
261  * is 16.\r
262  *\r
263  * @param usStackDepth The size of the task stack specified as the number of\r
264  * variables the stack can hold - not the number of bytes.  For example, if\r
265  * the stack is 16 bits wide and usStackDepth is defined as 100, 200 bytes\r
266  * will be allocated for stack storage.\r
267  *\r
268  * @param pvParameters Pointer that will be used as the parameter for the task\r
269  * being created.\r
270  *\r
271  * @param uxPriority The priority at which the task should run.  Systems that\r
272  * include MPU support can optionally create tasks in a privileged (system)\r
273  * mode by setting bit portPRIVILEGE_BIT of the priority parameter.  For\r
274  * example, to create a privileged task at priority 2 the uxPriority parameter\r
275  * should be set to ( 2 | portPRIVILEGE_BIT ).\r
276  *\r
277  * @param pvCreatedTask Used to pass back a handle by which the created task\r
278  * can be referenced.\r
279  *\r
280  * @return pdPASS if the task was successfully created and added to a ready\r
281  * list, otherwise an error code defined in the file errors. h\r
282  *\r
283  * Example usage:\r
284    <pre>\r
285  // Task to be created.\r
286  void vTaskCode( void * pvParameters )\r
287  {\r
288          for( ;; )\r
289          {\r
290                  // Task code goes here.\r
291          }\r
292  }\r
293 \r
294  // Function that creates a task.\r
295  void vOtherFunction( void )\r
296  {\r
297  static unsigned char ucParameterToPass;\r
298  xTaskHandle xHandle;\r
299 \r
300          // Create the task, storing the handle.  Note that the passed parameter ucParameterToPass\r
301          // must exist for the lifetime of the task, so in this case is declared static.  If it was just an\r
302          // an automatic stack variable it might no longer exist, or at least have been corrupted, by the time\r
303          // the new task attempts to access it.\r
304          xTaskCreate( vTaskCode, "NAME", STACK_SIZE, &ucParameterToPass, tskIDLE_PRIORITY, &xHandle );\r
305 \r
306          // Use the handle to delete the task.\r
307          vTaskDelete( xHandle );\r
308  }\r
309    </pre>\r
310  * \defgroup xTaskCreate xTaskCreate\r
311  * \ingroup Tasks\r
312  */\r
313 #define xTaskCreate( pvTaskCode, pcName, usStackDepth, pvParameters, uxPriority, pxCreatedTask ) xTaskGenericCreate( ( pvTaskCode ), ( pcName ), ( usStackDepth ), ( pvParameters ), ( uxPriority ), ( pxCreatedTask ), ( NULL ), ( NULL ) )\r
314 \r
315 /**\r
316  * task. h\r
317  *<pre>\r
318  portBASE_TYPE xTaskCreateRestricted( xTaskParameters *pxTaskDefinition, xTaskHandle *pxCreatedTask );</pre>\r
319  *\r
320  * xTaskCreateRestricted() should only be used in systems that include an MPU\r
321  * implementation.\r
322  *\r
323  * Create a new task and add it to the list of tasks that are ready to run.\r
324  * The function parameters define the memory regions and associated access\r
325  * permissions allocated to the task.\r
326  *\r
327  * @param pxTaskDefinition Pointer to a structure that contains a member\r
328  * for each of the normal xTaskCreate() parameters (see the xTaskCreate() API\r
329  * documentation) plus an optional stack buffer and the memory region\r
330  * definitions.\r
331  *\r
332  * @param pxCreatedTask Used to pass back a handle by which the created task\r
333  * can be referenced.\r
334  *\r
335  * @return pdPASS if the task was successfully created and added to a ready\r
336  * list, otherwise an error code defined in the file errors. h\r
337  *\r
338  * Example usage:\r
339    <pre>\r
340 // Create an xTaskParameters structure that defines the task to be created.\r
341 static const xTaskParameters xCheckTaskParameters =\r
342 {\r
343         vATask,         // pvTaskCode - the function that implements the task.\r
344         "ATask",        // pcName - just a text name for the task to assist debugging.\r
345         100,            // usStackDepth - the stack size DEFINED IN WORDS.\r
346         NULL,           // pvParameters - passed into the task function as the function parameters.\r
347         ( 1UL | portPRIVILEGE_BIT ),// uxPriority - task priority, set the portPRIVILEGE_BIT if the task should run in a privileged state.\r
348         cStackBuffer,// puxStackBuffer - the buffer to be used as the task stack.\r
349 \r
350         // xRegions - Allocate up to three separate memory regions for access by\r
351         // the task, with appropriate access permissions.  Different processors have\r
352         // different memory alignment requirements - refer to the FreeRTOS documentation\r
353         // for full information.\r
354         {\r
355                 // Base address                                 Length  Parameters\r
356         { cReadWriteArray,                              32,             portMPU_REGION_READ_WRITE },\r
357         { cReadOnlyArray,                               32,             portMPU_REGION_READ_ONLY },\r
358         { cPrivilegedOnlyAccessArray,   128,    portMPU_REGION_PRIVILEGED_READ_WRITE }\r
359         }\r
360 };\r
361 \r
362 int main( void )\r
363 {\r
364 xTaskHandle xHandle;\r
365 \r
366         // Create a task from the const structure defined above.  The task handle\r
367         // is requested (the second parameter is not NULL) but in this case just for\r
368         // demonstration purposes as its not actually used.\r
369         xTaskCreateRestricted( &xRegTest1Parameters, &xHandle );\r
370 \r
371         // Start the scheduler.\r
372         vTaskStartScheduler();\r
373 \r
374         // Will only get here if there was insufficient memory to create the idle\r
375         // task.\r
376         for( ;; );\r
377 }\r
378    </pre>\r
379  * \defgroup xTaskCreateRestricted xTaskCreateRestricted\r
380  * \ingroup Tasks\r
381  */\r
382 #define xTaskCreateRestricted( x, pxCreatedTask ) xTaskGenericCreate( ((x)->pvTaskCode), ((x)->pcName), ((x)->usStackDepth), ((x)->pvParameters), ((x)->uxPriority), (pxCreatedTask), ((x)->puxStackBuffer), ((x)->xRegions) )\r
383 \r
384 /**\r
385  * task. h\r
386  *<pre>\r
387  void vTaskAllocateMPURegions( xTaskHandle xTask, const xMemoryRegion * const pxRegions );</pre>\r
388  *\r
389  * Memory regions are assigned to a restricted task when the task is created by\r
390  * a call to xTaskCreateRestricted().  These regions can be redefined using\r
391  * vTaskAllocateMPURegions().\r
392  *\r
393  * @param xTask The handle of the task being updated.\r
394  *\r
395  * @param xRegions A pointer to an xMemoryRegion structure that contains the\r
396  * new memory region definitions.\r
397  *\r
398  * Example usage:\r
399    <pre>\r
400 // Define an array of xMemoryRegion structures that configures an MPU region\r
401 // allowing read/write access for 1024 bytes starting at the beginning of the\r
402 // ucOneKByte array.  The other two of the maximum 3 definable regions are\r
403 // unused so set to zero.\r
404 static const xMemoryRegion xAltRegions[ portNUM_CONFIGURABLE_REGIONS ] =\r
405 {\r
406         // Base address         Length          Parameters\r
407         { ucOneKByte,           1024,           portMPU_REGION_READ_WRITE },\r
408         { 0,                            0,                      0 },\r
409         { 0,                            0,                      0 }\r
410 };\r
411 \r
412 void vATask( void *pvParameters )\r
413 {\r
414         // This task was created such that it has access to certain regions of\r
415         // memory as defined by the MPU configuration.  At some point it is\r
416         // desired that these MPU regions are replaced with that defined in the\r
417         // xAltRegions const struct above.  Use a call to vTaskAllocateMPURegions()\r
418         // for this purpose.  NULL is used as the task handle to indicate that this\r
419         // function should modify the MPU regions of the calling task.\r
420         vTaskAllocateMPURegions( NULL, xAltRegions );\r
421 \r
422         // Now the task can continue its function, but from this point on can only\r
423         // access its stack and the ucOneKByte array (unless any other statically\r
424         // defined or shared regions have been declared elsewhere).\r
425 }\r
426    </pre>\r
427  * \defgroup xTaskCreateRestricted xTaskCreateRestricted\r
428  * \ingroup Tasks\r
429  */\r
430 void vTaskAllocateMPURegions( xTaskHandle xTask, const xMemoryRegion * const pxRegions ) PRIVILEGED_FUNCTION;\r
431 \r
432 /**\r
433  * task. h\r
434  * <pre>void vTaskDelete( xTaskHandle xTask );</pre>\r
435  *\r
436  * INCLUDE_vTaskDelete must be defined as 1 for this function to be available.\r
437  * See the configuration section for more information.\r
438  *\r
439  * Remove a task from the RTOS real time kernels management.  The task being\r
440  * deleted will be removed from all ready, blocked, suspended and event lists.\r
441  *\r
442  * NOTE:  The idle task is responsible for freeing the kernel allocated\r
443  * memory from tasks that have been deleted.  It is therefore important that\r
444  * the idle task is not starved of microcontroller processing time if your\r
445  * application makes any calls to vTaskDelete ().  Memory allocated by the\r
446  * task code is not automatically freed, and should be freed before the task\r
447  * is deleted.\r
448  *\r
449  * See the demo application file death.c for sample code that utilises\r
450  * vTaskDelete ().\r
451  *\r
452  * @param xTask The handle of the task to be deleted.  Passing NULL will\r
453  * cause the calling task to be deleted.\r
454  *\r
455  * Example usage:\r
456    <pre>\r
457  void vOtherFunction( void )\r
458  {\r
459  xTaskHandle xHandle;\r
460 \r
461          // Create the task, storing the handle.\r
462          xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );\r
463 \r
464          // Use the handle to delete the task.\r
465          vTaskDelete( xHandle );\r
466  }\r
467    </pre>\r
468  * \defgroup vTaskDelete vTaskDelete\r
469  * \ingroup Tasks\r
470  */\r
471 void vTaskDelete( xTaskHandle xTaskToDelete ) PRIVILEGED_FUNCTION;\r
472 \r
473 /*-----------------------------------------------------------\r
474  * TASK CONTROL API\r
475  *----------------------------------------------------------*/\r
476 \r
477 /**\r
478  * task. h\r
479  * <pre>void vTaskDelay( portTickType xTicksToDelay );</pre>\r
480  *\r
481  * Delay a task for a given number of ticks.  The actual time that the\r
482  * task remains blocked depends on the tick rate.  The constant\r
483  * portTICK_RATE_MS can be used to calculate real time from the tick\r
484  * rate - with the resolution of one tick period.\r
485  *\r
486  * INCLUDE_vTaskDelay must be defined as 1 for this function to be available.\r
487  * See the configuration section for more information.\r
488  *\r
489  *\r
490  * vTaskDelay() specifies a time at which the task wishes to unblock relative to\r
491  * the time at which vTaskDelay() is called.  For example, specifying a block\r
492  * period of 100 ticks will cause the task to unblock 100 ticks after\r
493  * vTaskDelay() is called.  vTaskDelay() does not therefore provide a good method\r
494  * of controlling the frequency of a cyclical task as the path taken through the\r
495  * code, as well as other task and interrupt activity, will effect the frequency\r
496  * at which vTaskDelay() gets called and therefore the time at which the task\r
497  * next executes.  See vTaskDelayUntil() for an alternative API function designed\r
498  * to facilitate fixed frequency execution.  It does this by specifying an\r
499  * absolute time (rather than a relative time) at which the calling task should\r
500  * unblock.\r
501  *\r
502  * @param xTicksToDelay The amount of time, in tick periods, that\r
503  * the calling task should block.\r
504  *\r
505  * Example usage:\r
506 \r
507  void vTaskFunction( void * pvParameters )\r
508  {\r
509  void vTaskFunction( void * pvParameters )\r
510  {\r
511  // Block for 500ms.\r
512  const portTickType xDelay = 500 / portTICK_RATE_MS;\r
513 \r
514          for( ;; )\r
515          {\r
516                  // Simply toggle the LED every 500ms, blocking between each toggle.\r
517                  vToggleLED();\r
518                  vTaskDelay( xDelay );\r
519          }\r
520  }\r
521 \r
522  * \defgroup vTaskDelay vTaskDelay\r
523  * \ingroup TaskCtrl\r
524  */\r
525 void vTaskDelay( portTickType xTicksToDelay ) PRIVILEGED_FUNCTION;\r
526 \r
527 /**\r
528  * task. h\r
529  * <pre>void vTaskDelayUntil( portTickType *pxPreviousWakeTime, portTickType xTimeIncrement );</pre>\r
530  *\r
531  * INCLUDE_vTaskDelayUntil must be defined as 1 for this function to be available.\r
532  * See the configuration section for more information.\r
533  *\r
534  * Delay a task until a specified time.  This function can be used by cyclical\r
535  * tasks to ensure a constant execution frequency.\r
536  *\r
537  * This function differs from vTaskDelay () in one important aspect:  vTaskDelay () will\r
538  * cause a task to block for the specified number of ticks from the time vTaskDelay () is\r
539  * called.  It is therefore difficult to use vTaskDelay () by itself to generate a fixed\r
540  * execution frequency as the time between a task starting to execute and that task\r
541  * calling vTaskDelay () may not be fixed [the task may take a different path though the\r
542  * code between calls, or may get interrupted or preempted a different number of times\r
543  * each time it executes].\r
544  *\r
545  * Whereas vTaskDelay () specifies a wake time relative to the time at which the function\r
546  * is called, vTaskDelayUntil () specifies the absolute (exact) time at which it wishes to\r
547  * unblock.\r
548  *\r
549  * The constant portTICK_RATE_MS can be used to calculate real time from the tick\r
550  * rate - with the resolution of one tick period.\r
551  *\r
552  * @param pxPreviousWakeTime Pointer to a variable that holds the time at which the\r
553  * task was last unblocked.  The variable must be initialised with the current time\r
554  * prior to its first use (see the example below).  Following this the variable is\r
555  * automatically updated within vTaskDelayUntil ().\r
556  *\r
557  * @param xTimeIncrement The cycle time period.  The task will be unblocked at\r
558  * time *pxPreviousWakeTime + xTimeIncrement.  Calling vTaskDelayUntil with the\r
559  * same xTimeIncrement parameter value will cause the task to execute with\r
560  * a fixed interface period.\r
561  *\r
562  * Example usage:\r
563    <pre>\r
564  // Perform an action every 10 ticks.\r
565  void vTaskFunction( void * pvParameters )\r
566  {\r
567  portTickType xLastWakeTime;\r
568  const portTickType xFrequency = 10;\r
569 \r
570          // Initialise the xLastWakeTime variable with the current time.\r
571          xLastWakeTime = xTaskGetTickCount ();\r
572          for( ;; )\r
573          {\r
574                  // Wait for the next cycle.\r
575                  vTaskDelayUntil( &xLastWakeTime, xFrequency );\r
576 \r
577                  // Perform action here.\r
578          }\r
579  }\r
580    </pre>\r
581  * \defgroup vTaskDelayUntil vTaskDelayUntil\r
582  * \ingroup TaskCtrl\r
583  */\r
584 void vTaskDelayUntil( portTickType * const pxPreviousWakeTime, portTickType xTimeIncrement ) PRIVILEGED_FUNCTION;\r
585 \r
586 /**\r
587  * task. h\r
588  * <pre>unsigned portBASE_TYPE uxTaskPriorityGet( xTaskHandle xTask );</pre>\r
589  *\r
590  * INCLUDE_xTaskPriorityGet must be defined as 1 for this function to be available.\r
591  * See the configuration section for more information.\r
592  *\r
593  * Obtain the priority of any task.\r
594  *\r
595  * @param xTask Handle of the task to be queried.  Passing a NULL\r
596  * handle results in the priority of the calling task being returned.\r
597  *\r
598  * @return The priority of xTask.\r
599  *\r
600  * Example usage:\r
601    <pre>\r
602  void vAFunction( void )\r
603  {\r
604  xTaskHandle xHandle;\r
605 \r
606          // Create a task, storing the handle.\r
607          xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );\r
608 \r
609          // ...\r
610 \r
611          // Use the handle to obtain the priority of the created task.\r
612          // It was created with tskIDLE_PRIORITY, but may have changed\r
613          // it itself.\r
614          if( uxTaskPriorityGet( xHandle ) != tskIDLE_PRIORITY )\r
615          {\r
616                  // The task has changed it's priority.\r
617          }\r
618 \r
619          // ...\r
620 \r
621          // Is our priority higher than the created task?\r
622          if( uxTaskPriorityGet( xHandle ) < uxTaskPriorityGet( NULL ) )\r
623          {\r
624                  // Our priority (obtained using NULL handle) is higher.\r
625          }\r
626  }\r
627    </pre>\r
628  * \defgroup uxTaskPriorityGet uxTaskPriorityGet\r
629  * \ingroup TaskCtrl\r
630  */\r
631 unsigned portBASE_TYPE uxTaskPriorityGet( xTaskHandle xTask ) PRIVILEGED_FUNCTION;\r
632 \r
633 /**\r
634  * task. h\r
635  * <pre>eTaskState eTaskGetState( xTaskHandle xTask );</pre>\r
636  *\r
637  * INCLUDE_eTaskGetState must be defined as 1 for this function to be available.\r
638  * See the configuration section for more information.\r
639  *\r
640  * Obtain the state of any task.  States are encoded by the eTaskState\r
641  * enumerated type.\r
642  *\r
643  * @param xTask Handle of the task to be queried.\r
644  *\r
645  * @return The state of xTask at the time the function was called.  Note the\r
646  * state of the task might change between the function being called, and the\r
647  * functions return value being tested by the calling task.\r
648  */\r
649 eTaskState eTaskGetState( xTaskHandle xTask ) PRIVILEGED_FUNCTION;\r
650 \r
651 /**\r
652  * task. h\r
653  * <pre>void vTaskPrioritySet( xTaskHandle xTask, unsigned portBASE_TYPE uxNewPriority );</pre>\r
654  *\r
655  * INCLUDE_vTaskPrioritySet must be defined as 1 for this function to be available.\r
656  * See the configuration section for more information.\r
657  *\r
658  * Set the priority of any task.\r
659  *\r
660  * A context switch will occur before the function returns if the priority\r
661  * being set is higher than the currently executing task.\r
662  *\r
663  * @param xTask Handle to the task for which the priority is being set.\r
664  * Passing a NULL handle results in the priority of the calling task being set.\r
665  *\r
666  * @param uxNewPriority The priority to which the task will be set.\r
667  *\r
668  * Example usage:\r
669    <pre>\r
670  void vAFunction( void )\r
671  {\r
672  xTaskHandle xHandle;\r
673 \r
674          // Create a task, storing the handle.\r
675          xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );\r
676 \r
677          // ...\r
678 \r
679          // Use the handle to raise the priority of the created task.\r
680          vTaskPrioritySet( xHandle, tskIDLE_PRIORITY + 1 );\r
681 \r
682          // ...\r
683 \r
684          // Use a NULL handle to raise our priority to the same value.\r
685          vTaskPrioritySet( NULL, tskIDLE_PRIORITY + 1 );\r
686  }\r
687    </pre>\r
688  * \defgroup vTaskPrioritySet vTaskPrioritySet\r
689  * \ingroup TaskCtrl\r
690  */\r
691 void vTaskPrioritySet( xTaskHandle xTask, unsigned portBASE_TYPE uxNewPriority ) PRIVILEGED_FUNCTION;\r
692 \r
693 /**\r
694  * task. h\r
695  * <pre>void vTaskSuspend( xTaskHandle xTaskToSuspend );</pre>\r
696  *\r
697  * INCLUDE_vTaskSuspend must be defined as 1 for this function to be available.\r
698  * See the configuration section for more information.\r
699  *\r
700  * Suspend any task.  When suspended a task will never get any microcontroller\r
701  * processing time, no matter what its priority.\r
702  *\r
703  * Calls to vTaskSuspend are not accumulative -\r
704  * i.e. calling vTaskSuspend () twice on the same task still only requires one\r
705  * call to vTaskResume () to ready the suspended task.\r
706  *\r
707  * @param xTaskToSuspend Handle to the task being suspended.  Passing a NULL\r
708  * handle will cause the calling task to be suspended.\r
709  *\r
710  * Example usage:\r
711    <pre>\r
712  void vAFunction( void )\r
713  {\r
714  xTaskHandle xHandle;\r
715 \r
716          // Create a task, storing the handle.\r
717          xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );\r
718 \r
719          // ...\r
720 \r
721          // Use the handle to suspend the created task.\r
722          vTaskSuspend( xHandle );\r
723 \r
724          // ...\r
725 \r
726          // The created task will not run during this period, unless\r
727          // another task calls vTaskResume( xHandle ).\r
728 \r
729          //...\r
730 \r
731 \r
732          // Suspend ourselves.\r
733          vTaskSuspend( NULL );\r
734 \r
735          // We cannot get here unless another task calls vTaskResume\r
736          // with our handle as the parameter.\r
737  }\r
738    </pre>\r
739  * \defgroup vTaskSuspend vTaskSuspend\r
740  * \ingroup TaskCtrl\r
741  */\r
742 void vTaskSuspend( xTaskHandle xTaskToSuspend ) PRIVILEGED_FUNCTION;\r
743 \r
744 /**\r
745  * task. h\r
746  * <pre>void vTaskResume( xTaskHandle xTaskToResume );</pre>\r
747  *\r
748  * INCLUDE_vTaskSuspend must be defined as 1 for this function to be available.\r
749  * See the configuration section for more information.\r
750  *\r
751  * Resumes a suspended task.\r
752  *\r
753  * A task that has been suspended by one of more calls to vTaskSuspend ()\r
754  * will be made available for running again by a single call to\r
755  * vTaskResume ().\r
756  *\r
757  * @param xTaskToResume Handle to the task being readied.\r
758  *\r
759  * Example usage:\r
760    <pre>\r
761  void vAFunction( void )\r
762  {\r
763  xTaskHandle xHandle;\r
764 \r
765          // Create a task, storing the handle.\r
766          xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );\r
767 \r
768          // ...\r
769 \r
770          // Use the handle to suspend the created task.\r
771          vTaskSuspend( xHandle );\r
772 \r
773          // ...\r
774 \r
775          // The created task will not run during this period, unless\r
776          // another task calls vTaskResume( xHandle ).\r
777 \r
778          //...\r
779 \r
780 \r
781          // Resume the suspended task ourselves.\r
782          vTaskResume( xHandle );\r
783 \r
784          // The created task will once again get microcontroller processing\r
785          // time in accordance with it priority within the system.\r
786  }\r
787    </pre>\r
788  * \defgroup vTaskResume vTaskResume\r
789  * \ingroup TaskCtrl\r
790  */\r
791 void vTaskResume( xTaskHandle xTaskToResume ) PRIVILEGED_FUNCTION;\r
792 \r
793 /**\r
794  * task. h\r
795  * <pre>void xTaskResumeFromISR( xTaskHandle xTaskToResume );</pre>\r
796  *\r
797  * INCLUDE_xTaskResumeFromISR must be defined as 1 for this function to be\r
798  * available.  See the configuration section for more information.\r
799  *\r
800  * An implementation of vTaskResume() that can be called from within an ISR.\r
801  *\r
802  * A task that has been suspended by one of more calls to vTaskSuspend ()\r
803  * will be made available for running again by a single call to\r
804  * xTaskResumeFromISR ().\r
805  *\r
806  * @param xTaskToResume Handle to the task being readied.\r
807  *\r
808  * \defgroup vTaskResumeFromISR vTaskResumeFromISR\r
809  * \ingroup TaskCtrl\r
810  */\r
811 portBASE_TYPE xTaskResumeFromISR( xTaskHandle xTaskToResume ) PRIVILEGED_FUNCTION;\r
812 \r
813 /*-----------------------------------------------------------\r
814  * SCHEDULER CONTROL\r
815  *----------------------------------------------------------*/\r
816 \r
817 /**\r
818  * task. h\r
819  * <pre>void vTaskStartScheduler( void );</pre>\r
820  *\r
821  * Starts the real time kernel tick processing.  After calling the kernel\r
822  * has control over which tasks are executed and when.  This function\r
823  * does not return until an executing task calls vTaskEndScheduler ().\r
824  *\r
825  * At least one task should be created via a call to xTaskCreate ()\r
826  * before calling vTaskStartScheduler ().  The idle task is created\r
827  * automatically when the first application task is created.\r
828  *\r
829  * See the demo application file main.c for an example of creating\r
830  * tasks and starting the kernel.\r
831  *\r
832  * Example usage:\r
833    <pre>\r
834  void vAFunction( void )\r
835  {\r
836          // Create at least one task before starting the kernel.\r
837          xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );\r
838 \r
839          // Start the real time kernel with preemption.\r
840          vTaskStartScheduler ();\r
841 \r
842          // Will not get here unless a task calls vTaskEndScheduler ()\r
843  }\r
844    </pre>\r
845  *\r
846  * \defgroup vTaskStartScheduler vTaskStartScheduler\r
847  * \ingroup SchedulerControl\r
848  */\r
849 void vTaskStartScheduler( void ) PRIVILEGED_FUNCTION;\r
850 \r
851 /**\r
852  * task. h\r
853  * <pre>void vTaskEndScheduler( void );</pre>\r
854  *\r
855  * Stops the real time kernel tick.  All created tasks will be automatically\r
856  * deleted and multitasking (either preemptive or cooperative) will\r
857  * stop.  Execution then resumes from the point where vTaskStartScheduler ()\r
858  * was called, as if vTaskStartScheduler () had just returned.\r
859  *\r
860  * See the demo application file main. c in the demo/PC directory for an\r
861  * example that uses vTaskEndScheduler ().\r
862  *\r
863  * vTaskEndScheduler () requires an exit function to be defined within the\r
864  * portable layer (see vPortEndScheduler () in port. c for the PC port).  This\r
865  * performs hardware specific operations such as stopping the kernel tick.\r
866  *\r
867  * vTaskEndScheduler () will cause all of the resources allocated by the\r
868  * kernel to be freed - but will not free resources allocated by application\r
869  * tasks.\r
870  *\r
871  * Example usage:\r
872    <pre>\r
873  void vTaskCode( void * pvParameters )\r
874  {\r
875          for( ;; )\r
876          {\r
877                  // Task code goes here.\r
878 \r
879                  // At some point we want to end the real time kernel processing\r
880                  // so call ...\r
881                  vTaskEndScheduler ();\r
882          }\r
883  }\r
884 \r
885  void vAFunction( void )\r
886  {\r
887          // Create at least one task before starting the kernel.\r
888          xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );\r
889 \r
890          // Start the real time kernel with preemption.\r
891          vTaskStartScheduler ();\r
892 \r
893          // Will only get here when the vTaskCode () task has called\r
894          // vTaskEndScheduler ().  When we get here we are back to single task\r
895          // execution.\r
896  }\r
897    </pre>\r
898  *\r
899  * \defgroup vTaskEndScheduler vTaskEndScheduler\r
900  * \ingroup SchedulerControl\r
901  */\r
902 void vTaskEndScheduler( void ) PRIVILEGED_FUNCTION;\r
903 \r
904 /**\r
905  * task. h\r
906  * <pre>void vTaskSuspendAll( void );</pre>\r
907  *\r
908  * Suspends all real time kernel activity while keeping interrupts (including the\r
909  * kernel tick) enabled.\r
910  *\r
911  * After calling vTaskSuspendAll () the calling task will continue to execute\r
912  * without risk of being swapped out until a call to xTaskResumeAll () has been\r
913  * made.\r
914  *\r
915  * API functions that have the potential to cause a context switch (for example,\r
916  * vTaskDelayUntil(), xQueueSend(), etc.) must not be called while the scheduler\r
917  * is suspended.\r
918  *\r
919  * Example usage:\r
920    <pre>\r
921  void vTask1( void * pvParameters )\r
922  {\r
923          for( ;; )\r
924          {\r
925                  // Task code goes here.\r
926 \r
927                  // ...\r
928 \r
929                  // At some point the task wants to perform a long operation during\r
930                  // which it does not want to get swapped out.  It cannot use\r
931                  // taskENTER_CRITICAL ()/taskEXIT_CRITICAL () as the length of the\r
932                  // operation may cause interrupts to be missed - including the\r
933                  // ticks.\r
934 \r
935                  // Prevent the real time kernel swapping out the task.\r
936                  vTaskSuspendAll ();\r
937 \r
938                  // Perform the operation here.  There is no need to use critical\r
939                  // sections as we have all the microcontroller processing time.\r
940                  // During this time interrupts will still operate and the kernel\r
941                  // tick count will be maintained.\r
942 \r
943                  // ...\r
944 \r
945                  // The operation is complete.  Restart the kernel.\r
946                  xTaskResumeAll ();\r
947          }\r
948  }\r
949    </pre>\r
950  * \defgroup vTaskSuspendAll vTaskSuspendAll\r
951  * \ingroup SchedulerControl\r
952  */\r
953 void vTaskSuspendAll( void ) PRIVILEGED_FUNCTION;\r
954 \r
955 /**\r
956  * task. h\r
957  * <pre>char xTaskResumeAll( void );</pre>\r
958  *\r
959  * Resumes real time kernel activity following a call to vTaskSuspendAll ().\r
960  * After a call to vTaskSuspendAll () the kernel will take control of which\r
961  * task is executing at any time.\r
962  *\r
963  * @return If resuming the scheduler caused a context switch then pdTRUE is\r
964  *                returned, otherwise pdFALSE is returned.\r
965  *\r
966  * Example usage:\r
967    <pre>\r
968  void vTask1( void * pvParameters )\r
969  {\r
970          for( ;; )\r
971          {\r
972                  // Task code goes here.\r
973 \r
974                  // ...\r
975 \r
976                  // At some point the task wants to perform a long operation during\r
977                  // which it does not want to get swapped out.  It cannot use\r
978                  // taskENTER_CRITICAL ()/taskEXIT_CRITICAL () as the length of the\r
979                  // operation may cause interrupts to be missed - including the\r
980                  // ticks.\r
981 \r
982                  // Prevent the real time kernel swapping out the task.\r
983                  vTaskSuspendAll ();\r
984 \r
985                  // Perform the operation here.  There is no need to use critical\r
986                  // sections as we have all the microcontroller processing time.\r
987                  // During this time interrupts will still operate and the real\r
988                  // time kernel tick count will be maintained.\r
989 \r
990                  // ...\r
991 \r
992                  // The operation is complete.  Restart the kernel.  We want to force\r
993                  // a context switch - but there is no point if resuming the scheduler\r
994                  // caused a context switch already.\r
995                  if( !xTaskResumeAll () )\r
996                  {\r
997                           taskYIELD ();\r
998                  }\r
999          }\r
1000  }\r
1001    </pre>\r
1002  * \defgroup xTaskResumeAll xTaskResumeAll\r
1003  * \ingroup SchedulerControl\r
1004  */\r
1005 signed portBASE_TYPE xTaskResumeAll( void ) PRIVILEGED_FUNCTION;\r
1006 \r
1007 /**\r
1008  * task. h\r
1009  * <pre>signed portBASE_TYPE xTaskIsTaskSuspended( const xTaskHandle xTask );</pre>\r
1010  *\r
1011  * Utility task that simply returns pdTRUE if the task referenced by xTask is\r
1012  * currently in the Suspended state, or pdFALSE if the task referenced by xTask\r
1013  * is in any other state.\r
1014  *\r
1015  */\r
1016 signed portBASE_TYPE xTaskIsTaskSuspended( xTaskHandle xTask ) PRIVILEGED_FUNCTION;\r
1017 \r
1018 /*-----------------------------------------------------------\r
1019  * TASK UTILITIES\r
1020  *----------------------------------------------------------*/\r
1021 \r
1022 /**\r
1023  * task. h\r
1024  * <PRE>portTickType xTaskGetTickCount( void );</PRE>\r
1025  *\r
1026  * @return The count of ticks since vTaskStartScheduler was called.\r
1027  *\r
1028  * \defgroup xTaskGetTickCount xTaskGetTickCount\r
1029  * \ingroup TaskUtils\r
1030  */\r
1031 portTickType xTaskGetTickCount( void ) PRIVILEGED_FUNCTION;\r
1032 \r
1033 /**\r
1034  * task. h\r
1035  * <PRE>portTickType xTaskGetTickCountFromISR( void );</PRE>\r
1036  *\r
1037  * @return The count of ticks since vTaskStartScheduler was called.\r
1038  *\r
1039  * This is a version of xTaskGetTickCount() that is safe to be called from an\r
1040  * ISR - provided that portTickType is the natural word size of the\r
1041  * microcontroller being used or interrupt nesting is either not supported or\r
1042  * not being used.\r
1043  *\r
1044  * \defgroup xTaskGetTickCount xTaskGetTickCount\r
1045  * \ingroup TaskUtils\r
1046  */\r
1047 portTickType xTaskGetTickCountFromISR( void ) PRIVILEGED_FUNCTION;\r
1048 \r
1049 /**\r
1050  * task. h\r
1051  * <PRE>unsigned short uxTaskGetNumberOfTasks( void );</PRE>\r
1052  *\r
1053  * @return The number of tasks that the real time kernel is currently managing.\r
1054  * This includes all ready, blocked and suspended tasks.  A task that\r
1055  * has been deleted but not yet freed by the idle task will also be\r
1056  * included in the count.\r
1057  *\r
1058  * \defgroup uxTaskGetNumberOfTasks uxTaskGetNumberOfTasks\r
1059  * \ingroup TaskUtils\r
1060  */\r
1061 unsigned portBASE_TYPE uxTaskGetNumberOfTasks( void ) PRIVILEGED_FUNCTION;\r
1062 \r
1063 /**\r
1064  * task. h\r
1065  * <PRE>signed char *pcTaskGetTaskName( xTaskHandle xTaskToQuery );</PRE>\r
1066  *\r
1067  * @return The text (human readable) name of the task referenced by the handle\r
1068  * xTaskToQueury.  A task can query its own name by either passing in its own\r
1069  * handle, or by setting xTaskToQuery to NULL.  INCLUDE_pcTaskGetTaskName must be\r
1070  * set to 1 in FreeRTOSConfig.h for pcTaskGetTaskName() to be available.\r
1071  *\r
1072  * \defgroup pcTaskGetTaskName pcTaskGetTaskName\r
1073  * \ingroup TaskUtils\r
1074  */\r
1075 signed char *pcTaskGetTaskName( xTaskHandle xTaskToQuery );\r
1076 \r
1077 /**\r
1078  * task.h\r
1079  * <PRE>unsigned portBASE_TYPE uxTaskGetStackHighWaterMark( xTaskHandle xTask );</PRE>\r
1080  *\r
1081  * INCLUDE_uxTaskGetStackHighWaterMark must be set to 1 in FreeRTOSConfig.h for\r
1082  * this function to be available.\r
1083  *\r
1084  * Returns the high water mark of the stack associated with xTask.  That is,\r
1085  * the minimum free stack space there has been (in words, so on a 32 bit machine\r
1086  * a value of 1 means 4 bytes) since the task started.  The smaller the returned\r
1087  * number the closer the task has come to overflowing its stack.\r
1088  *\r
1089  * @param xTask Handle of the task associated with the stack to be checked.\r
1090  * Set xTask to NULL to check the stack of the calling task.\r
1091  *\r
1092  * @return The smallest amount of free stack space there has been (in bytes)\r
1093  * since the task referenced by xTask was created.\r
1094  */\r
1095 unsigned portBASE_TYPE uxTaskGetStackHighWaterMark( xTaskHandle xTask ) PRIVILEGED_FUNCTION;\r
1096 \r
1097 /* When using trace macros it is sometimes necessary to include tasks.h before\r
1098 FreeRTOS.h.  When this is done pdTASK_HOOK_CODE will not yet have been defined,\r
1099 so the following two prototypes will cause a compilation error.  This can be\r
1100 fixed by simply guarding against the inclusion of these two prototypes unless\r
1101 they are explicitly required by the configUSE_APPLICATION_TASK_TAG configuration\r
1102 constant. */\r
1103 #ifdef configUSE_APPLICATION_TASK_TAG\r
1104         #if configUSE_APPLICATION_TASK_TAG == 1\r
1105                 /**\r
1106                  * task.h\r
1107                  * <pre>void vTaskSetApplicationTaskTag( xTaskHandle xTask, pdTASK_HOOK_CODE pxHookFunction );</pre>\r
1108                  *\r
1109                  * Sets pxHookFunction to be the task hook function used by the task xTask.\r
1110                  * Passing xTask as NULL has the effect of setting the calling tasks hook\r
1111                  * function.\r
1112                  */\r
1113                 void vTaskSetApplicationTaskTag( xTaskHandle xTask, pdTASK_HOOK_CODE pxHookFunction ) PRIVILEGED_FUNCTION;\r
1114 \r
1115                 /**\r
1116                  * task.h\r
1117                  * <pre>void xTaskGetApplicationTaskTag( xTaskHandle xTask );</pre>\r
1118                  *\r
1119                  * Returns the pxHookFunction value assigned to the task xTask.\r
1120                  */\r
1121                 pdTASK_HOOK_CODE xTaskGetApplicationTaskTag( xTaskHandle xTask ) PRIVILEGED_FUNCTION;\r
1122         #endif /* configUSE_APPLICATION_TASK_TAG ==1 */\r
1123 #endif /* ifdef configUSE_APPLICATION_TASK_TAG */\r
1124 \r
1125 /**\r
1126  * task.h\r
1127  * <pre>portBASE_TYPE xTaskCallApplicationTaskHook( xTaskHandle xTask, pdTASK_HOOK_CODE pxHookFunction );</pre>\r
1128  *\r
1129  * Calls the hook function associated with xTask.  Passing xTask as NULL has\r
1130  * the effect of calling the Running tasks (the calling task) hook function.\r
1131  *\r
1132  * pvParameter is passed to the hook function for the task to interpret as it\r
1133  * wants.\r
1134  */\r
1135 portBASE_TYPE xTaskCallApplicationTaskHook( xTaskHandle xTask, void *pvParameter ) PRIVILEGED_FUNCTION;\r
1136 \r
1137 /**\r
1138  * xTaskGetIdleTaskHandle() is only available if\r
1139  * INCLUDE_xTaskGetIdleTaskHandle is set to 1 in FreeRTOSConfig.h.\r
1140  *\r
1141  * Simply returns the handle of the idle task.  It is not valid to call\r
1142  * xTaskGetIdleTaskHandle() before the scheduler has been started.\r
1143  */\r
1144 xTaskHandle xTaskGetIdleTaskHandle( void );\r
1145 \r
1146 /**\r
1147  * configUSE_TRACE_FACILITY must bet defined as 1 in FreeRTOSConfig.h for\r
1148  * uxTaskGetSystemState() to be available.\r
1149  *\r
1150  * uxTaskGetSystemState() populates an xTaskStatusType structure for each task in\r
1151  * the system.  xTaskStatusType structures contain, among other things, members\r
1152  * for the task handle, task name, task priority, task state, and total amount\r
1153  * of run time consumed by the task.  See the xTaskStatusType structure\r
1154  * definition in this file for the full member list.\r
1155  *\r
1156  * NOTE:  This function is intended for debugging use only as its use results in\r
1157  * the scheduler remaining suspended for an extended period.\r
1158  *\r
1159  * @param pxTaskStatusArray A pointer to an array of xTaskStatusType structures.\r
1160  * The array must contain at least one xTaskStatusType structure for each task \r
1161  * that is under the control of the RTOS.  The number of tasks under the control \r
1162  * of the RTOS can be determined using the uxTaskGetNumberOfTasks() API function.\r
1163  *\r
1164  * @param uxArraySize The size of the array pointed to by the pxTaskStatusArray\r
1165  * parameter.  The size is specified as the number of indexes in the array, or\r
1166  * the number of xTaskStatusType structures contained in the array, not by the\r
1167  * number of bytes in the array.\r
1168  *\r
1169  * @param pulTotalRunTime If configGENERATE_RUN_TIME_STATS is set to 1 in\r
1170  * FreeRTOSConfig.h then *pulTotalRunTime is set by uxTaskGetSystemState() to the\r
1171  * total run time (as defined by the run time stats clock, see\r
1172  * http://www.freertos.org/rtos-run-time-stats.html) since the target booted.\r
1173  * pulTotalRunTime can be set to NULL to omit the total run time information.\r
1174  *\r
1175  * @return The number of xTaskStatusType structures that were populated by\r
1176  * uxTaskGetSystemState().  This should equal the number returned by the\r
1177  * uxTaskGetNumberOfTasks() API function, but will be zero if the value passed\r
1178  * in the uxArraySize parameter was too small.\r
1179  *\r
1180  * Example usage:\r
1181    <pre>\r
1182     // This example demonstrates how a human readable table of run time stats\r
1183         // information is generated from raw data provided by uxTaskGetSystemState().\r
1184         // The human readable table is written to pcWriteBuffer\r
1185         void vTaskGetRunTimeStats( signed char *pcWriteBuffer )\r
1186         {\r
1187         xTaskStatusType *pxTaskStatusArray;\r
1188         volatile unsigned portBASE_TYPE uxArraySize, x;\r
1189         unsigned long ulTotalRunTime, ulStatsAsPercentage;\r
1190 \r
1191                 // Make sure the write buffer does not contain a string.\r
1192                 *pcWriteBuffer = 0x00;\r
1193 \r
1194                 // Take a snapshot of the number of tasks in case it changes while this\r
1195                 // function is executing.\r
1196                 uxArraySize = uxCurrentNumberOfTasks();\r
1197 \r
1198                 // Allocate a xTaskStatusType structure for each task.  An array could be\r
1199                 // allocated statically at compile time.\r
1200                 pxTaskStatusArray = pvPortMalloc( uxCurrentNumberOfTasks * sizeof( xTaskStatusType ) );\r
1201 \r
1202                 if( pxTaskStatusArray != NULL )\r
1203                 {\r
1204                         // Generate raw status information about each task.\r
1205                         uxArraySize = uxTaskGetSystemState( pxTaskStatusArray, uxArraySize, &ulTotalRunTime );\r
1206 \r
1207                         // For percentage calculations.\r
1208                         ulTotalRunTime /= 100UL;\r
1209 \r
1210                         // Avoid divide by zero errors.\r
1211                         if( ulTotalRunTime > 0 )\r
1212                         {\r
1213                                 // For each populated position in the pxTaskStatusArray array,\r
1214                                 // format the raw data as human readable ASCII data\r
1215                                 for( x = 0; x < uxArraySize; x++ )\r
1216                                 {\r
1217                                         // What percentage of the total run time has the task used?\r
1218                                         // This will always be rounded down to the nearest integer.\r
1219                                         // ulTotalRunTimeDiv100 has already been divided by 100.\r
1220                                         ulStatsAsPercentage = pxTaskStatusArray[ x ].ulRunTimeCounter / ulTotalRunTime;\r
1221 \r
1222                                         if( ulStatsAsPercentage > 0UL )\r
1223                                         {\r
1224                                                 sprintf( ( char * ) pcWriteBuffer, ( char * ) "%s\t\t%lu\t\t%lu%%\r\n", pxTaskStatusArray[ x ].pcTaskName, pxTaskStatusArray[ x ].ulRunTimeCounter, ulStatsAsPercentage );\r
1225                                         }\r
1226                                         else\r
1227                                         {\r
1228                                                 // If the percentage is zero here then the task has\r
1229                                                 // consumed less than 1% of the total run time.\r
1230                                                 sprintf( ( char * ) pcWriteBuffer, ( char * ) "%s\t\t%lu\t\t<1%%\r\n", pxTaskStatusArray[ x ].pcTaskName, pxTaskStatusArray[ x ].ulRunTimeCounter );\r
1231                                         }\r
1232 \r
1233                                         pcWriteBuffer += strlen( ( char * ) pcWriteBuffer );\r
1234                                 }\r
1235                         }\r
1236 \r
1237                         // The array is no longer needed, free the memory it consumes.\r
1238                         vPortFree( pxTaskStatusArray );\r
1239                 }\r
1240         }\r
1241         </pre>\r
1242  */\r
1243 unsigned portBASE_TYPE uxTaskGetSystemState( xTaskStatusType *pxTaskStatusArray, unsigned portBASE_TYPE uxArraySize, unsigned long *pulTotalRunTime );\r
1244 \r
1245 /**\r
1246  * task. h\r
1247  * <PRE>void vTaskList( char *pcWriteBuffer );</PRE>\r
1248  *\r
1249  * configUSE_TRACE_FACILITY and configUSE_STATS_FORMATTING_FUNCTIONS must\r
1250  * both be defined as 1 for this function to be available.  See the\r
1251  * configuration section of the FreeRTOS.org website for more information.\r
1252  *\r
1253  * NOTE 1: This function will disable interrupts for its duration.  It is\r
1254  * not intended for normal application runtime use but as a debug aid.\r
1255  *\r
1256  * Lists all the current tasks, along with their current state and stack\r
1257  * usage high water mark.\r
1258  *\r
1259  * Tasks are reported as blocked ('B'), ready ('R'), deleted ('D') or\r
1260  * suspended ('S').\r
1261  *\r
1262  * PLEASE NOTE:\r
1263  *\r
1264  * This function is provided for convenience only, and is used by many of the\r
1265  * demo applications.  Do not consider it to be part of the scheduler.\r
1266  *\r
1267  * vTaskList() calls uxTaskGetSystemState(), then formats part of the\r
1268  * uxTaskGetSystemState() output into a human readable table that displays task\r
1269  * names, states and stack usage.\r
1270  *\r
1271  * vTaskList() has a dependency on the sprintf() C library function that might\r
1272  * bloat the code size, use a lot of stack, and provide different results on\r
1273  * different platforms.  An alternative, tiny, third party, and limited\r
1274  * functionality implementation of sprintf() is provided in many of the\r
1275  * FreeRTOS/Demo sub-directories in a file called printf-stdarg.c (note\r
1276  * printf-stdarg.c does not provide a full snprintf() implementation!).\r
1277  *\r
1278  * It is recommended that production systems call uxTaskGetSystemState()\r
1279  * directly to get access to raw stats data, rather than indirectly through a\r
1280  * call to vTaskList().\r
1281  *\r
1282  * @param pcWriteBuffer A buffer into which the above mentioned details\r
1283  * will be written, in ascii form.  This buffer is assumed to be large\r
1284  * enough to contain the generated report.  Approximately 40 bytes per\r
1285  * task should be sufficient.\r
1286  *\r
1287  * \defgroup vTaskList vTaskList\r
1288  * \ingroup TaskUtils\r
1289  */\r
1290 void vTaskList( signed char *pcWriteBuffer ) PRIVILEGED_FUNCTION;\r
1291 \r
1292 /**\r
1293  * task. h\r
1294  * <PRE>void vTaskGetRunTimeStats( char *pcWriteBuffer );</PRE>\r
1295  *\r
1296  * configGENERATE_RUN_TIME_STATS and configUSE_STATS_FORMATTING_FUNCTIONS\r
1297  * must both be defined as 1 for this function to be available.  The application\r
1298  * must also then provide definitions for\r
1299  * portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() and portGET_RUN_TIME_COUNTER_VALUE\r
1300  * to configure a peripheral timer/counter and return the timers current count\r
1301  * value respectively.  The counter should be at least 10 times the frequency of\r
1302  * the tick count.\r
1303  *\r
1304  * NOTE 1: This function will disable interrupts for its duration.  It is\r
1305  * not intended for normal application runtime use but as a debug aid.\r
1306  *\r
1307  * Setting configGENERATE_RUN_TIME_STATS to 1 will result in a total\r
1308  * accumulated execution time being stored for each task.  The resolution\r
1309  * of the accumulated time value depends on the frequency of the timer\r
1310  * configured by the portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() macro.\r
1311  * Calling vTaskGetRunTimeStats() writes the total execution time of each\r
1312  * task into a buffer, both as an absolute count value and as a percentage\r
1313  * of the total system execution time.\r
1314  *\r
1315  * NOTE 2:\r
1316  *\r
1317  * This function is provided for convenience only, and is used by many of the\r
1318  * demo applications.  Do not consider it to be part of the scheduler.\r
1319  *\r
1320  * vTaskGetRunTimeStats() calls uxTaskGetSystemState(), then formats part of the\r
1321  * uxTaskGetSystemState() output into a human readable table that displays the\r
1322  * amount of time each task has spent in the Running state in both absolute and\r
1323  * percentage terms.\r
1324  *\r
1325  * vTaskGetRunTimeStats() has a dependency on the sprintf() C library function\r
1326  * that might bloat the code size, use a lot of stack, and provide different\r
1327  * results on different platforms.  An alternative, tiny, third party, and\r
1328  * limited functionality implementation of sprintf() is provided in many of the\r
1329  * FreeRTOS/Demo sub-directories in a file called printf-stdarg.c (note\r
1330  * printf-stdarg.c does not provide a full snprintf() implementation!).\r
1331  *\r
1332  * It is recommended that production systems call uxTaskGetSystemState() directly\r
1333  * to get access to raw stats data, rather than indirectly through a call to\r
1334  * vTaskGetRunTimeStats().\r
1335  *\r
1336  * @param pcWriteBuffer A buffer into which the execution times will be\r
1337  * written, in ascii form.  This buffer is assumed to be large enough to\r
1338  * contain the generated report.  Approximately 40 bytes per task should\r
1339  * be sufficient.\r
1340  *\r
1341  * \defgroup vTaskGetRunTimeStats vTaskGetRunTimeStats\r
1342  * \ingroup TaskUtils\r
1343  */\r
1344 void vTaskGetRunTimeStats( signed char *pcWriteBuffer ) PRIVILEGED_FUNCTION;\r
1345 \r
1346 /*-----------------------------------------------------------\r
1347  * SCHEDULER INTERNALS AVAILABLE FOR PORTING PURPOSES\r
1348  *----------------------------------------------------------*/\r
1349 \r
1350 /*\r
1351  * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE.  IT IS ONLY\r
1352  * INTENDED FOR USE WHEN IMPLEMENTING A PORT OF THE SCHEDULER AND IS\r
1353  * AN INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.\r
1354  *\r
1355  * Called from the real time kernel tick (either preemptive or cooperative),\r
1356  * this increments the tick count and checks if any tasks that are blocked\r
1357  * for a finite period required removing from a blocked list and placing on\r
1358  * a ready list.  If a non-zero value is returned then a context switch is\r
1359  * required because either:\r
1360  *   + A task was removed from a blocked list because its timeout had expired,\r
1361  *     or\r
1362  *   + Time slicing is in use and there is a task of equal priority to the\r
1363  *     currently running task.\r
1364  */\r
1365 portBASE_TYPE xTaskIncrementTick( void ) PRIVILEGED_FUNCTION;\r
1366 \r
1367 /*\r
1368  * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE.  IT IS AN\r
1369  * INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.\r
1370  *\r
1371  * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED.\r
1372  *\r
1373  * Removes the calling task from the ready list and places it both\r
1374  * on the list of tasks waiting for a particular event, and the\r
1375  * list of delayed tasks.  The task will be removed from both lists\r
1376  * and replaced on the ready list should either the event occur (and\r
1377  * there be no higher priority tasks waiting on the same event) or\r
1378  * the delay period expires.\r
1379  *\r
1380  * @param pxEventList The list containing tasks that are blocked waiting\r
1381  * for the event to occur.\r
1382  *\r
1383  * @param xTicksToWait The maximum amount of time that the task should wait\r
1384  * for the event to occur.  This is specified in kernel ticks,the constant\r
1385  * portTICK_RATE_MS can be used to convert kernel ticks into a real time\r
1386  * period.\r
1387  */\r
1388 void vTaskPlaceOnEventList( xList * const pxEventList, portTickType xTicksToWait ) PRIVILEGED_FUNCTION;\r
1389 \r
1390 /*\r
1391  * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE.  IT IS AN\r
1392  * INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.\r
1393  *\r
1394  * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED.\r
1395  *\r
1396  * This function performs nearly the same function as vTaskPlaceOnEventList().\r
1397  * The difference being that this function does not permit tasks to block\r
1398  * indefinitely, whereas vTaskPlaceOnEventList() does.\r
1399  *\r
1400  * @return pdTRUE if the task being removed has a higher priority than the task\r
1401  * making the call, otherwise pdFALSE.\r
1402  */\r
1403 void vTaskPlaceOnEventListRestricted( xList * const pxEventList, portTickType xTicksToWait ) PRIVILEGED_FUNCTION;\r
1404 \r
1405 /*\r
1406  * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE.  IT IS AN\r
1407  * INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.\r
1408  *\r
1409  * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED.\r
1410  *\r
1411  * Removes a task from both the specified event list and the list of blocked\r
1412  * tasks, and places it on a ready queue.\r
1413  *\r
1414  * xTaskRemoveFromEventList () will be called if either an event occurs to\r
1415  * unblock a task, or the block timeout period expires.\r
1416  *\r
1417  * @return pdTRUE if the task being removed has a higher priority than the task\r
1418  * making the call, otherwise pdFALSE.\r
1419  */\r
1420 signed portBASE_TYPE xTaskRemoveFromEventList( const xList * const pxEventList ) PRIVILEGED_FUNCTION;\r
1421 \r
1422 /*\r
1423  * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE.  IT IS ONLY\r
1424  * INTENDED FOR USE WHEN IMPLEMENTING A PORT OF THE SCHEDULER AND IS\r
1425  * AN INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.\r
1426  *\r
1427  * Sets the pointer to the current TCB to the TCB of the highest priority task\r
1428  * that is ready to run.\r
1429  */\r
1430 void vTaskSwitchContext( void ) PRIVILEGED_FUNCTION;\r
1431 \r
1432 /*\r
1433  * Return the handle of the calling task.\r
1434  */\r
1435 xTaskHandle xTaskGetCurrentTaskHandle( void ) PRIVILEGED_FUNCTION;\r
1436 \r
1437 /*\r
1438  * Capture the current time status for future reference.\r
1439  */\r
1440 void vTaskSetTimeOutState( xTimeOutType * const pxTimeOut ) PRIVILEGED_FUNCTION;\r
1441 \r
1442 /*\r
1443  * Compare the time status now with that previously captured to see if the\r
1444  * timeout has expired.\r
1445  */\r
1446 portBASE_TYPE xTaskCheckForTimeOut( xTimeOutType * const pxTimeOut, portTickType * const pxTicksToWait ) PRIVILEGED_FUNCTION;\r
1447 \r
1448 /*\r
1449  * Shortcut used by the queue implementation to prevent unnecessary call to\r
1450  * taskYIELD();\r
1451  */\r
1452 void vTaskMissedYield( void ) PRIVILEGED_FUNCTION;\r
1453 \r
1454 /*\r
1455  * Returns the scheduler state as taskSCHEDULER_RUNNING,\r
1456  * taskSCHEDULER_NOT_STARTED or taskSCHEDULER_SUSPENDED.\r
1457  */\r
1458 portBASE_TYPE xTaskGetSchedulerState( void ) PRIVILEGED_FUNCTION;\r
1459 \r
1460 /*\r
1461  * Raises the priority of the mutex holder to that of the calling task should\r
1462  * the mutex holder have a priority less than the calling task.\r
1463  */\r
1464 void vTaskPriorityInherit( xTaskHandle const pxMutexHolder ) PRIVILEGED_FUNCTION;\r
1465 \r
1466 /*\r
1467  * Set the priority of a task back to its proper priority in the case that it\r
1468  * inherited a higher priority while it was holding a semaphore.\r
1469  */\r
1470 void vTaskPriorityDisinherit( xTaskHandle const pxMutexHolder ) PRIVILEGED_FUNCTION;\r
1471 \r
1472 /*\r
1473  * Generic version of the task creation function which is in turn called by the\r
1474  * xTaskCreate() and xTaskCreateRestricted() macros.\r
1475  */\r
1476 signed portBASE_TYPE xTaskGenericCreate( pdTASK_CODE pxTaskCode, const signed char * const pcName, unsigned short usStackDepth, void *pvParameters, unsigned portBASE_TYPE uxPriority, xTaskHandle *pxCreatedTask, portSTACK_TYPE *puxStackBuffer, const xMemoryRegion * const xRegions ) PRIVILEGED_FUNCTION;\r
1477 \r
1478 /*\r
1479  * Get the uxTCBNumber assigned to the task referenced by the xTask parameter.\r
1480  */\r
1481 unsigned portBASE_TYPE uxTaskGetTaskNumber( xTaskHandle xTask );\r
1482 \r
1483 /*\r
1484  * Set the uxTCBNumber of the task referenced by the xTask parameter to\r
1485  * ucHandle.\r
1486  */\r
1487 void vTaskSetTaskNumber( xTaskHandle xTask, unsigned portBASE_TYPE uxHandle );\r
1488 \r
1489 /*\r
1490  * If tickless mode is being used, or a low power mode is implemented, then\r
1491  * the tick interrupt will not execute during idle periods.  When this is the\r
1492  * case, the tick count value maintained by the scheduler needs to be kept up\r
1493  * to date with the actual execution time by being skipped forward by the by\r
1494  * a time equal to the idle period.\r
1495  */\r
1496 void vTaskStepTick( portTickType xTicksToJump );\r
1497 \r
1498 /*\r
1499  * Provided for use within portSUPPRESS_TICKS_AND_SLEEP() to allow the port\r
1500  * specific sleep function to determine if it is ok to proceed with the sleep,\r
1501  * and if it is ok to proceed, if it is ok to sleep indefinitely.\r
1502  *\r
1503  * This function is necessary because portSUPPRESS_TICKS_AND_SLEEP() is only\r
1504  * called with the scheduler suspended, not from within a critical section.  It\r
1505  * is therefore possible for an interrupt to request a context switch between\r
1506  * portSUPPRESS_TICKS_AND_SLEEP() and the low power mode actually being\r
1507  * entered.  eTaskConfirmSleepModeStatus() should be called from a short\r
1508  * critical section between the timer being stopped and the sleep mode being\r
1509  * entered to ensure it is ok to proceed into the sleep mode.\r
1510  */\r
1511 eSleepModeStatus eTaskConfirmSleepModeStatus( void );\r
1512 \r
1513 #ifdef __cplusplus\r
1514 }\r
1515 #endif\r
1516 #endif /* INC_TASK_H */\r
1517 \r
1518 \r
1519 \r