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