]> git.sur5r.net Git - freertos/blob - Source/include/task.h
Update ready for V5.1.0 release.
[freertos] / Source / include / task.h
1 /*\r
2         FreeRTOS.org V5.1.0 - Copyright (C) 2003-2008 Richard Barry.\r
3 \r
4         This file is part of the FreeRTOS.org distribution.\r
5 \r
6         FreeRTOS.org is free software; you can redistribute it and/or modify\r
7         it under the terms of the GNU General Public License as published by\r
8         the Free Software Foundation; either version 2 of the License, or\r
9         (at your option) any later version.\r
10 \r
11         FreeRTOS.org is distributed in the hope that it will be useful,\r
12         but WITHOUT ANY WARRANTY; without even the implied warranty of\r
13         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
14         GNU General Public License for more details.\r
15 \r
16         You should have received a copy of the GNU General Public License\r
17         along with FreeRTOS.org; if not, write to the Free Software\r
18         Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\r
19 \r
20         A special exception to the GPL can be applied should you wish to distribute\r
21         a combined work that includes FreeRTOS.org, without being obliged to provide\r
22         the source code for any proprietary components.  See the licensing section\r
23         of http://www.FreeRTOS.org for full details of how and when the exception\r
24         can be applied.\r
25 \r
26     ***************************************************************************\r
27     ***************************************************************************\r
28     *                                                                         *\r
29     * SAVE TIME AND MONEY!  We can port FreeRTOS.org to your own hardware,    *\r
30     * and even write all or part of your application on your behalf.          *\r
31     * See http://www.OpenRTOS.com for details of the services we provide to   *\r
32     * expedite your project.                                                  *\r
33     *                                                                         *\r
34     ***************************************************************************\r
35     ***************************************************************************\r
36 \r
37         Please ensure to read the configuration and relevant port sections of the\r
38         online documentation.\r
39 \r
40         http://www.FreeRTOS.org - Documentation, latest information, license and \r
41         contact details.\r
42 \r
43         http://www.SafeRTOS.com - A version that is certified for use in safety \r
44         critical systems.\r
45 \r
46         http://www.OpenRTOS.com - Commercial support, development, porting, \r
47         licensing and training services.\r
48 */\r
49 \r
50 \r
51 #ifndef INC_FREERTOS_H\r
52         #error "#include FreeRTOS.h" must appear in source files before "#include task.h"\r
53 #endif\r
54 \r
55 \r
56 \r
57 #ifndef TASK_H\r
58 #define TASK_H\r
59 \r
60 #include "portable.h"\r
61 #include "list.h"\r
62 \r
63 #ifdef __cplusplus\r
64 extern "C" {\r
65 #endif\r
66 /*-----------------------------------------------------------\r
67  * MACROS AND DEFINITIONS\r
68  *----------------------------------------------------------*/\r
69 \r
70 #define tskKERNEL_VERSION_NUMBER "V5.1.0"\r
71 \r
72 /**\r
73  * task. h\r
74  *\r
75  * Type by which tasks are referenced.  For example, a call to xTaskCreate\r
76  * returns (via a pointer parameter) an xTaskHandle variable that can then\r
77  * be used as a parameter to vTaskDelete to delete the task.\r
78  *\r
79  * \page xTaskHandle xTaskHandle\r
80  * \ingroup Tasks\r
81  */\r
82 typedef void * xTaskHandle;\r
83 \r
84 /*\r
85  * Used internally only.\r
86  */\r
87 typedef struct xTIME_OUT\r
88 {\r
89     portBASE_TYPE xOverflowCount;\r
90     portTickType  xTimeOnEntering;\r
91 } xTimeOutType;\r
92 \r
93 /*\r
94  * Defines the priority used by the idle task.  This must not be modified.\r
95  *\r
96  * \ingroup TaskUtils\r
97  */\r
98 #define tskIDLE_PRIORITY                        ( ( unsigned portBASE_TYPE ) 0 )\r
99 \r
100 /**\r
101  * task. h\r
102  *\r
103  * Macro for forcing a context switch.\r
104  *\r
105  * \page taskYIELD taskYIELD\r
106  * \ingroup SchedulerControl\r
107  */\r
108 #define taskYIELD()                                     portYIELD()\r
109 \r
110 /**\r
111  * task. h\r
112  *\r
113  * Macro to mark the start of a critical code region.  Preemptive context\r
114  * switches cannot occur when in a critical region.\r
115  *\r
116  * NOTE: This may alter the stack (depending on the portable implementation)\r
117  * so must be used with care!\r
118  *\r
119  * \page taskENTER_CRITICAL taskENTER_CRITICAL\r
120  * \ingroup SchedulerControl\r
121  */\r
122 #define taskENTER_CRITICAL()            portENTER_CRITICAL()\r
123 \r
124 /**\r
125  * task. h\r
126  *\r
127  * Macro to mark the end of a critical code region.  Preemptive context\r
128  * switches cannot occur when in a critical region.\r
129  *\r
130  * NOTE: This may alter the stack (depending on the portable implementation)\r
131  * so must be used with care!\r
132  *\r
133  * \page taskEXIT_CRITICAL taskEXIT_CRITICAL\r
134  * \ingroup SchedulerControl\r
135  */\r
136 #define taskEXIT_CRITICAL()                     portEXIT_CRITICAL()\r
137 \r
138 /**\r
139  * task. h\r
140  *\r
141  * Macro to disable all maskable interrupts.\r
142  *\r
143  * \page taskDISABLE_INTERRUPTS taskDISABLE_INTERRUPTS\r
144  * \ingroup SchedulerControl\r
145  */\r
146 #define taskDISABLE_INTERRUPTS()        portDISABLE_INTERRUPTS()\r
147 \r
148 /**\r
149  * task. h\r
150  *\r
151  * Macro to enable microcontroller interrupts.\r
152  *\r
153  * \page taskENABLE_INTERRUPTS taskENABLE_INTERRUPTS\r
154  * \ingroup SchedulerControl\r
155  */\r
156 #define taskENABLE_INTERRUPTS()         portENABLE_INTERRUPTS()\r
157 \r
158 /* Definitions returned by xTaskGetSchedulerState(). */\r
159 #define taskSCHEDULER_NOT_STARTED       0\r
160 #define taskSCHEDULER_RUNNING           1\r
161 #define taskSCHEDULER_SUSPENDED         2\r
162 \r
163 /*-----------------------------------------------------------\r
164  * TASK CREATION API\r
165  *----------------------------------------------------------*/\r
166 \r
167 /**\r
168  * task. h\r
169  *<pre>\r
170  portBASE_TYPE xTaskCreate(\r
171                               pdTASK_CODE pvTaskCode,\r
172                               const portCHAR * const pcName,\r
173                               unsigned portSHORT usStackDepth,\r
174                               void *pvParameters,\r
175                               unsigned portBASE_TYPE uxPriority,\r
176                               xTaskHandle *pvCreatedTask\r
177                           );</pre>\r
178  *\r
179  * Create a new task and add it to the list of tasks that are ready to run.\r
180  *\r
181  * @param pvTaskCode Pointer to the task entry function.  Tasks\r
182  * must be implemented to never return (i.e. continuous loop).\r
183  *\r
184  * @param pcName A descriptive name for the task.  This is mainly used to\r
185  * facilitate debugging.  Max length defined by tskMAX_TASK_NAME_LEN - default\r
186  * is 16.\r
187  *\r
188  * @param usStackDepth The size of the task stack specified as the number of\r
189  * variables the stack can hold - not the number of bytes.  For example, if\r
190  * the stack is 16 bits wide and usStackDepth is defined as 100, 200 bytes\r
191  * will be allocated for stack storage.\r
192  *\r
193  * @param pvParameters Pointer that will be used as the parameter for the task\r
194  * being created.\r
195  *\r
196  * @param uxPriority The priority at which the task should run.\r
197  *\r
198  * @param pvCreatedTask Used to pass back a handle by which the created task\r
199  * can be referenced.\r
200  *\r
201  * @return pdPASS if the task was successfully created and added to a ready\r
202  * list, otherwise an error code defined in the file errors. h\r
203  *\r
204  * Example usage:\r
205    <pre>\r
206  // Task to be created.\r
207  void vTaskCode( void * pvParameters )\r
208  {\r
209      for( ;; )\r
210      {\r
211          // Task code goes here.\r
212      }\r
213  }\r
214 \r
215  // Function that creates a task.\r
216  void vOtherFunction( void )\r
217  {\r
218  static unsigned char ucParameterToPass;\r
219  xTaskHandle xHandle;\r
220                 \r
221      // Create the task, storing the handle.  Note that the passed parameter ucParameterToPass\r
222      // must exist for the lifetime of the task, so in this case is declared static.  If it was just an\r
223      // an automatic stack variable it might no longer exist, or at least have been corrupted, by the time\r
224      // the new time attempts to access it.\r
225      xTaskCreate( vTaskCode, "NAME", STACK_SIZE, &ucParameterToPass, tskIDLE_PRIORITY, &xHandle );\r
226                 \r
227      // Use the handle to delete the task.\r
228      vTaskDelete( xHandle );\r
229  }\r
230    </pre>\r
231  * \defgroup xTaskCreate xTaskCreate\r
232  * \ingroup Tasks\r
233  */\r
234 signed portBASE_TYPE xTaskCreate( pdTASK_CODE pvTaskCode, const signed portCHAR * const pcName, unsigned portSHORT usStackDepth, void *pvParameters, unsigned portBASE_TYPE uxPriority, xTaskHandle *pvCreatedTask );\r
235 \r
236 /**\r
237  * task. h\r
238  * <pre>void vTaskDelete( xTaskHandle pxTask );</pre>\r
239  *\r
240  * INCLUDE_vTaskDelete must be defined as 1 for this function to be available.\r
241  * See the configuration section for more information.\r
242  *\r
243  * Remove a task from the RTOS real time kernels management.  The task being\r
244  * deleted will be removed from all ready, blocked, suspended and event lists.\r
245  *\r
246  * NOTE:  The idle task is responsible for freeing the kernel allocated\r
247  * memory from tasks that have been deleted.  It is therefore important that\r
248  * the idle task is not starved of microcontroller processing time if your\r
249  * application makes any calls to vTaskDelete ().  Memory allocated by the\r
250  * task code is not automatically freed, and should be freed before the task\r
251  * is deleted.\r
252  *\r
253  * See the demo application file death.c for sample code that utilises\r
254  * vTaskDelete ().\r
255  *\r
256  * @param pxTask The handle of the task to be deleted.  Passing NULL will\r
257  * cause the calling task to be deleted.\r
258  *\r
259  * Example usage:\r
260    <pre>\r
261  void vOtherFunction( void )\r
262  {\r
263  xTaskHandle xHandle;\r
264                 \r
265      // Create the task, storing the handle.\r
266      xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );\r
267                 \r
268      // Use the handle to delete the task.\r
269      vTaskDelete( xHandle );\r
270  }\r
271    </pre>\r
272  * \defgroup vTaskDelete vTaskDelete\r
273  * \ingroup Tasks\r
274  */\r
275 void vTaskDelete( xTaskHandle pxTask );\r
276 \r
277 \r
278 /*-----------------------------------------------------------\r
279  * TASK CONTROL API\r
280  *----------------------------------------------------------*/\r
281 \r
282 /**\r
283  * task. h\r
284  * <pre>void vTaskDelay( portTickType xTicksToDelay );</pre>\r
285  *\r
286  * Delay a task for a given number of ticks.  The actual time that the\r
287  * task remains blocked depends on the tick rate.  The constant\r
288  * portTICK_RATE_MS can be used to calculate real time from the tick\r
289  * rate - with the resolution of one tick period.\r
290  *\r
291  * INCLUDE_vTaskDelay must be defined as 1 for this function to be available.\r
292  * See the configuration section for more information.\r
293  *\r
294  *\r
295  * vTaskDelay() specifies a time at which the task wishes to unblock relative to\r
296  * the time at which vTaskDelay() is called.  For example, specifying a block \r
297  * period of 100 ticks will cause the task to unblock 100 ticks after \r
298  * vTaskDelay() is called.  vTaskDelay() does not therefore provide a good method\r
299  * of controlling the frequency of a cyclical task as the path taken through the \r
300  * code, as well as other task and interrupt activity, will effect the frequency \r
301  * at which vTaskDelay() gets called and therefore the time at which the task \r
302  * next executes.  See vTaskDelayUntil() for an alternative API function designed \r
303  * to facilitate fixed frequency execution.  It does this by specifying an \r
304  * absolute time (rather than a relative time) at which the calling task should \r
305  * unblock.\r
306  *\r
307  * @param xTicksToDelay The amount of time, in tick periods, that\r
308  * the calling task should block.\r
309  *\r
310  * Example usage:\r
311 \r
312  void vTaskFunction( void * pvParameters )\r
313  {\r
314  void vTaskFunction( void * pvParameters )\r
315  {\r
316  // Block for 500ms.\r
317  const portTickType xDelay = 500 / portTICK_RATE_MS;\r
318 \r
319      for( ;; )\r
320      {\r
321          // Simply toggle the LED every 500ms, blocking between each toggle.\r
322          vToggleLED();\r
323          vTaskDelay( xDelay );\r
324      }\r
325  }\r
326 \r
327  * \defgroup vTaskDelay vTaskDelay\r
328  * \ingroup TaskCtrl\r
329  */\r
330 void vTaskDelay( portTickType xTicksToDelay );\r
331 \r
332 /**\r
333  * task. h\r
334  * <pre>void vTaskDelayUntil( portTickType *pxPreviousWakeTime, portTickType xTimeIncrement );</pre>\r
335  *\r
336  * INCLUDE_vTaskDelayUntil must be defined as 1 for this function to be available.\r
337  * See the configuration section for more information.\r
338  *\r
339  * Delay a task until a specified time.  This function can be used by cyclical\r
340  * tasks to ensure a constant execution frequency.\r
341  *\r
342  * This function differs from vTaskDelay () in one important aspect:  vTaskDelay () will\r
343  * cause a task to block for the specified number of ticks from the time vTaskDelay () is\r
344  * called.  It is therefore difficult to use vTaskDelay () by itself to generate a fixed\r
345  * execution frequency as the time between a task starting to execute and that task\r
346  * calling vTaskDelay () may not be fixed [the task may take a different path though the\r
347  * code between calls, or may get interrupted or preempted a different number of times\r
348  * each time it executes].\r
349  *\r
350  * Whereas vTaskDelay () specifies a wake time relative to the time at which the function\r
351  * is called, vTaskDelayUntil () specifies the absolute (exact) time at which it wishes to\r
352  * unblock.\r
353  *\r
354  * The constant portTICK_RATE_MS can be used to calculate real time from the tick\r
355  * rate - with the resolution of one tick period.\r
356  *\r
357  * @param pxPreviousWakeTime Pointer to a variable that holds the time at which the\r
358  * task was last unblocked.  The variable must be initialised with the current time\r
359  * prior to its first use (see the example below).  Following this the variable is\r
360  * automatically updated within vTaskDelayUntil ().\r
361  *\r
362  * @param xTimeIncrement The cycle time period.  The task will be unblocked at\r
363  * time *pxPreviousWakeTime + xTimeIncrement.  Calling vTaskDelayUntil with the\r
364  * same xTimeIncrement parameter value will cause the task to execute with\r
365  * a fixed interface period.\r
366  *\r
367  * Example usage:\r
368    <pre>\r
369  // Perform an action every 10 ticks.\r
370  void vTaskFunction( void * pvParameters )\r
371  {\r
372  portTickType xLastWakeTime;\r
373  const portTickType xFrequency = 10;\r
374 \r
375      // Initialise the xLastWakeTime variable with the current time.\r
376      xLastWakeTime = xTaskGetTickCount ();\r
377      for( ;; )\r
378      {\r
379          // Wait for the next cycle.\r
380          vTaskDelayUntil( &xLastWakeTime, xFrequency );\r
381 \r
382          // Perform action here.\r
383      }\r
384  }\r
385    </pre>\r
386  * \defgroup vTaskDelayUntil vTaskDelayUntil\r
387  * \ingroup TaskCtrl\r
388  */\r
389 void vTaskDelayUntil( portTickType * const pxPreviousWakeTime, portTickType xTimeIncrement );\r
390 \r
391 /**\r
392  * task. h\r
393  * <pre>unsigned portBASE_TYPE uxTaskPriorityGet( xTaskHandle pxTask );</pre>\r
394  *\r
395  * INCLUDE_xTaskPriorityGet must be defined as 1 for this function to be available.\r
396  * See the configuration section for more information.\r
397  *\r
398  * Obtain the priority of any task.\r
399  *\r
400  * @param pxTask Handle of the task to be queried.  Passing a NULL\r
401  * handle results in the priority of the calling task being returned.\r
402  *\r
403  * @return The priority of pxTask.\r
404  *\r
405  * Example usage:\r
406    <pre>\r
407  void vAFunction( void )\r
408  {\r
409  xTaskHandle xHandle;\r
410                 \r
411      // Create a task, storing the handle.\r
412      xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );\r
413                 \r
414      // ...\r
415 \r
416      // Use the handle to obtain the priority of the created task.\r
417      // It was created with tskIDLE_PRIORITY, but may have changed\r
418      // it itself.\r
419      if( uxTaskPriorityGet( xHandle ) != tskIDLE_PRIORITY )\r
420      {\r
421          // The task has changed it's priority.\r
422      }\r
423 \r
424      // ...\r
425 \r
426      // Is our priority higher than the created task?\r
427      if( uxTaskPriorityGet( xHandle ) < uxTaskPriorityGet( NULL ) )\r
428      {\r
429          // Our priority (obtained using NULL handle) is higher.\r
430      }\r
431  }\r
432    </pre>\r
433  * \defgroup uxTaskPriorityGet uxTaskPriorityGet\r
434  * \ingroup TaskCtrl\r
435  */\r
436 unsigned portBASE_TYPE uxTaskPriorityGet( xTaskHandle pxTask );\r
437 \r
438 /**\r
439  * task. h\r
440  * <pre>void vTaskPrioritySet( xTaskHandle pxTask, unsigned portBASE_TYPE uxNewPriority );</pre>\r
441  *\r
442  * INCLUDE_vTaskPrioritySet must be defined as 1 for this function to be available.\r
443  * See the configuration section for more information.\r
444  *\r
445  * Set the priority of any task.\r
446  *\r
447  * A context switch will occur before the function returns if the priority\r
448  * being set is higher than the currently executing task.\r
449  *\r
450  * @param pxTask Handle to the task for which the priority is being set.\r
451  * Passing a NULL handle results in the priority of the calling task being set.\r
452  *\r
453  * @param uxNewPriority The priority to which the task will be set.\r
454  *\r
455  * Example usage:\r
456    <pre>\r
457  void vAFunction( void )\r
458  {\r
459  xTaskHandle xHandle;\r
460                 \r
461      // Create a task, storing the handle.\r
462      xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );\r
463 \r
464      // ...\r
465 \r
466      // Use the handle to raise the priority of the created task.\r
467      vTaskPrioritySet( xHandle, tskIDLE_PRIORITY + 1 );\r
468 \r
469      // ...\r
470 \r
471      // Use a NULL handle to raise our priority to the same value.\r
472      vTaskPrioritySet( NULL, tskIDLE_PRIORITY + 1 );\r
473  }\r
474    </pre>\r
475  * \defgroup vTaskPrioritySet vTaskPrioritySet\r
476  * \ingroup TaskCtrl\r
477  */\r
478 void vTaskPrioritySet( xTaskHandle pxTask, unsigned portBASE_TYPE uxNewPriority );\r
479 \r
480 /**\r
481  * task. h\r
482  * <pre>void vTaskSuspend( xTaskHandle pxTaskToSuspend );</pre>\r
483  *\r
484  * INCLUDE_vTaskSuspend must be defined as 1 for this function to be available.\r
485  * See the configuration section for more information.\r
486  *\r
487  * Suspend any task.  When suspended a task will never get any microcontroller\r
488  * processing time, no matter what its priority.\r
489  *\r
490  * Calls to vTaskSuspend are not accumulative -\r
491  * i.e. calling vTaskSuspend () twice on the same task still only requires one\r
492  * call to vTaskResume () to ready the suspended task.\r
493  *\r
494  * @param pxTaskToSuspend Handle to the task being suspended.  Passing a NULL\r
495  * handle will cause the calling task to be suspended.\r
496  *\r
497  * Example usage:\r
498    <pre>\r
499  void vAFunction( void )\r
500  {\r
501  xTaskHandle xHandle;\r
502                 \r
503      // Create a task, storing the handle.\r
504      xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );\r
505                 \r
506      // ...\r
507 \r
508      // Use the handle to suspend the created task.\r
509      vTaskSuspend( xHandle );\r
510 \r
511      // ...\r
512                 \r
513      // The created task will not run during this period, unless\r
514      // another task calls vTaskResume( xHandle ).\r
515                 \r
516      //...\r
517                 \r
518 \r
519      // Suspend ourselves.\r
520      vTaskSuspend( NULL );\r
521 \r
522      // We cannot get here unless another task calls vTaskResume\r
523      // with our handle as the parameter.\r
524  }\r
525    </pre>\r
526  * \defgroup vTaskSuspend vTaskSuspend\r
527  * \ingroup TaskCtrl\r
528  */\r
529 void vTaskSuspend( xTaskHandle pxTaskToSuspend );\r
530 \r
531 /**\r
532  * task. h\r
533  * <pre>void vTaskResume( xTaskHandle pxTaskToResume );</pre>\r
534  *\r
535  * INCLUDE_vTaskSuspend must be defined as 1 for this function to be available.\r
536  * See the configuration section for more information.\r
537  *\r
538  * Resumes a suspended task.\r
539  *\r
540  * A task that has been suspended by one of more calls to vTaskSuspend ()\r
541  * will be made available for running again by a single call to\r
542  * vTaskResume ().\r
543  *\r
544  * @param pxTaskToResume Handle to the task being readied.\r
545  *\r
546  * Example usage:\r
547    <pre>\r
548  void vAFunction( void )\r
549  {\r
550  xTaskHandle xHandle;\r
551                 \r
552      // Create a task, storing the handle.\r
553      xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );\r
554                 \r
555      // ...\r
556 \r
557      // Use the handle to suspend the created task.\r
558      vTaskSuspend( xHandle );\r
559 \r
560      // ...\r
561         \r
562      // The created task will not run during this period, unless\r
563      // another task calls vTaskResume( xHandle ).\r
564                 \r
565      //...\r
566                 \r
567 \r
568      // Resume the suspended task ourselves.\r
569      vTaskResume( xHandle );\r
570 \r
571      // The created task will once again get microcontroller processing\r
572      // time in accordance with it priority within the system.\r
573  }\r
574    </pre>\r
575  * \defgroup vTaskResume vTaskResume\r
576  * \ingroup TaskCtrl\r
577  */\r
578 void vTaskResume( xTaskHandle pxTaskToResume );\r
579 \r
580 /**\r
581  * task. h\r
582  * <pre>void xTaskResumeFromISR( xTaskHandle pxTaskToResume );</pre>\r
583  *\r
584  * INCLUDE_xTaskResumeFromISR must be defined as 1 for this function to be \r
585  * available.  See the configuration section for more information.\r
586  *\r
587  * An implementation of vTaskResume() that can be called from within an ISR.\r
588  *\r
589  * A task that has been suspended by one of more calls to vTaskSuspend ()\r
590  * will be made available for running again by a single call to\r
591  * xTaskResumeFromISR ().\r
592  *\r
593  * @param pxTaskToResume Handle to the task being readied.\r
594  *\r
595  * \defgroup vTaskResumeFromISR vTaskResumeFromISR\r
596  * \ingroup TaskCtrl\r
597  */\r
598 portBASE_TYPE xTaskResumeFromISR( xTaskHandle pxTaskToResume );\r
599 \r
600 /*-----------------------------------------------------------\r
601  * SCHEDULER CONTROL\r
602  *----------------------------------------------------------*/\r
603 \r
604 /**\r
605  * task. h\r
606  * <pre>void vTaskStartScheduler( void );</pre>\r
607  *\r
608  * Starts the real time kernel tick processing.  After calling the kernel\r
609  * has control over which tasks are executed and when.  This function\r
610  * does not return until an executing task calls vTaskEndScheduler ().\r
611  *\r
612  * At least one task should be created via a call to xTaskCreate ()\r
613  * before calling vTaskStartScheduler ().  The idle task is created\r
614  * automatically when the first application task is created.\r
615  *\r
616  * See the demo application file main.c for an example of creating\r
617  * tasks and starting the kernel.\r
618  *\r
619  * Example usage:\r
620    <pre>\r
621  void vAFunction( void )\r
622  {\r
623      // Create at least one task before starting the kernel.\r
624      xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );\r
625 \r
626      // Start the real time kernel with preemption.\r
627      vTaskStartScheduler ();\r
628 \r
629      // Will not get here unless a task calls vTaskEndScheduler ()\r
630  }\r
631    </pre>\r
632  *\r
633  * \defgroup vTaskStartScheduler vTaskStartScheduler\r
634  * \ingroup SchedulerControl\r
635  */\r
636 void vTaskStartScheduler( void );\r
637 \r
638 /**\r
639  * task. h\r
640  * <pre>void vTaskEndScheduler( void );</pre>\r
641  *\r
642  * Stops the real time kernel tick.  All created tasks will be automatically\r
643  * deleted and multitasking (either preemptive or cooperative) will\r
644  * stop.  Execution then resumes from the point where vTaskStartScheduler ()\r
645  * was called, as if vTaskStartScheduler () had just returned.\r
646  *\r
647  * See the demo application file main. c in the demo/PC directory for an\r
648  * example that uses vTaskEndScheduler ().\r
649  *\r
650  * vTaskEndScheduler () requires an exit function to be defined within the\r
651  * portable layer (see vPortEndScheduler () in port. c for the PC port).  This\r
652  * performs hardware specific operations such as stopping the kernel tick.\r
653  *\r
654  * vTaskEndScheduler () will cause all of the resources allocated by the\r
655  * kernel to be freed - but will not free resources allocated by application\r
656  * tasks.\r
657  *\r
658  * Example usage:\r
659    <pre>\r
660  void vTaskCode( void * pvParameters )\r
661  {\r
662      for( ;; )\r
663      {\r
664          // Task code goes here.\r
665 \r
666          // At some point we want to end the real time kernel processing\r
667          // so call ...\r
668          vTaskEndScheduler ();\r
669      }\r
670  }\r
671 \r
672  void vAFunction( void )\r
673  {\r
674      // Create at least one task before starting the kernel.\r
675      xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );\r
676 \r
677      // Start the real time kernel with preemption.\r
678      vTaskStartScheduler ();\r
679 \r
680      // Will only get here when the vTaskCode () task has called\r
681      // vTaskEndScheduler ().  When we get here we are back to single task\r
682      // execution.\r
683  }\r
684    </pre>\r
685  *\r
686  * \defgroup vTaskEndScheduler vTaskEndScheduler\r
687  * \ingroup SchedulerControl\r
688  */\r
689 void vTaskEndScheduler( void );\r
690 \r
691 /**\r
692  * task. h\r
693  * <pre>void vTaskSuspendAll( void );</pre>\r
694  *\r
695  * Suspends all real time kernel activity while keeping interrupts (including the\r
696  * kernel tick) enabled.\r
697  *\r
698  * After calling vTaskSuspendAll () the calling task will continue to execute\r
699  * without risk of being swapped out until a call to xTaskResumeAll () has been\r
700  * made.\r
701  *\r
702  * API functions that have the potential to cause a context switch (for example, \r
703  * vTaskDelayUntil(), xQueueSend(), etc.) must not be called while the scheduler \r
704  * is suspended.\r
705  *\r
706  * Example usage:\r
707    <pre>\r
708  void vTask1( void * pvParameters )\r
709  {\r
710      for( ;; )\r
711      {\r
712          // Task code goes here.\r
713 \r
714          // ...\r
715 \r
716          // At some point the task wants to perform a long operation during\r
717          // which it does not want to get swapped out.  It cannot use\r
718          // taskENTER_CRITICAL ()/taskEXIT_CRITICAL () as the length of the\r
719          // operation may cause interrupts to be missed - including the\r
720          // ticks.\r
721 \r
722          // Prevent the real time kernel swapping out the task.\r
723          vTaskSuspendAll ();\r
724 \r
725          // Perform the operation here.  There is no need to use critical\r
726          // sections as we have all the microcontroller processing time.\r
727          // During this time interrupts will still operate and the kernel\r
728          // tick count will be maintained.\r
729 \r
730          // ...\r
731 \r
732          // The operation is complete.  Restart the kernel.\r
733          xTaskResumeAll ();\r
734      }\r
735  }\r
736    </pre>\r
737  * \defgroup vTaskSuspendAll vTaskSuspendAll\r
738  * \ingroup SchedulerControl\r
739  */\r
740 void vTaskSuspendAll( void );\r
741 \r
742 /**\r
743  * task. h\r
744  * <pre>portCHAR xTaskResumeAll( void );</pre>\r
745  *\r
746  * Resumes real time kernel activity following a call to vTaskSuspendAll ().\r
747  * After a call to vTaskSuspendAll () the kernel will take control of which\r
748  * task is executing at any time.\r
749  *\r
750  * @return If resuming the scheduler caused a context switch then pdTRUE is\r
751  *         returned, otherwise pdFALSE is returned.\r
752  *\r
753  * Example usage:\r
754    <pre>\r
755  void vTask1( void * pvParameters )\r
756  {\r
757      for( ;; )\r
758      {\r
759          // Task code goes here.\r
760 \r
761          // ...\r
762 \r
763          // At some point the task wants to perform a long operation during\r
764          // which it does not want to get swapped out.  It cannot use\r
765          // taskENTER_CRITICAL ()/taskEXIT_CRITICAL () as the length of the\r
766          // operation may cause interrupts to be missed - including the\r
767          // ticks.\r
768 \r
769          // Prevent the real time kernel swapping out the task.\r
770          vTaskSuspendAll ();\r
771 \r
772          // Perform the operation here.  There is no need to use critical\r
773          // sections as we have all the microcontroller processing time.\r
774          // During this time interrupts will still operate and the real\r
775          // time kernel tick count will be maintained.\r
776 \r
777          // ...\r
778 \r
779          // The operation is complete.  Restart the kernel.  We want to force\r
780          // a context switch - but there is no point if resuming the scheduler\r
781          // caused a context switch already.\r
782          if( !xTaskResumeAll () )\r
783          {\r
784               taskYIELD ();\r
785          }\r
786      }\r
787  }\r
788    </pre>\r
789  * \defgroup xTaskResumeAll xTaskResumeAll\r
790  * \ingroup SchedulerControl\r
791  */\r
792 signed portBASE_TYPE xTaskResumeAll( void );\r
793 \r
794 /**\r
795  * task. h\r
796  * <pre>signed portBASE_TYPE xTaskIsTaskSuspended( xTaskHandle xTask );</pre>\r
797  *\r
798  * Utility task that simply returns pdTRUE if the task referenced by xTask is\r
799  * currently in the Suspended state, or pdFALSE if the task referenced by xTask\r
800  * is in any other state.\r
801  *\r
802  */\r
803 signed portBASE_TYPE xTaskIsTaskSuspended( xTaskHandle xTask );\r
804 \r
805 /*-----------------------------------------------------------\r
806  * TASK UTILITIES\r
807  *----------------------------------------------------------*/\r
808 \r
809 /**\r
810  * task. h\r
811  * <PRE>volatile portTickType xTaskGetTickCount( void );</PRE>\r
812  *\r
813  * @return The count of ticks since vTaskStartScheduler was called.\r
814  *\r
815  * \page xTaskGetTickCount xTaskGetTickCount\r
816  * \ingroup TaskUtils\r
817  */\r
818 portTickType xTaskGetTickCount( void );\r
819 \r
820 /**\r
821  * task. h\r
822  * <PRE>unsigned portSHORT uxTaskGetNumberOfTasks( void );</PRE>\r
823  *\r
824  * @return The number of tasks that the real time kernel is currently managing.\r
825  * This includes all ready, blocked and suspended tasks.  A task that\r
826  * has been deleted but not yet freed by the idle task will also be\r
827  * included in the count.\r
828  *\r
829  * \page uxTaskGetNumberOfTasks uxTaskGetNumberOfTasks\r
830  * \ingroup TaskUtils\r
831  */\r
832 unsigned portBASE_TYPE uxTaskGetNumberOfTasks( void );\r
833 \r
834 /**\r
835  * task. h\r
836  * <PRE>void vTaskList( portCHAR *pcWriteBuffer );</PRE>\r
837  *\r
838  * configUSE_TRACE_FACILITY, INCLUDE_vTaskDelete and INCLUDE_vTaskSuspend\r
839  * must all be defined as 1 for this function to be available.\r
840  * See the configuration section for more information.\r
841  *\r
842  * NOTE: This function will disable interrupts for its duration.  It is\r
843  * not intended for normal application runtime use but as a debug aid.\r
844  *\r
845  * Lists all the current tasks, along with their current state and stack\r
846  * usage high water mark.\r
847  *\r
848  * Tasks are reported as blocked ('B'), ready ('R'), deleted ('D') or\r
849  * suspended ('S').\r
850  *\r
851  * @param pcWriteBuffer A buffer into which the above mentioned details\r
852  * will be written, in ascii form.  This buffer is assumed to be large\r
853  * enough to contain the generated report.  Approximately 40 bytes per\r
854  * task should be sufficient.\r
855  *\r
856  * \page vTaskList vTaskList\r
857  * \ingroup TaskUtils\r
858  */\r
859 void vTaskList( signed portCHAR *pcWriteBuffer );\r
860 \r
861 /**\r
862  * task. h\r
863  * <PRE>void vTaskStartTrace( portCHAR * pcBuffer, unsigned portBASE_TYPE uxBufferSize );</PRE>\r
864  *\r
865  * Starts a real time kernel activity trace.  The trace logs the identity of\r
866  * which task is running when.\r
867  *\r
868  * The trace file is stored in binary format.  A separate DOS utility called\r
869  * convtrce.exe is used to convert this into a tab delimited text file which\r
870  * can be viewed and plotted in a spread sheet.\r
871  *\r
872  * @param pcBuffer The buffer into which the trace will be written.\r
873  *\r
874  * @param ulBufferSize The size of pcBuffer in bytes.  The trace will continue\r
875  * until either the buffer in full, or ulTaskEndTrace () is called.\r
876  *\r
877  * \page vTaskStartTrace vTaskStartTrace\r
878  * \ingroup TaskUtils\r
879  */\r
880 void vTaskStartTrace( signed portCHAR * pcBuffer, unsigned portLONG ulBufferSize );\r
881 \r
882 /**\r
883  * task. h\r
884  * <PRE>unsigned portLONG ulTaskEndTrace( void );</PRE>\r
885  *\r
886  * Stops a kernel activity trace.  See vTaskStartTrace ().\r
887  *\r
888  * @return The number of bytes that have been written into the trace buffer.\r
889  *\r
890  * \page usTaskEndTrace usTaskEndTrace\r
891  * \ingroup TaskUtils\r
892  */\r
893 unsigned portLONG ulTaskEndTrace( void );\r
894 \r
895 /**\r
896  * task.h\r
897  * <PRE>unsigned portBASE_TYPE uxTaskGetStackHighWaterMark( xTaskHandle xTask );</PRE>\r
898  *\r
899  * INCLUDE_uxTaskGetStackHighWaterMark must be set to 1 in FreeRTOSConfig.h for\r
900  * this function to be available.\r
901  *\r
902  * Returns the high water mark of the stack associated with xTask.  That is,\r
903  * the minimum free stack space there has been (in bytes) since the task\r
904  * started.  The smaller the returned number the closer the task has come\r
905  * to overflowing its stack.\r
906  *\r
907  * @param xTask Handle of the task associated with the stack to be checked.\r
908  * Set xTask to NULL to check the stack of the calling task.\r
909  *\r
910  * @return The smallest amount of free stack space there has been (in bytes)\r
911  * since the task referenced by xTask was created.\r
912  */\r
913 unsigned portBASE_TYPE uxTaskGetStackHighWaterMark( xTaskHandle xTask );\r
914 \r
915 /**\r
916  * task.h\r
917  * <pre>void vTaskSetApplicationTaskTag( xTaskHandle xTask, pdTASK_HOOK_CODE pxHookFunction );</pre>\r
918  *\r
919  * Sets pxHookFunction to be the task hook function used by the task xTask.\r
920  * Passing xTask as NULL has the effect of setting the calling tasks hook\r
921  * function.\r
922  */\r
923 void vTaskSetApplicationTaskTag( xTaskHandle xTask, pdTASK_HOOK_CODE pxHookFunction );\r
924 \r
925 /**\r
926  * task.h\r
927  * <pre>portBASE_TYPE xTaskCallApplicationTaskHook( xTaskHandle xTask, pdTASK_HOOK_CODE pxHookFunction );</pre>\r
928  *\r
929  * Calls the hook function associated with xTask.  Passing xTask as NULL has\r
930  * the effect of calling the Running tasks (the calling task) hook function.\r
931  *\r
932  * pvParameter is passed to the hook function for the task to interpret as it\r
933  * wants.\r
934  */\r
935 portBASE_TYPE xTaskCallApplicationTaskHook( xTaskHandle xTask, void *pvParameter );\r
936 \r
937 \r
938 /*-----------------------------------------------------------\r
939  * SCHEDULER INTERNALS AVAILABLE FOR PORTING PURPOSES\r
940  *----------------------------------------------------------*/\r
941 \r
942 /*\r
943  * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE.  IT IS ONLY\r
944  * INTENDED FOR USE WHEN IMPLEMENTING A PORT OF THE SCHEDULER AND IS\r
945  * AN INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.\r
946  *\r
947  * Called from the real time kernel tick (either preemptive or cooperative),\r
948  * this increments the tick count and checks if any tasks that are blocked\r
949  * for a finite period required removing from a blocked list and placing on\r
950  * a ready list.\r
951  */\r
952 void vTaskIncrementTick( void );\r
953 \r
954 /*\r
955  * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE.  IT IS AN\r
956  * INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.\r
957  *\r
958  * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED.\r
959  *\r
960  * Removes the calling task from the ready list and places it both\r
961  * on the list of tasks waiting for a particular event, and the\r
962  * list of delayed tasks.  The task will be removed from both lists\r
963  * and replaced on the ready list should either the event occur (and\r
964  * there be no higher priority tasks waiting on the same event) or\r
965  * the delay period expires.\r
966  *\r
967  * @param pxEventList The list containing tasks that are blocked waiting\r
968  * for the event to occur.\r
969  *\r
970  * @param xTicksToWait The maximum amount of time that the task should wait\r
971  * for the event to occur.  This is specified in kernel ticks,the constant\r
972  * portTICK_RATE_MS can be used to convert kernel ticks into a real time\r
973  * period.\r
974  */\r
975 void vTaskPlaceOnEventList( const xList * const pxEventList, portTickType xTicksToWait );\r
976 \r
977 /*\r
978  * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE.  IT IS AN\r
979  * INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.\r
980  *\r
981  * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED.\r
982  *\r
983  * Removes a task from both the specified event list and the list of blocked\r
984  * tasks, and places it on a ready queue.\r
985  *\r
986  * xTaskRemoveFromEventList () will be called if either an event occurs to\r
987  * unblock a task, or the block timeout period expires.\r
988  *\r
989  * @return pdTRUE if the task being removed has a higher priority than the task\r
990  * making the call, otherwise pdFALSE.\r
991  */\r
992 signed portBASE_TYPE xTaskRemoveFromEventList( const xList * const pxEventList );\r
993 \r
994 /*\r
995  * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE.  IT IS AN\r
996  * INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.\r
997  *\r
998  * INCLUDE_vTaskCleanUpResources and INCLUDE_vTaskSuspend must be defined as 1\r
999  * for this function to be available.\r
1000  * See the configuration section for more information.\r
1001  *\r
1002  * Empties the ready and delayed queues of task control blocks, freeing the\r
1003  * memory allocated for the task control block and task stacks as it goes.\r
1004  */\r
1005 void vTaskCleanUpResources( void );\r
1006 \r
1007 /*\r
1008  * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE.  IT IS ONLY\r
1009  * INTENDED FOR USE WHEN IMPLEMENTING A PORT OF THE SCHEDULER AND IS\r
1010  * AN INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.\r
1011  *\r
1012  * Sets the pointer to the current TCB to the TCB of the highest priority task\r
1013  * that is ready to run.\r
1014  */\r
1015 void vTaskSwitchContext( void );\r
1016 \r
1017 /*\r
1018  * Return the handle of the calling task.\r
1019  */\r
1020 xTaskHandle xTaskGetCurrentTaskHandle( void );\r
1021 \r
1022 /*\r
1023  * Capture the current time status for future reference.\r
1024  */\r
1025 void vTaskSetTimeOutState( xTimeOutType * const pxTimeOut );\r
1026 \r
1027 /*\r
1028  * Compare the time status now with that previously captured to see if the\r
1029  * timeout has expired.\r
1030  */\r
1031 portBASE_TYPE xTaskCheckForTimeOut( xTimeOutType * const pxTimeOut, portTickType * const pxTicksToWait );\r
1032 \r
1033 /*\r
1034  * Shortcut used by the queue implementation to prevent unnecessary call to\r
1035  * taskYIELD();\r
1036  */\r
1037 void vTaskMissedYield( void );\r
1038 \r
1039 /*\r
1040  * Returns the scheduler state as taskSCHEDULER_RUNNING,\r
1041  * taskSCHEDULER_NOT_STARTED or taskSCHEDULER_SUSPENDED.\r
1042  */\r
1043 portBASE_TYPE xTaskGetSchedulerState( void );\r
1044 \r
1045 /*\r
1046  * Raises the priority of the mutex holder to that of the calling task should\r
1047  * the mutex holder have a priority less than the calling task.\r
1048  */\r
1049 void vTaskPriorityInherit( xTaskHandle * const pxMutexHolder );\r
1050 \r
1051 /*\r
1052  * Set the priority of a task back to its proper priority in the case that it\r
1053  * inherited a higher priority while it was holding a semaphore.\r
1054  */\r
1055 void vTaskPriorityDisinherit( xTaskHandle * const pxMutexHolder );\r
1056 \r
1057 #ifdef __cplusplus\r
1058 }\r
1059 #endif\r
1060 #endif /* TASK_H */\r
1061 \r
1062 \r
1063 \r