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