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