]> git.sur5r.net Git - freertos/blob - Source/include/task.h
Added a #error line to check that FreeRTOS.h is included before one of the subordinat...
[freertos] / Source / include / task.h
1 /*\r
2         FreeRTOS.org V5.0.3 - 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.0.3"\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  unsigned char ucParameterToPass;\r
219  xTaskHandle xHandle;\r
220                 \r
221      // Create the task, storing the handle.\r
222      xTaskCreate( vTaskCode, "NAME", STACK_SIZE, &ucParameterToPass, tskIDLE_PRIORITY, &xHandle );\r
223                 \r
224      // Use the handle to delete the task.\r
225      vTaskDelete( xHandle );\r
226  }\r
227    </pre>\r
228  * \defgroup xTaskCreate xTaskCreate\r
229  * \ingroup Tasks\r
230  */\r
231 signed portBASE_TYPE xTaskCreate( pdTASK_CODE pvTaskCode, const signed portCHAR * const pcName, unsigned portSHORT usStackDepth, void *pvParameters, unsigned portBASE_TYPE uxPriority, xTaskHandle *pvCreatedTask );\r
232 \r
233 /**\r
234  * task. h\r
235  * <pre>void vTaskDelete( xTaskHandle pxTask );</pre>\r
236  *\r
237  * INCLUDE_vTaskDelete must be defined as 1 for this function to be available.\r
238  * See the configuration section for more information.\r
239  *\r
240  * Remove a task from the RTOS real time kernels management.  The task being\r
241  * deleted will be removed from all ready, blocked, suspended and event lists.\r
242  *\r
243  * NOTE:  The idle task is responsible for freeing the kernel allocated\r
244  * memory from tasks that have been deleted.  It is therefore important that\r
245  * the idle task is not starved of microcontroller processing time if your\r
246  * application makes any calls to vTaskDelete ().  Memory allocated by the\r
247  * task code is not automatically freed, and should be freed before the task\r
248  * is deleted.\r
249  *\r
250  * See the demo application file death.c for sample code that utilises\r
251  * vTaskDelete ().\r
252  *\r
253  * @param pxTask The handle of the task to be deleted.  Passing NULL will\r
254  * cause the calling task to be deleted.\r
255  *\r
256  * Example usage:\r
257    <pre>\r
258  void vOtherFunction( void )\r
259  {\r
260  xTaskHandle xHandle;\r
261                 \r
262      // Create the task, storing the handle.\r
263      xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );\r
264                 \r
265      // Use the handle to delete the task.\r
266      vTaskDelete( xHandle );\r
267  }\r
268    </pre>\r
269  * \defgroup vTaskDelete vTaskDelete\r
270  * \ingroup Tasks\r
271  */\r
272 void vTaskDelete( xTaskHandle pxTask );\r
273 \r
274 \r
275 /*-----------------------------------------------------------\r
276  * TASK CONTROL API\r
277  *----------------------------------------------------------*/\r
278 \r
279 /**\r
280  * task. h\r
281  * <pre>void vTaskDelay( portTickType xTicksToDelay );</pre>\r
282  *\r
283  * Delay a task for a given number of ticks.  The actual time that the\r
284  * task remains blocked depends on the tick rate.  The constant\r
285  * portTICK_RATE_MS can be used to calculate real time from the tick\r
286  * rate - with the resolution of one tick period.\r
287  *\r
288  * INCLUDE_vTaskDelay must be defined as 1 for this function to be available.\r
289  * See the configuration section for more information.\r
290  *\r
291  *\r
292  * vTaskDelay() specifies a time at which the task wishes to unblock relative to\r
293  * the time at which vTaskDelay() is called.  For example, specifying a block \r
294  * period of 100 ticks will cause the task to unblock 100 ticks after \r
295  * vTaskDelay() is called.  vTaskDelay() does not therefore provide a good method\r
296  * of controlling the frequency of a cyclical task as the path taken through the \r
297  * code, as well as other task and interrupt activity, will effect the frequency \r
298  * at which vTaskDelay() gets called and therefore the time at which the task \r
299  * next executes.  See vTaskDelayUntil() for an alternative API function designed \r
300  * to facilitate fixed frequency execution.  It does this by specifying an \r
301  * absolute time (rather than a relative time) at which the calling task should \r
302  * unblock.\r
303  *\r
304  * @param xTicksToDelay The amount of time, in tick periods, that\r
305  * the calling task should block.\r
306  *\r
307  * Example usage:\r
308 \r
309  void vTaskFunction( void * pvParameters )\r
310  {\r
311  void vTaskFunction( void * pvParameters )\r
312  {\r
313  // Block for 500ms.\r
314  const portTickType xDelay = 500 / portTICK_RATE_MS;\r
315 \r
316      for( ;; )\r
317      {\r
318          // Simply toggle the LED every 500ms, blocking between each toggle.\r
319          vToggleLED();\r
320          vTaskDelay( xDelay );\r
321      }\r
322  }\r
323 \r
324  * \defgroup vTaskDelay vTaskDelay\r
325  * \ingroup TaskCtrl\r
326  */\r
327 void vTaskDelay( portTickType xTicksToDelay );\r
328 \r
329 /**\r
330  * task. h\r
331  * <pre>void vTaskDelayUntil( portTickType *pxPreviousWakeTime, portTickType xTimeIncrement );</pre>\r
332  *\r
333  * INCLUDE_vTaskDelayUntil must be defined as 1 for this function to be available.\r
334  * See the configuration section for more information.\r
335  *\r
336  * Delay a task until a specified time.  This function can be used by cyclical\r
337  * tasks to ensure a constant execution frequency.\r
338  *\r
339  * This function differs from vTaskDelay () in one important aspect:  vTaskDelay () will\r
340  * cause a task to block for the specified number of ticks from the time vTaskDelay () is\r
341  * called.  It is therefore difficult to use vTaskDelay () by itself to generate a fixed\r
342  * execution frequency as the time between a task starting to execute and that task\r
343  * calling vTaskDelay () may not be fixed [the task may take a different path though the\r
344  * code between calls, or may get interrupted or preempted a different number of times\r
345  * each time it executes].\r
346  *\r
347  * Whereas vTaskDelay () specifies a wake time relative to the time at which the function\r
348  * is called, vTaskDelayUntil () specifies the absolute (exact) time at which it wishes to\r
349  * unblock.\r
350  *\r
351  * The constant portTICK_RATE_MS can be used to calculate real time from the tick\r
352  * rate - with the resolution of one tick period.\r
353  *\r
354  * @param pxPreviousWakeTime Pointer to a variable that holds the time at which the\r
355  * task was last unblocked.  The variable must be initialised with the current time\r
356  * prior to its first use (see the example below).  Following this the variable is\r
357  * automatically updated within vTaskDelayUntil ().\r
358  *\r
359  * @param xTimeIncrement The cycle time period.  The task will be unblocked at\r
360  * time *pxPreviousWakeTime + xTimeIncrement.  Calling vTaskDelayUntil with the\r
361  * same xTimeIncrement parameter value will cause the task to execute with\r
362  * a fixed interface period.\r
363  *\r
364  * Example usage:\r
365    <pre>\r
366  // Perform an action every 10 ticks.\r
367  void vTaskFunction( void * pvParameters )\r
368  {\r
369  portTickType xLastWakeTime;\r
370  const portTickType xFrequency = 10;\r
371 \r
372      // Initialise the xLastWakeTime variable with the current time.\r
373      xLastWakeTime = xTaskGetTickCount ();\r
374      for( ;; )\r
375      {\r
376          // Wait for the next cycle.\r
377          vTaskDelayUntil( &xLastWakeTime, xFrequency );\r
378 \r
379          // Perform action here.\r
380      }\r
381  }\r
382    </pre>\r
383  * \defgroup vTaskDelayUntil vTaskDelayUntil\r
384  * \ingroup TaskCtrl\r
385  */\r
386 void vTaskDelayUntil( portTickType * const pxPreviousWakeTime, portTickType xTimeIncrement );\r
387 \r
388 /**\r
389  * task. h\r
390  * <pre>unsigned portBASE_TYPE uxTaskPriorityGet( xTaskHandle pxTask );</pre>\r
391  *\r
392  * INCLUDE_xTaskPriorityGet must be defined as 1 for this function to be available.\r
393  * See the configuration section for more information.\r
394  *\r
395  * Obtain the priority of any task.\r
396  *\r
397  * @param pxTask Handle of the task to be queried.  Passing a NULL\r
398  * handle results in the priority of the calling task being returned.\r
399  *\r
400  * @return The priority of pxTask.\r
401  *\r
402  * Example usage:\r
403    <pre>\r
404  void vAFunction( void )\r
405  {\r
406  xTaskHandle xHandle;\r
407                 \r
408      // Create a task, storing the handle.\r
409      xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );\r
410                 \r
411      // ...\r
412 \r
413      // Use the handle to obtain the priority of the created task.\r
414      // It was created with tskIDLE_PRIORITY, but may have changed\r
415      // it itself.\r
416      if( uxTaskPriorityGet( xHandle ) != tskIDLE_PRIORITY )\r
417      {\r
418          // The task has changed it's priority.\r
419      }\r
420 \r
421      // ...\r
422 \r
423      // Is our priority higher than the created task?\r
424      if( uxTaskPriorityGet( xHandle ) < uxTaskPriorityGet( NULL ) )\r
425      {\r
426          // Our priority (obtained using NULL handle) is higher.\r
427      }\r
428  }\r
429    </pre>\r
430  * \defgroup uxTaskPriorityGet uxTaskPriorityGet\r
431  * \ingroup TaskCtrl\r
432  */\r
433 unsigned portBASE_TYPE uxTaskPriorityGet( xTaskHandle pxTask );\r
434 \r
435 /**\r
436  * task. h\r
437  * <pre>void vTaskPrioritySet( xTaskHandle pxTask, unsigned portBASE_TYPE uxNewPriority );</pre>\r
438  *\r
439  * INCLUDE_vTaskPrioritySet must be defined as 1 for this function to be available.\r
440  * See the configuration section for more information.\r
441  *\r
442  * Set the priority of any task.\r
443  *\r
444  * A context switch will occur before the function returns if the priority\r
445  * being set is higher than the currently executing task.\r
446  *\r
447  * @param pxTask Handle to the task for which the priority is being set.\r
448  * Passing a NULL handle results in the priority of the calling task being set.\r
449  *\r
450  * @param uxNewPriority The priority to which the task will be set.\r
451  *\r
452  * Example usage:\r
453    <pre>\r
454  void vAFunction( void )\r
455  {\r
456  xTaskHandle xHandle;\r
457                 \r
458      // Create a task, storing the handle.\r
459      xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );\r
460 \r
461      // ...\r
462 \r
463      // Use the handle to raise the priority of the created task.\r
464      vTaskPrioritySet( xHandle, tskIDLE_PRIORITY + 1 );\r
465 \r
466      // ...\r
467 \r
468      // Use a NULL handle to raise our priority to the same value.\r
469      vTaskPrioritySet( NULL, tskIDLE_PRIORITY + 1 );\r
470  }\r
471    </pre>\r
472  * \defgroup vTaskPrioritySet vTaskPrioritySet\r
473  * \ingroup TaskCtrl\r
474  */\r
475 void vTaskPrioritySet( xTaskHandle pxTask, unsigned portBASE_TYPE uxNewPriority );\r
476 \r
477 /**\r
478  * task. h\r
479  * <pre>void vTaskSuspend( xTaskHandle pxTaskToSuspend );</pre>\r
480  *\r
481  * INCLUDE_vTaskSuspend must be defined as 1 for this function to be available.\r
482  * See the configuration section for more information.\r
483  *\r
484  * Suspend any task.  When suspended a task will never get any microcontroller\r
485  * processing time, no matter what its priority.\r
486  *\r
487  * Calls to vTaskSuspend are not accumulative -\r
488  * i.e. calling vTaskSuspend () twice on the same task still only requires one\r
489  * call to vTaskResume () to ready the suspended task.\r
490  *\r
491  * @param pxTaskToSuspend Handle to the task being suspended.  Passing a NULL\r
492  * handle will cause the calling task to be suspended.\r
493  *\r
494  * Example usage:\r
495    <pre>\r
496  void vAFunction( void )\r
497  {\r
498  xTaskHandle xHandle;\r
499                 \r
500      // Create a task, storing the handle.\r
501      xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );\r
502                 \r
503      // ...\r
504 \r
505      // Use the handle to suspend the created task.\r
506      vTaskSuspend( xHandle );\r
507 \r
508      // ...\r
509                 \r
510      // The created task will not run during this period, unless\r
511      // another task calls vTaskResume( xHandle ).\r
512                 \r
513      //...\r
514                 \r
515 \r
516      // Suspend ourselves.\r
517      vTaskSuspend( NULL );\r
518 \r
519      // We cannot get here unless another task calls vTaskResume\r
520      // with our handle as the parameter.\r
521  }\r
522    </pre>\r
523  * \defgroup vTaskSuspend vTaskSuspend\r
524  * \ingroup TaskCtrl\r
525  */\r
526 void vTaskSuspend( xTaskHandle pxTaskToSuspend );\r
527 \r
528 /**\r
529  * task. h\r
530  * <pre>void vTaskResume( xTaskHandle pxTaskToResume );</pre>\r
531  *\r
532  * INCLUDE_vTaskSuspend must be defined as 1 for this function to be available.\r
533  * See the configuration section for more information.\r
534  *\r
535  * Resumes a suspended task.\r
536  *\r
537  * A task that has been suspended by one of more calls to vTaskSuspend ()\r
538  * will be made available for running again by a single call to\r
539  * vTaskResume ().\r
540  *\r
541  * @param pxTaskToResume Handle to the task being readied.\r
542  *\r
543  * Example usage:\r
544    <pre>\r
545  void vAFunction( void )\r
546  {\r
547  xTaskHandle xHandle;\r
548                 \r
549      // Create a task, storing the handle.\r
550      xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );\r
551                 \r
552      // ...\r
553 \r
554      // Use the handle to suspend the created task.\r
555      vTaskSuspend( xHandle );\r
556 \r
557      // ...\r
558         \r
559      // The created task will not run during this period, unless\r
560      // another task calls vTaskResume( xHandle ).\r
561                 \r
562      //...\r
563                 \r
564 \r
565      // Resume the suspended task ourselves.\r
566      vTaskResume( xHandle );\r
567 \r
568      // The created task will once again get microcontroller processing\r
569      // time in accordance with it priority within the system.\r
570  }\r
571    </pre>\r
572  * \defgroup vTaskResume vTaskResume\r
573  * \ingroup TaskCtrl\r
574  */\r
575 void vTaskResume( xTaskHandle pxTaskToResume );\r
576 \r
577 /**\r
578  * task. h\r
579  * <pre>void xTaskResumeFromISR( xTaskHandle pxTaskToResume );</pre>\r
580  *\r
581  * INCLUDE_xTaskResumeFromISR must be defined as 1 for this function to be \r
582  * available.  See the configuration section for more information.\r
583  *\r
584  * An implementation of vTaskResume() that can be called from within an ISR.\r
585  *\r
586  * A task that has been suspended by one of more calls to vTaskSuspend ()\r
587  * will be made available for running again by a single call to\r
588  * xTaskResumeFromISR ().\r
589  *\r
590  * @param pxTaskToResume Handle to the task being readied.\r
591  *\r
592  * \defgroup vTaskResumeFromISR vTaskResumeFromISR\r
593  * \ingroup TaskCtrl\r
594  */\r
595 portBASE_TYPE xTaskResumeFromISR( xTaskHandle pxTaskToResume );\r
596 \r
597 /*-----------------------------------------------------------\r
598  * SCHEDULER CONTROL\r
599  *----------------------------------------------------------*/\r
600 \r
601 /**\r
602  * task. h\r
603  * <pre>void vTaskStartScheduler( void );</pre>\r
604  *\r
605  * Starts the real time kernel tick processing.  After calling the kernel\r
606  * has control over which tasks are executed and when.  This function\r
607  * does not return until an executing task calls vTaskEndScheduler ().\r
608  *\r
609  * At least one task should be created via a call to xTaskCreate ()\r
610  * before calling vTaskStartScheduler ().  The idle task is created\r
611  * automatically when the first application task is created.\r
612  *\r
613  * See the demo application file main.c for an example of creating\r
614  * tasks and starting the kernel.\r
615  *\r
616  * Example usage:\r
617    <pre>\r
618  void vAFunction( void )\r
619  {\r
620      // Create at least one task before starting the kernel.\r
621      xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );\r
622 \r
623      // Start the real time kernel with preemption.\r
624      vTaskStartScheduler ();\r
625 \r
626      // Will not get here unless a task calls vTaskEndScheduler ()\r
627  }\r
628    </pre>\r
629  *\r
630  * \defgroup vTaskStartScheduler vTaskStartScheduler\r
631  * \ingroup SchedulerControl\r
632  */\r
633 void vTaskStartScheduler( void );\r
634 \r
635 /**\r
636  * task. h\r
637  * <pre>void vTaskEndScheduler( void );</pre>\r
638  *\r
639  * Stops the real time kernel tick.  All created tasks will be automatically\r
640  * deleted and multitasking (either preemptive or cooperative) will\r
641  * stop.  Execution then resumes from the point where vTaskStartScheduler ()\r
642  * was called, as if vTaskStartScheduler () had just returned.\r
643  *\r
644  * See the demo application file main. c in the demo/PC directory for an\r
645  * example that uses vTaskEndScheduler ().\r
646  *\r
647  * vTaskEndScheduler () requires an exit function to be defined within the\r
648  * portable layer (see vPortEndScheduler () in port. c for the PC port).  This\r
649  * performs hardware specific operations such as stopping the kernel tick.\r
650  *\r
651  * vTaskEndScheduler () will cause all of the resources allocated by the\r
652  * kernel to be freed - but will not free resources allocated by application\r
653  * tasks.\r
654  *\r
655  * Example usage:\r
656    <pre>\r
657  void vTaskCode( void * pvParameters )\r
658  {\r
659      for( ;; )\r
660      {\r
661          // Task code goes here.\r
662 \r
663          // At some point we want to end the real time kernel processing\r
664          // so call ...\r
665          vTaskEndScheduler ();\r
666      }\r
667  }\r
668 \r
669  void vAFunction( void )\r
670  {\r
671      // Create at least one task before starting the kernel.\r
672      xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );\r
673 \r
674      // Start the real time kernel with preemption.\r
675      vTaskStartScheduler ();\r
676 \r
677      // Will only get here when the vTaskCode () task has called\r
678      // vTaskEndScheduler ().  When we get here we are back to single task\r
679      // execution.\r
680  }\r
681    </pre>\r
682  *\r
683  * \defgroup vTaskEndScheduler vTaskEndScheduler\r
684  * \ingroup SchedulerControl\r
685  */\r
686 void vTaskEndScheduler( void );\r
687 \r
688 /**\r
689  * task. h\r
690  * <pre>void vTaskSuspendAll( void );</pre>\r
691  *\r
692  * Suspends all real time kernel activity while keeping interrupts (including the\r
693  * kernel tick) enabled.\r
694  *\r
695  * After calling vTaskSuspendAll () the calling task will continue to execute\r
696  * without risk of being swapped out until a call to xTaskResumeAll () has been\r
697  * made.\r
698  *\r
699  * API functions that have the potential to cause a context switch (for example, \r
700  * vTaskDelayUntil(), xQueueSend(), etc.) must not be called while the scheduler \r
701  * is suspended.\r
702  *\r
703  * Example usage:\r
704    <pre>\r
705  void vTask1( void * pvParameters )\r
706  {\r
707      for( ;; )\r
708      {\r
709          // Task code goes here.\r
710 \r
711          // ...\r
712 \r
713          // At some point the task wants to perform a long operation during\r
714          // which it does not want to get swapped out.  It cannot use\r
715          // taskENTER_CRITICAL ()/taskEXIT_CRITICAL () as the length of the\r
716          // operation may cause interrupts to be missed - including the\r
717          // ticks.\r
718 \r
719          // Prevent the real time kernel swapping out the task.\r
720          vTaskSuspendAll ();\r
721 \r
722          // Perform the operation here.  There is no need to use critical\r
723          // sections as we have all the microcontroller processing time.\r
724          // During this time interrupts will still operate and the kernel\r
725          // tick count will be maintained.\r
726 \r
727          // ...\r
728 \r
729          // The operation is complete.  Restart the kernel.\r
730          xTaskResumeAll ();\r
731      }\r
732  }\r
733    </pre>\r
734  * \defgroup vTaskSuspendAll vTaskSuspendAll\r
735  * \ingroup SchedulerControl\r
736  */\r
737 void vTaskSuspendAll( void );\r
738 \r
739 /**\r
740  * task. h\r
741  * <pre>portCHAR xTaskResumeAll( void );</pre>\r
742  *\r
743  * Resumes real time kernel activity following a call to vTaskSuspendAll ().\r
744  * After a call to vTaskSuspendAll () the kernel will take control of which\r
745  * task is executing at any time.\r
746  *\r
747  * @return If resuming the scheduler caused a context switch then pdTRUE is\r
748  *         returned, otherwise pdFALSE is returned.\r
749  *\r
750  * Example usage:\r
751    <pre>\r
752  void vTask1( void * pvParameters )\r
753  {\r
754      for( ;; )\r
755      {\r
756          // Task code goes here.\r
757 \r
758          // ...\r
759 \r
760          // At some point the task wants to perform a long operation during\r
761          // which it does not want to get swapped out.  It cannot use\r
762          // taskENTER_CRITICAL ()/taskEXIT_CRITICAL () as the length of the\r
763          // operation may cause interrupts to be missed - including the\r
764          // ticks.\r
765 \r
766          // Prevent the real time kernel swapping out the task.\r
767          vTaskSuspendAll ();\r
768 \r
769          // Perform the operation here.  There is no need to use critical\r
770          // sections as we have all the microcontroller processing time.\r
771          // During this time interrupts will still operate and the real\r
772          // time kernel tick count will be maintained.\r
773 \r
774          // ...\r
775 \r
776          // The operation is complete.  Restart the kernel.  We want to force\r
777          // a context switch - but there is no point if resuming the scheduler\r
778          // caused a context switch already.\r
779          if( !xTaskResumeAll () )\r
780          {\r
781               taskYIELD ();\r
782          }\r
783      }\r
784  }\r
785    </pre>\r
786  * \defgroup xTaskResumeAll xTaskResumeAll\r
787  * \ingroup SchedulerControl\r
788  */\r
789 signed portBASE_TYPE xTaskResumeAll( void );\r
790 \r
791 /**\r
792  * task. h\r
793  * <pre>signed portBASE_TYPE xTaskIsTaskSuspended( xTaskHandle xTask );</pre>\r
794  *\r
795  * Utility task that simply returns pdTRUE if the task referenced by xTask is\r
796  * currently in the Suspended state, or pdFALSE if the task referenced by xTask\r
797  * is in any other state.\r
798  *\r
799  */\r
800 signed portBASE_TYPE xTaskIsTaskSuspended( xTaskHandle xTask );\r
801 \r
802 /*-----------------------------------------------------------\r
803  * TASK UTILITIES\r
804  *----------------------------------------------------------*/\r
805 \r
806 /**\r
807  * task. h\r
808  * <PRE>volatile portTickType xTaskGetTickCount( void );</PRE>\r
809  *\r
810  * @return The count of ticks since vTaskStartScheduler was called.\r
811  *\r
812  * \page xTaskGetTickCount xTaskGetTickCount\r
813  * \ingroup TaskUtils\r
814  */\r
815 portTickType xTaskGetTickCount( void );\r
816 \r
817 /**\r
818  * task. h\r
819  * <PRE>unsigned portSHORT uxTaskGetNumberOfTasks( void );</PRE>\r
820  *\r
821  * @return The number of tasks that the real time kernel is currently managing.\r
822  * This includes all ready, blocked and suspended tasks.  A task that\r
823  * has been deleted but not yet freed by the idle task will also be\r
824  * included in the count.\r
825  *\r
826  * \page uxTaskGetNumberOfTasks uxTaskGetNumberOfTasks\r
827  * \ingroup TaskUtils\r
828  */\r
829 unsigned portBASE_TYPE uxTaskGetNumberOfTasks( void );\r
830 \r
831 /**\r
832  * task. h\r
833  * <PRE>void vTaskList( portCHAR *pcWriteBuffer );</PRE>\r
834  *\r
835  * configUSE_TRACE_FACILITY, INCLUDE_vTaskDelete and INCLUDE_vTaskSuspend\r
836  * must all be defined as 1 for this function to be available.\r
837  * See the configuration section for more information.\r
838  *\r
839  * NOTE: This function will disable interrupts for its duration.  It is\r
840  * not intended for normal application runtime use but as a debug aid.\r
841  *\r
842  * Lists all the current tasks, along with their current state and stack\r
843  * usage high water mark.\r
844  *\r
845  * Tasks are reported as blocked ('B'), ready ('R'), deleted ('D') or\r
846  * suspended ('S').\r
847  *\r
848  * @param pcWriteBuffer A buffer into which the above mentioned details\r
849  * will be written, in ascii form.  This buffer is assumed to be large\r
850  * enough to contain the generated report.  Approximately 40 bytes per\r
851  * task should be sufficient.\r
852  *\r
853  * \page vTaskList vTaskList\r
854  * \ingroup TaskUtils\r
855  */\r
856 void vTaskList( signed portCHAR *pcWriteBuffer );\r
857 \r
858 /**\r
859  * task. h\r
860  * <PRE>void vTaskStartTrace( portCHAR * pcBuffer, unsigned portBASE_TYPE uxBufferSize );</PRE>\r
861  *\r
862  * Starts a real time kernel activity trace.  The trace logs the identity of\r
863  * which task is running when.\r
864  *\r
865  * The trace file is stored in binary format.  A separate DOS utility called\r
866  * convtrce.exe is used to convert this into a tab delimited text file which\r
867  * can be viewed and plotted in a spread sheet.\r
868  *\r
869  * @param pcBuffer The buffer into which the trace will be written.\r
870  *\r
871  * @param ulBufferSize The size of pcBuffer in bytes.  The trace will continue\r
872  * until either the buffer in full, or ulTaskEndTrace () is called.\r
873  *\r
874  * \page vTaskStartTrace vTaskStartTrace\r
875  * \ingroup TaskUtils\r
876  */\r
877 void vTaskStartTrace( signed portCHAR * pcBuffer, unsigned portLONG ulBufferSize );\r
878 \r
879 /**\r
880  * task. h\r
881  * <PRE>unsigned portLONG ulTaskEndTrace( void );</PRE>\r
882  *\r
883  * Stops a kernel activity trace.  See vTaskStartTrace ().\r
884  *\r
885  * @return The number of bytes that have been written into the trace buffer.\r
886  *\r
887  * \page usTaskEndTrace usTaskEndTrace\r
888  * \ingroup TaskUtils\r
889  */\r
890 unsigned portLONG ulTaskEndTrace( void );\r
891 \r
892 /**\r
893  * task.h\r
894  * <PRE>unsigned portBASE_TYPE uxTaskGetStackHighWaterMark( xTaskHandle xTask );</PRE>\r
895  *\r
896  * INCLUDE_uxTaskGetStackHighWaterMark must be set to 1 in FreeRTOSConfig.h for\r
897  * this function to be available.\r
898  *\r
899  * Returns the high water mark of the stack associated with xTask.  That is,\r
900  * the minimum free stack space there has been (in bytes) since the task\r
901  * started.  The smaller the returned number the closer the task has come\r
902  * to overflowing its stack.\r
903  *\r
904  * @param xTask Handle of the task associated with the stack to be checked.\r
905  * Set xTask to NULL to check the stack of the calling task.\r
906  *\r
907  * @return The smallest amount of free stack space there has been (in bytes)\r
908  * since the task referenced by xTask was created.\r
909  */\r
910 unsigned portBASE_TYPE uxTaskGetStackHighWaterMark( xTaskHandle xTask );\r
911 \r
912 /**\r
913  * task.h\r
914  * <pre>void vTaskSetApplicationTaskTag( xTaskHandle xTask, pdTASK_HOOK_CODE pxHookFunction );</pre>\r
915  *\r
916  * Sets pxHookFunction to be the task hook function used by the task xTask.\r
917  * Passing xTask as NULL has the effect of setting the calling tasks hook\r
918  * function.\r
919  */\r
920 void vTaskSetApplicationTaskTag( xTaskHandle xTask, pdTASK_HOOK_CODE pxHookFunction );\r
921 \r
922 /**\r
923  * task.h\r
924  * <pre>portBASE_TYPE xTaskCallApplicationTaskHook( xTaskHandle xTask, pdTASK_HOOK_CODE pxHookFunction );</pre>\r
925  *\r
926  * Calls the hook function associated with xTask.  Passing xTask as NULL has\r
927  * the effect of calling the Running tasks (the calling task) hook function.\r
928  *\r
929  * pvParameter is passed to the hook function for the task to interpret as it\r
930  * wants.\r
931  */\r
932 portBASE_TYPE xTaskCallApplicationTaskHook( xTaskHandle xTask, void *pvParameter );\r
933 \r
934 \r
935 /*-----------------------------------------------------------\r
936  * SCHEDULER INTERNALS AVAILABLE FOR PORTING PURPOSES\r
937  *----------------------------------------------------------*/\r
938 \r
939 /*\r
940  * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE.  IT IS ONLY\r
941  * INTENDED FOR USE WHEN IMPLEMENTING A PORT OF THE SCHEDULER AND IS\r
942  * AN INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.\r
943  *\r
944  * Called from the real time kernel tick (either preemptive or cooperative),\r
945  * this increments the tick count and checks if any tasks that are blocked\r
946  * for a finite period required removing from a blocked list and placing on\r
947  * a ready list.\r
948  */\r
949 void vTaskIncrementTick( void );\r
950 \r
951 /*\r
952  * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE.  IT IS AN\r
953  * INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.\r
954  *\r
955  * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED.\r
956  *\r
957  * Removes the calling task from the ready list and places it both\r
958  * on the list of tasks waiting for a particular event, and the\r
959  * list of delayed tasks.  The task will be removed from both lists\r
960  * and replaced on the ready list should either the event occur (and\r
961  * there be no higher priority tasks waiting on the same event) or\r
962  * the delay period expires.\r
963  *\r
964  * @param pxEventList The list containing tasks that are blocked waiting\r
965  * for the event to occur.\r
966  *\r
967  * @param xTicksToWait The maximum amount of time that the task should wait\r
968  * for the event to occur.  This is specified in kernel ticks,the constant\r
969  * portTICK_RATE_MS can be used to convert kernel ticks into a real time\r
970  * period.\r
971  */\r
972 void vTaskPlaceOnEventList( const xList * const pxEventList, portTickType xTicksToWait );\r
973 \r
974 /*\r
975  * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE.  IT IS AN\r
976  * INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.\r
977  *\r
978  * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED.\r
979  *\r
980  * Removes a task from both the specified event list and the list of blocked\r
981  * tasks, and places it on a ready queue.\r
982  *\r
983  * xTaskRemoveFromEventList () will be called if either an event occurs to\r
984  * unblock a task, or the block timeout period expires.\r
985  *\r
986  * @return pdTRUE if the task being removed has a higher priority than the task\r
987  * making the call, otherwise pdFALSE.\r
988  */\r
989 signed portBASE_TYPE xTaskRemoveFromEventList( const xList * const pxEventList );\r
990 \r
991 /*\r
992  * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE.  IT IS AN\r
993  * INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.\r
994  *\r
995  * INCLUDE_vTaskCleanUpResources and INCLUDE_vTaskSuspend must be defined as 1\r
996  * for this function to be available.\r
997  * See the configuration section for more information.\r
998  *\r
999  * Empties the ready and delayed queues of task control blocks, freeing the\r
1000  * memory allocated for the task control block and task stacks as it goes.\r
1001  */\r
1002 void vTaskCleanUpResources( void );\r
1003 \r
1004 /*\r
1005  * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE.  IT IS ONLY\r
1006  * INTENDED FOR USE WHEN IMPLEMENTING A PORT OF THE SCHEDULER AND IS\r
1007  * AN INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.\r
1008  *\r
1009  * Sets the pointer to the current TCB to the TCB of the highest priority task\r
1010  * that is ready to run.\r
1011  */\r
1012 void vTaskSwitchContext( void );\r
1013 \r
1014 /*\r
1015  * Return the handle of the calling task.\r
1016  */\r
1017 xTaskHandle xTaskGetCurrentTaskHandle( void );\r
1018 \r
1019 /*\r
1020  * Capture the current time status for future reference.\r
1021  */\r
1022 void vTaskSetTimeOutState( xTimeOutType * const pxTimeOut );\r
1023 \r
1024 /*\r
1025  * Compare the time status now with that previously captured to see if the\r
1026  * timeout has expired.\r
1027  */\r
1028 portBASE_TYPE xTaskCheckForTimeOut( xTimeOutType * const pxTimeOut, portTickType * const pxTicksToWait );\r
1029 \r
1030 /*\r
1031  * Shortcut used by the queue implementation to prevent unnecessary call to\r
1032  * taskYIELD();\r
1033  */\r
1034 void vTaskMissedYield( void );\r
1035 \r
1036 /*\r
1037  * Returns the scheduler state as taskSCHEDULER_RUNNING,\r
1038  * taskSCHEDULER_NOT_STARTED or taskSCHEDULER_SUSPENDED.\r
1039  */\r
1040 portBASE_TYPE xTaskGetSchedulerState( void );\r
1041 \r
1042 /*\r
1043  * Raises the priority of the mutex holder to that of the calling task should\r
1044  * the mutex holder have a priority less than the calling task.\r
1045  */\r
1046 void vTaskPriorityInherit( xTaskHandle * const pxMutexHolder );\r
1047 \r
1048 /*\r
1049  * Set the priority of a task back to its proper priority in the case that it\r
1050  * inherited a higher priority while it was holding a semaphore.\r
1051  */\r
1052 void vTaskPriorityDisinherit( xTaskHandle * const pxMutexHolder );\r
1053 \r
1054 #ifdef __cplusplus\r
1055 }\r
1056 #endif\r
1057 #endif /* TASK_H */\r
1058 \r
1059 \r
1060 \r