]> granicus.if.org Git - esp-idf/blob - components/freertos/include/freertos/task.h
freertos: add configTASKLIST_INCLUDE_COREID
[esp-idf] / components / freertos / include / freertos / task.h
1 /*
2     FreeRTOS V8.2.0 - Copyright (C) 2015 Real Time Engineers Ltd.
3     All rights reserved
4
5     VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
6
7     This file is part of the FreeRTOS distribution.
8
9     FreeRTOS is free software; you can redistribute it and/or modify it under
10     the terms of the GNU General Public License (version 2) as published by the
11     Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
12
13         ***************************************************************************
14     >>!   NOTE: The modification to the GPL is included to allow you to     !<<
15     >>!   distribute a combined work that includes FreeRTOS without being   !<<
16     >>!   obliged to provide the source code for proprietary components     !<<
17     >>!   outside of the FreeRTOS kernel.                                   !<<
18         ***************************************************************************
19
20     FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
21     WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
22     FOR A PARTICULAR PURPOSE.  Full license text is available on the following
23     link: http://www.freertos.org/a00114.html
24
25     ***************************************************************************
26      *                                                                       *
27      *    FreeRTOS provides completely free yet professionally developed,    *
28      *    robust, strictly quality controlled, supported, and cross          *
29      *    platform software that is more than just the market leader, it     *
30      *    is the industry's de facto standard.                               *
31      *                                                                       *
32      *    Help yourself get started quickly while simultaneously helping     *
33      *    to support the FreeRTOS project by purchasing a FreeRTOS           *
34      *    tutorial book, reference manual, or both:                          *
35      *    http://www.FreeRTOS.org/Documentation                              *
36      *                                                                       *
37     ***************************************************************************
38
39     http://www.FreeRTOS.org/FAQHelp.html - Having a problem?  Start by reading
40         the FAQ page "My application does not run, what could be wrong?".  Have you
41         defined configASSERT()?
42
43         http://www.FreeRTOS.org/support - In return for receiving this top quality
44         embedded software for free we request you assist our global community by
45         participating in the support forum.
46
47         http://www.FreeRTOS.org/training - Investing in training allows your team to
48         be as productive as possible as early as possible.  Now you can receive
49         FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers
50         Ltd, and the world's leading authority on the world's leading RTOS.
51
52     http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
53     including FreeRTOS+Trace - an indispensable productivity tool, a DOS
54     compatible FAT file system, and our tiny thread aware UDP/IP stack.
55
56     http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.
57     Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.
58
59     http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High
60     Integrity Systems ltd. to sell under the OpenRTOS brand.  Low cost OpenRTOS
61     licenses offer ticketed support, indemnification and commercial middleware.
62
63     http://www.SafeRTOS.com - High Integrity Systems also provide a safety
64     engineered and independently SIL3 certified version for use in safety and
65     mission critical applications that require provable dependability.
66
67     1 tab == 4 spaces!
68 */
69
70
71 #ifndef INC_TASK_H
72 #define INC_TASK_H
73
74 #ifndef INC_FREERTOS_H
75         #error "include FreeRTOS.h must appear in source files before include task.h"
76 #endif
77
78 #include <limits.h>
79
80 #include "list.h"
81 #include "portmacro.h"
82
83 #ifdef __cplusplus
84 extern "C" {
85 #endif
86
87 /*-----------------------------------------------------------
88  * MACROS AND DEFINITIONS
89  *----------------------------------------------------------*/
90
91 #define tskKERNEL_VERSION_NUMBER "V8.2.0"
92 #define tskKERNEL_VERSION_MAJOR 8
93 #define tskKERNEL_VERSION_MINOR 2
94 #define tskKERNEL_VERSION_BUILD 0
95
96 #define tskNO_AFFINITY INT_MAX
97
98 /**
99  * task. h
100  *
101  * Type by which tasks are referenced.  For example, a call to xTaskCreate
102  * returns (via a pointer parameter) an TaskHandle_t variable that can then
103  * be used as a parameter to vTaskDelete to delete the task.
104  *
105  * \ingroup Tasks
106  */
107 typedef void * TaskHandle_t;
108
109 /**
110  * Defines the prototype to which the application task hook function must
111  * conform.
112  */
113 typedef BaseType_t (*TaskHookFunction_t)( void * );
114
115 /** Task states returned by eTaskGetState. */
116 typedef enum
117 {
118         eRunning = 0,   /*!< A task is querying the state of itself, so must be running. */
119         eReady,                 /*!< The task being queried is in a read or pending ready list. */
120         eBlocked,               /*!< The task being queried is in the Blocked state. */
121         eSuspended,             /*!< The task being queried is in the Suspended state, or is in the Blocked state with an infinite time out. */
122         eDeleted                /*!< The task being queried has been deleted, but its TCB has not yet been freed. */
123 } eTaskState;
124
125 /** Actions that can be performed when vTaskNotify() is called. */
126 typedef enum
127 {
128         eNoAction = 0,                          /*!< Notify the task without updating its notify value. */
129         eSetBits,                                       /*!< Set bits in the task's notification value. */
130         eIncrement,                                     /*!< Increment the task's notification value. */
131         eSetValueWithOverwrite,         /*!< Set the task's notification value to a specific value even if the previous value has not yet been read by the task. */
132         eSetValueWithoutOverwrite       /*!< Set the task's notification value if the previous value has been read by the task. */
133 } eNotifyAction;
134
135 /** @cond */
136 /**
137  * Used internally only.
138  */
139 typedef struct xTIME_OUT
140 {
141         BaseType_t xOverflowCount;
142         TickType_t xTimeOnEntering;
143 } TimeOut_t;
144
145 /**
146  * Defines the memory ranges allocated to the task when an MPU is used.
147  */
148 typedef struct xMEMORY_REGION
149 {
150         void *pvBaseAddress;
151         uint32_t ulLengthInBytes;
152         uint32_t ulParameters;
153 } MemoryRegion_t;
154
155 /**
156  * Parameters required to create an MPU protected task.
157  */
158 typedef struct xTASK_PARAMETERS
159 {
160         TaskFunction_t pvTaskCode;
161         const char * const pcName;      /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
162         uint32_t usStackDepth;
163         void *pvParameters;
164         UBaseType_t uxPriority;
165         StackType_t *puxStackBuffer;
166         MemoryRegion_t xRegions[ portNUM_CONFIGURABLE_REGIONS ];
167 } TaskParameters_t;
168 /** @endcond */
169
170 /**
171  *  Used with the uxTaskGetSystemState() function to return the state of each task in the system.
172 */
173 typedef struct xTASK_STATUS
174 {
175         TaskHandle_t xHandle;                   /*!< The handle of the task to which the rest of the information in the structure relates. */
176         const char *pcTaskName;                 /*!< A pointer to the task's name.  This value will be invalid if the task was deleted since the structure was populated! */ /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
177         UBaseType_t xTaskNumber;                /*!< A number unique to the task. */
178         eTaskState eCurrentState;               /*!< The state in which the task existed when the structure was populated. */
179         UBaseType_t uxCurrentPriority;  /*!< The priority at which the task was running (may be inherited) when the structure was populated. */
180         UBaseType_t uxBasePriority;             /*!< The priority to which the task will return if the task's current priority has been inherited to avoid unbounded priority inversion when obtaining a mutex.  Only valid if configUSE_MUTEXES is defined as 1 in FreeRTOSConfig.h. */
181         uint32_t ulRunTimeCounter;              /*!< The total run time allocated to the task so far, as defined by the run time stats clock.  See http://www.freertos.org/rtos-run-time-stats.html.  Only valid when configGENERATE_RUN_TIME_STATS is defined as 1 in FreeRTOSConfig.h. */
182         StackType_t *pxStackBase;               /*!< Points to the lowest address of the task's stack area. */
183         uint32_t usStackHighWaterMark;  /*!< The minimum amount of stack space that has remained for the task since the task was created.  The closer this value is to zero the closer the task has come to overflowing its stack. */
184 #if configTASKLIST_INCLUDE_COREID
185         BaseType_t xCoreID;                             /*!< Core this task is pinned to. This field is present if CONFIG_FREERTOS_VTASKLIST_INCLUDE_COREID is set. */
186 #endif
187 } TaskStatus_t;
188
189 /**
190  * Used with the uxTaskGetSnapshotAll() function to save memory snapshot of each task in the system.
191  * We need this struct because TCB_t is defined (hidden) in tasks.c.
192  */
193 typedef struct xTASK_SNAPSHOT
194 {
195         void        *pxTCB;         /*!< Address of task control block. */
196         StackType_t *pxTopOfStack;  /*!< Points to the location of the last item placed on the tasks stack. */
197         StackType_t *pxEndOfStack;  /*!< Points to the end of the stack. pxTopOfStack < pxEndOfStack, stack grows hi2lo
198                                                                         pxTopOfStack > pxEndOfStack, stack grows lo2hi*/
199 } TaskSnapshot_t;
200
201 /**
202  * Possible return values for eTaskConfirmSleepModeStatus().
203  */
204 typedef enum
205 {
206         eAbortSleep = 0,                /*!< A task has been made ready or a context switch pended since portSUPPORESS_TICKS_AND_SLEEP() was called - abort entering a sleep mode. */
207         eStandardSleep,                 /*!< Enter a sleep mode that will not last any longer than the expected idle time. */
208         eNoTasksWaitingTimeout  /*!< No tasks are waiting for a timeout so it is safe to enter a sleep mode that can only be exited by an external interrupt. */
209 } eSleepModeStatus;
210
211
212 /**
213  * Defines the priority used by the idle task.  This must not be modified.
214  *
215  * \ingroup TaskUtils
216  */
217 #define tskIDLE_PRIORITY                        ( ( UBaseType_t ) 0U )
218
219 /**
220  * task. h
221  *
222  * Macro for forcing a context switch.
223  *
224  * \ingroup SchedulerControl
225  */
226 #define taskYIELD()                                     portYIELD()
227
228 /**
229  * task. h
230  *
231  * Macro to mark the start of a critical code region.  Preemptive context
232  * switches cannot occur when in a critical region.
233  *
234  * @note This may alter the stack (depending on the portable implementation)
235  * so must be used with care!
236  *
237  * \ingroup SchedulerControl
238  */
239 #ifdef _ESP_FREERTOS_INTERNAL
240 #define taskENTER_CRITICAL(mux)         portENTER_CRITICAL(mux)
241 #else
242 #define taskENTER_CRITICAL(mux) _Pragma("GCC warning \"'taskENTER_CRITICAL(mux)' is deprecated in ESP-IDF, consider using 'portENTER_CRITICAL(mux)'\"") portENTER_CRITICAL(mux)
243 #endif
244 #define taskENTER_CRITICAL_ISR(mux)             portENTER_CRITICAL_ISR(mux)
245
246 /**
247  * task. h
248  *
249  * Macro to mark the end of a critical code region.  Preemptive context
250  * switches cannot occur when in a critical region.
251  *
252  * @note This may alter the stack (depending on the portable implementation)
253  * so must be used with care!
254  *
255  * \ingroup SchedulerControl
256  */
257 #ifdef _ESP_FREERTOS_INTERNAL
258 #define taskEXIT_CRITICAL(mux)                  portEXIT_CRITICAL(mux)
259 #else
260 #define taskEXIT_CRITICAL(mux) _Pragma("GCC warning \"'taskEXIT_CRITICAL(mux)' is deprecated in ESP-IDF, consider using 'portEXIT_CRITICAL(mux)'\"") portEXIT_CRITICAL(mux)
261 #endif
262 #define taskEXIT_CRITICAL_ISR(mux)              portEXIT_CRITICAL_ISR(mux)
263
264 /**
265  * task. h
266  *
267  * Macro to disable all maskable interrupts.
268  *
269  * \ingroup SchedulerControl
270  */
271 #define taskDISABLE_INTERRUPTS()        portDISABLE_INTERRUPTS()
272
273 /**
274  * task. h
275  *
276  * Macro to enable microcontroller interrupts.
277  *
278  * \ingroup SchedulerControl
279  */
280 #define taskENABLE_INTERRUPTS()         portENABLE_INTERRUPTS()
281
282 /* Definitions returned by xTaskGetSchedulerState().  taskSCHEDULER_SUSPENDED is
283 0 to generate more optimal code when configASSERT() is defined as the constant
284 is used in assert() statements. */
285 #define taskSCHEDULER_SUSPENDED         ( ( BaseType_t ) 0 )
286 #define taskSCHEDULER_NOT_STARTED       ( ( BaseType_t ) 1 )
287 #define taskSCHEDULER_RUNNING           ( ( BaseType_t ) 2 )
288
289
290 /*-----------------------------------------------------------
291  * TASK CREATION API
292  *----------------------------------------------------------*/
293
294 /**
295  * Create a new task with a specified affinity.
296  *
297  * This function is similar to xTaskCreate, but allows setting task affinity
298  * in SMP system.
299  *
300  * @param pvTaskCode Pointer to the task entry function.  Tasks
301  * must be implemented to never return (i.e. continuous loop).
302  *
303  * @param pcName A descriptive name for the task.  This is mainly used to
304  * facilitate debugging.  Max length defined by configMAX_TASK_NAME_LEN - default
305  * is 16.
306  *
307  * @param usStackDepth The size of the task stack specified as the number of
308  * variables the stack can hold - not the number of bytes.  For example, if
309  * the stack is 16 bits wide and usStackDepth is defined as 100, 200 bytes
310  * will be allocated for stack storage.
311  *
312  * @param pvParameters Pointer that will be used as the parameter for the task
313  * being created.
314  *
315  * @param uxPriority The priority at which the task should run.  Systems that
316  * include MPU support can optionally create tasks in a privileged (system)
317  * mode by setting bit portPRIVILEGE_BIT of the priority parameter.  For
318  * example, to create a privileged task at priority 2 the uxPriority parameter
319  * should be set to ( 2 | portPRIVILEGE_BIT ).
320  *
321  * @param pvCreatedTask Used to pass back a handle by which the created task
322  * can be referenced.
323  *
324  * @param xCoreID If the value is tskNO_AFFINITY, the created task is not
325  * pinned to any CPU, and the scheduler can run it on any core available.
326  * Other values indicate the index number of the CPU which the task should
327  * be pinned to. Specifying values larger than (portNUM_PROCESSORS - 1) will
328  * cause the function to fail.
329  *
330  * @return pdPASS if the task was successfully created and added to a ready
331  * list, otherwise an error code defined in the file projdefs.h
332  *
333  * \ingroup Tasks
334  */
335 #if( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
336         BaseType_t xTaskCreatePinnedToCore(     TaskFunction_t pvTaskCode,
337                                                                                 const char * const pcName,
338                                                                                 const uint32_t usStackDepth,
339                                                                                 void * const pvParameters,
340                                                                                 UBaseType_t uxPriority,
341                                                                                 TaskHandle_t * const pvCreatedTask,
342                                                                                 const BaseType_t xCoreID);
343
344 #endif
345
346 /**
347  * Create a new task and add it to the list of tasks that are ready to run.
348  *
349  * Internally, within the FreeRTOS implementation, tasks use two blocks of
350  * memory.  The first block is used to hold the task's data structures.  The
351  * second block is used by the task as its stack.  If a task is created using
352  * xTaskCreate() then both blocks of memory are automatically dynamically
353  * allocated inside the xTaskCreate() function.  (see
354  * http://www.freertos.org/a00111.html).  If a task is created using
355  * xTaskCreateStatic() then the application writer must provide the required
356  * memory.  xTaskCreateStatic() therefore allows a task to be created without
357  * using any dynamic memory allocation.
358  *
359  * See xTaskCreateStatic() for a version that does not use any dynamic memory
360  * allocation.
361  *
362  * xTaskCreate() can only be used to create a task that has unrestricted
363  * access to the entire microcontroller memory map.  Systems that include MPU
364  * support can alternatively create an MPU constrained task using
365  * xTaskCreateRestricted().
366  *
367  * @param pvTaskCode Pointer to the task entry function.  Tasks
368  * must be implemented to never return (i.e. continuous loop).
369  *
370  * @param pcName A descriptive name for the task.  This is mainly used to
371  * facilitate debugging.  Max length defined by configMAX_TASK_NAME_LEN - default
372  * is 16.
373  *
374  * @param usStackDepth The size of the task stack specified as the number of
375  * variables the stack can hold - not the number of bytes.  For example, if
376  * the stack is 16 bits wide and usStackDepth is defined as 100, 200 bytes
377  * will be allocated for stack storage.
378  *
379  * @param pvParameters Pointer that will be used as the parameter for the task
380  * being created.
381  *
382  * @param uxPriority The priority at which the task should run.  Systems that
383  * include MPU support can optionally create tasks in a privileged (system)
384  * mode by setting bit portPRIVILEGE_BIT of the priority parameter.  For
385  * example, to create a privileged task at priority 2 the uxPriority parameter
386  * should be set to ( 2 | portPRIVILEGE_BIT ).
387  *
388  * @param pvCreatedTask Used to pass back a handle by which the created task
389  * can be referenced.
390  *
391  * @return pdPASS if the task was successfully created and added to a ready
392  * list, otherwise an error code defined in the file projdefs.h
393  *
394  * @note If program uses thread local variables (ones specified with "__thread" keyword)
395  * then storage for them will be allocated on the task's stack.
396  *
397  * Example usage:
398  * @code{c}
399  *  // Task to be created.
400  *  void vTaskCode( void * pvParameters )
401  *  {
402  *   for( ;; )
403  *   {
404  *       // Task code goes here.
405  *   }
406  *  }
407  *
408  *  // Function that creates a task.
409  *  void vOtherFunction( void )
410  *  {
411  *  static uint8_t ucParameterToPass;
412  *  TaskHandle_t xHandle = NULL;
413  *
414  *   // Create the task, storing the handle.  Note that the passed parameter ucParameterToPass
415  *   // must exist for the lifetime of the task, so in this case is declared static.  If it was just an
416  *   // an automatic stack variable it might no longer exist, or at least have been corrupted, by the time
417  *   // the new task attempts to access it.
418  *   xTaskCreate( vTaskCode, "NAME", STACK_SIZE, &ucParameterToPass, tskIDLE_PRIORITY, &xHandle );
419  *      configASSERT( xHandle );
420  *
421  *   // Use the handle to delete the task.
422  *      if( xHandle != NULL )
423  *      {
424  *       vTaskDelete( xHandle );
425  *      }
426  *  }
427  * @endcode
428  * \ingroup Tasks
429  */
430
431 #if( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
432
433         static inline IRAM_ATTR BaseType_t xTaskCreate(
434                         TaskFunction_t pvTaskCode,
435                         const char * const pcName,
436                         const uint32_t usStackDepth,
437                         void * const pvParameters,
438                         UBaseType_t uxPriority,
439                         TaskHandle_t * const pvCreatedTask)
440         {
441                 return xTaskCreatePinnedToCore( pvTaskCode, pcName, usStackDepth, pvParameters, uxPriority, pvCreatedTask, tskNO_AFFINITY );
442         }
443
444 #endif
445
446
447
448
449 /**
450  * Create a new task with a specified affinity.
451  *
452  * This function is similar to xTaskCreateStatic, but allows specifying
453  * task affinity in an SMP system.
454  *
455  * @param pvTaskCode Pointer to the task entry function.  Tasks
456  * must be implemented to never return (i.e. continuous loop).
457  *
458  * @param pcName A descriptive name for the task.  This is mainly used to
459  * facilitate debugging.  The maximum length of the string is defined by
460  * configMAX_TASK_NAME_LEN in FreeRTOSConfig.h.
461  *
462  * @param ulStackDepth The size of the task stack specified as the number of
463  * variables the stack can hold - not the number of bytes.  For example, if
464  * the stack is 32-bits wide and ulStackDepth is defined as 100 then 400 bytes
465  * will be allocated for stack storage.
466  *
467  * @param pvParameters Pointer that will be used as the parameter for the task
468  * being created.
469  *
470  * @param uxPriority The priority at which the task will run.
471  *
472  * @param pxStackBuffer Must point to a StackType_t array that has at least
473  * ulStackDepth indexes - the array will then be used as the task's stack,
474  * removing the need for the stack to be allocated dynamically.
475  *
476  * @param pxTaskBuffer Must point to a variable of type StaticTask_t, which will
477  * then be used to hold the task's data structures, removing the need for the
478  * memory to be allocated dynamically.
479  *
480  * @param xCoreID If the value is tskNO_AFFINITY, the created task is not
481  * pinned to any CPU, and the scheduler can run it on any core available.
482  * Other values indicate the index number of the CPU which the task should
483  * be pinned to. Specifying values larger than (portNUM_PROCESSORS - 1) will
484  * cause the function to fail.
485  *
486  * @return If neither pxStackBuffer or pxTaskBuffer are NULL, then the task will
487  * be created and pdPASS is returned.  If either pxStackBuffer or pxTaskBuffer
488  * are NULL then the task will not be created and
489  * errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY is returned.
490  *
491  * \ingroup Tasks
492  */
493 #if( configSUPPORT_STATIC_ALLOCATION == 1 )
494         TaskHandle_t xTaskCreateStaticPinnedToCore(     TaskFunction_t pvTaskCode,
495                                                                                                 const char * const pcName,
496                                                                                                 const uint32_t ulStackDepth,
497                                                                                                 void * const pvParameters,
498                                                                                                 UBaseType_t uxPriority,
499                                                                                                 StackType_t * const pxStackBuffer,
500                                                                                                 StaticTask_t * const pxTaskBuffer,
501                                                                                                 const BaseType_t xCoreID );
502 #endif /* configSUPPORT_STATIC_ALLOCATION */
503
504 /**
505  * Create a new task and add it to the list of tasks that are ready to run.
506  *
507  * Internally, within the FreeRTOS implementation, tasks use two blocks of
508  * memory.  The first block is used to hold the task's data structures.  The
509  * second block is used by the task as its stack.  If a task is created using
510  * xTaskCreate() then both blocks of memory are automatically dynamically
511  * allocated inside the xTaskCreate() function.  (see
512  * http://www.freertos.org/a00111.html).  If a task is created using
513  * xTaskCreateStatic() then the application writer must provide the required
514  * memory.  xTaskCreateStatic() therefore allows a task to be created without
515  * using any dynamic memory allocation.
516  *
517  * @param pvTaskCode Pointer to the task entry function.  Tasks
518  * must be implemented to never return (i.e. continuous loop).
519  *
520  * @param pcName A descriptive name for the task.  This is mainly used to
521  * facilitate debugging.  The maximum length of the string is defined by
522  * configMAX_TASK_NAME_LEN in FreeRTOSConfig.h.
523  *
524  * @param ulStackDepth The size of the task stack specified as the number of
525  * variables the stack can hold - not the number of bytes.  For example, if
526  * the stack is 32-bits wide and ulStackDepth is defined as 100 then 400 bytes
527  * will be allocated for stack storage.
528  *
529  * @param pvParameters Pointer that will be used as the parameter for the task
530  * being created.
531  *
532  * @param uxPriority The priority at which the task will run.
533  *
534  * @param pxStackBuffer Must point to a StackType_t array that has at least
535  * ulStackDepth indexes - the array will then be used as the task's stack,
536  * removing the need for the stack to be allocated dynamically.
537  *
538  * @param pxTaskBuffer Must point to a variable of type StaticTask_t, which will
539  * then be used to hold the task's data structures, removing the need for the
540  * memory to be allocated dynamically.
541  *
542  * @return If neither pxStackBuffer or pxTaskBuffer are NULL, then the task will
543  * be created and pdPASS is returned.  If either pxStackBuffer or pxTaskBuffer
544  * are NULL then the task will not be created and
545  * errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY is returned.
546  *
547  * @note If program uses thread local variables (ones specified with "__thread" keyword)
548  * then storage for them will be allocated on the task's stack.
549  *
550  * Example usage:
551  * @code{c}
552  *
553  *     // Dimensions the buffer that the task being created will use as its stack.
554  *     // NOTE:  This is the number of words the stack will hold, not the number of
555  *     // bytes.  For example, if each stack item is 32-bits, and this is set to 100,
556  *     // then 400 bytes (100 * 32-bits) will be allocated.
557  *     #define STACK_SIZE 200
558  *
559  *     // Structure that will hold the TCB of the task being created.
560  *     StaticTask_t xTaskBuffer;
561  *
562  *     // Buffer that the task being created will use as its stack.  Note this is
563  *     // an array of StackType_t variables.  The size of StackType_t is dependent on
564  *     // the RTOS port.
565  *     StackType_t xStack[ STACK_SIZE ];
566  *
567  *     // Function that implements the task being created.
568  *     void vTaskCode( void * pvParameters )
569  *     {
570  *         // The parameter value is expected to be 1 as 1 is passed in the
571  *         // pvParameters value in the call to xTaskCreateStatic().
572  *         configASSERT( ( uint32_t ) pvParameters == 1UL );
573  *
574  *         for( ;; )
575  *         {
576  *             // Task code goes here.
577  *         }
578  *     }
579  *
580  *     // Function that creates a task.
581  *     void vOtherFunction( void )
582  *     {
583  *         TaskHandle_t xHandle = NULL;
584  *
585  *         // Create the task without using any dynamic memory allocation.
586  *         xHandle = xTaskCreateStatic(
587  *                       vTaskCode,       // Function that implements the task.
588  *                       "NAME",          // Text name for the task.
589  *                       STACK_SIZE,      // Stack size in words, not bytes.
590  *                       ( void * ) 1,    // Parameter passed into the task.
591  *                       tskIDLE_PRIORITY,// Priority at which the task is created.
592  *                       xStack,          // Array to use as the task's stack.
593  *                       &xTaskBuffer );  // Variable to hold the task's data structure.
594  *
595  *         // puxStackBuffer and pxTaskBuffer were not NULL, so the task will have
596  *         // been created, and xHandle will be the task's handle.  Use the handle
597  *         // to suspend the task.
598  *         vTaskSuspend( xHandle );
599  *     }
600  * @endcode
601  * \ingroup Tasks
602  */
603
604 #if( configSUPPORT_STATIC_ALLOCATION == 1 )
605         static inline IRAM_ATTR TaskHandle_t xTaskCreateStatic(
606                         TaskFunction_t pvTaskCode,
607                         const char * const pcName,
608                         const uint32_t ulStackDepth,
609                         void * const pvParameters,
610                         UBaseType_t uxPriority,
611                         StackType_t * const pxStackBuffer,
612                         StaticTask_t * const pxTaskBuffer)
613         {
614                 return xTaskCreateStaticPinnedToCore( pvTaskCode, pcName, ulStackDepth, pvParameters, uxPriority, pxStackBuffer, pxTaskBuffer, tskNO_AFFINITY );
615         }
616 #endif /* configSUPPORT_STATIC_ALLOCATION */
617
618 /** @cond */
619 /**
620  * xTaskCreateRestricted() should only be used in systems that include an MPU
621  * implementation.
622  *
623  * Create a new task and add it to the list of tasks that are ready to run.
624  * The function parameters define the memory regions and associated access
625  * permissions allocated to the task.
626  *
627  * @param pxTaskDefinition Pointer to a structure that contains a member
628  * for each of the normal xTaskCreate() parameters (see the xTaskCreate() API
629  * documentation) plus an optional stack buffer and the memory region
630  * definitions.
631  *
632  * @param pxCreatedTask Used to pass back a handle by which the created task
633  * can be referenced.
634  *
635  * @return pdPASS if the task was successfully created and added to a ready
636  * list, otherwise an error code defined in the file projdefs.h
637  *
638  * Example usage:
639  * @code{c}
640  * // Create an TaskParameters_t structure that defines the task to be created.
641  * static const TaskParameters_t xCheckTaskParameters =
642  * {
643  *      vATask,         // pvTaskCode - the function that implements the task.
644  *      "ATask",        // pcName - just a text name for the task to assist debugging.
645  *      100,            // usStackDepth - the stack size DEFINED IN WORDS.
646  *      NULL,           // pvParameters - passed into the task function as the function parameters.
647  *      ( 1UL | portPRIVILEGE_BIT ),// uxPriority - task priority, set the portPRIVILEGE_BIT if the task should run in a privileged state.
648  *      cStackBuffer,// puxStackBuffer - the buffer to be used as the task stack.
649  *
650  *      // xRegions - Allocate up to three separate memory regions for access by
651  *      // the task, with appropriate access permissions.  Different processors have
652  *      // different memory alignment requirements - refer to the FreeRTOS documentation
653  *      // for full information.
654  *      {
655  *              // Base address                                 Length  Parameters
656  *         { cReadWriteArray,                           32,             portMPU_REGION_READ_WRITE },
657  *         { cReadOnlyArray,                            32,             portMPU_REGION_READ_ONLY },
658  *         { cPrivilegedOnlyAccessArray,        128,    portMPU_REGION_PRIVILEGED_READ_WRITE }
659  *      }
660  * };
661  *
662  * int main( void )
663  * {
664  * TaskHandle_t xHandle;
665  *
666  *      // Create a task from the const structure defined above.  The task handle
667  *      // is requested (the second parameter is not NULL) but in this case just for
668  *      // demonstration purposes as its not actually used.
669  *      xTaskCreateRestricted( &xRegTest1Parameters, &xHandle );
670  *
671  *      // Start the scheduler.
672  *      vTaskStartScheduler();
673  *
674  *      // Will only get here if there was insufficient memory to create the idle
675  *      // and/or timer task.
676  *      for( ;; );
677  * }
678  * @endcode
679  * \ingroup Tasks
680  */
681 #if( portUSING_MPU_WRAPPERS == 1 )
682         BaseType_t xTaskCreateRestricted( const TaskParameters_t * const pxTaskDefinition, TaskHandle_t *pxCreatedTask ) PRIVILEGED_FUNCTION;
683 #endif
684
685
686 /**
687  * Memory regions are assigned to a restricted task when the task is created by
688  * a call to xTaskCreateRestricted().  These regions can be redefined using
689  * vTaskAllocateMPURegions().
690  *
691  * @param xTask The handle of the task being updated.
692  *
693  * @param xRegions A pointer to an MemoryRegion_t structure that contains the
694  * new memory region definitions.
695  *
696  * Example usage:
697  *
698  * @code{c}
699  * // Define an array of MemoryRegion_t structures that configures an MPU region
700  * // allowing read/write access for 1024 bytes starting at the beginning of the
701  * // ucOneKByte array.  The other two of the maximum 3 definable regions are
702  * // unused so set to zero.
703  * static const MemoryRegion_t xAltRegions[ portNUM_CONFIGURABLE_REGIONS ] =
704  * {
705  *      // Base address         Length          Parameters
706  *      { ucOneKByte,           1024,           portMPU_REGION_READ_WRITE },
707  *      { 0,                            0,                      0 },
708  *      { 0,                            0,                      0 }
709  * };
710  *
711  * void vATask( void *pvParameters )
712  * {
713  *      // This task was created such that it has access to certain regions of
714  *      // memory as defined by the MPU configuration.  At some point it is
715  *      // desired that these MPU regions are replaced with that defined in the
716  *      // xAltRegions const struct above.  Use a call to vTaskAllocateMPURegions()
717  *      // for this purpose.  NULL is used as the task handle to indicate that this
718  *      // function should modify the MPU regions of the calling task.
719  *      vTaskAllocateMPURegions( NULL, xAltRegions );
720  *
721  *      // Now the task can continue its function, but from this point on can only
722  *      // access its stack and the ucOneKByte array (unless any other statically
723  *      // defined or shared regions have been declared elsewhere).
724  * }
725  * @endcode
726  * \ingroup Tasks
727  */
728 void vTaskAllocateMPURegions( TaskHandle_t xTask, const MemoryRegion_t * const pxRegions ) PRIVILEGED_FUNCTION;
729
730 /** @endcond */
731
732 /**
733  * Remove a task from the RTOS real time kernel's management.
734  *
735  * The task being deleted will be removed from all ready, blocked, suspended
736  * and event lists.
737  *
738  * INCLUDE_vTaskDelete must be defined as 1 for this function to be available.
739  * See the configuration section for more information.
740  *
741  * @note The idle task is responsible for freeing the kernel allocated
742  * memory from tasks that have been deleted.  It is therefore important that
743  * the idle task is not starved of microcontroller processing time if your
744  * application makes any calls to vTaskDelete ().  Memory allocated by the
745  * task code is not automatically freed, and should be freed before the task
746  * is deleted.
747  *
748  * See the demo application file death.c for sample code that utilises
749  * vTaskDelete ().
750  *
751  * @param xTaskToDelete The handle of the task to be deleted.  Passing NULL will
752  * cause the calling task to be deleted.
753  *
754  * Example usage:
755  * @code{c}
756  *  void vOtherFunction( void )
757  *  {
758  *  TaskHandle_t xHandle;
759  *
760  *       // Create the task, storing the handle.
761  *       xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
762  *
763  *       // Use the handle to delete the task.
764  *       vTaskDelete( xHandle );
765  *  }
766  * @endcode
767  * \ingroup Tasks
768  */
769 void vTaskDelete( TaskHandle_t xTaskToDelete ) PRIVILEGED_FUNCTION;
770
771 /*-----------------------------------------------------------
772  * TASK CONTROL API
773  *----------------------------------------------------------*/
774
775 /**
776  * Delay a task for a given number of ticks.
777  *
778  * The actual time that the task remains blocked depends on the tick rate.
779  * The constant portTICK_PERIOD_MS can be used to calculate real time from
780  * the tick rate - with the resolution of one tick period.
781  *
782  * INCLUDE_vTaskDelay must be defined as 1 for this function to be available.
783  * See the configuration section for more information.
784  *
785  * vTaskDelay() specifies a time at which the task wishes to unblock relative to
786  * the time at which vTaskDelay() is called.  For example, specifying a block
787  * period of 100 ticks will cause the task to unblock 100 ticks after
788  * vTaskDelay() is called.  vTaskDelay() does not therefore provide a good method
789  * of controlling the frequency of a periodic task as the path taken through the
790  * code, as well as other task and interrupt activity, will effect the frequency
791  * at which vTaskDelay() gets called and therefore the time at which the task
792  * next executes.  See vTaskDelayUntil() for an alternative API function designed
793  * to facilitate fixed frequency execution.  It does this by specifying an
794  * absolute time (rather than a relative time) at which the calling task should
795  * unblock.
796  *
797  * @param xTicksToDelay The amount of time, in tick periods, that
798  * the calling task should block.
799  *
800  * Example usage:
801  * @code{c}
802  *  void vTaskFunction( void * pvParameters )
803  *  {
804  *  // Block for 500ms.
805  *  const TickType_t xDelay = 500 / portTICK_PERIOD_MS;
806  *
807  *       for( ;; )
808  *       {
809  *               // Simply toggle the LED every 500ms, blocking between each toggle.
810  *               vToggleLED();
811  *               vTaskDelay( xDelay );
812  *       }
813  *  }
814  * @endcode
815  * \ingroup TaskCtrl
816  */
817 void vTaskDelay( const TickType_t xTicksToDelay ) PRIVILEGED_FUNCTION;
818
819 /**
820  * Delay a task until a specified time.
821  *
822  * INCLUDE_vTaskDelayUntil must be defined as 1 for this function to be available.
823  * See the configuration section for more information.
824  *
825  * This function can be used by periodic tasks to ensure a constant execution frequency.
826  *
827  * This function differs from vTaskDelay () in one important aspect:  vTaskDelay () will
828  * cause a task to block for the specified number of ticks from the time vTaskDelay () is
829  * called.  It is therefore difficult to use vTaskDelay () by itself to generate a fixed
830  * execution frequency as the time between a task starting to execute and that task
831  * calling vTaskDelay () may not be fixed [the task may take a different path though the
832  * code between calls, or may get interrupted or preempted a different number of times
833  * each time it executes].
834  *
835  * Whereas vTaskDelay () specifies a wake time relative to the time at which the function
836  * is called, vTaskDelayUntil () specifies the absolute (exact) time at which it wishes to
837  * unblock.
838  *
839  * The constant portTICK_PERIOD_MS can be used to calculate real time from the tick
840  * rate - with the resolution of one tick period.
841  *
842  * @param pxPreviousWakeTime Pointer to a variable that holds the time at which the
843  * task was last unblocked.  The variable must be initialised with the current time
844  * prior to its first use (see the example below).  Following this the variable is
845  * automatically updated within vTaskDelayUntil ().
846  *
847  * @param xTimeIncrement The cycle time period.  The task will be unblocked at
848  * time *pxPreviousWakeTime + xTimeIncrement.  Calling vTaskDelayUntil with the
849  * same xTimeIncrement parameter value will cause the task to execute with
850  * a fixed interface period.
851  *
852  * Example usage:
853  * @code{c}
854  *  // Perform an action every 10 ticks.
855  *  void vTaskFunction( void * pvParameters )
856  *  {
857  *  TickType_t xLastWakeTime;
858  *  const TickType_t xFrequency = 10;
859  *
860  *       // Initialise the xLastWakeTime variable with the current time.
861  *       xLastWakeTime = xTaskGetTickCount ();
862  *       for( ;; )
863  *       {
864  *               // Wait for the next cycle.
865  *               vTaskDelayUntil( &xLastWakeTime, xFrequency );
866  *
867  *               // Perform action here.
868  *       }
869  *  }
870  * @endcode
871  * \ingroup TaskCtrl
872  */
873 void vTaskDelayUntil( TickType_t * const pxPreviousWakeTime, const TickType_t xTimeIncrement ) PRIVILEGED_FUNCTION;
874
875 /**
876  * Obtain the priority of any task.
877  *
878  * INCLUDE_uxTaskPriorityGet must be defined as 1 for this function to be available.
879  * See the configuration section for more information.
880  *
881  * @param xTask Handle of the task to be queried.  Passing a NULL
882  * handle results in the priority of the calling task being returned.
883  *
884  * @return The priority of xTask.
885  *
886  * Example usage:
887  * @code{c}
888  *  void vAFunction( void )
889  *  {
890  *  TaskHandle_t xHandle;
891  *
892  *   // Create a task, storing the handle.
893  *   xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
894  *
895  *   // ...
896  *
897  *   // Use the handle to obtain the priority of the created task.
898  *   // It was created with tskIDLE_PRIORITY, but may have changed
899  *   // it itself.
900  *   if( uxTaskPriorityGet( xHandle ) != tskIDLE_PRIORITY )
901  *   {
902  *       // The task has changed it's priority.
903  *   }
904  *
905  *   // ...
906  *
907  *   // Is our priority higher than the created task?
908  *   if( uxTaskPriorityGet( xHandle ) < uxTaskPriorityGet( NULL ) )
909  *   {
910  *       // Our priority (obtained using NULL handle) is higher.
911  *   }
912  * }
913  * @endcode
914  * \ingroup TaskCtrl
915  */
916 UBaseType_t uxTaskPriorityGet( TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
917
918 /**
919  * A version of uxTaskPriorityGet() that can be used from an ISR.
920  *
921  * @param xTask Handle of the task to be queried.  Passing a NULL
922  * handle results in the priority of the calling task being returned.
923  *
924  * @return The priority of xTask.
925  *
926  */
927 UBaseType_t uxTaskPriorityGetFromISR( TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
928
929 /**
930  * Obtain the state of any task.
931  *
932  * States are encoded by the eTaskState enumerated type.
933  *
934  * INCLUDE_eTaskGetState must be defined as 1 for this function to be available.
935  * See the configuration section for more information.
936  *
937  * @param xTask Handle of the task to be queried.
938  *
939  * @return The state of xTask at the time the function was called.  Note the
940  * state of the task might change between the function being called, and the
941  * functions return value being tested by the calling task.
942  */
943 eTaskState eTaskGetState( TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
944
945 /**
946  * Set the priority of any task.
947  *
948  * INCLUDE_vTaskPrioritySet must be defined as 1 for this function to be available.
949  * See the configuration section for more information.
950  *
951  * A context switch will occur before the function returns if the priority
952  * being set is higher than the currently executing task.
953  *
954  * @param xTask Handle to the task for which the priority is being set.
955  * Passing a NULL handle results in the priority of the calling task being set.
956  *
957  * @param uxNewPriority The priority to which the task will be set.
958  *
959  * Example usage:
960  * @code{c}
961  *  void vAFunction( void )
962  *  {
963  *  TaskHandle_t xHandle;
964  *
965  *   // Create a task, storing the handle.
966  *   xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
967  *
968  *   // ...
969  *
970  *   // Use the handle to raise the priority of the created task.
971  *   vTaskPrioritySet( xHandle, tskIDLE_PRIORITY + 1 );
972  *
973  *   // ...
974  *
975  *   // Use a NULL handle to raise our priority to the same value.
976  *   vTaskPrioritySet( NULL, tskIDLE_PRIORITY + 1 );
977  *  }
978  * @endcode
979  * \ingroup TaskCtrl
980  */
981 void vTaskPrioritySet( TaskHandle_t xTask, UBaseType_t uxNewPriority ) PRIVILEGED_FUNCTION;
982
983 /**
984  * Suspend a task.
985  *
986  * INCLUDE_vTaskSuspend must be defined as 1 for this function to be available.
987  * See the configuration section for more information.
988  *
989  * When suspended, a task will never get any microcontroller processing time,
990  * no matter what its priority.
991  *
992  * Calls to vTaskSuspend are not accumulative -
993  * i.e. calling vTaskSuspend () twice on the same task still only requires one
994  * call to vTaskResume () to ready the suspended task.
995  *
996  * @param xTaskToSuspend Handle to the task being suspended.  Passing a NULL
997  * handle will cause the calling task to be suspended.
998  *
999  * Example usage:
1000  * @code{c}
1001  *  void vAFunction( void )
1002  *  {
1003  *  TaskHandle_t xHandle;
1004  *
1005  *   // Create a task, storing the handle.
1006  *   xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
1007  *
1008  *   // ...
1009  *
1010  *   // Use the handle to suspend the created task.
1011  *   vTaskSuspend( xHandle );
1012  *
1013  *   // ...
1014  *
1015  *   // The created task will not run during this period, unless
1016  *   // another task calls vTaskResume( xHandle ).
1017  *
1018  *   //...
1019  *
1020  *
1021  *   // Suspend ourselves.
1022  *   vTaskSuspend( NULL );
1023  *
1024  *   // We cannot get here unless another task calls vTaskResume
1025  *   // with our handle as the parameter.
1026  *  }
1027  * @endcode
1028  * \ingroup TaskCtrl
1029  */
1030 void vTaskSuspend( TaskHandle_t xTaskToSuspend ) PRIVILEGED_FUNCTION;
1031
1032 /**
1033  * Resumes a suspended task.
1034  *
1035  * INCLUDE_vTaskSuspend must be defined as 1 for this function to be available.
1036  * See the configuration section for more information.
1037  *
1038  * A task that has been suspended by one or more calls to vTaskSuspend ()
1039  * will be made available for running again by a single call to
1040  * vTaskResume ().
1041  *
1042  * @param xTaskToResume Handle to the task being readied.
1043  *
1044  * Example usage:
1045  * @code{c}
1046  *  void vAFunction( void )
1047  *  {
1048  *  TaskHandle_t xHandle;
1049  *
1050  *   // Create a task, storing the handle.
1051  *   xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
1052  *
1053  *   // ...
1054  *
1055  *   // Use the handle to suspend the created task.
1056  *   vTaskSuspend( xHandle );
1057  *
1058  *   // ...
1059  *
1060  *   // The created task will not run during this period, unless
1061  *   // another task calls vTaskResume( xHandle ).
1062  *
1063  *   //...
1064  *
1065  *
1066  *   // Resume the suspended task ourselves.
1067  *   vTaskResume( xHandle );
1068  *
1069  *   // The created task will once again get microcontroller processing
1070  *   // time in accordance with its priority within the system.
1071  *  }
1072  * @endcode
1073  * \ingroup TaskCtrl
1074  */
1075 void vTaskResume( TaskHandle_t xTaskToResume ) PRIVILEGED_FUNCTION;
1076
1077 /**
1078  * An implementation of vTaskResume() that can be called from within an ISR.
1079  *
1080  * INCLUDE_xTaskResumeFromISR must be defined as 1 for this function to be
1081  * available.  See the configuration section for more information.
1082  *
1083  * A task that has been suspended by one or more calls to vTaskSuspend ()
1084  * will be made available for running again by a single call to
1085  * xTaskResumeFromISR ().
1086  *
1087  * xTaskResumeFromISR() should not be used to synchronise a task with an
1088  * interrupt if there is a chance that the interrupt could arrive prior to the
1089  * task being suspended - as this can lead to interrupts being missed. Use of a
1090  * semaphore as a synchronisation mechanism would avoid this eventuality.
1091  *
1092  * @param xTaskToResume Handle to the task being readied.
1093  *
1094  * @return pdTRUE if resuming the task should result in a context switch,
1095  * otherwise pdFALSE. This is used by the ISR to determine if a context switch
1096  * may be required following the ISR.
1097  *
1098  * \ingroup TaskCtrl
1099  */
1100 BaseType_t xTaskResumeFromISR( TaskHandle_t xTaskToResume ) PRIVILEGED_FUNCTION;
1101
1102 /*-----------------------------------------------------------
1103  * SCHEDULER CONTROL
1104  *----------------------------------------------------------*/
1105 /** @cond */
1106 /**
1107  * Starts the real time kernel tick processing.
1108  *
1109  * After calling the kernel has control over which tasks are executed and when.
1110  *
1111  * See the demo application file main.c for an example of creating
1112  * tasks and starting the kernel.
1113  *
1114  * Example usage:
1115  * @code{c}
1116  *  void vAFunction( void )
1117  *  {
1118  *   // Create at least one task before starting the kernel.
1119  *   xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
1120  *
1121  *   // Start the real time kernel with preemption.
1122  *   vTaskStartScheduler ();
1123  *
1124  *   // Will not get here unless a task calls vTaskEndScheduler ()
1125  *  }
1126  * @endcode
1127  *
1128  * \ingroup SchedulerControl
1129  */
1130 void vTaskStartScheduler( void ) PRIVILEGED_FUNCTION;
1131
1132 /**
1133  * Stops the real time kernel tick.
1134  *
1135  * @note At the time of writing only the x86 real mode port, which runs on a PC
1136  * in place of DOS, implements this function.
1137  *
1138  * All created tasks will be automatically deleted and multitasking
1139  * (either preemptive or cooperative) will stop.
1140  * Execution then resumes from the point where vTaskStartScheduler ()
1141  * was called, as if vTaskStartScheduler () had just returned.
1142  *
1143  * See the demo application file main. c in the demo/PC directory for an
1144  * example that uses vTaskEndScheduler ().
1145  *
1146  * vTaskEndScheduler () requires an exit function to be defined within the
1147  * portable layer (see vPortEndScheduler () in port. c for the PC port).  This
1148  * performs hardware specific operations such as stopping the kernel tick.
1149  *
1150  * vTaskEndScheduler () will cause all of the resources allocated by the
1151  * kernel to be freed - but will not free resources allocated by application
1152  * tasks.
1153  *
1154  * Example usage:
1155  * @code{c}
1156  *  void vTaskCode( void * pvParameters )
1157  *  {
1158  *   for( ;; )
1159  *   {
1160  *       // Task code goes here.
1161  *
1162  *       // At some point we want to end the real time kernel processing
1163  *       // so call ...
1164  *       vTaskEndScheduler ();
1165  *   }
1166  *  }
1167  *
1168  *  void vAFunction( void )
1169  *  {
1170  *   // Create at least one task before starting the kernel.
1171  *   xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
1172  *
1173  *   // Start the real time kernel with preemption.
1174  *   vTaskStartScheduler ();
1175  *
1176  *   // Will only get here when the vTaskCode () task has called
1177  *   // vTaskEndScheduler ().  When we get here we are back to single task
1178  *   // execution.
1179  *  }
1180  * @endcode
1181  * \ingroup SchedulerControl
1182  */
1183 void vTaskEndScheduler( void ) PRIVILEGED_FUNCTION;
1184
1185 /** @endcond */
1186
1187 /**
1188  * Suspends the scheduler without disabling interrupts.
1189  *
1190  * Context switches will not occur while the scheduler is suspended.
1191  *
1192  * After calling vTaskSuspendAll () the calling task will continue to execute
1193  * without risk of being swapped out until a call to xTaskResumeAll () has been
1194  * made.
1195  *
1196  * API functions that have the potential to cause a context switch (for example,
1197  * vTaskDelayUntil(), xQueueSend(), etc.) must not be called while the scheduler
1198  * is suspended.
1199  *
1200  * Example usage:
1201  * @code{c}
1202  *  void vTask1( void * pvParameters )
1203  *  {
1204  *   for( ;; )
1205  *   {
1206  *       // Task code goes here.
1207  *
1208  *       // ...
1209  *
1210  *       // At some point the task wants to perform a long operation during
1211  *       // which it does not want to get swapped out.  It cannot use
1212  *       // taskENTER_CRITICAL ()/taskEXIT_CRITICAL () as the length of the
1213  *       // operation may cause interrupts to be missed - including the
1214  *       // ticks.
1215  *
1216  *       // Prevent the real time kernel swapping out the task.
1217  *       vTaskSuspendAll ();
1218  *
1219  *       // Perform the operation here.  There is no need to use critical
1220  *       // sections as we have all the microcontroller processing time.
1221  *       // During this time interrupts will still operate and the kernel
1222  *       // tick count will be maintained.
1223  *
1224  *       // ...
1225  *
1226  *       // The operation is complete.  Restart the kernel.
1227  *       xTaskResumeAll ();
1228  *   }
1229  *  }
1230  * @endcode
1231  * \ingroup SchedulerControl
1232  */
1233 void vTaskSuspendAll( void ) PRIVILEGED_FUNCTION;
1234
1235 /**
1236  * Resumes scheduler activity after it was suspended by a call to
1237  * vTaskSuspendAll().
1238  *
1239  * xTaskResumeAll() only resumes the scheduler.  It does not unsuspend tasks
1240  * that were previously suspended by a call to vTaskSuspend().
1241  *
1242  * @return If resuming the scheduler caused a context switch then pdTRUE is
1243  *                returned, otherwise pdFALSE is returned.
1244  *
1245  * Example usage:
1246  * @code{c}
1247  *  void vTask1( void * pvParameters )
1248  *  {
1249  *   for( ;; )
1250  *   {
1251  *       // Task code goes here.
1252  *
1253  *       // ...
1254  *
1255  *       // At some point the task wants to perform a long operation during
1256  *       // which it does not want to get swapped out.  It cannot use
1257  *       // taskENTER_CRITICAL ()/taskEXIT_CRITICAL () as the length of the
1258  *       // operation may cause interrupts to be missed - including the
1259  *       // ticks.
1260  *
1261  *       // Prevent the real time kernel swapping out the task.
1262  *       vTaskSuspendAll ();
1263  *
1264  *       // Perform the operation here.  There is no need to use critical
1265  *       // sections as we have all the microcontroller processing time.
1266  *       // During this time interrupts will still operate and the real
1267  *       // time kernel tick count will be maintained.
1268  *
1269  *       // ...
1270  *
1271  *       // The operation is complete.  Restart the kernel.  We want to force
1272  *       // a context switch - but there is no point if resuming the scheduler
1273  *       // caused a context switch already.
1274  *       if( !xTaskResumeAll () )
1275  *       {
1276  *            taskYIELD ();
1277  *       }
1278  *   }
1279  *  }
1280  * @endcode
1281  * \ingroup SchedulerControl
1282  */
1283 BaseType_t xTaskResumeAll( void ) PRIVILEGED_FUNCTION;
1284
1285 /*-----------------------------------------------------------
1286  * TASK UTILITIES
1287  *----------------------------------------------------------*/
1288
1289 /**
1290  * Get tick count
1291  *
1292  * @return The count of ticks since vTaskStartScheduler was called.
1293  *
1294  * \ingroup TaskUtils
1295  */
1296 TickType_t xTaskGetTickCount( void ) PRIVILEGED_FUNCTION;
1297
1298 /**
1299  * Get tick count from ISR
1300  *
1301  * @return The count of ticks since vTaskStartScheduler was called.
1302  *
1303  * This is a version of xTaskGetTickCount() that is safe to be called from an
1304  * ISR - provided that TickType_t is the natural word size of the
1305  * microcontroller being used or interrupt nesting is either not supported or
1306  * not being used.
1307  *
1308  * \ingroup TaskUtils
1309  */
1310 TickType_t xTaskGetTickCountFromISR( void ) PRIVILEGED_FUNCTION;
1311
1312 /**
1313  * Get current number of tasks
1314  *
1315  * @return The number of tasks that the real time kernel is currently managing.
1316  * This includes all ready, blocked and suspended tasks.  A task that
1317  * has been deleted but not yet freed by the idle task will also be
1318  * included in the count.
1319  *
1320  * \ingroup TaskUtils
1321  */
1322 UBaseType_t uxTaskGetNumberOfTasks( void ) PRIVILEGED_FUNCTION;
1323
1324 /**
1325  * Get task name
1326  *
1327  * @return The text (human readable) name of the task referenced by the handle
1328  * xTaskToQuery.  A task can query its own name by either passing in its own
1329  * handle, or by setting xTaskToQuery to NULL.  INCLUDE_pcTaskGetTaskName must be
1330  * set to 1 in FreeRTOSConfig.h for pcTaskGetTaskName() to be available.
1331  *
1332  * \ingroup TaskUtils
1333  */
1334 char *pcTaskGetTaskName( TaskHandle_t xTaskToQuery ) PRIVILEGED_FUNCTION; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
1335
1336 /**
1337  * Returns the high water mark of the stack associated with xTask.
1338  *
1339  * INCLUDE_uxTaskGetStackHighWaterMark must be set to 1 in FreeRTOSConfig.h for
1340  * this function to be available.
1341  *
1342  * High water mark is the minimum free stack space there has been (in words,
1343  * so on a 32 bit machine a value of 1 means 4 bytes) since the task started.
1344  * The smaller the returned number the closer the task has come to overflowing its stack.
1345  *
1346  * @param xTask Handle of the task associated with the stack to be checked.
1347  * Set xTask to NULL to check the stack of the calling task.
1348  *
1349  * @return The smallest amount of free stack space there has been (in words, so
1350  * actual spaces on the stack rather than bytes) since the task referenced by
1351  * xTask was created.
1352  */
1353 UBaseType_t uxTaskGetStackHighWaterMark( TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
1354
1355 /**
1356  * Returns the start of the stack associated with xTask.
1357  *
1358  * INCLUDE_pxTaskGetStackStart must be set to 1 in FreeRTOSConfig.h for
1359  * this function to be available.
1360  *
1361  * Returns the highest stack memory address on architectures where the stack grows down
1362  * from high memory, and the lowest memory address on architectures where the
1363  * stack grows up from low memory.
1364  *
1365  * @param xTask Handle of the task associated with the stack returned.
1366  * Set xTask to NULL to return the stack of the calling task.
1367  *
1368  * @return A pointer to the start of the stack.
1369  */
1370 uint8_t* pxTaskGetStackStart( TaskHandle_t xTask) PRIVILEGED_FUNCTION;
1371
1372 /* When using trace macros it is sometimes necessary to include task.h before
1373 FreeRTOS.h.  When this is done TaskHookFunction_t will not yet have been defined,
1374 so the following two prototypes will cause a compilation error.  This can be
1375 fixed by simply guarding against the inclusion of these two prototypes unless
1376 they are explicitly required by the configUSE_APPLICATION_TASK_TAG configuration
1377 constant. */
1378 #ifdef configUSE_APPLICATION_TASK_TAG
1379         #if configUSE_APPLICATION_TASK_TAG == 1
1380                 /**
1381                  * Sets pxHookFunction to be the task hook function used by the task xTask.
1382                  * @param xTask Handle of the task to set the hook function for
1383                  *              Passing xTask as NULL has the effect of setting the calling
1384                  *              tasks hook function.
1385                  * @param pxHookFunction  Pointer to the hook function.
1386                  */
1387                 void vTaskSetApplicationTaskTag( TaskHandle_t xTask, TaskHookFunction_t pxHookFunction ) PRIVILEGED_FUNCTION;
1388
1389                 /**
1390                  * Get the hook function assigned to given task.
1391                  * @param xTask Handle of the task to get the hook function for
1392                  *              Passing xTask as NULL has the effect of getting the calling
1393                  *              tasks hook function.
1394                  * @return The pxHookFunction value assigned to the task xTask.
1395                  */
1396                 TaskHookFunction_t xTaskGetApplicationTaskTag( TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
1397         #endif /* configUSE_APPLICATION_TASK_TAG ==1 */
1398 #endif /* ifdef configUSE_APPLICATION_TASK_TAG */
1399 #if( configNUM_THREAD_LOCAL_STORAGE_POINTERS > 0 )
1400
1401         /**
1402          * Set local storage pointer specific to the given task.
1403          *
1404          * Each task contains an array of pointers that is dimensioned by the
1405          * configNUM_THREAD_LOCAL_STORAGE_POINTERS setting in FreeRTOSConfig.h.
1406          * The kernel does not use the pointers itself, so the application writer
1407          * can use the pointers for any purpose they wish.
1408          *
1409          * @param xTaskToSet  Task to set thread local storage pointer for
1410          * @param xIndex The index of the pointer to set, from 0 to
1411          *               configNUM_THREAD_LOCAL_STORAGE_POINTERS - 1.
1412          * @param pvValue  Pointer value to set.
1413          */
1414         void vTaskSetThreadLocalStoragePointer( TaskHandle_t xTaskToSet, BaseType_t xIndex, void *pvValue ) PRIVILEGED_FUNCTION;
1415
1416
1417         /**
1418          * Get local storage pointer specific to the given task.
1419          *
1420          * Each task contains an array of pointers that is dimensioned by the
1421          * configNUM_THREAD_LOCAL_STORAGE_POINTERS setting in FreeRTOSConfig.h.
1422          * The kernel does not use the pointers itself, so the application writer
1423          * can use the pointers for any purpose they wish.
1424          *
1425          * @param xTaskToQuery  Task to get thread local storage pointer for
1426          * @param xIndex The index of the pointer to get, from 0 to
1427          *               configNUM_THREAD_LOCAL_STORAGE_POINTERS - 1.
1428          * @return  Pointer value
1429          */
1430         void *pvTaskGetThreadLocalStoragePointer( TaskHandle_t xTaskToQuery, BaseType_t xIndex ) PRIVILEGED_FUNCTION;
1431
1432         #if ( configTHREAD_LOCAL_STORAGE_DELETE_CALLBACKS )
1433
1434                 /**
1435                  * Prototype of local storage pointer deletion callback.
1436                  */
1437                 typedef void (*TlsDeleteCallbackFunction_t)( int, void * );
1438
1439                 /**
1440                  * Set local storage pointer and deletion callback.
1441                  *
1442                  * Each task contains an array of pointers that is dimensioned by the
1443                  * configNUM_THREAD_LOCAL_STORAGE_POINTERS setting in FreeRTOSConfig.h.
1444                  * The kernel does not use the pointers itself, so the application writer
1445                  * can use the pointers for any purpose they wish.
1446                  *
1447                  * Local storage pointers set for a task can reference dynamically
1448                  * allocated resources. This function is similar to
1449                  * vTaskSetThreadLocalStoragePointer, but provides a way to release
1450                  * these resources when the task gets deleted. For each pointer,
1451                  * a callback function can be set. This function will be called
1452                  * when task is deleted, with the local storage pointer index
1453                  * and value as arguments.
1454                  *
1455                  * @param xTaskToSet  Task to set thread local storage pointer for
1456                  * @param xIndex The index of the pointer to set, from 0 to
1457                  *               configNUM_THREAD_LOCAL_STORAGE_POINTERS - 1.
1458                  * @param pvValue  Pointer value to set.
1459                  * @param pvDelCallback  Function to call to dispose of the local
1460                  *                       storage pointer when the task is deleted.
1461                  */
1462                 void vTaskSetThreadLocalStoragePointerAndDelCallback( TaskHandle_t xTaskToSet, BaseType_t xIndex, void *pvValue, TlsDeleteCallbackFunction_t pvDelCallback);
1463         #endif
1464
1465 #endif
1466
1467 /**
1468  * Calls the hook function associated with xTask. Passing xTask as NULL has
1469  * the effect of calling the Running tasks (the calling task) hook function.
1470  *
1471  * @param xTask  Handle of the task to call the hook for.
1472  * @param pvParameter  Parameter passed to the hook function for the task to interpret as it
1473  * wants.  The return value is the value returned by the task hook function
1474  * registered by the user.
1475  */
1476 BaseType_t xTaskCallApplicationTaskHook( TaskHandle_t xTask, void *pvParameter ) PRIVILEGED_FUNCTION;
1477
1478 /**
1479  * Get the handle of idle task for the current CPU.
1480  *
1481  * xTaskGetIdleTaskHandle() is only available if
1482  * INCLUDE_xTaskGetIdleTaskHandle is set to 1 in FreeRTOSConfig.h.
1483  *
1484  * @return The handle of the idle task.  It is not valid to call
1485  * xTaskGetIdleTaskHandle() before the scheduler has been started.
1486  */
1487 TaskHandle_t xTaskGetIdleTaskHandle( void );
1488
1489 /**
1490  * Get the handle of idle task for the given CPU.
1491  *
1492  * xTaskGetIdleTaskHandleForCPU() is only available if
1493  * INCLUDE_xTaskGetIdleTaskHandle is set to 1 in FreeRTOSConfig.h.
1494  *
1495  * @param cpuid The CPU to get the handle for
1496  *
1497  * @return Idle task handle of a given cpu. It is not valid to call
1498  * xTaskGetIdleTaskHandleForCPU() before the scheduler has been started.
1499  */
1500 TaskHandle_t xTaskGetIdleTaskHandleForCPU( UBaseType_t cpuid );
1501
1502 /**
1503  * Get the state of tasks in the system.
1504  *
1505  * configUSE_TRACE_FACILITY must be defined as 1 in FreeRTOSConfig.h for
1506  * uxTaskGetSystemState() to be available.
1507  *
1508  * uxTaskGetSystemState() populates an TaskStatus_t structure for each task in
1509  * the system.  TaskStatus_t structures contain, among other things, members
1510  * for the task handle, task name, task priority, task state, and total amount
1511  * of run time consumed by the task.  See the TaskStatus_t structure
1512  * definition in this file for the full member list.
1513  *
1514  * @note  This function is intended for debugging use only as its use results in
1515  * the scheduler remaining suspended for an extended period.
1516  *
1517  * @param pxTaskStatusArray A pointer to an array of TaskStatus_t structures.
1518  * The array must contain at least one TaskStatus_t structure for each task
1519  * that is under the control of the RTOS.  The number of tasks under the control
1520  * of the RTOS can be determined using the uxTaskGetNumberOfTasks() API function.
1521  *
1522  * @param uxArraySize The size of the array pointed to by the pxTaskStatusArray
1523  * parameter.  The size is specified as the number of indexes in the array, or
1524  * the number of TaskStatus_t structures contained in the array, not by the
1525  * number of bytes in the array.
1526  *
1527  * @param pulTotalRunTime If configGENERATE_RUN_TIME_STATS is set to 1 in
1528  * FreeRTOSConfig.h then *pulTotalRunTime is set by uxTaskGetSystemState() to the
1529  * total run time (as defined by the run time stats clock, see
1530  * http://www.freertos.org/rtos-run-time-stats.html) since the target booted.
1531  * pulTotalRunTime can be set to NULL to omit the total run time information.
1532  *
1533  * @return The number of TaskStatus_t structures that were populated by
1534  * uxTaskGetSystemState().  This should equal the number returned by the
1535  * uxTaskGetNumberOfTasks() API function, but will be zero if the value passed
1536  * in the uxArraySize parameter was too small.
1537  *
1538  * Example usage:
1539  * @code{c}
1540  * // This example demonstrates how a human readable table of run time stats
1541  * // information is generated from raw data provided by uxTaskGetSystemState().
1542  * // The human readable table is written to pcWriteBuffer
1543  * void vTaskGetRunTimeStats( char *pcWriteBuffer )
1544  * {
1545  * TaskStatus_t *pxTaskStatusArray;
1546  * volatile UBaseType_t uxArraySize, x;
1547  * uint32_t ulTotalRunTime, ulStatsAsPercentage;
1548  *
1549  *  // Make sure the write buffer does not contain a string.
1550  *  *pcWriteBuffer = 0x00;
1551  *
1552  *  // Take a snapshot of the number of tasks in case it changes while this
1553  *  // function is executing.
1554  *  uxArraySize = uxTaskGetNumberOfTasks();
1555  *
1556  *  // Allocate a TaskStatus_t structure for each task.  An array could be
1557  *  // allocated statically at compile time.
1558  *  pxTaskStatusArray = pvPortMalloc( uxArraySize * sizeof( TaskStatus_t ) );
1559  *
1560  *  if( pxTaskStatusArray != NULL )
1561  *  {
1562  *      // Generate raw status information about each task.
1563  *      uxArraySize = uxTaskGetSystemState( pxTaskStatusArray, uxArraySize, &ulTotalRunTime );
1564  *
1565  *      // For percentage calculations.
1566  *      ulTotalRunTime /= 100UL;
1567  *
1568  *      // Avoid divide by zero errors.
1569  *      if( ulTotalRunTime > 0 )
1570  *      {
1571  *          // For each populated position in the pxTaskStatusArray array,
1572  *          // format the raw data as human readable ASCII data
1573  *          for( x = 0; x < uxArraySize; x++ )
1574  *          {
1575  *              // What percentage of the total run time has the task used?
1576  *              // This will always be rounded down to the nearest integer.
1577  *              // ulTotalRunTimeDiv100 has already been divided by 100.
1578  *              ulStatsAsPercentage = pxTaskStatusArray[ x ].ulRunTimeCounter / ulTotalRunTime;
1579  *
1580  *              if( ulStatsAsPercentage > 0UL )
1581  *              {
1582  *                  sprintf( pcWriteBuffer, "%s\t\t%lu\t\t%lu%%\r\n", pxTaskStatusArray[ x ].pcTaskName, pxTaskStatusArray[ x ].ulRunTimeCounter, ulStatsAsPercentage );
1583  *              }
1584  *              else
1585  *              {
1586  *                  // If the percentage is zero here then the task has
1587  *                  // consumed less than 1% of the total run time.
1588  *                  sprintf( pcWriteBuffer, "%s\t\t%lu\t\t<1%%\r\n", pxTaskStatusArray[ x ].pcTaskName, pxTaskStatusArray[ x ].ulRunTimeCounter );
1589  *              }
1590  *
1591  *              pcWriteBuffer += strlen( ( char * ) pcWriteBuffer );
1592  *          }
1593  *      }
1594  *
1595  *      // The array is no longer needed, free the memory it consumes.
1596  *      vPortFree( pxTaskStatusArray );
1597  *  }
1598  * }
1599  * @endcode
1600  */
1601 UBaseType_t uxTaskGetSystemState( TaskStatus_t * const pxTaskStatusArray, const UBaseType_t uxArraySize, uint32_t * const pulTotalRunTime );
1602
1603 /**
1604  * List all the current tasks.
1605  *
1606  * configUSE_TRACE_FACILITY and configUSE_STATS_FORMATTING_FUNCTIONS must
1607  * both be defined as 1 for this function to be available.  See the
1608  * configuration section of the FreeRTOS.org website for more information.
1609  *
1610  * @note This function will disable interrupts for its duration.  It is
1611  * not intended for normal application runtime use but as a debug aid.
1612  *
1613  * Lists all the current tasks, along with their current state and stack
1614  * usage high water mark.
1615  *
1616  * Tasks are reported as blocked ('B'), ready ('R'), deleted ('D') or
1617  * suspended ('S').
1618  *
1619  * @note This function is provided for convenience only, and is used by many of the
1620  * demo applications.  Do not consider it to be part of the scheduler.
1621  *
1622  * vTaskList() calls uxTaskGetSystemState(), then formats part of the
1623  * uxTaskGetSystemState() output into a human readable table that displays task
1624  * names, states and stack usage.
1625  *
1626  * vTaskList() has a dependency on the sprintf() C library function that might
1627  * bloat the code size, use a lot of stack, and provide different results on
1628  * different platforms.  An alternative, tiny, third party, and limited
1629  * functionality implementation of sprintf() is provided in many of the
1630  * FreeRTOS/Demo sub-directories in a file called printf-stdarg.c (note
1631  * printf-stdarg.c does not provide a full snprintf() implementation!).
1632  *
1633  * It is recommended that production systems call uxTaskGetSystemState()
1634  * directly to get access to raw stats data, rather than indirectly through a
1635  * call to vTaskList().
1636  *
1637  * @param pcWriteBuffer A buffer into which the above mentioned details
1638  * will be written, in ASCII form.  This buffer is assumed to be large
1639  * enough to contain the generated report.  Approximately 40 bytes per
1640  * task should be sufficient.
1641  *
1642  * \ingroup TaskUtils
1643  */
1644 void vTaskList( char * pcWriteBuffer ) PRIVILEGED_FUNCTION; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
1645
1646 /**
1647  * Get the state of running tasks as a string
1648  *
1649  * configGENERATE_RUN_TIME_STATS and configUSE_STATS_FORMATTING_FUNCTIONS
1650  * must both be defined as 1 for this function to be available.  The application
1651  * must also then provide definitions for
1652  * portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() and portGET_RUN_TIME_COUNTER_VALUE()
1653  * to configure a peripheral timer/counter and return the timers current count
1654  * value respectively.  The counter should be at least 10 times the frequency of
1655  * the tick count.
1656  *
1657  * @note This function will disable interrupts for its duration.  It is
1658  * not intended for normal application runtime use but as a debug aid.
1659  *
1660  * Setting configGENERATE_RUN_TIME_STATS to 1 will result in a total
1661  * accumulated execution time being stored for each task.  The resolution
1662  * of the accumulated time value depends on the frequency of the timer
1663  * configured by the portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() macro.
1664  * Calling vTaskGetRunTimeStats() writes the total execution time of each
1665  * task into a buffer, both as an absolute count value and as a percentage
1666  * of the total system execution time.
1667  *
1668  * @note This function is provided for convenience only, and is used by many of the
1669  * demo applications.  Do not consider it to be part of the scheduler.
1670  *
1671  * vTaskGetRunTimeStats() calls uxTaskGetSystemState(), then formats part of the
1672  * uxTaskGetSystemState() output into a human readable table that displays the
1673  * amount of time each task has spent in the Running state in both absolute and
1674  * percentage terms.
1675  *
1676  * vTaskGetRunTimeStats() has a dependency on the sprintf() C library function
1677  * that might bloat the code size, use a lot of stack, and provide different
1678  * results on different platforms.  An alternative, tiny, third party, and
1679  * limited functionality implementation of sprintf() is provided in many of the
1680  * FreeRTOS/Demo sub-directories in a file called printf-stdarg.c (note
1681  * printf-stdarg.c does not provide a full snprintf() implementation!).
1682  *
1683  * It is recommended that production systems call uxTaskGetSystemState() directly
1684  * to get access to raw stats data, rather than indirectly through a call to
1685  * vTaskGetRunTimeStats().
1686  *
1687  * @param pcWriteBuffer A buffer into which the execution times will be
1688  * written, in ASCII form.  This buffer is assumed to be large enough to
1689  * contain the generated report.  Approximately 40 bytes per task should
1690  * be sufficient.
1691  *
1692  * \ingroup TaskUtils
1693  */
1694 void vTaskGetRunTimeStats( char *pcWriteBuffer ) PRIVILEGED_FUNCTION; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
1695
1696 /**
1697  * Send task notification.
1698  *
1699  * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for this
1700  * function to be available.
1701  *
1702  * When configUSE_TASK_NOTIFICATIONS is set to one each task has its own private
1703  * "notification value", which is a 32-bit unsigned integer (uint32_t).
1704  *
1705  * Events can be sent to a task using an intermediary object.  Examples of such
1706  * objects are queues, semaphores, mutexes and event groups.  Task notifications
1707  * are a method of sending an event directly to a task without the need for such
1708  * an intermediary object.
1709  *
1710  * A notification sent to a task can optionally perform an action, such as
1711  * update, overwrite or increment the task's notification value.  In that way
1712  * task notifications can be used to send data to a task, or be used as light
1713  * weight and fast binary or counting semaphores.
1714  *
1715  * A notification sent to a task will remain pending until it is cleared by the
1716  * task calling xTaskNotifyWait() or ulTaskNotifyTake().  If the task was
1717  * already in the Blocked state to wait for a notification when the notification
1718  * arrives then the task will automatically be removed from the Blocked state
1719  * (unblocked) and the notification cleared.
1720  *
1721  * A task can use xTaskNotifyWait() to [optionally] block to wait for a
1722  * notification to be pending, or ulTaskNotifyTake() to [optionally] block
1723  * to wait for its notification value to have a non-zero value.  The task does
1724  * not consume any CPU time while it is in the Blocked state.
1725  *
1726  * See http://www.FreeRTOS.org/RTOS-task-notifications.html for details.
1727  *
1728  * @param xTaskToNotify The handle of the task being notified.  The handle to a
1729  * task can be returned from the xTaskCreate() API function used to create the
1730  * task, and the handle of the currently running task can be obtained by calling
1731  * xTaskGetCurrentTaskHandle().
1732  *
1733  * @param ulValue Data that can be sent with the notification.  How the data is
1734  * used depends on the value of the eAction parameter.
1735  *
1736  * @param eAction Specifies how the notification updates the task's notification
1737  * value, if at all.  Valid values for eAction are as follows:
1738  *      - eSetBits:
1739  *        The task's notification value is bitwise ORed with ulValue.  xTaskNofify()
1740  *        always returns pdPASS in this case.
1741  *
1742  *      - eIncrement:
1743  *        The task's notification value is incremented.  ulValue is not used and
1744  *        xTaskNotify() always returns pdPASS in this case.
1745  *
1746  *      - eSetValueWithOverwrite:
1747  *        The task's notification value is set to the value of ulValue, even if the
1748  *        task being notified had not yet processed the previous notification (the
1749  *        task already had a notification pending).  xTaskNotify() always returns
1750  *        pdPASS in this case.
1751  *
1752  *      - eSetValueWithoutOverwrite:
1753  *        If the task being notified did not already have a notification pending then
1754  *        the task's notification value is set to ulValue and xTaskNotify() will
1755  *        return pdPASS.  If the task being notified already had a notification
1756  *        pending then no action is performed and pdFAIL is returned.
1757  *
1758  *      - eNoAction:
1759  *        The task receives a notification without its notification value being
1760  *      Â Â updated.  ulValue is not used and xTaskNotify() always returns pdPASS in
1761  *        this case.
1762  *
1763  * @return Dependent on the value of eAction.  See the description of the
1764  * eAction parameter.
1765  *
1766  * \ingroup TaskNotifications
1767  */
1768 BaseType_t xTaskNotify( TaskHandle_t xTaskToNotify, uint32_t ulValue, eNotifyAction eAction );
1769
1770 /**
1771  * Send task notification from an ISR.
1772  *
1773  * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for this
1774  * function to be available.
1775  *
1776  * When configUSE_TASK_NOTIFICATIONS is set to one each task has its own private
1777  * "notification value", which is a 32-bit unsigned integer (uint32_t).
1778  *
1779  * A version of xTaskNotify() that can be used from an interrupt service routine
1780  * (ISR).
1781  *
1782  * Events can be sent to a task using an intermediary object.  Examples of such
1783  * objects are queues, semaphores, mutexes and event groups.  Task notifications
1784  * are a method of sending an event directly to a task without the need for such
1785  * an intermediary object.
1786  *
1787  * A notification sent to a task can optionally perform an action, such as
1788  * update, overwrite or increment the task's notification value.  In that way
1789  * task notifications can be used to send data to a task, or be used as light
1790  * weight and fast binary or counting semaphores.
1791  *
1792  * A notification sent to a task will remain pending until it is cleared by the
1793  * task calling xTaskNotifyWait() or ulTaskNotifyTake().  If the task was
1794  * already in the Blocked state to wait for a notification when the notification
1795  * arrives then the task will automatically be removed from the Blocked state
1796  * (unblocked) and the notification cleared.
1797  *
1798  * A task can use xTaskNotifyWait() to [optionally] block to wait for a
1799  * notification to be pending, or ulTaskNotifyTake() to [optionally] block
1800  * to wait for its notification value to have a non-zero value.  The task does
1801  * not consume any CPU time while it is in the Blocked state.
1802  *
1803  * See http://www.FreeRTOS.org/RTOS-task-notifications.html for details.
1804  *
1805  * @param xTaskToNotify The handle of the task being notified.  The handle to a
1806  * task can be returned from the xTaskCreate() API function used to create the
1807  * task, and the handle of the currently running task can be obtained by calling
1808  * xTaskGetCurrentTaskHandle().
1809  *
1810  * @param ulValue Data that can be sent with the notification.  How the data is
1811  * used depends on the value of the eAction parameter.
1812  *
1813  * @param eAction Specifies how the notification updates the task's notification
1814  * value, if at all.  Valid values for eAction are as follows:
1815  *      - eSetBits:
1816  *        The task's notification value is bitwise ORed with ulValue.  xTaskNofify()
1817  *        always returns pdPASS in this case.
1818  *
1819  *      - eIncrement:
1820  *        The task's notification value is incremented.  ulValue is not used and
1821  *        xTaskNotify() always returns pdPASS in this case.
1822  *
1823  *      - eSetValueWithOverwrite:
1824  *        The task's notification value is set to the value of ulValue, even if the
1825  *        task being notified had not yet processed the previous notification (the
1826  *        task already had a notification pending).  xTaskNotify() always returns
1827  *        pdPASS in this case.
1828  *
1829  *      - eSetValueWithoutOverwrite:
1830  *        If the task being notified did not already have a notification pending then
1831  *        the task's notification value is set to ulValue and xTaskNotify() will
1832  *        return pdPASS.  If the task being notified already had a notification
1833  *        pending then no action is performed and pdFAIL is returned.
1834  *
1835  *      - eNoAction:
1836  *        The task receives a notification without its notification value being
1837  *        updated.  ulValue is not used and xTaskNotify() always returns pdPASS in
1838  *        this case.
1839  *
1840  * @param pxHigherPriorityTaskWoken  xTaskNotifyFromISR() will set
1841  * *pxHigherPriorityTaskWoken to pdTRUE if sending the notification caused the
1842  * task to which the notification was sent to leave the Blocked state, and the
1843  * unblocked task has a priority higher than the currently running task.  If
1844  * xTaskNotifyFromISR() sets this value to pdTRUE then a context switch should
1845  * be requested before the interrupt is exited.  How a context switch is
1846  * requested from an ISR is dependent on the port - see the documentation page
1847  * for the port in use.
1848  *
1849  * @return Dependent on the value of eAction.  See the description of the
1850  * eAction parameter.
1851  *
1852  * \ingroup TaskNotifications
1853  */
1854 BaseType_t xTaskNotifyFromISR( TaskHandle_t xTaskToNotify, uint32_t ulValue, eNotifyAction eAction, BaseType_t *pxHigherPriorityTaskWoken );
1855
1856 /**
1857  * Wait for task notification
1858  *
1859  * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for this
1860  * function to be available.
1861  *
1862  * When configUSE_TASK_NOTIFICATIONS is set to one each task has its own private
1863  * "notification value", which is a 32-bit unsigned integer (uint32_t).
1864  *
1865  * Events can be sent to a task using an intermediary object.  Examples of such
1866  * objects are queues, semaphores, mutexes and event groups.  Task notifications
1867  * are a method of sending an event directly to a task without the need for such
1868  * an intermediary object.
1869  *
1870  * A notification sent to a task can optionally perform an action, such as
1871  * update, overwrite or increment the task's notification value.  In that way
1872  * task notifications can be used to send data to a task, or be used as light
1873  * weight and fast binary or counting semaphores.
1874  *
1875  * A notification sent to a task will remain pending until it is cleared by the
1876  * task calling xTaskNotifyWait() or ulTaskNotifyTake().  If the task was
1877  * already in the Blocked state to wait for a notification when the notification
1878  * arrives then the task will automatically be removed from the Blocked state
1879  * (unblocked) and the notification cleared.
1880  *
1881  * A task can use xTaskNotifyWait() to [optionally] block to wait for a
1882  * notification to be pending, or ulTaskNotifyTake() to [optionally] block
1883  * to wait for its notification value to have a non-zero value.  The task does
1884  * not consume any CPU time while it is in the Blocked state.
1885  *
1886  * See http://www.FreeRTOS.org/RTOS-task-notifications.html for details.
1887  *
1888  * @param ulBitsToClearOnEntry Bits that are set in ulBitsToClearOnEntry value
1889  * will be cleared in the calling task's notification value before the task
1890  * checks to see if any notifications are pending, and optionally blocks if no
1891  * notifications are pending.  Setting ulBitsToClearOnEntry to ULONG_MAX (if
1892  * limits.h is included) or 0xffffffffUL (if limits.h is not included) will have
1893  * the effect of resetting the task's notification value to 0.  Setting
1894  * ulBitsToClearOnEntry to 0 will leave the task's notification value unchanged.
1895  *
1896  * @param ulBitsToClearOnExit If a notification is pending or received before
1897  * the calling task exits the xTaskNotifyWait() function then the task's
1898  * notification value (see the xTaskNotify() API function) is passed out using
1899  * the pulNotificationValue parameter.  Then any bits that are set in
1900  * ulBitsToClearOnExit will be cleared in the task's notification value (note
1901  * *pulNotificationValue is set before any bits are cleared).  Setting
1902  * ulBitsToClearOnExit to ULONG_MAX (if limits.h is included) or 0xffffffffUL
1903  * (if limits.h is not included) will have the effect of resetting the task's
1904  * notification value to 0 before the function exits.  Setting
1905  * ulBitsToClearOnExit to 0 will leave the task's notification value unchanged
1906  * when the function exits (in which case the value passed out in
1907  * pulNotificationValue will match the task's notification value).
1908  *
1909  * @param pulNotificationValue Used to pass the task's notification value out
1910  * of the function.  Note the value passed out will not be effected by the
1911  * clearing of any bits caused by ulBitsToClearOnExit being non-zero.
1912  *
1913  * @param xTicksToWait The maximum amount of time that the task should wait in
1914  * the Blocked state for a notification to be received, should a notification
1915  * not already be pending when xTaskNotifyWait() was called.  The task
1916  * will not consume any processing time while it is in the Blocked state.  This
1917  * is specified in kernel ticks, the macro pdMS_TO_TICSK( value_in_ms ) can be
1918  * used to convert a time specified in milliseconds to a time specified in
1919  * ticks.
1920  *
1921  * @return If a notification was received (including notifications that were
1922  * already pending when xTaskNotifyWait was called) then pdPASS is
1923  * returned.  Otherwise pdFAIL is returned.
1924  *
1925  * \ingroup TaskNotifications
1926  */
1927 BaseType_t xTaskNotifyWait( uint32_t ulBitsToClearOnEntry, uint32_t ulBitsToClearOnExit, uint32_t *pulNotificationValue, TickType_t xTicksToWait );
1928
1929 /**
1930  * Simplified macro for sending task notification.
1931  *
1932  * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for this macro
1933  * to be available.
1934  *
1935  * When configUSE_TASK_NOTIFICATIONS is set to one each task has its own private
1936  * "notification value", which is a 32-bit unsigned integer (uint32_t).
1937  *
1938  * Events can be sent to a task using an intermediary object.  Examples of such
1939  * objects are queues, semaphores, mutexes and event groups.  Task notifications
1940  * are a method of sending an event directly to a task without the need for such
1941  * an intermediary object.
1942  *
1943  * A notification sent to a task can optionally perform an action, such as
1944  * update, overwrite or increment the task's notification value.  In that way
1945  * task notifications can be used to send data to a task, or be used as light
1946  * weight and fast binary or counting semaphores.
1947  *
1948  * xTaskNotifyGive() is a helper macro intended for use when task notifications
1949  * are used as light weight and faster binary or counting semaphore equivalents.
1950  * Actual FreeRTOS semaphores are given using the xSemaphoreGive() API function,
1951  * the equivalent action that instead uses a task notification is
1952  * xTaskNotifyGive().
1953  *
1954  * When task notifications are being used as a binary or counting semaphore
1955  * equivalent then the task being notified should wait for the notification
1956  * using the ulTaskNotificationTake() API function rather than the
1957  * xTaskNotifyWait() API function.
1958  *
1959  * See http://www.FreeRTOS.org/RTOS-task-notifications.html for more details.
1960  *
1961  * @param xTaskToNotify The handle of the task being notified.  The handle to a
1962  * task can be returned from the xTaskCreate() API function used to create the
1963  * task, and the handle of the currently running task can be obtained by calling
1964  * xTaskGetCurrentTaskHandle().
1965  *
1966  * @return xTaskNotifyGive() is a macro that calls xTaskNotify() with the
1967  * eAction parameter set to eIncrement - so pdPASS is always returned.
1968  *
1969  * \ingroup TaskNotifications
1970  */
1971 #define xTaskNotifyGive( xTaskToNotify ) xTaskNotify( ( xTaskToNotify ), 0, eIncrement );
1972
1973 /**
1974  * Simplified macro for sending task notification from ISR.
1975  *
1976  * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for this macro
1977  * to be available.
1978  *
1979  * When configUSE_TASK_NOTIFICATIONS is set to one each task has its own private
1980  * "notification value", which is a 32-bit unsigned integer (uint32_t).
1981  *
1982  * A version of xTaskNotifyGive() that can be called from an interrupt service
1983  * routine (ISR).
1984  *
1985  * Events can be sent to a task using an intermediary object.  Examples of such
1986  * objects are queues, semaphores, mutexes and event groups.  Task notifications
1987  * are a method of sending an event directly to a task without the need for such
1988  * an intermediary object.
1989  *
1990  * A notification sent to a task can optionally perform an action, such as
1991  * update, overwrite or increment the task's notification value.  In that way
1992  * task notifications can be used to send data to a task, or be used as light
1993  * weight and fast binary or counting semaphores.
1994  *
1995  * vTaskNotifyGiveFromISR() is intended for use when task notifications are
1996  * used as light weight and faster binary or counting semaphore equivalents.
1997  * Actual FreeRTOS semaphores are given from an ISR using the
1998  * xSemaphoreGiveFromISR() API function, the equivalent action that instead uses
1999  * a task notification is vTaskNotifyGiveFromISR().
2000  *
2001  * When task notifications are being used as a binary or counting semaphore
2002  * equivalent then the task being notified should wait for the notification
2003  * using the ulTaskNotificationTake() API function rather than the
2004  * xTaskNotifyWait() API function.
2005  *
2006  * See http://www.FreeRTOS.org/RTOS-task-notifications.html for more details.
2007  *
2008  * @param xTaskToNotify The handle of the task being notified.  The handle to a
2009  * task can be returned from the xTaskCreate() API function used to create the
2010  * task, and the handle of the currently running task can be obtained by calling
2011  * xTaskGetCurrentTaskHandle().
2012  *
2013  * @param pxHigherPriorityTaskWoken  vTaskNotifyGiveFromISR() will set
2014  * *pxHigherPriorityTaskWoken to pdTRUE if sending the notification caused the
2015  * task to which the notification was sent to leave the Blocked state, and the
2016  * unblocked task has a priority higher than the currently running task.  If
2017  * vTaskNotifyGiveFromISR() sets this value to pdTRUE then a context switch
2018  * should be requested before the interrupt is exited.  How a context switch is
2019  * requested from an ISR is dependent on the port - see the documentation page
2020  * for the port in use.
2021  *
2022  * \ingroup TaskNotifications
2023  */
2024 void vTaskNotifyGiveFromISR( TaskHandle_t xTaskToNotify, BaseType_t *pxHigherPriorityTaskWoken );
2025
2026 /**
2027  * Simplified macro for receiving task notification.
2028  *
2029  * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for this
2030  * function to be available.
2031  *
2032  * When configUSE_TASK_NOTIFICATIONS is set to one each task has its own private
2033  * "notification value", which is a 32-bit unsigned integer (uint32_t).
2034  *
2035  * Events can be sent to a task using an intermediary object.  Examples of such
2036  * objects are queues, semaphores, mutexes and event groups.  Task notifications
2037  * are a method of sending an event directly to a task without the need for such
2038  * an intermediary object.
2039  *
2040  * A notification sent to a task can optionally perform an action, such as
2041  * update, overwrite or increment the task's notification value.  In that way
2042  * task notifications can be used to send data to a task, or be used as light
2043  * weight and fast binary or counting semaphores.
2044  *
2045  * ulTaskNotifyTake() is intended for use when a task notification is used as a
2046  * faster and lighter weight binary or counting semaphore alternative.  Actual
2047  * FreeRTOS semaphores are taken using the xSemaphoreTake() API function, the
2048  * equivalent action that instead uses a task notification is
2049  * ulTaskNotifyTake().
2050  *
2051  * When a task is using its notification value as a binary or counting semaphore
2052  * other tasks should send notifications to it using the xTaskNotifyGive()
2053  * macro, or xTaskNotify() function with the eAction parameter set to
2054  * eIncrement.
2055  *
2056  * ulTaskNotifyTake() can either clear the task's notification value to
2057  * zero on exit, in which case the notification value acts like a binary
2058  * semaphore, or decrement the task's notification value on exit, in which case
2059  * the notification value acts like a counting semaphore.
2060  *
2061  * A task can use ulTaskNotifyTake() to [optionally] block to wait for a
2062  * the task's notification value to be non-zero.  The task does not consume any
2063  * CPU time while it is in the Blocked state.
2064  *
2065  * Where as xTaskNotifyWait() will return when a notification is pending,
2066  * ulTaskNotifyTake() will return when the task's notification value is
2067  * not zero.
2068  *
2069  * See http://www.FreeRTOS.org/RTOS-task-notifications.html for details.
2070  *
2071  * @param xClearCountOnExit if xClearCountOnExit is pdFALSE then the task's
2072  * notification value is decremented when the function exits.  In this way the
2073  * notification value acts like a counting semaphore.  If xClearCountOnExit is
2074  * not pdFALSE then the task's notification value is cleared to zero when the
2075  * function exits.  In this way the notification value acts like a binary
2076  * semaphore.
2077  *
2078  * @param xTicksToWait The maximum amount of time that the task should wait in
2079  * the Blocked state for the task's notification value to be greater than zero,
2080  * should the count not already be greater than zero when
2081  * ulTaskNotifyTake() was called.  The task will not consume any processing
2082  * time while it is in the Blocked state.  This is specified in kernel ticks,
2083  * the macro pdMS_TO_TICSK( value_in_ms ) can be used to convert a time
2084  * specified in milliseconds to a time specified in ticks.
2085  *
2086  * @return The task's notification count before it is either cleared to zero or
2087  * decremented (see the xClearCountOnExit parameter).
2088  *
2089  * \ingroup TaskNotifications
2090  */
2091 uint32_t ulTaskNotifyTake( BaseType_t xClearCountOnExit, TickType_t xTicksToWait );
2092
2093 /*-----------------------------------------------------------
2094  * SCHEDULER INTERNALS AVAILABLE FOR PORTING PURPOSES
2095  *----------------------------------------------------------*/
2096 /** @cond */
2097 /*
2098  * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE.  IT IS ONLY
2099  * INTENDED FOR USE WHEN IMPLEMENTING A PORT OF THE SCHEDULER AND IS
2100  * AN INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.
2101  *
2102  * Called from the real time kernel tick (either preemptive or cooperative),
2103  * this increments the tick count and checks if any tasks that are blocked
2104  * for a finite period required removing from a blocked list and placing on
2105  * a ready list.  If a non-zero value is returned then a context switch is
2106  * required because either:
2107  *   + A task was removed from a blocked list because its timeout had expired,
2108  *     or
2109  *   + Time slicing is in use and there is a task of equal priority to the
2110  *     currently running task.
2111  */
2112 BaseType_t xTaskIncrementTick( void ) PRIVILEGED_FUNCTION;
2113
2114 /*
2115  * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE.  IT IS AN
2116  * INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.
2117  *
2118  * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED.
2119  *
2120  * Removes the calling task from the ready list and places it both
2121  * on the list of tasks waiting for a particular event, and the
2122  * list of delayed tasks.  The task will be removed from both lists
2123  * and replaced on the ready list should either the event occur (and
2124  * there be no higher priority tasks waiting on the same event) or
2125  * the delay period expires.
2126  *
2127  * The 'unordered' version replaces the event list item value with the
2128  * xItemValue value, and inserts the list item at the end of the list.
2129  *
2130  * The 'ordered' version uses the existing event list item value (which is the
2131  * owning tasks priority) to insert the list item into the event list is task
2132  * priority order.
2133  *
2134  * @param pxEventList The list containing tasks that are blocked waiting
2135  * for the event to occur.
2136  *
2137  * @param xItemValue The item value to use for the event list item when the
2138  * event list is not ordered by task priority.
2139  *
2140  * @param xTicksToWait The maximum amount of time that the task should wait
2141  * for the event to occur.  This is specified in kernel ticks,the constant
2142  * portTICK_PERIOD_MS can be used to convert kernel ticks into a real time
2143  * period.
2144  */
2145 void vTaskPlaceOnEventList( List_t * const pxEventList, const TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
2146 void vTaskPlaceOnUnorderedEventList( List_t * pxEventList, const TickType_t xItemValue, const TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
2147
2148 /*
2149  * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE.  IT IS AN
2150  * INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.
2151  *
2152  * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED.
2153  *
2154  * This function performs nearly the same function as vTaskPlaceOnEventList().
2155  * The difference being that this function does not permit tasks to block
2156  * indefinitely, whereas vTaskPlaceOnEventList() does.
2157  *
2158  */
2159 void vTaskPlaceOnEventListRestricted( List_t * const pxEventList, const TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
2160
2161 /*
2162  * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE.  IT IS AN
2163  * INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.
2164  *
2165  * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED.
2166  *
2167  * Removes a task from both the specified event list and the list of blocked
2168  * tasks, and places it on a ready queue.
2169  *
2170  * xTaskRemoveFromEventList()/xTaskRemoveFromUnorderedEventList() will be called
2171  * if either an event occurs to unblock a task, or the block timeout period
2172  * expires.
2173  *
2174  * xTaskRemoveFromEventList() is used when the event list is in task priority
2175  * order.  It removes the list item from the head of the event list as that will
2176  * have the highest priority owning task of all the tasks on the event list.
2177  * xTaskRemoveFromUnorderedEventList() is used when the event list is not
2178  * ordered and the event list items hold something other than the owning tasks
2179  * priority.  In this case the event list item value is updated to the value
2180  * passed in the xItemValue parameter.
2181  *
2182  * @return pdTRUE if the task being removed has a higher priority than the task
2183  * making the call, otherwise pdFALSE.
2184  */
2185 BaseType_t xTaskRemoveFromEventList( const List_t * const pxEventList ) PRIVILEGED_FUNCTION;
2186 BaseType_t xTaskRemoveFromUnorderedEventList( ListItem_t * pxEventListItem, const TickType_t xItemValue ) PRIVILEGED_FUNCTION;
2187
2188 /*
2189  * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE.  IT IS ONLY
2190  * INTENDED FOR USE WHEN IMPLEMENTING A PORT OF THE SCHEDULER AND IS
2191  * AN INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.
2192  *
2193  * Sets the pointer to the current TCB to the TCB of the highest priority task
2194  * that is ready to run.
2195  */
2196 void vTaskSwitchContext( void ) PRIVILEGED_FUNCTION;
2197
2198 /*
2199  * THESE FUNCTIONS MUST NOT BE USED FROM APPLICATION CODE.  THEY ARE USED BY
2200  * THE EVENT BITS MODULE.
2201  */
2202 TickType_t uxTaskResetEventItemValue( void ) PRIVILEGED_FUNCTION;
2203
2204 /*
2205  * Return the handle of the calling task.
2206  */
2207 TaskHandle_t xTaskGetCurrentTaskHandle( void ) PRIVILEGED_FUNCTION;
2208
2209
2210
2211 /*
2212  * Return the handle of the task running on a certain CPU. Because of
2213  * the nature of SMP processing, there is no guarantee that this
2214  * value will still be valid on return and should only be used for
2215  * debugging purposes.
2216  */
2217 TaskHandle_t xTaskGetCurrentTaskHandleForCPU( BaseType_t cpuid );
2218
2219
2220 /*
2221  * Capture the current time status for future reference.
2222  */
2223 void vTaskSetTimeOutState( TimeOut_t * const pxTimeOut ) PRIVILEGED_FUNCTION;
2224
2225 /*
2226  * Compare the time status now with that previously captured to see if the
2227  * timeout has expired.
2228  */
2229 BaseType_t xTaskCheckForTimeOut( TimeOut_t * const pxTimeOut, TickType_t * const pxTicksToWait ) PRIVILEGED_FUNCTION;
2230
2231 /*
2232  * Shortcut used by the queue implementation to prevent unnecessary call to
2233  * taskYIELD();
2234  */
2235 void vTaskMissedYield( void ) PRIVILEGED_FUNCTION;
2236
2237 /*
2238  * Returns the scheduler state as taskSCHEDULER_RUNNING,
2239  * taskSCHEDULER_NOT_STARTED or taskSCHEDULER_SUSPENDED.
2240  */
2241 BaseType_t xTaskGetSchedulerState( void ) PRIVILEGED_FUNCTION;
2242
2243 /*
2244  * Raises the priority of the mutex holder to that of the calling task should
2245  * the mutex holder have a priority less than the calling task.
2246  */
2247 void vTaskPriorityInherit( TaskHandle_t const pxMutexHolder ) PRIVILEGED_FUNCTION;
2248
2249 /*
2250  * Set the priority of a task back to its proper priority in the case that it
2251  * inherited a higher priority while it was holding a semaphore.
2252  */
2253 BaseType_t xTaskPriorityDisinherit( TaskHandle_t const pxMutexHolder ) PRIVILEGED_FUNCTION;
2254
2255 /*
2256  * Get the uxTCBNumber assigned to the task referenced by the xTask parameter.
2257  */
2258 UBaseType_t uxTaskGetTaskNumber( TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
2259
2260
2261 /*
2262  * Get the current core affinity of a task
2263  */
2264 BaseType_t xTaskGetAffinity( TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
2265
2266 /*
2267  * Set the uxTaskNumber of the task referenced by the xTask parameter to
2268  * uxHandle.
2269  */
2270 void vTaskSetTaskNumber( TaskHandle_t xTask, const UBaseType_t uxHandle ) PRIVILEGED_FUNCTION;
2271
2272 /*
2273  * Only available when configUSE_TICKLESS_IDLE is set to 1.
2274  * If tickless mode is being used, or a low power mode is implemented, then
2275  * the tick interrupt will not execute during idle periods.  When this is the
2276  * case, the tick count value maintained by the scheduler needs to be kept up
2277  * to date with the actual execution time by being skipped forward by a time
2278  * equal to the idle period.
2279  */
2280 void vTaskStepTick( const TickType_t xTicksToJump ) PRIVILEGED_FUNCTION;
2281
2282 /*
2283  * Only avilable when configUSE_TICKLESS_IDLE is set to 1.
2284  * Provided for use within portSUPPRESS_TICKS_AND_SLEEP() to allow the port
2285  * specific sleep function to determine if it is ok to proceed with the sleep,
2286  * and if it is ok to proceed, if it is ok to sleep indefinitely.
2287  *
2288  * This function is necessary because portSUPPRESS_TICKS_AND_SLEEP() is only
2289  * called with the scheduler suspended, not from within a critical section.  It
2290  * is therefore possible for an interrupt to request a context switch between
2291  * portSUPPRESS_TICKS_AND_SLEEP() and the low power mode actually being
2292  * entered.  eTaskConfirmSleepModeStatus() should be called from a short
2293  * critical section between the timer being stopped and the sleep mode being
2294  * entered to ensure it is ok to proceed into the sleep mode.
2295  */
2296 eSleepModeStatus eTaskConfirmSleepModeStatus( void ) PRIVILEGED_FUNCTION;
2297
2298 /*
2299  * For internal use only.  Increment the mutex held count when a mutex is
2300  * taken and return the handle of the task that has taken the mutex.
2301  */
2302 void *pvTaskIncrementMutexHeldCount( void );
2303
2304 /*
2305  * This function fills array with TaskSnapshot_t structures for every task in the system.
2306  * Used by core dump facility to get snapshots of all tasks in the system.
2307  * Only available when configENABLE_TASK_SNAPSHOT is set to 1.
2308  * @param pxTaskSnapshotArray Pointer to array of TaskSnapshot_t structures to store tasks snapshot data.
2309  * @param uxArraySize Size of tasks snapshots array.
2310  * @param pxTcbSz Pointer to store size of TCB.
2311  * @return Number of elements stored in array.
2312  */
2313 UBaseType_t uxTaskGetSnapshotAll( TaskSnapshot_t * const pxTaskSnapshotArray, const UBaseType_t uxArraySize, UBaseType_t * const pxTcbSz );
2314
2315 /** @endcond */
2316
2317 #ifdef __cplusplus
2318 }
2319 #endif
2320 #endif /* INC_TASK_H */
2321
2322
2323