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