1 /*
2  * FreeRTOS Kernel <DEVELOPMENT BRANCH>
3  * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4  *
5  * SPDX-License-Identifier: MIT
6  *
7  * Permission is hereby granted, free of charge, to any person obtaining a copy of
8  * this software and associated documentation files (the "Software"), to deal in
9  * the Software without restriction, including without limitation the rights to
10  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11  * the Software, and to permit persons to whom the Software is furnished to do so,
12  * subject to the following conditions:
13  *
14  * The above copyright notice and this permission notice shall be included in all
15  * copies or substantial portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  *
24  * https://www.FreeRTOS.org
25  * https://github.com/FreeRTOS
26  *
27  */
28 
29 
30 #ifndef INC_TASK_H
31 #define INC_TASK_H
32 
33 #ifndef INC_FREERTOS_H
34     #error "include FreeRTOS.h must appear in source files before include task.h"
35 #endif
36 
37 #include "list.h"
38 
39 /* *INDENT-OFF* */
40 #ifdef __cplusplus
41     extern "C" {
42 #endif
43 /* *INDENT-ON* */
44 
45 /*-----------------------------------------------------------
46 * MACROS AND DEFINITIONS
47 *----------------------------------------------------------*/
48 
49 /*
50  * If tskKERNEL_VERSION_NUMBER ends with + it represents the version in development
51  * after the numbered release.
52  *
53  * The tskKERNEL_VERSION_MAJOR, tskKERNEL_VERSION_MINOR, tskKERNEL_VERSION_BUILD
54  * values will reflect the last released version number.
55  */
56 #define tskKERNEL_VERSION_NUMBER                      "V11.1.0+"
57 #define tskKERNEL_VERSION_MAJOR                       11
58 #define tskKERNEL_VERSION_MINOR                       1
59 #define tskKERNEL_VERSION_BUILD                       0
60 
61 /* MPU region parameters passed in ulParameters
62  * of MemoryRegion_t struct. */
63 #define tskMPU_REGION_READ_ONLY                       ( 1U << 0U )
64 #define tskMPU_REGION_READ_WRITE                      ( 1U << 1U )
65 #define tskMPU_REGION_EXECUTE_NEVER                   ( 1U << 2U )
66 #define tskMPU_REGION_NORMAL_MEMORY                   ( 1U << 3U )
67 #define tskMPU_REGION_DEVICE_MEMORY                   ( 1U << 4U )
68 #if defined( portARMV8M_MINOR_VERSION ) && ( portARMV8M_MINOR_VERSION >= 1 )
69     #define tskMPU_REGION_PRIVILEGED_EXECUTE_NEVER    ( 1U << 5U )
70 #endif /* portARMV8M_MINOR_VERSION >= 1 */
71 
72 /* MPU region permissions stored in MPU settings to
73  * authorize access requests. */
74 #define tskMPU_READ_PERMISSION        ( 1U << 0U )
75 #define tskMPU_WRITE_PERMISSION       ( 1U << 1U )
76 
77 /* The direct to task notification feature used to have only a single notification
78  * per task.  Now there is an array of notifications per task that is dimensioned by
79  * configTASK_NOTIFICATION_ARRAY_ENTRIES.  For backward compatibility, any use of the
80  * original direct to task notification defaults to using the first index in the
81  * array. */
82 #define tskDEFAULT_INDEX_TO_NOTIFY    ( 0 )
83 
84 /**
85  * task. h
86  *
87  * Type by which tasks are referenced.  For example, a call to xTaskCreate
88  * returns (via a pointer parameter) an TaskHandle_t variable that can then
89  * be used as a parameter to vTaskDelete to delete the task.
90  *
91  * \defgroup TaskHandle_t TaskHandle_t
92  * \ingroup Tasks
93  */
94 struct tskTaskControlBlock; /* The old naming convention is used to prevent breaking kernel aware debuggers. */
95 typedef struct tskTaskControlBlock         * TaskHandle_t;
96 typedef const struct tskTaskControlBlock   * ConstTaskHandle_t;
97 
98 /*
99  * Defines the prototype to which the application task hook function must
100  * conform.
101  */
102 typedef BaseType_t (* TaskHookFunction_t)( void * arg );
103 
104 /* Task states returned by eTaskGetState. */
105 typedef enum
106 {
107     eRunning = 0, /* A task is querying the state of itself, so must be running. */
108     eReady,       /* The task being queried is in a ready or pending ready list. */
109     eBlocked,     /* The task being queried is in the Blocked state. */
110     eSuspended,   /* The task being queried is in the Suspended state, or is in the Blocked state with an infinite time out. */
111     eDeleted,     /* The task being queried has been deleted, but its TCB has not yet been freed. */
112     eInvalid      /* Used as an 'invalid state' value. */
113 } eTaskState;
114 
115 /* Actions that can be performed when vTaskNotify() is called. */
116 typedef enum
117 {
118     eNoAction = 0,            /* Notify the task without updating its notify value. */
119     eSetBits,                 /* Set bits in the task's notification value. */
120     eIncrement,               /* Increment the task's notification value. */
121     eSetValueWithOverwrite,   /* Set the task's notification value to a specific value even if the previous value has not yet been read by the task. */
122     eSetValueWithoutOverwrite /* Set the task's notification value if the previous value has been read by the task. */
123 } eNotifyAction;
124 
125 /*
126  * Used internally only.
127  */
128 typedef struct xTIME_OUT
129 {
130     BaseType_t xOverflowCount;
131     TickType_t xTimeOnEntering;
132 } TimeOut_t;
133 
134 /*
135  * Defines the memory ranges allocated to the task when an MPU is used.
136  */
137 typedef struct xMEMORY_REGION
138 {
139     void * pvBaseAddress;
140     uint32_t ulLengthInBytes;
141     uint32_t ulParameters;
142 } MemoryRegion_t;
143 
144 /*
145  * Parameters required to create an MPU protected task.
146  */
147 typedef struct xTASK_PARAMETERS
148 {
149     TaskFunction_t pvTaskCode;
150     const char * pcName;
151     configSTACK_DEPTH_TYPE usStackDepth;
152     void * pvParameters;
153     UBaseType_t uxPriority;
154     StackType_t * puxStackBuffer;
155     MemoryRegion_t xRegions[ portNUM_CONFIGURABLE_REGIONS ];
156     #if ( ( portUSING_MPU_WRAPPERS == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 1 ) )
157         StaticTask_t * const pxTaskBuffer;
158     #endif
159 } TaskParameters_t;
160 
161 /* Used with the uxTaskGetSystemState() function to return the state of each task
162  * in the system. */
163 typedef struct xTASK_STATUS
164 {
165     TaskHandle_t xHandle;                         /* The handle of the task to which the rest of the information in the structure relates. */
166     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! */
167     UBaseType_t xTaskNumber;                      /* A number unique to the task. Note that this is not the task number that may be modified using vTaskSetTaskNumber() and uxTaskGetTaskNumber(), but a separate TCB-specific and unique identifier automatically assigned on task generation. */
168     eTaskState eCurrentState;                     /* The state in which the task existed when the structure was populated. */
169     UBaseType_t uxCurrentPriority;                /* The priority at which the task was running (may be inherited) when the structure was populated. */
170     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. */
171     configRUN_TIME_COUNTER_TYPE ulRunTimeCounter; /* The total run time allocated to the task so far, as defined by the run time stats clock.  See https://www.FreeRTOS.org/rtos-run-time-stats.html.  Only valid when configGENERATE_RUN_TIME_STATS is defined as 1 in FreeRTOSConfig.h. */
172     StackType_t * pxStackBase;                    /* Points to the lowest address of the task's stack area. */
173     #if ( ( portSTACK_GROWTH > 0 ) || ( configRECORD_STACK_HIGH_ADDRESS == 1 ) )
174         StackType_t * pxTopOfStack;               /* Points to the top address of the task's stack area. */
175         StackType_t * pxEndOfStack;               /* Points to the end address of the task's stack area. */
176     #endif
177     configSTACK_DEPTH_TYPE 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. */
178     #if ( ( configUSE_CORE_AFFINITY == 1 ) && ( configNUMBER_OF_CORES > 1 ) )
179         UBaseType_t uxCoreAffinityMask;           /* The core affinity mask for the task */
180     #endif
181 } TaskStatus_t;
182 
183 /* Possible return values for eTaskConfirmSleepModeStatus(). */
184 typedef enum
185 {
186     eAbortSleep = 0, /* A task has been made ready or a context switch pended since portSUPPRESS_TICKS_AND_SLEEP() was called - abort entering a sleep mode. */
187     eStandardSleep   /* Enter a sleep mode that will not last any longer than the expected idle time. */
188     #if ( INCLUDE_vTaskSuspend == 1 )
189         ,
190         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. */
191     #endif /* INCLUDE_vTaskSuspend */
192 } eSleepModeStatus;
193 
194 /**
195  * Defines the priority used by the idle task.  This must not be modified.
196  *
197  * \ingroup TaskUtils
198  */
199 #define tskIDLE_PRIORITY    ( ( UBaseType_t ) 0U )
200 
201 /**
202  * Defines affinity to all available cores.
203  *
204  * \ingroup TaskUtils
205  */
206 #define tskNO_AFFINITY      ( ( UBaseType_t ) -1 )
207 
208 /**
209  * task. h
210  *
211  * Macro for forcing a context switch.
212  *
213  * \defgroup taskYIELD taskYIELD
214  * \ingroup SchedulerControl
215  */
216 #define taskYIELD()                          portYIELD()
217 
218 /**
219  * task. h
220  *
221  * Macro to mark the start of a critical code region.  Preemptive context
222  * switches cannot occur when in a critical region.
223  *
224  * NOTE: This may alter the stack (depending on the portable implementation)
225  * so must be used with care!
226  *
227  * \defgroup taskENTER_CRITICAL taskENTER_CRITICAL
228  * \ingroup SchedulerControl
229  */
230 #define taskENTER_CRITICAL()                 portENTER_CRITICAL()
231 #if ( configNUMBER_OF_CORES == 1 )
232     #define taskENTER_CRITICAL_FROM_ISR()    portSET_INTERRUPT_MASK_FROM_ISR()
233 #else
234     #define taskENTER_CRITICAL_FROM_ISR()    portENTER_CRITICAL_FROM_ISR()
235 #endif
236 
237 /**
238  * task. h
239  *
240  * Macro to mark the end of a critical code region.  Preemptive context
241  * switches cannot occur when in a critical region.
242  *
243  * NOTE: This may alter the stack (depending on the portable implementation)
244  * so must be used with care!
245  *
246  * \defgroup taskEXIT_CRITICAL taskEXIT_CRITICAL
247  * \ingroup SchedulerControl
248  */
249 #define taskEXIT_CRITICAL()                    portEXIT_CRITICAL()
250 #if ( configNUMBER_OF_CORES == 1 )
251     #define taskEXIT_CRITICAL_FROM_ISR( x )    portCLEAR_INTERRUPT_MASK_FROM_ISR( x )
252 #else
253     #define taskEXIT_CRITICAL_FROM_ISR( x )    portEXIT_CRITICAL_FROM_ISR( x )
254 #endif
255 
256 /**
257  * task. h
258  *
259  * Macro to disable all maskable interrupts.
260  *
261  * \defgroup taskDISABLE_INTERRUPTS taskDISABLE_INTERRUPTS
262  * \ingroup SchedulerControl
263  */
264 #define taskDISABLE_INTERRUPTS()    portDISABLE_INTERRUPTS()
265 
266 /**
267  * task. h
268  *
269  * Macro to enable microcontroller interrupts.
270  *
271  * \defgroup taskENABLE_INTERRUPTS taskENABLE_INTERRUPTS
272  * \ingroup SchedulerControl
273  */
274 #define taskENABLE_INTERRUPTS()     portENABLE_INTERRUPTS()
275 
276 /* Definitions returned by xTaskGetSchedulerState().  taskSCHEDULER_SUSPENDED is
277  * 0 to generate more optimal code when configASSERT() is defined as the constant
278  * is used in assert() statements. */
279 #define taskSCHEDULER_SUSPENDED      ( ( BaseType_t ) 0 )
280 #define taskSCHEDULER_NOT_STARTED    ( ( BaseType_t ) 1 )
281 #define taskSCHEDULER_RUNNING        ( ( BaseType_t ) 2 )
282 
283 /* Checks if core ID is valid. */
284 #define taskVALID_CORE_ID( xCoreID )    ( ( ( ( ( BaseType_t ) 0 <= ( xCoreID ) ) && ( ( xCoreID ) < ( BaseType_t ) configNUMBER_OF_CORES ) ) ) ? ( pdTRUE ) : ( pdFALSE ) )
285 
286 /*-----------------------------------------------------------
287 * TASK CREATION API
288 *----------------------------------------------------------*/
289 
290 /**
291  * task. h
292  * @code{c}
293  * BaseType_t xTaskCreate(
294  *                            TaskFunction_t pxTaskCode,
295  *                            const char * const pcName,
296  *                            const configSTACK_DEPTH_TYPE uxStackDepth,
297  *                            void *pvParameters,
298  *                            UBaseType_t uxPriority,
299  *                            TaskHandle_t *pxCreatedTask
300  *                        );
301  * @endcode
302  *
303  * Create a new task and add it to the list of tasks that are ready to run.
304  *
305  * Internally, within the FreeRTOS implementation, tasks use two blocks of
306  * memory.  The first block is used to hold the task's data structures.  The
307  * second block is used by the task as its stack.  If a task is created using
308  * xTaskCreate() then both blocks of memory are automatically dynamically
309  * allocated inside the xTaskCreate() function.  (see
310  * https://www.FreeRTOS.org/a00111.html).  If a task is created using
311  * xTaskCreateStatic() then the application writer must provide the required
312  * memory.  xTaskCreateStatic() therefore allows a task to be created without
313  * using any dynamic memory allocation.
314  *
315  * See xTaskCreateStatic() for a version that does not use any dynamic memory
316  * allocation.
317  *
318  * xTaskCreate() can only be used to create a task that has unrestricted
319  * access to the entire microcontroller memory map.  Systems that include MPU
320  * support can alternatively create an MPU constrained task using
321  * xTaskCreateRestricted().
322  *
323  * @param pxTaskCode Pointer to the task entry function.  Tasks
324  * must be implemented to never return (i.e. continuous loop).
325  *
326  * @param pcName A descriptive name for the task.  This is mainly used to
327  * facilitate debugging.  Max length defined by configMAX_TASK_NAME_LEN - default
328  * is 16.
329  *
330  * @param uxStackDepth The size of the task stack specified as the number of
331  * variables the stack can hold - not the number of bytes.  For example, if
332  * the stack is 16 bits wide and uxStackDepth is defined as 100, 200 bytes
333  * will be allocated for stack storage.
334  *
335  * @param pvParameters Pointer that will be used as the parameter for the task
336  * being created.
337  *
338  * @param uxPriority The priority at which the task should run.  Systems that
339  * include MPU support can optionally create tasks in a privileged (system)
340  * mode by setting bit portPRIVILEGE_BIT of the priority parameter.  For
341  * example, to create a privileged task at priority 2 the uxPriority parameter
342  * should be set to ( 2 | portPRIVILEGE_BIT ).
343  *
344  * @param pxCreatedTask Used to pass back a handle by which the created task
345  * can be referenced.
346  *
347  * @return pdPASS if the task was successfully created and added to a ready
348  * list, otherwise an error code defined in the file projdefs.h
349  *
350  * Example usage:
351  * @code{c}
352  * // Task to be created.
353  * void vTaskCode( void * pvParameters )
354  * {
355  *   for( ;; )
356  *   {
357  *       // Task code goes here.
358  *   }
359  * }
360  *
361  * // Function that creates a task.
362  * void vOtherFunction( void )
363  * {
364  * static uint8_t ucParameterToPass;
365  * TaskHandle_t xHandle = NULL;
366  *
367  *   // Create the task, storing the handle.  Note that the passed parameter ucParameterToPass
368  *   // must exist for the lifetime of the task, so in this case is declared static.  If it was just an
369  *   // an automatic stack variable it might no longer exist, or at least have been corrupted, by the time
370  *   // the new task attempts to access it.
371  *   xTaskCreate( vTaskCode, "NAME", STACK_SIZE, &ucParameterToPass, tskIDLE_PRIORITY, &xHandle );
372  *   configASSERT( xHandle );
373  *
374  *   // Use the handle to delete the task.
375  *   if( xHandle != NULL )
376  *   {
377  *      vTaskDelete( xHandle );
378  *   }
379  * }
380  * @endcode
381  * \defgroup xTaskCreate xTaskCreate
382  * \ingroup Tasks
383  */
384 #if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
385     BaseType_t xTaskCreate( TaskFunction_t pxTaskCode,
386                             const char * const pcName,
387                             const configSTACK_DEPTH_TYPE uxStackDepth,
388                             void * const pvParameters,
389                             UBaseType_t uxPriority,
390                             TaskHandle_t * const pxCreatedTask ) PRIVILEGED_FUNCTION;
391 #endif
392 
393 #if ( ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) && ( configNUMBER_OF_CORES > 1 ) && ( configUSE_CORE_AFFINITY == 1 ) )
394     BaseType_t xTaskCreateAffinitySet( TaskFunction_t pxTaskCode,
395                                        const char * const pcName,
396                                        const configSTACK_DEPTH_TYPE uxStackDepth,
397                                        void * const pvParameters,
398                                        UBaseType_t uxPriority,
399                                        UBaseType_t uxCoreAffinityMask,
400                                        TaskHandle_t * const pxCreatedTask ) PRIVILEGED_FUNCTION;
401 #endif
402 
403 /**
404  * task. h
405  * @code{c}
406  * TaskHandle_t xTaskCreateStatic( TaskFunction_t pxTaskCode,
407  *                               const char * const pcName,
408  *                               const configSTACK_DEPTH_TYPE uxStackDepth,
409  *                               void *pvParameters,
410  *                               UBaseType_t uxPriority,
411  *                               StackType_t *puxStackBuffer,
412  *                               StaticTask_t *pxTaskBuffer );
413  * @endcode
414  *
415  * Create a new task and add it to the list of tasks that are ready to run.
416  *
417  * Internally, within the FreeRTOS implementation, tasks use two blocks of
418  * memory.  The first block is used to hold the task's data structures.  The
419  * second block is used by the task as its stack.  If a task is created using
420  * xTaskCreate() then both blocks of memory are automatically dynamically
421  * allocated inside the xTaskCreate() function.  (see
422  * https://www.FreeRTOS.org/a00111.html).  If a task is created using
423  * xTaskCreateStatic() then the application writer must provide the required
424  * memory.  xTaskCreateStatic() therefore allows a task to be created without
425  * using any dynamic memory allocation.
426  *
427  * @param pxTaskCode Pointer to the task entry function.  Tasks
428  * must be implemented to never return (i.e. continuous loop).
429  *
430  * @param pcName A descriptive name for the task.  This is mainly used to
431  * facilitate debugging.  The maximum length of the string is defined by
432  * configMAX_TASK_NAME_LEN in FreeRTOSConfig.h.
433  *
434  * @param uxStackDepth The size of the task stack specified as the number of
435  * variables the stack can hold - not the number of bytes.  For example, if
436  * the stack is 32-bits wide and uxStackDepth is defined as 100 then 400 bytes
437  * will be allocated for stack storage.
438  *
439  * @param pvParameters Pointer that will be used as the parameter for the task
440  * being created.
441  *
442  * @param uxPriority The priority at which the task will run.
443  *
444  * @param puxStackBuffer Must point to a StackType_t array that has at least
445  * uxStackDepth indexes - the array will then be used as the task's stack,
446  * removing the need for the stack to be allocated dynamically.
447  *
448  * @param pxTaskBuffer Must point to a variable of type StaticTask_t, which will
449  * then be used to hold the task's data structures, removing the need for the
450  * memory to be allocated dynamically.
451  *
452  * @return If neither puxStackBuffer nor pxTaskBuffer are NULL, then the task
453  * will be created and a handle to the created task is returned.  If either
454  * puxStackBuffer or pxTaskBuffer are NULL then the task will not be created and
455  * NULL is returned.
456  *
457  * Example usage:
458  * @code{c}
459  *
460  *  // Dimensions of the buffer that the task being created will use as its stack.
461  *  // NOTE:  This is the number of words the stack will hold, not the number of
462  *  // bytes.  For example, if each stack item is 32-bits, and this is set to 100,
463  *  // then 400 bytes (100 * 32-bits) will be allocated.
464  #define STACK_SIZE 200
465  *
466  *  // Structure that will hold the TCB of the task being created.
467  *  StaticTask_t xTaskBuffer;
468  *
469  *  // Buffer that the task being created will use as its stack.  Note this is
470  *  // an array of StackType_t variables.  The size of StackType_t is dependent on
471  *  // the RTOS port.
472  *  StackType_t xStack[ STACK_SIZE ];
473  *
474  *  // Function that implements the task being created.
475  *  void vTaskCode( void * pvParameters )
476  *  {
477  *      // The parameter value is expected to be 1 as 1 is passed in the
478  *      // pvParameters value in the call to xTaskCreateStatic().
479  *      configASSERT( ( uint32_t ) pvParameters == 1U );
480  *
481  *      for( ;; )
482  *      {
483  *          // Task code goes here.
484  *      }
485  *  }
486  *
487  *  // Function that creates a task.
488  *  void vOtherFunction( void )
489  *  {
490  *      TaskHandle_t xHandle = NULL;
491  *
492  *      // Create the task without using any dynamic memory allocation.
493  *      xHandle = xTaskCreateStatic(
494  *                    vTaskCode,       // Function that implements the task.
495  *                    "NAME",          // Text name for the task.
496  *                    STACK_SIZE,      // Stack size in words, not bytes.
497  *                    ( void * ) 1,    // Parameter passed into the task.
498  *                    tskIDLE_PRIORITY,// Priority at which the task is created.
499  *                    xStack,          // Array to use as the task's stack.
500  *                    &xTaskBuffer );  // Variable to hold the task's data structure.
501  *
502  *      // puxStackBuffer and pxTaskBuffer were not NULL, so the task will have
503  *      // been created, and xHandle will be the task's handle.  Use the handle
504  *      // to suspend the task.
505  *      vTaskSuspend( xHandle );
506  *  }
507  * @endcode
508  * \defgroup xTaskCreateStatic xTaskCreateStatic
509  * \ingroup Tasks
510  */
511 #if ( configSUPPORT_STATIC_ALLOCATION == 1 )
512     TaskHandle_t xTaskCreateStatic( TaskFunction_t pxTaskCode,
513                                     const char * const pcName,
514                                     const configSTACK_DEPTH_TYPE uxStackDepth,
515                                     void * const pvParameters,
516                                     UBaseType_t uxPriority,
517                                     StackType_t * const puxStackBuffer,
518                                     StaticTask_t * const pxTaskBuffer ) PRIVILEGED_FUNCTION;
519 #endif /* configSUPPORT_STATIC_ALLOCATION */
520 
521 #if ( ( configSUPPORT_STATIC_ALLOCATION == 1 ) && ( configNUMBER_OF_CORES > 1 ) && ( configUSE_CORE_AFFINITY == 1 ) )
522     TaskHandle_t xTaskCreateStaticAffinitySet( TaskFunction_t pxTaskCode,
523                                                const char * const pcName,
524                                                const configSTACK_DEPTH_TYPE uxStackDepth,
525                                                void * const pvParameters,
526                                                UBaseType_t uxPriority,
527                                                StackType_t * const puxStackBuffer,
528                                                StaticTask_t * const pxTaskBuffer,
529                                                UBaseType_t uxCoreAffinityMask ) PRIVILEGED_FUNCTION;
530 #endif
531 
532 /**
533  * task. h
534  * @code{c}
535  * BaseType_t xTaskCreateRestricted( TaskParameters_t *pxTaskDefinition, TaskHandle_t *pxCreatedTask );
536  * @endcode
537  *
538  * Only available when configSUPPORT_DYNAMIC_ALLOCATION is set to 1.
539  *
540  * xTaskCreateRestricted() should only be used in systems that include an MPU
541  * implementation.
542  *
543  * Create a new task and add it to the list of tasks that are ready to run.
544  * The function parameters define the memory regions and associated access
545  * permissions allocated to the task.
546  *
547  * See xTaskCreateRestrictedStatic() for a version that does not use any
548  * dynamic memory allocation.
549  *
550  * @param pxTaskDefinition Pointer to a structure that contains a member
551  * for each of the normal xTaskCreate() parameters (see the xTaskCreate() API
552  * documentation) plus an optional stack buffer and the memory region
553  * definitions.
554  *
555  * @param pxCreatedTask Used to pass back a handle by which the created task
556  * can be referenced.
557  *
558  * @return pdPASS if the task was successfully created and added to a ready
559  * list, otherwise an error code defined in the file projdefs.h
560  *
561  * Example usage:
562  * @code{c}
563  * // Create an TaskParameters_t structure that defines the task to be created.
564  * static const TaskParameters_t xCheckTaskParameters =
565  * {
566  *  vATask,     // pvTaskCode - the function that implements the task.
567  *  "ATask",    // pcName - just a text name for the task to assist debugging.
568  *  100,        // uxStackDepth - the stack size DEFINED IN WORDS.
569  *  NULL,       // pvParameters - passed into the task function as the function parameters.
570  *  ( 1U | portPRIVILEGE_BIT ),// uxPriority - task priority, set the portPRIVILEGE_BIT if the task should run in a privileged state.
571  *  cStackBuffer,// puxStackBuffer - the buffer to be used as the task stack.
572  *
573  *  // xRegions - Allocate up to three separate memory regions for access by
574  *  // the task, with appropriate access permissions.  Different processors have
575  *  // different memory alignment requirements - refer to the FreeRTOS documentation
576  *  // for full information.
577  *  {
578  *      // Base address                 Length  Parameters
579  *      { cReadWriteArray,              32,     portMPU_REGION_READ_WRITE },
580  *      { cReadOnlyArray,               32,     portMPU_REGION_READ_ONLY },
581  *      { cPrivilegedOnlyAccessArray,   128,    portMPU_REGION_PRIVILEGED_READ_WRITE }
582  *  }
583  * };
584  *
585  * int main( void )
586  * {
587  * TaskHandle_t xHandle;
588  *
589  *  // Create a task from the const structure defined above.  The task handle
590  *  // is requested (the second parameter is not NULL) but in this case just for
591  *  // demonstration purposes as its not actually used.
592  *  xTaskCreateRestricted( &xRegTest1Parameters, &xHandle );
593  *
594  *  // Start the scheduler.
595  *  vTaskStartScheduler();
596  *
597  *  // Will only get here if there was insufficient memory to create the idle
598  *  // and/or timer task.
599  *  for( ;; );
600  * }
601  * @endcode
602  * \defgroup xTaskCreateRestricted xTaskCreateRestricted
603  * \ingroup Tasks
604  */
605 #if ( portUSING_MPU_WRAPPERS == 1 )
606     BaseType_t xTaskCreateRestricted( const TaskParameters_t * const pxTaskDefinition,
607                                       TaskHandle_t * pxCreatedTask ) PRIVILEGED_FUNCTION;
608 #endif
609 
610 #if ( ( portUSING_MPU_WRAPPERS == 1 ) && ( configNUMBER_OF_CORES > 1 ) && ( configUSE_CORE_AFFINITY == 1 ) )
611     BaseType_t xTaskCreateRestrictedAffinitySet( const TaskParameters_t * const pxTaskDefinition,
612                                                  UBaseType_t uxCoreAffinityMask,
613                                                  TaskHandle_t * pxCreatedTask ) PRIVILEGED_FUNCTION;
614 #endif
615 
616 /**
617  * task. h
618  * @code{c}
619  * BaseType_t xTaskCreateRestrictedStatic( TaskParameters_t *pxTaskDefinition, TaskHandle_t *pxCreatedTask );
620  * @endcode
621  *
622  * Only available when configSUPPORT_STATIC_ALLOCATION is set to 1.
623  *
624  * xTaskCreateRestrictedStatic() should only be used in systems that include an
625  * MPU implementation.
626  *
627  * Internally, within the FreeRTOS implementation, tasks use two blocks of
628  * memory.  The first block is used to hold the task's data structures.  The
629  * second block is used by the task as its stack.  If a task is created using
630  * xTaskCreateRestricted() then the stack is provided by the application writer,
631  * and the memory used to hold the task's data structure is automatically
632  * dynamically allocated inside the xTaskCreateRestricted() function.  If a task
633  * is created using xTaskCreateRestrictedStatic() then the application writer
634  * must provide the memory used to hold the task's data structures too.
635  * xTaskCreateRestrictedStatic() therefore allows a memory protected task to be
636  * created without using any dynamic memory allocation.
637  *
638  * @param pxTaskDefinition Pointer to a structure that contains a member
639  * for each of the normal xTaskCreate() parameters (see the xTaskCreate() API
640  * documentation) plus an optional stack buffer and the memory region
641  * definitions.  If configSUPPORT_STATIC_ALLOCATION is set to 1 the structure
642  * contains an additional member, which is used to point to a variable of type
643  * StaticTask_t - which is then used to hold the task's data structure.
644  *
645  * @param pxCreatedTask Used to pass back a handle by which the created task
646  * can be referenced.
647  *
648  * @return pdPASS if the task was successfully created and added to a ready
649  * list, otherwise an error code defined in the file projdefs.h
650  *
651  * Example usage:
652  * @code{c}
653  * // Create an TaskParameters_t structure that defines the task to be created.
654  * // The StaticTask_t variable is only included in the structure when
655  * // configSUPPORT_STATIC_ALLOCATION is set to 1.  The PRIVILEGED_DATA macro can
656  * // be used to force the variable into the RTOS kernel's privileged data area.
657  * static PRIVILEGED_DATA StaticTask_t xTaskBuffer;
658  * static const TaskParameters_t xCheckTaskParameters =
659  * {
660  *  vATask,     // pvTaskCode - the function that implements the task.
661  *  "ATask",    // pcName - just a text name for the task to assist debugging.
662  *  100,        // uxStackDepth - the stack size DEFINED IN WORDS.
663  *  NULL,       // pvParameters - passed into the task function as the function parameters.
664  *  ( 1U | portPRIVILEGE_BIT ),// uxPriority - task priority, set the portPRIVILEGE_BIT if the task should run in a privileged state.
665  *  cStackBuffer,// puxStackBuffer - the buffer to be used as the task stack.
666  *
667  *  // xRegions - Allocate up to three separate memory regions for access by
668  *  // the task, with appropriate access permissions.  Different processors have
669  *  // different memory alignment requirements - refer to the FreeRTOS documentation
670  *  // for full information.
671  *  {
672  *      // Base address                 Length  Parameters
673  *      { cReadWriteArray,              32,     portMPU_REGION_READ_WRITE },
674  *      { cReadOnlyArray,               32,     portMPU_REGION_READ_ONLY },
675  *      { cPrivilegedOnlyAccessArray,   128,    portMPU_REGION_PRIVILEGED_READ_WRITE }
676  *  }
677  *
678  *  &xTaskBuffer; // Holds the task's data structure.
679  * };
680  *
681  * int main( void )
682  * {
683  * TaskHandle_t xHandle;
684  *
685  *  // Create a task from the const structure defined above.  The task handle
686  *  // is requested (the second parameter is not NULL) but in this case just for
687  *  // demonstration purposes as its not actually used.
688  *  xTaskCreateRestrictedStatic( &xRegTest1Parameters, &xHandle );
689  *
690  *  // Start the scheduler.
691  *  vTaskStartScheduler();
692  *
693  *  // Will only get here if there was insufficient memory to create the idle
694  *  // and/or timer task.
695  *  for( ;; );
696  * }
697  * @endcode
698  * \defgroup xTaskCreateRestrictedStatic xTaskCreateRestrictedStatic
699  * \ingroup Tasks
700  */
701 #if ( ( portUSING_MPU_WRAPPERS == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 1 ) )
702     BaseType_t xTaskCreateRestrictedStatic( const TaskParameters_t * const pxTaskDefinition,
703                                             TaskHandle_t * pxCreatedTask ) PRIVILEGED_FUNCTION;
704 #endif
705 
706 #if ( ( portUSING_MPU_WRAPPERS == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 1 ) && ( configNUMBER_OF_CORES > 1 ) && ( configUSE_CORE_AFFINITY == 1 ) )
707     BaseType_t xTaskCreateRestrictedStaticAffinitySet( const TaskParameters_t * const pxTaskDefinition,
708                                                        UBaseType_t uxCoreAffinityMask,
709                                                        TaskHandle_t * pxCreatedTask ) PRIVILEGED_FUNCTION;
710 #endif
711 
712 /**
713  * task. h
714  * @code{c}
715  * void vTaskAllocateMPURegions( TaskHandle_t xTask, const MemoryRegion_t * const pxRegions );
716  * @endcode
717  *
718  * Memory regions are assigned to a restricted task when the task is created by
719  * a call to xTaskCreateRestricted().  These regions can be redefined using
720  * vTaskAllocateMPURegions().
721  *
722  * @param xTaskToModify The handle of the task being updated.
723  *
724  * @param[in] pxRegions A pointer to a MemoryRegion_t structure that contains the
725  * new memory region definitions.
726  *
727  * Example usage:
728  * @code{c}
729  * // Define an array of MemoryRegion_t structures that configures an MPU region
730  * // allowing read/write access for 1024 bytes starting at the beginning of the
731  * // ucOneKByte array.  The other two of the maximum 3 definable regions are
732  * // unused so set to zero.
733  * static const MemoryRegion_t xAltRegions[ portNUM_CONFIGURABLE_REGIONS ] =
734  * {
735  *  // Base address     Length      Parameters
736  *  { ucOneKByte,       1024,       portMPU_REGION_READ_WRITE },
737  *  { 0,                0,          0 },
738  *  { 0,                0,          0 }
739  * };
740  *
741  * void vATask( void *pvParameters )
742  * {
743  *  // This task was created such that it has access to certain regions of
744  *  // memory as defined by the MPU configuration.  At some point it is
745  *  // desired that these MPU regions are replaced with that defined in the
746  *  // xAltRegions const struct above.  Use a call to vTaskAllocateMPURegions()
747  *  // for this purpose.  NULL is used as the task handle to indicate that this
748  *  // function should modify the MPU regions of the calling task.
749  *  vTaskAllocateMPURegions( NULL, xAltRegions );
750  *
751  *  // Now the task can continue its function, but from this point on can only
752  *  // access its stack and the ucOneKByte array (unless any other statically
753  *  // defined or shared regions have been declared elsewhere).
754  * }
755  * @endcode
756  * \defgroup vTaskAllocateMPURegions vTaskAllocateMPURegions
757  * \ingroup Tasks
758  */
759 #if ( portUSING_MPU_WRAPPERS == 1 )
760     void vTaskAllocateMPURegions( TaskHandle_t xTaskToModify,
761                                   const MemoryRegion_t * const pxRegions ) PRIVILEGED_FUNCTION;
762 #endif
763 
764 /**
765  * task. h
766  * @code{c}
767  * void vTaskDelete( TaskHandle_t xTaskToDelete );
768  * @endcode
769  *
770  * INCLUDE_vTaskDelete must be defined as 1 for this function to be available.
771  * See the configuration section for more information.
772  *
773  * Remove a task from the RTOS real time kernel's management.  The task being
774  * deleted will be removed from all ready, blocked, suspended and event lists.
775  *
776  * NOTE:  The idle task is responsible for freeing the kernel allocated
777  * memory from tasks that have been deleted.  It is therefore important that
778  * the idle task is not starved of microcontroller processing time if your
779  * application makes any calls to vTaskDelete ().  Memory allocated by the
780  * task code is not automatically freed, and should be freed before the task
781  * is deleted.
782  *
783  * See the demo application file death.c for sample code that utilises
784  * vTaskDelete ().
785  *
786  * @param xTaskToDelete The handle of the task to be deleted.  Passing NULL will
787  * cause the calling task to be deleted.
788  *
789  * Example usage:
790  * @code{c}
791  * void vOtherFunction( void )
792  * {
793  * TaskHandle_t xHandle;
794  *
795  *   // Create the task, storing the handle.
796  *   xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
797  *
798  *   // Use the handle to delete the task.
799  *   vTaskDelete( xHandle );
800  * }
801  * @endcode
802  * \defgroup vTaskDelete vTaskDelete
803  * \ingroup Tasks
804  */
805 void vTaskDelete( TaskHandle_t xTaskToDelete ) PRIVILEGED_FUNCTION;
806 
807 /*-----------------------------------------------------------
808 * TASK CONTROL API
809 *----------------------------------------------------------*/
810 
811 /**
812  * task. h
813  * @code{c}
814  * void vTaskDelay( const TickType_t xTicksToDelay );
815  * @endcode
816  *
817  * Delay a task for a given number of ticks.  The actual time that the
818  * task remains blocked depends on the tick rate.  The constant
819  * portTICK_PERIOD_MS can be used to calculate real time from the tick
820  * rate - with the resolution of one tick period.
821  *
822  * INCLUDE_vTaskDelay must be defined as 1 for this function to be available.
823  * See the configuration section for more information.
824  *
825  *
826  * vTaskDelay() specifies a time at which the task wishes to unblock relative to
827  * the time at which vTaskDelay() is called.  For example, specifying a block
828  * period of 100 ticks will cause the task to unblock 100 ticks after
829  * vTaskDelay() is called.  vTaskDelay() does not therefore provide a good method
830  * of controlling the frequency of a periodic task as the path taken through the
831  * code, as well as other task and interrupt activity, will affect the frequency
832  * at which vTaskDelay() gets called and therefore the time at which the task
833  * next executes.  See xTaskDelayUntil() for an alternative API function designed
834  * to facilitate fixed frequency execution.  It does this by specifying an
835  * absolute time (rather than a relative time) at which the calling task should
836  * unblock.
837  *
838  * @param xTicksToDelay The amount of time, in tick periods, that
839  * the calling task should block.
840  *
841  * Example usage:
842  *
843  * void vTaskFunction( void * pvParameters )
844  * {
845  * // Block for 500ms.
846  * const TickType_t xDelay = 500 / portTICK_PERIOD_MS;
847  *
848  *   for( ;; )
849  *   {
850  *       // Simply toggle the LED every 500ms, blocking between each toggle.
851  *       vToggleLED();
852  *       vTaskDelay( xDelay );
853  *   }
854  * }
855  *
856  * \defgroup vTaskDelay vTaskDelay
857  * \ingroup TaskCtrl
858  */
859 void vTaskDelay( const TickType_t xTicksToDelay ) PRIVILEGED_FUNCTION;
860 
861 /**
862  * task. h
863  * @code{c}
864  * BaseType_t xTaskDelayUntil( TickType_t *pxPreviousWakeTime, const TickType_t xTimeIncrement );
865  * @endcode
866  *
867  * INCLUDE_xTaskDelayUntil must be defined as 1 for this function to be available.
868  * See the configuration section for more information.
869  *
870  * Delay a task until a specified time.  This function can be used by periodic
871  * tasks to ensure a constant execution frequency.
872  *
873  * This function differs from vTaskDelay () in one important aspect:  vTaskDelay () will
874  * cause a task to block for the specified number of ticks from the time vTaskDelay () is
875  * called.  It is therefore difficult to use vTaskDelay () by itself to generate a fixed
876  * execution frequency as the time between a task starting to execute and that task
877  * calling vTaskDelay () may not be fixed [the task may take a different path though the
878  * code between calls, or may get interrupted or preempted a different number of times
879  * each time it executes].
880  *
881  * Whereas vTaskDelay () specifies a wake time relative to the time at which the function
882  * is called, xTaskDelayUntil () specifies the absolute (exact) time at which it wishes to
883  * unblock.
884  *
885  * The macro pdMS_TO_TICKS() can be used to calculate the number of ticks from a
886  * time specified in milliseconds with a resolution of one tick period.
887  *
888  * @param pxPreviousWakeTime Pointer to a variable that holds the time at which the
889  * task was last unblocked.  The variable must be initialised with the current time
890  * prior to its first use (see the example below).  Following this the variable is
891  * automatically updated within xTaskDelayUntil ().
892  *
893  * @param xTimeIncrement The cycle time period.  The task will be unblocked at
894  * time *pxPreviousWakeTime + xTimeIncrement.  Calling xTaskDelayUntil with the
895  * same xTimeIncrement parameter value will cause the task to execute with
896  * a fixed interface period.
897  *
898  * @return Value which can be used to check whether the task was actually delayed.
899  * Will be pdTRUE if the task way delayed and pdFALSE otherwise.  A task will not
900  * be delayed if the next expected wake time is in the past.
901  *
902  * Example usage:
903  * @code{c}
904  * // Perform an action every 10 ticks.
905  * void vTaskFunction( void * pvParameters )
906  * {
907  * TickType_t xLastWakeTime;
908  * const TickType_t xFrequency = 10;
909  * BaseType_t xWasDelayed;
910  *
911  *     // Initialise the xLastWakeTime variable with the current time.
912  *     xLastWakeTime = xTaskGetTickCount ();
913  *     for( ;; )
914  *     {
915  *         // Wait for the next cycle.
916  *         xWasDelayed = xTaskDelayUntil( &xLastWakeTime, xFrequency );
917  *
918  *         // Perform action here. xWasDelayed value can be used to determine
919  *         // whether a deadline was missed if the code here took too long.
920  *     }
921  * }
922  * @endcode
923  * \defgroup xTaskDelayUntil xTaskDelayUntil
924  * \ingroup TaskCtrl
925  */
926 BaseType_t xTaskDelayUntil( TickType_t * const pxPreviousWakeTime,
927                             const TickType_t xTimeIncrement ) PRIVILEGED_FUNCTION;
928 
929 /*
930  * vTaskDelayUntil() is the older version of xTaskDelayUntil() and does not
931  * return a value.
932  */
933 #define vTaskDelayUntil( pxPreviousWakeTime, xTimeIncrement )                   \
934     do {                                                                        \
935         ( void ) xTaskDelayUntil( ( pxPreviousWakeTime ), ( xTimeIncrement ) ); \
936     } while( 0 )
937 
938 
939 /**
940  * task. h
941  * @code{c}
942  * BaseType_t xTaskAbortDelay( TaskHandle_t xTask );
943  * @endcode
944  *
945  * INCLUDE_xTaskAbortDelay must be defined as 1 in FreeRTOSConfig.h for this
946  * function to be available.
947  *
948  * A task will enter the Blocked state when it is waiting for an event.  The
949  * event it is waiting for can be a temporal event (waiting for a time), such
950  * as when vTaskDelay() is called, or an event on an object, such as when
951  * xQueueReceive() or ulTaskNotifyTake() is called.  If the handle of a task
952  * that is in the Blocked state is used in a call to xTaskAbortDelay() then the
953  * task will leave the Blocked state, and return from whichever function call
954  * placed the task into the Blocked state.
955  *
956  * There is no 'FromISR' version of this function as an interrupt would need to
957  * know which object a task was blocked on in order to know which actions to
958  * take.  For example, if the task was blocked on a queue the interrupt handler
959  * would then need to know if the queue was locked.
960  *
961  * @param xTask The handle of the task to remove from the Blocked state.
962  *
963  * @return If the task referenced by xTask was not in the Blocked state then
964  * pdFAIL is returned.  Otherwise pdPASS is returned.
965  *
966  * \defgroup xTaskAbortDelay xTaskAbortDelay
967  * \ingroup TaskCtrl
968  */
969 #if ( INCLUDE_xTaskAbortDelay == 1 )
970     BaseType_t xTaskAbortDelay( TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
971 #endif
972 
973 /**
974  * task. h
975  * @code{c}
976  * UBaseType_t uxTaskPriorityGet( const TaskHandle_t xTask );
977  * @endcode
978  *
979  * INCLUDE_uxTaskPriorityGet must be defined as 1 for this function to be available.
980  * See the configuration section for more information.
981  *
982  * Obtain the priority of any task.
983  *
984  * @param xTask Handle of the task to be queried.  Passing a NULL
985  * handle results in the priority of the calling task being returned.
986  *
987  * @return The priority of xTask.
988  *
989  * Example usage:
990  * @code{c}
991  * void vAFunction( void )
992  * {
993  * TaskHandle_t xHandle;
994  *
995  *   // Create a task, storing the handle.
996  *   xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
997  *
998  *   // ...
999  *
1000  *   // Use the handle to obtain the priority of the created task.
1001  *   // It was created with tskIDLE_PRIORITY, but may have changed
1002  *   // it itself.
1003  *   if( uxTaskPriorityGet( xHandle ) != tskIDLE_PRIORITY )
1004  *   {
1005  *       // The task has changed it's priority.
1006  *   }
1007  *
1008  *   // ...
1009  *
1010  *   // Is our priority higher than the created task?
1011  *   if( uxTaskPriorityGet( xHandle ) < uxTaskPriorityGet( NULL ) )
1012  *   {
1013  *       // Our priority (obtained using NULL handle) is higher.
1014  *   }
1015  * }
1016  * @endcode
1017  * \defgroup uxTaskPriorityGet uxTaskPriorityGet
1018  * \ingroup TaskCtrl
1019  */
1020 UBaseType_t uxTaskPriorityGet( const TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
1021 
1022 /**
1023  * task. h
1024  * @code{c}
1025  * UBaseType_t uxTaskPriorityGetFromISR( const TaskHandle_t xTask );
1026  * @endcode
1027  *
1028  * A version of uxTaskPriorityGet() that can be used from an ISR.
1029  */
1030 UBaseType_t uxTaskPriorityGetFromISR( const TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
1031 
1032 /**
1033  * task. h
1034  * @code{c}
1035  * UBaseType_t uxTaskBasePriorityGet( const TaskHandle_t xTask );
1036  * @endcode
1037  *
1038  * INCLUDE_uxTaskPriorityGet and configUSE_MUTEXES must be defined as 1 for this
1039  * function to be available. See the configuration section for more information.
1040  *
1041  * Obtain the base priority of any task.
1042  *
1043  * @param xTask Handle of the task to be queried.  Passing a NULL
1044  * handle results in the base priority of the calling task being returned.
1045  *
1046  * @return The base priority of xTask.
1047  *
1048  * \defgroup uxTaskPriorityGet uxTaskBasePriorityGet
1049  * \ingroup TaskCtrl
1050  */
1051 UBaseType_t uxTaskBasePriorityGet( const TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
1052 
1053 /**
1054  * task. h
1055  * @code{c}
1056  * UBaseType_t uxTaskBasePriorityGetFromISR( const TaskHandle_t xTask );
1057  * @endcode
1058  *
1059  * A version of uxTaskBasePriorityGet() that can be used from an ISR.
1060  */
1061 UBaseType_t uxTaskBasePriorityGetFromISR( const TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
1062 
1063 /**
1064  * task. h
1065  * @code{c}
1066  * eTaskState eTaskGetState( TaskHandle_t xTask );
1067  * @endcode
1068  *
1069  * INCLUDE_eTaskGetState must be defined as 1 for this function to be available.
1070  * See the configuration section for more information.
1071  *
1072  * Obtain the state of any task.  States are encoded by the eTaskState
1073  * enumerated type.
1074  *
1075  * @param xTask Handle of the task to be queried.
1076  *
1077  * @return The state of xTask at the time the function was called.  Note the
1078  * state of the task might change between the function being called, and the
1079  * functions return value being tested by the calling task.
1080  */
1081 #if ( ( INCLUDE_eTaskGetState == 1 ) || ( configUSE_TRACE_FACILITY == 1 ) || ( INCLUDE_xTaskAbortDelay == 1 ) )
1082     eTaskState eTaskGetState( TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
1083 #endif
1084 
1085 /**
1086  * task. h
1087  * @code{c}
1088  * void vTaskGetInfo( TaskHandle_t xTask, TaskStatus_t *pxTaskStatus, BaseType_t xGetFreeStackSpace, eTaskState eState );
1089  * @endcode
1090  *
1091  * configUSE_TRACE_FACILITY must be defined as 1 for this function to be
1092  * available.  See the configuration section for more information.
1093  *
1094  * Populates a TaskStatus_t structure with information about a task.
1095  *
1096  * @param xTask Handle of the task being queried.  If xTask is NULL then
1097  * information will be returned about the calling task.
1098  *
1099  * @param pxTaskStatus A pointer to the TaskStatus_t structure that will be
1100  * filled with information about the task referenced by the handle passed using
1101  * the xTask parameter.
1102  *
1103  * @param xGetFreeStackSpace The TaskStatus_t structure contains a member to report
1104  * the stack high water mark of the task being queried.  Calculating the stack
1105  * high water mark takes a relatively long time, and can make the system
1106  * temporarily unresponsive - so the xGetFreeStackSpace parameter is provided to
1107  * allow the high water mark checking to be skipped.  The high watermark value
1108  * will only be written to the TaskStatus_t structure if xGetFreeStackSpace is
1109  * not set to pdFALSE;
1110  *
1111  * @param eState The TaskStatus_t structure contains a member to report the
1112  * state of the task being queried.  Obtaining the task state is not as fast as
1113  * a simple assignment - so the eState parameter is provided to allow the state
1114  * information to be omitted from the TaskStatus_t structure.  To obtain state
1115  * information then set eState to eInvalid - otherwise the value passed in
1116  * eState will be reported as the task state in the TaskStatus_t structure.
1117  *
1118  * Example usage:
1119  * @code{c}
1120  * void vAFunction( void )
1121  * {
1122  * TaskHandle_t xHandle;
1123  * TaskStatus_t xTaskDetails;
1124  *
1125  *  // Obtain the handle of a task from its name.
1126  *  xHandle = xTaskGetHandle( "Task_Name" );
1127  *
1128  *  // Check the handle is not NULL.
1129  *  configASSERT( xHandle );
1130  *
1131  *  // Use the handle to obtain further information about the task.
1132  *  vTaskGetInfo( xHandle,
1133  *                &xTaskDetails,
1134  *                pdTRUE, // Include the high water mark in xTaskDetails.
1135  *                eInvalid ); // Include the task state in xTaskDetails.
1136  * }
1137  * @endcode
1138  * \defgroup vTaskGetInfo vTaskGetInfo
1139  * \ingroup TaskCtrl
1140  */
1141 #if ( configUSE_TRACE_FACILITY == 1 )
1142     void vTaskGetInfo( TaskHandle_t xTask,
1143                        TaskStatus_t * pxTaskStatus,
1144                        BaseType_t xGetFreeStackSpace,
1145                        eTaskState eState ) PRIVILEGED_FUNCTION;
1146 #endif
1147 
1148 /**
1149  * task. h
1150  * @code{c}
1151  * void vTaskPrioritySet( TaskHandle_t xTask, UBaseType_t uxNewPriority );
1152  * @endcode
1153  *
1154  * INCLUDE_vTaskPrioritySet must be defined as 1 for this function to be available.
1155  * See the configuration section for more information.
1156  *
1157  * Set the priority of any task.
1158  *
1159  * A context switch will occur before the function returns if the priority
1160  * being set is higher than the currently executing task.
1161  *
1162  * @param xTask Handle to the task for which the priority is being set.
1163  * Passing a NULL handle results in the priority of the calling task being set.
1164  *
1165  * @param uxNewPriority The priority to which the task will be set.
1166  *
1167  * Example usage:
1168  * @code{c}
1169  * void vAFunction( void )
1170  * {
1171  * TaskHandle_t xHandle;
1172  *
1173  *   // Create a task, storing the handle.
1174  *   xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
1175  *
1176  *   // ...
1177  *
1178  *   // Use the handle to raise the priority of the created task.
1179  *   vTaskPrioritySet( xHandle, tskIDLE_PRIORITY + 1 );
1180  *
1181  *   // ...
1182  *
1183  *   // Use a NULL handle to raise our priority to the same value.
1184  *   vTaskPrioritySet( NULL, tskIDLE_PRIORITY + 1 );
1185  * }
1186  * @endcode
1187  * \defgroup vTaskPrioritySet vTaskPrioritySet
1188  * \ingroup TaskCtrl
1189  */
1190 void vTaskPrioritySet( TaskHandle_t xTask,
1191                        UBaseType_t uxNewPriority ) PRIVILEGED_FUNCTION;
1192 
1193 /**
1194  * task. h
1195  * @code{c}
1196  * void vTaskSuspend( TaskHandle_t xTaskToSuspend );
1197  * @endcode
1198  *
1199  * INCLUDE_vTaskSuspend must be defined as 1 for this function to be available.
1200  * See the configuration section for more information.
1201  *
1202  * Suspend any task.  When suspended a task will never get any microcontroller
1203  * processing time, no matter what its priority.
1204  *
1205  * Calls to vTaskSuspend are not accumulative -
1206  * i.e. calling vTaskSuspend () twice on the same task still only requires one
1207  * call to vTaskResume () to ready the suspended task.
1208  *
1209  * @param xTaskToSuspend Handle to the task being suspended.  Passing a NULL
1210  * handle will cause the calling task to be suspended.
1211  *
1212  * Example usage:
1213  * @code{c}
1214  * void vAFunction( void )
1215  * {
1216  * TaskHandle_t xHandle;
1217  *
1218  *   // Create a task, storing the handle.
1219  *   xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
1220  *
1221  *   // ...
1222  *
1223  *   // Use the handle to suspend the created task.
1224  *   vTaskSuspend( xHandle );
1225  *
1226  *   // ...
1227  *
1228  *   // The created task will not run during this period, unless
1229  *   // another task calls vTaskResume( xHandle ).
1230  *
1231  *   //...
1232  *
1233  *
1234  *   // Suspend ourselves.
1235  *   vTaskSuspend( NULL );
1236  *
1237  *   // We cannot get here unless another task calls vTaskResume
1238  *   // with our handle as the parameter.
1239  * }
1240  * @endcode
1241  * \defgroup vTaskSuspend vTaskSuspend
1242  * \ingroup TaskCtrl
1243  */
1244 void vTaskSuspend( TaskHandle_t xTaskToSuspend ) PRIVILEGED_FUNCTION;
1245 
1246 /**
1247  * task. h
1248  * @code{c}
1249  * void vTaskResume( TaskHandle_t xTaskToResume );
1250  * @endcode
1251  *
1252  * INCLUDE_vTaskSuspend must be defined as 1 for this function to be available.
1253  * See the configuration section for more information.
1254  *
1255  * Resumes a suspended task.
1256  *
1257  * A task that has been suspended by one or more calls to vTaskSuspend ()
1258  * will be made available for running again by a single call to
1259  * vTaskResume ().
1260  *
1261  * @param xTaskToResume Handle to the task being readied.
1262  *
1263  * Example usage:
1264  * @code{c}
1265  * void vAFunction( void )
1266  * {
1267  * TaskHandle_t xHandle;
1268  *
1269  *   // Create a task, storing the handle.
1270  *   xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
1271  *
1272  *   // ...
1273  *
1274  *   // Use the handle to suspend the created task.
1275  *   vTaskSuspend( xHandle );
1276  *
1277  *   // ...
1278  *
1279  *   // The created task will not run during this period, unless
1280  *   // another task calls vTaskResume( xHandle ).
1281  *
1282  *   //...
1283  *
1284  *
1285  *   // Resume the suspended task ourselves.
1286  *   vTaskResume( xHandle );
1287  *
1288  *   // The created task will once again get microcontroller processing
1289  *   // time in accordance with its priority within the system.
1290  * }
1291  * @endcode
1292  * \defgroup vTaskResume vTaskResume
1293  * \ingroup TaskCtrl
1294  */
1295 void vTaskResume( TaskHandle_t xTaskToResume ) PRIVILEGED_FUNCTION;
1296 
1297 /**
1298  * task. h
1299  * @code{c}
1300  * void xTaskResumeFromISR( TaskHandle_t xTaskToResume );
1301  * @endcode
1302  *
1303  * INCLUDE_xTaskResumeFromISR must be defined as 1 for this function to be
1304  * available.  See the configuration section for more information.
1305  *
1306  * An implementation of vTaskResume() that can be called from within an ISR.
1307  *
1308  * A task that has been suspended by one or more calls to vTaskSuspend ()
1309  * will be made available for running again by a single call to
1310  * xTaskResumeFromISR ().
1311  *
1312  * xTaskResumeFromISR() should not be used to synchronise a task with an
1313  * interrupt if there is a chance that the interrupt could arrive prior to the
1314  * task being suspended - as this can lead to interrupts being missed. Use of a
1315  * semaphore as a synchronisation mechanism would avoid this eventuality.
1316  *
1317  * @param xTaskToResume Handle to the task being readied.
1318  *
1319  * @return pdTRUE if resuming the task should result in a context switch,
1320  * otherwise pdFALSE. This is used by the ISR to determine if a context switch
1321  * may be required following the ISR.
1322  *
1323  * \defgroup vTaskResumeFromISR vTaskResumeFromISR
1324  * \ingroup TaskCtrl
1325  */
1326 BaseType_t xTaskResumeFromISR( TaskHandle_t xTaskToResume ) PRIVILEGED_FUNCTION;
1327 
1328 #if ( configUSE_CORE_AFFINITY == 1 )
1329 
1330 /**
1331  * @brief Sets the core affinity mask for a task.
1332  *
1333  * It sets the cores on which a task can run. configUSE_CORE_AFFINITY must
1334  * be defined as 1 for this function to be available.
1335  *
1336  * @param xTask The handle of the task to set the core affinity mask for.
1337  * Passing NULL will set the core affinity mask for the calling task.
1338  *
1339  * @param uxCoreAffinityMask A bitwise value that indicates the cores on
1340  * which the task can run. Cores are numbered from 0 to configNUMBER_OF_CORES - 1.
1341  * For example, to ensure that a task can run on core 0 and core 1, set
1342  * uxCoreAffinityMask to 0x03.
1343  *
1344  * Example usage:
1345  *
1346  * // The function that creates task.
1347  * void vAFunction( void )
1348  * {
1349  * TaskHandle_t xHandle;
1350  * UBaseType_t uxCoreAffinityMask;
1351  *
1352  *      // Create a task, storing the handle.
1353  *      xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &( xHandle ) );
1354  *
1355  *      // Define the core affinity mask such that this task can only run
1356  *      // on core 0 and core 2.
1357  *      uxCoreAffinityMask = ( ( 1 << 0 ) | ( 1 << 2 ) );
1358  *
1359  *      //Set the core affinity mask for the task.
1360  *      vTaskCoreAffinitySet( xHandle, uxCoreAffinityMask );
1361  * }
1362  */
1363     void vTaskCoreAffinitySet( const TaskHandle_t xTask,
1364                                UBaseType_t uxCoreAffinityMask );
1365 #endif
1366 
1367 #if ( ( configNUMBER_OF_CORES > 1 ) && ( configUSE_CORE_AFFINITY == 1 ) )
1368 
1369 /**
1370  * @brief Gets the core affinity mask for a task.
1371  *
1372  * configUSE_CORE_AFFINITY must be defined as 1 for this function to be
1373  * available.
1374  *
1375  * @param xTask The handle of the task to get the core affinity mask for.
1376  * Passing NULL will get the core affinity mask for the calling task.
1377  *
1378  * @return The core affinity mask which is a bitwise value that indicates
1379  * the cores on which a task can run. Cores are numbered from 0 to
1380  * configNUMBER_OF_CORES - 1. For example, if a task can run on core 0 and core 1,
1381  * the core affinity mask is 0x03.
1382  *
1383  * Example usage:
1384  *
1385  * // Task handle of the networking task - it is populated elsewhere.
1386  * TaskHandle_t xNetworkingTaskHandle;
1387  *
1388  * void vAFunction( void )
1389  * {
1390  * TaskHandle_t xHandle;
1391  * UBaseType_t uxNetworkingCoreAffinityMask;
1392  *
1393  *     // Create a task, storing the handle.
1394  *     xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &( xHandle ) );
1395  *
1396  *     //Get the core affinity mask for the networking task.
1397  *     uxNetworkingCoreAffinityMask = vTaskCoreAffinityGet( xNetworkingTaskHandle );
1398  *
1399  *     // Here is a hypothetical scenario, just for the example. Assume that we
1400  *     // have 2 cores - Core 0 and core 1. We want to pin the application task to
1401  *     // the core different than the networking task to ensure that the
1402  *     // application task does not interfere with networking.
1403  *     if( ( uxNetworkingCoreAffinityMask & ( 1 << 0 ) ) != 0 )
1404  *     {
1405  *         // The networking task can run on core 0, pin our task to core 1.
1406  *         vTaskCoreAffinitySet( xHandle, ( 1 << 1 ) );
1407  *     }
1408  *     else
1409  *     {
1410  *         // Otherwise, pin our task to core 0.
1411  *         vTaskCoreAffinitySet( xHandle, ( 1 << 0 ) );
1412  *     }
1413  * }
1414  */
1415     UBaseType_t vTaskCoreAffinityGet( ConstTaskHandle_t xTask );
1416 #endif
1417 
1418 #if ( configUSE_TASK_PREEMPTION_DISABLE == 1 )
1419 
1420 /**
1421  * @brief Disables preemption for a task.
1422  *
1423  * @param xTask The handle of the task to disable preemption. Passing NULL
1424  * disables preemption for the calling task.
1425  *
1426  * Example usage:
1427  *
1428  * void vTaskCode( void *pvParameters )
1429  * {
1430  *     // Silence warnings about unused parameters.
1431  *     ( void ) pvParameters;
1432  *
1433  *     for( ;; )
1434  *     {
1435  *         // ... Perform some function here.
1436  *
1437  *         // Disable preemption for this task.
1438  *         vTaskPreemptionDisable( NULL );
1439  *
1440  *         // The task will not be preempted when it is executing in this portion ...
1441  *
1442  *         // ... until the preemption is enabled again.
1443  *         vTaskPreemptionEnable( NULL );
1444  *
1445  *         // The task can be preempted when it is executing in this portion.
1446  *     }
1447  * }
1448  */
1449     void vTaskPreemptionDisable( const TaskHandle_t xTask );
1450 #endif
1451 
1452 #if ( configUSE_TASK_PREEMPTION_DISABLE == 1 )
1453 
1454 /**
1455  * @brief Enables preemption for a task.
1456  *
1457  * @param xTask The handle of the task to enable preemption. Passing NULL
1458  * enables preemption for the calling task.
1459  *
1460  * Example usage:
1461  *
1462  * void vTaskCode( void *pvParameters )
1463  * {
1464  *     // Silence warnings about unused parameters.
1465  *     ( void ) pvParameters;
1466  *
1467  *     for( ;; )
1468  *     {
1469  *         // ... Perform some function here.
1470  *
1471  *         // Disable preemption for this task.
1472  *         vTaskPreemptionDisable( NULL );
1473  *
1474  *         // The task will not be preempted when it is executing in this portion ...
1475  *
1476  *         // ... until the preemption is enabled again.
1477  *         vTaskPreemptionEnable( NULL );
1478  *
1479  *         // The task can be preempted when it is executing in this portion.
1480  *     }
1481  * }
1482  */
1483     void vTaskPreemptionEnable( const TaskHandle_t xTask );
1484 #endif
1485 
1486 /*-----------------------------------------------------------
1487 * SCHEDULER CONTROL
1488 *----------------------------------------------------------*/
1489 
1490 /**
1491  * task. h
1492  * @code{c}
1493  * void vTaskStartScheduler( void );
1494  * @endcode
1495  *
1496  * Starts the real time kernel tick processing.  After calling the kernel
1497  * has control over which tasks are executed and when.
1498  *
1499  * See the demo application file main.c for an example of creating
1500  * tasks and starting the kernel.
1501  *
1502  * Example usage:
1503  * @code{c}
1504  * void vAFunction( void )
1505  * {
1506  *   // Create at least one task before starting the kernel.
1507  *   xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
1508  *
1509  *   // Start the real time kernel with preemption.
1510  *   vTaskStartScheduler ();
1511  *
1512  *   // Will not get here unless a task calls vTaskEndScheduler ()
1513  * }
1514  * @endcode
1515  *
1516  * \defgroup vTaskStartScheduler vTaskStartScheduler
1517  * \ingroup SchedulerControl
1518  */
1519 void vTaskStartScheduler( void ) PRIVILEGED_FUNCTION;
1520 
1521 /**
1522  * task. h
1523  * @code{c}
1524  * void vTaskEndScheduler( void );
1525  * @endcode
1526  *
1527  * NOTE:  At the time of writing only the x86 real mode port, which runs on a PC
1528  * in place of DOS, implements this function.
1529  *
1530  * Stops the real time kernel tick.  All created tasks will be automatically
1531  * deleted and multitasking (either preemptive or cooperative) will
1532  * stop.  Execution then resumes from the point where vTaskStartScheduler ()
1533  * was called, as if vTaskStartScheduler () had just returned.
1534  *
1535  * See the demo application file main. c in the demo/PC directory for an
1536  * example that uses vTaskEndScheduler ().
1537  *
1538  * vTaskEndScheduler () requires an exit function to be defined within the
1539  * portable layer (see vPortEndScheduler () in port. c for the PC port).  This
1540  * performs hardware specific operations such as stopping the kernel tick.
1541  *
1542  * vTaskEndScheduler () will cause all of the resources allocated by the
1543  * kernel to be freed - but will not free resources allocated by application
1544  * tasks.
1545  *
1546  * Example usage:
1547  * @code{c}
1548  * void vTaskCode( void * pvParameters )
1549  * {
1550  *   for( ;; )
1551  *   {
1552  *       // Task code goes here.
1553  *
1554  *       // At some point we want to end the real time kernel processing
1555  *       // so call ...
1556  *       vTaskEndScheduler ();
1557  *   }
1558  * }
1559  *
1560  * void vAFunction( void )
1561  * {
1562  *   // Create at least one task before starting the kernel.
1563  *   xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
1564  *
1565  *   // Start the real time kernel with preemption.
1566  *   vTaskStartScheduler ();
1567  *
1568  *   // Will only get here when the vTaskCode () task has called
1569  *   // vTaskEndScheduler ().  When we get here we are back to single task
1570  *   // execution.
1571  * }
1572  * @endcode
1573  *
1574  * \defgroup vTaskEndScheduler vTaskEndScheduler
1575  * \ingroup SchedulerControl
1576  */
1577 void vTaskEndScheduler( void ) PRIVILEGED_FUNCTION;
1578 
1579 /**
1580  * task. h
1581  * @code{c}
1582  * void vTaskSuspendAll( void );
1583  * @endcode
1584  *
1585  * Suspends the scheduler without disabling interrupts.  Context switches will
1586  * not occur while the scheduler is suspended.
1587  *
1588  * After calling vTaskSuspendAll () the calling task will continue to execute
1589  * without risk of being swapped out until a call to xTaskResumeAll () has been
1590  * made.
1591  *
1592  * API functions that have the potential to cause a context switch (for example,
1593  * xTaskDelayUntil(), xQueueSend(), etc.) must not be called while the scheduler
1594  * is suspended.
1595  *
1596  * Example usage:
1597  * @code{c}
1598  * void vTask1( void * pvParameters )
1599  * {
1600  *   for( ;; )
1601  *   {
1602  *       // Task code goes here.
1603  *
1604  *       // ...
1605  *
1606  *       // At some point the task wants to perform a long operation during
1607  *       // which it does not want to get swapped out.  It cannot use
1608  *       // taskENTER_CRITICAL ()/taskEXIT_CRITICAL () as the length of the
1609  *       // operation may cause interrupts to be missed - including the
1610  *       // ticks.
1611  *
1612  *       // Prevent the real time kernel swapping out the task.
1613  *       vTaskSuspendAll ();
1614  *
1615  *       // Perform the operation here.  There is no need to use critical
1616  *       // sections as we have all the microcontroller processing time.
1617  *       // During this time interrupts will still operate and the kernel
1618  *       // tick count will be maintained.
1619  *
1620  *       // ...
1621  *
1622  *       // The operation is complete.  Restart the kernel.
1623  *       xTaskResumeAll ();
1624  *   }
1625  * }
1626  * @endcode
1627  * \defgroup vTaskSuspendAll vTaskSuspendAll
1628  * \ingroup SchedulerControl
1629  */
1630 void vTaskSuspendAll( void ) PRIVILEGED_FUNCTION;
1631 
1632 /**
1633  * task. h
1634  * @code{c}
1635  * BaseType_t xTaskResumeAll( void );
1636  * @endcode
1637  *
1638  * Resumes scheduler activity after it was suspended by a call to
1639  * vTaskSuspendAll().
1640  *
1641  * xTaskResumeAll() only resumes the scheduler.  It does not unsuspend tasks
1642  * that were previously suspended by a call to vTaskSuspend().
1643  *
1644  * @return If resuming the scheduler caused a context switch then pdTRUE is
1645  *         returned, otherwise pdFALSE is returned.
1646  *
1647  * Example usage:
1648  * @code{c}
1649  * void vTask1( void * pvParameters )
1650  * {
1651  *   for( ;; )
1652  *   {
1653  *       // Task code goes here.
1654  *
1655  *       // ...
1656  *
1657  *       // At some point the task wants to perform a long operation during
1658  *       // which it does not want to get swapped out.  It cannot use
1659  *       // taskENTER_CRITICAL ()/taskEXIT_CRITICAL () as the length of the
1660  *       // operation may cause interrupts to be missed - including the
1661  *       // ticks.
1662  *
1663  *       // Prevent the real time kernel swapping out the task.
1664  *       vTaskSuspendAll ();
1665  *
1666  *       // Perform the operation here.  There is no need to use critical
1667  *       // sections as we have all the microcontroller processing time.
1668  *       // During this time interrupts will still operate and the real
1669  *       // time kernel tick count will be maintained.
1670  *
1671  *       // ...
1672  *
1673  *       // The operation is complete.  Restart the kernel.  We want to force
1674  *       // a context switch - but there is no point if resuming the scheduler
1675  *       // caused a context switch already.
1676  *       if( !xTaskResumeAll () )
1677  *       {
1678  *            taskYIELD ();
1679  *       }
1680  *   }
1681  * }
1682  * @endcode
1683  * \defgroup xTaskResumeAll xTaskResumeAll
1684  * \ingroup SchedulerControl
1685  */
1686 BaseType_t xTaskResumeAll( void ) PRIVILEGED_FUNCTION;
1687 
1688 /*-----------------------------------------------------------
1689 * TASK UTILITIES
1690 *----------------------------------------------------------*/
1691 
1692 /**
1693  * task. h
1694  * @code{c}
1695  * TickType_t xTaskGetTickCount( void );
1696  * @endcode
1697  *
1698  * @return The count of ticks since vTaskStartScheduler was called.
1699  *
1700  * \defgroup xTaskGetTickCount xTaskGetTickCount
1701  * \ingroup TaskUtils
1702  */
1703 TickType_t xTaskGetTickCount( void ) PRIVILEGED_FUNCTION;
1704 
1705 /**
1706  * task. h
1707  * @code{c}
1708  * TickType_t xTaskGetTickCountFromISR( void );
1709  * @endcode
1710  *
1711  * @return The count of ticks since vTaskStartScheduler was called.
1712  *
1713  * This is a version of xTaskGetTickCount() that is safe to be called from an
1714  * ISR - provided that TickType_t is the natural word size of the
1715  * microcontroller being used or interrupt nesting is either not supported or
1716  * not being used.
1717  *
1718  * \defgroup xTaskGetTickCountFromISR xTaskGetTickCountFromISR
1719  * \ingroup TaskUtils
1720  */
1721 TickType_t xTaskGetTickCountFromISR( void ) PRIVILEGED_FUNCTION;
1722 
1723 /**
1724  * task. h
1725  * @code{c}
1726  * uint16_t uxTaskGetNumberOfTasks( void );
1727  * @endcode
1728  *
1729  * @return The number of tasks that the real time kernel is currently managing.
1730  * This includes all ready, blocked and suspended tasks.  A task that
1731  * has been deleted but not yet freed by the idle task will also be
1732  * included in the count.
1733  *
1734  * \defgroup uxTaskGetNumberOfTasks uxTaskGetNumberOfTasks
1735  * \ingroup TaskUtils
1736  */
1737 UBaseType_t uxTaskGetNumberOfTasks( void ) PRIVILEGED_FUNCTION;
1738 
1739 /**
1740  * task. h
1741  * @code{c}
1742  * char *pcTaskGetName( TaskHandle_t xTaskToQuery );
1743  * @endcode
1744  *
1745  * @return The text (human readable) name of the task referenced by the handle
1746  * xTaskToQuery.  A task can query its own name by either passing in its own
1747  * handle, or by setting xTaskToQuery to NULL.
1748  *
1749  * \defgroup pcTaskGetName pcTaskGetName
1750  * \ingroup TaskUtils
1751  */
1752 char * pcTaskGetName( TaskHandle_t xTaskToQuery ) PRIVILEGED_FUNCTION;
1753 
1754 /**
1755  * task. h
1756  * @code{c}
1757  * TaskHandle_t xTaskGetHandle( const char *pcNameToQuery );
1758  * @endcode
1759  *
1760  * NOTE:  This function takes a relatively long time to complete and should be
1761  * used sparingly.
1762  *
1763  * @return The handle of the task that has the human readable name pcNameToQuery.
1764  * NULL is returned if no matching name is found.  INCLUDE_xTaskGetHandle
1765  * must be set to 1 in FreeRTOSConfig.h for pcTaskGetHandle() to be available.
1766  *
1767  * \defgroup pcTaskGetHandle pcTaskGetHandle
1768  * \ingroup TaskUtils
1769  */
1770 #if ( INCLUDE_xTaskGetHandle == 1 )
1771     TaskHandle_t xTaskGetHandle( const char * pcNameToQuery ) PRIVILEGED_FUNCTION;
1772 #endif
1773 
1774 /**
1775  * task. h
1776  * @code{c}
1777  * BaseType_t xTaskGetStaticBuffers( TaskHandle_t xTask,
1778  *                                   StackType_t ** ppuxStackBuffer,
1779  *                                   StaticTask_t ** ppxTaskBuffer );
1780  * @endcode
1781  *
1782  * Retrieve pointers to a statically created task's data structure
1783  * buffer and stack buffer. These are the same buffers that are supplied
1784  * at the time of creation.
1785  *
1786  * @param xTask The task for which to retrieve the buffers.
1787  *
1788  * @param ppuxStackBuffer Used to return a pointer to the task's stack buffer.
1789  *
1790  * @param ppxTaskBuffer Used to return a pointer to the task's data structure
1791  * buffer.
1792  *
1793  * @return pdTRUE if buffers were retrieved, pdFALSE otherwise.
1794  *
1795  * \defgroup xTaskGetStaticBuffers xTaskGetStaticBuffers
1796  * \ingroup TaskUtils
1797  */
1798 #if ( configSUPPORT_STATIC_ALLOCATION == 1 )
1799     BaseType_t xTaskGetStaticBuffers( TaskHandle_t xTask,
1800                                       StackType_t ** ppuxStackBuffer,
1801                                       StaticTask_t ** ppxTaskBuffer ) PRIVILEGED_FUNCTION;
1802 #endif /* configSUPPORT_STATIC_ALLOCATION */
1803 
1804 /**
1805  * task.h
1806  * @code{c}
1807  * UBaseType_t uxTaskGetStackHighWaterMark( TaskHandle_t xTask );
1808  * @endcode
1809  *
1810  * INCLUDE_uxTaskGetStackHighWaterMark must be set to 1 in FreeRTOSConfig.h for
1811  * this function to be available.
1812  *
1813  * Returns the high water mark of the stack associated with xTask.  That is,
1814  * the minimum free stack space there has been (in words, so on a 32 bit machine
1815  * a value of 1 means 4 bytes) since the task started.  The smaller the returned
1816  * number the closer the task has come to overflowing its stack.
1817  *
1818  * uxTaskGetStackHighWaterMark() and uxTaskGetStackHighWaterMark2() are the
1819  * same except for their return type.  Using configSTACK_DEPTH_TYPE allows the
1820  * user to determine the return type.  It gets around the problem of the value
1821  * overflowing on 8-bit types without breaking backward compatibility for
1822  * applications that expect an 8-bit return type.
1823  *
1824  * @param xTask Handle of the task associated with the stack to be checked.
1825  * Set xTask to NULL to check the stack of the calling task.
1826  *
1827  * @return The smallest amount of free stack space there has been (in words, so
1828  * actual spaces on the stack rather than bytes) since the task referenced by
1829  * xTask was created.
1830  */
1831 #if ( INCLUDE_uxTaskGetStackHighWaterMark == 1 )
1832     UBaseType_t uxTaskGetStackHighWaterMark( TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
1833 #endif
1834 
1835 /**
1836  * task.h
1837  * @code{c}
1838  * configSTACK_DEPTH_TYPE uxTaskGetStackHighWaterMark2( TaskHandle_t xTask );
1839  * @endcode
1840  *
1841  * INCLUDE_uxTaskGetStackHighWaterMark2 must be set to 1 in FreeRTOSConfig.h for
1842  * this function to be available.
1843  *
1844  * Returns the high water mark of the stack associated with xTask.  That is,
1845  * the minimum free stack space there has been (in words, so on a 32 bit machine
1846  * a value of 1 means 4 bytes) since the task started.  The smaller the returned
1847  * number the closer the task has come to overflowing its stack.
1848  *
1849  * uxTaskGetStackHighWaterMark() and uxTaskGetStackHighWaterMark2() are the
1850  * same except for their return type.  Using configSTACK_DEPTH_TYPE allows the
1851  * user to determine the return type.  It gets around the problem of the value
1852  * overflowing on 8-bit types without breaking backward compatibility for
1853  * applications that expect an 8-bit return type.
1854  *
1855  * @param xTask Handle of the task associated with the stack to be checked.
1856  * Set xTask to NULL to check the stack of the calling task.
1857  *
1858  * @return The smallest amount of free stack space there has been (in words, so
1859  * actual spaces on the stack rather than bytes) since the task referenced by
1860  * xTask was created.
1861  */
1862 #if ( INCLUDE_uxTaskGetStackHighWaterMark2 == 1 )
1863     configSTACK_DEPTH_TYPE uxTaskGetStackHighWaterMark2( TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
1864 #endif
1865 
1866 /* When using trace macros it is sometimes necessary to include task.h before
1867  * FreeRTOS.h.  When this is done TaskHookFunction_t will not yet have been defined,
1868  * so the following two prototypes will cause a compilation error.  This can be
1869  * fixed by simply guarding against the inclusion of these two prototypes unless
1870  * they are explicitly required by the configUSE_APPLICATION_TASK_TAG configuration
1871  * constant. */
1872 #ifdef configUSE_APPLICATION_TASK_TAG
1873     #if configUSE_APPLICATION_TASK_TAG == 1
1874 
1875 /**
1876  * task.h
1877  * @code{c}
1878  * void vTaskSetApplicationTaskTag( TaskHandle_t xTask, TaskHookFunction_t pxHookFunction );
1879  * @endcode
1880  *
1881  * Sets pxHookFunction to be the task hook function used by the task xTask.
1882  * Passing xTask as NULL has the effect of setting the calling tasks hook
1883  * function.
1884  */
1885         void vTaskSetApplicationTaskTag( TaskHandle_t xTask,
1886                                          TaskHookFunction_t pxHookFunction ) PRIVILEGED_FUNCTION;
1887 
1888 /**
1889  * task.h
1890  * @code{c}
1891  * void xTaskGetApplicationTaskTag( TaskHandle_t xTask );
1892  * @endcode
1893  *
1894  * Returns the pxHookFunction value assigned to the task xTask.  Do not
1895  * call from an interrupt service routine - call
1896  * xTaskGetApplicationTaskTagFromISR() instead.
1897  */
1898         TaskHookFunction_t xTaskGetApplicationTaskTag( TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
1899 
1900 /**
1901  * task.h
1902  * @code{c}
1903  * void xTaskGetApplicationTaskTagFromISR( TaskHandle_t xTask );
1904  * @endcode
1905  *
1906  * Returns the pxHookFunction value assigned to the task xTask.  Can
1907  * be called from an interrupt service routine.
1908  */
1909         TaskHookFunction_t xTaskGetApplicationTaskTagFromISR( TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
1910     #endif /* configUSE_APPLICATION_TASK_TAG ==1 */
1911 #endif /* ifdef configUSE_APPLICATION_TASK_TAG */
1912 
1913 #if ( configNUM_THREAD_LOCAL_STORAGE_POINTERS > 0 )
1914 
1915 /* Each task contains an array of pointers that is dimensioned by the
1916  * configNUM_THREAD_LOCAL_STORAGE_POINTERS setting in FreeRTOSConfig.h.  The
1917  * kernel does not use the pointers itself, so the application writer can use
1918  * the pointers for any purpose they wish.  The following two functions are
1919  * used to set and query a pointer respectively. */
1920     void vTaskSetThreadLocalStoragePointer( TaskHandle_t xTaskToSet,
1921                                             BaseType_t xIndex,
1922                                             void * pvValue ) PRIVILEGED_FUNCTION;
1923     void * pvTaskGetThreadLocalStoragePointer( TaskHandle_t xTaskToQuery,
1924                                                BaseType_t xIndex ) PRIVILEGED_FUNCTION;
1925 
1926 #endif
1927 
1928 #if ( configCHECK_FOR_STACK_OVERFLOW > 0 )
1929 
1930 /**
1931  * task.h
1932  * @code{c}
1933  * void vApplicationStackOverflowHook( TaskHandle_t xTask, char *pcTaskName);
1934  * @endcode
1935  *
1936  * The application stack overflow hook is called when a stack overflow is detected for a task.
1937  *
1938  * Details on stack overflow detection can be found here: https://www.FreeRTOS.org/Stacks-and-stack-overflow-checking.html
1939  *
1940  * @param xTask the task that just exceeded its stack boundaries.
1941  * @param pcTaskName A character string containing the name of the offending task.
1942  */
1943     /* MISRA Ref 8.6.1 [External linkage] */
1944     /* More details at: https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/MISRA.md#rule-86 */
1945     /* coverity[misra_c_2012_rule_8_6_violation] */
1946     void vApplicationStackOverflowHook( TaskHandle_t xTask,
1947                                         char * pcTaskName );
1948 
1949 #endif
1950 
1951 #if ( configUSE_IDLE_HOOK == 1 )
1952 
1953 /**
1954  * task.h
1955  * @code{c}
1956  * void vApplicationIdleHook( void );
1957  * @endcode
1958  *
1959  * The application idle hook is called by the idle task.
1960  * This allows the application designer to add background functionality without
1961  * the overhead of a separate task.
1962  * NOTE: vApplicationIdleHook() MUST NOT, UNDER ANY CIRCUMSTANCES, CALL A FUNCTION THAT MIGHT BLOCK.
1963  */
1964     /* MISRA Ref 8.6.1 [External linkage] */
1965     /* More details at: https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/MISRA.md#rule-86 */
1966     /* coverity[misra_c_2012_rule_8_6_violation] */
1967     void vApplicationIdleHook( void );
1968 
1969 #endif
1970 
1971 
1972 #if  ( configUSE_TICK_HOOK != 0 )
1973 
1974 /**
1975  *  task.h
1976  * @code{c}
1977  * void vApplicationTickHook( void );
1978  * @endcode
1979  *
1980  * This hook function is called in the system tick handler after any OS work is completed.
1981  */
1982     /* MISRA Ref 8.6.1 [External linkage] */
1983     /* More details at: https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/MISRA.md#rule-86 */
1984     /* coverity[misra_c_2012_rule_8_6_violation] */
1985     void vApplicationTickHook( void );
1986 
1987 #endif
1988 
1989 #if ( configSUPPORT_STATIC_ALLOCATION == 1 )
1990 
1991 /**
1992  * task.h
1993  * @code{c}
1994  * void vApplicationGetIdleTaskMemory( StaticTask_t ** ppxIdleTaskTCBBuffer, StackType_t ** ppxIdleTaskStackBuffer, configSTACK_DEPTH_TYPE * puxIdleTaskStackSize )
1995  * @endcode
1996  *
1997  * This function is used to provide a statically allocated block of memory to FreeRTOS to hold the Idle Task TCB.  This function is required when
1998  * configSUPPORT_STATIC_ALLOCATION is set.  For more information see this URI: https://www.FreeRTOS.org/a00110.html#configSUPPORT_STATIC_ALLOCATION
1999  *
2000  * @param ppxIdleTaskTCBBuffer A handle to a statically allocated TCB buffer
2001  * @param ppxIdleTaskStackBuffer A handle to a statically allocated Stack buffer for the idle task
2002  * @param puxIdleTaskStackSize A pointer to the number of elements that will fit in the allocated stack buffer
2003  */
2004     void vApplicationGetIdleTaskMemory( StaticTask_t ** ppxIdleTaskTCBBuffer,
2005                                         StackType_t ** ppxIdleTaskStackBuffer,
2006                                         configSTACK_DEPTH_TYPE * puxIdleTaskStackSize );
2007 
2008 /**
2009  * task.h
2010  * @code{c}
2011  * void vApplicationGetPassiveIdleTaskMemory( StaticTask_t ** ppxIdleTaskTCBBuffer, StackType_t ** ppxIdleTaskStackBuffer, configSTACK_DEPTH_TYPE * puxIdleTaskStackSize, BaseType_t xCoreID )
2012  * @endcode
2013  *
2014  * This function is used to provide a statically allocated block of memory to FreeRTOS to hold the Idle Tasks TCB.  This function is required when
2015  * configSUPPORT_STATIC_ALLOCATION is set.  For more information see this URI: https://www.FreeRTOS.org/a00110.html#configSUPPORT_STATIC_ALLOCATION
2016  *
2017  * In the FreeRTOS SMP, there are a total of configNUMBER_OF_CORES idle tasks:
2018  *  1. 1 Active idle task which does all the housekeeping.
2019  *  2. ( configNUMBER_OF_CORES - 1 ) Passive idle tasks which do nothing.
2020  * These idle tasks are created to ensure that each core has an idle task to run when
2021  * no other task is available to run.
2022  *
2023  * The function vApplicationGetPassiveIdleTaskMemory is called with passive idle
2024  * task index 0, 1 ... ( configNUMBER_OF_CORES - 2 ) to get memory for passive idle
2025  * tasks.
2026  *
2027  * @param ppxIdleTaskTCBBuffer A handle to a statically allocated TCB buffer
2028  * @param ppxIdleTaskStackBuffer A handle to a statically allocated Stack buffer for the idle task
2029  * @param puxIdleTaskStackSize A pointer to the number of elements that will fit in the allocated stack buffer
2030  * @param xPassiveIdleTaskIndex The passive idle task index of the idle task buffer
2031  */
2032     #if ( configNUMBER_OF_CORES > 1 )
2033         void vApplicationGetPassiveIdleTaskMemory( StaticTask_t ** ppxIdleTaskTCBBuffer,
2034                                                    StackType_t ** ppxIdleTaskStackBuffer,
2035                                                    configSTACK_DEPTH_TYPE * puxIdleTaskStackSize,
2036                                                    BaseType_t xPassiveIdleTaskIndex );
2037     #endif /* #if ( configNUMBER_OF_CORES > 1 ) */
2038 #endif /* if ( configSUPPORT_STATIC_ALLOCATION == 1 ) */
2039 
2040 /**
2041  * task.h
2042  * @code{c}
2043  * BaseType_t xTaskCallApplicationTaskHook( TaskHandle_t xTask, void *pvParameter );
2044  * @endcode
2045  *
2046  * Calls the hook function associated with xTask.  Passing xTask as NULL has
2047  * the effect of calling the Running tasks (the calling task) hook function.
2048  *
2049  * pvParameter is passed to the hook function for the task to interpret as it
2050  * wants.  The return value is the value returned by the task hook function
2051  * registered by the user.
2052  */
2053 #if ( configUSE_APPLICATION_TASK_TAG == 1 )
2054     BaseType_t xTaskCallApplicationTaskHook( TaskHandle_t xTask,
2055                                              void * pvParameter ) PRIVILEGED_FUNCTION;
2056 #endif
2057 
2058 /**
2059  * xTaskGetIdleTaskHandle() is only available if
2060  * INCLUDE_xTaskGetIdleTaskHandle is set to 1 in FreeRTOSConfig.h.
2061  *
2062  * In single-core FreeRTOS, this function simply returns the handle of the idle
2063  * task. It is not valid to call xTaskGetIdleTaskHandle() before the scheduler
2064  * has been started.
2065  *
2066  * In the FreeRTOS SMP, there are a total of configNUMBER_OF_CORES idle tasks:
2067  *  1. 1 Active idle task which does all the housekeeping.
2068  *  2. ( configNUMBER_OF_CORES - 1 ) Passive idle tasks which do nothing.
2069  * These idle tasks are created to ensure that each core has an idle task to run when
2070  * no other task is available to run. Call xTaskGetIdleTaskHandle() or
2071  * xTaskGetIdleTaskHandleForCore() with xCoreID set to 0  to get the Active
2072  * idle task handle. Call xTaskGetIdleTaskHandleForCore() with xCoreID set to
2073  * 1,2 ... ( configNUMBER_OF_CORES - 1 ) to get the Passive idle task handles.
2074  */
2075 #if ( INCLUDE_xTaskGetIdleTaskHandle == 1 )
2076     #if ( configNUMBER_OF_CORES == 1 )
2077         TaskHandle_t xTaskGetIdleTaskHandle( void ) PRIVILEGED_FUNCTION;
2078     #endif /* #if ( configNUMBER_OF_CORES == 1 ) */
2079 
2080     TaskHandle_t xTaskGetIdleTaskHandleForCore( BaseType_t xCoreID ) PRIVILEGED_FUNCTION;
2081 #endif /* #if ( INCLUDE_xTaskGetIdleTaskHandle == 1 ) */
2082 
2083 /**
2084  * configUSE_TRACE_FACILITY must be defined as 1 in FreeRTOSConfig.h for
2085  * uxTaskGetSystemState() to be available.
2086  *
2087  * uxTaskGetSystemState() populates an TaskStatus_t structure for each task in
2088  * the system.  TaskStatus_t structures contain, among other things, members
2089  * for the task handle, task name, task priority, task state, and total amount
2090  * of run time consumed by the task.  See the TaskStatus_t structure
2091  * definition in this file for the full member list.
2092  *
2093  * NOTE:  This function is intended for debugging use only as its use results in
2094  * the scheduler remaining suspended for an extended period.
2095  *
2096  * @param pxTaskStatusArray A pointer to an array of TaskStatus_t structures.
2097  * The array must contain at least one TaskStatus_t structure for each task
2098  * that is under the control of the RTOS.  The number of tasks under the control
2099  * of the RTOS can be determined using the uxTaskGetNumberOfTasks() API function.
2100  *
2101  * @param uxArraySize The size of the array pointed to by the pxTaskStatusArray
2102  * parameter.  The size is specified as the number of indexes in the array, or
2103  * the number of TaskStatus_t structures contained in the array, not by the
2104  * number of bytes in the array.
2105  *
2106  * @param pulTotalRunTime If configGENERATE_RUN_TIME_STATS is set to 1 in
2107  * FreeRTOSConfig.h then *pulTotalRunTime is set by uxTaskGetSystemState() to the
2108  * total run time (as defined by the run time stats clock, see
2109  * https://www.FreeRTOS.org/rtos-run-time-stats.html) since the target booted.
2110  * pulTotalRunTime can be set to NULL to omit the total run time information.
2111  *
2112  * @return The number of TaskStatus_t structures that were populated by
2113  * uxTaskGetSystemState().  This should equal the number returned by the
2114  * uxTaskGetNumberOfTasks() API function, but will be zero if the value passed
2115  * in the uxArraySize parameter was too small.
2116  *
2117  * Example usage:
2118  * @code{c}
2119  *  // This example demonstrates how a human readable table of run time stats
2120  *  // information is generated from raw data provided by uxTaskGetSystemState().
2121  *  // The human readable table is written to pcWriteBuffer
2122  *  void vTaskGetRunTimeStats( char *pcWriteBuffer )
2123  *  {
2124  *  TaskStatus_t *pxTaskStatusArray;
2125  *  volatile UBaseType_t uxArraySize, x;
2126  *  configRUN_TIME_COUNTER_TYPE ulTotalRunTime, ulStatsAsPercentage;
2127  *
2128  *      // Make sure the write buffer does not contain a string.
2129  * pcWriteBuffer = 0x00;
2130  *
2131  *      // Take a snapshot of the number of tasks in case it changes while this
2132  *      // function is executing.
2133  *      uxArraySize = uxTaskGetNumberOfTasks();
2134  *
2135  *      // Allocate a TaskStatus_t structure for each task.  An array could be
2136  *      // allocated statically at compile time.
2137  *      pxTaskStatusArray = pvPortMalloc( uxArraySize * sizeof( TaskStatus_t ) );
2138  *
2139  *      if( pxTaskStatusArray != NULL )
2140  *      {
2141  *          // Generate raw status information about each task.
2142  *          uxArraySize = uxTaskGetSystemState( pxTaskStatusArray, uxArraySize, &ulTotalRunTime );
2143  *
2144  *          // For percentage calculations.
2145  *          ulTotalRunTime /= 100U;
2146  *
2147  *          // Avoid divide by zero errors.
2148  *          if( ulTotalRunTime > 0 )
2149  *          {
2150  *              // For each populated position in the pxTaskStatusArray array,
2151  *              // format the raw data as human readable ASCII data
2152  *              for( x = 0; x < uxArraySize; x++ )
2153  *              {
2154  *                  // What percentage of the total run time has the task used?
2155  *                  // This will always be rounded down to the nearest integer.
2156  *                  // ulTotalRunTimeDiv100 has already been divided by 100.
2157  *                  ulStatsAsPercentage = pxTaskStatusArray[ x ].ulRunTimeCounter / ulTotalRunTime;
2158  *
2159  *                  if( ulStatsAsPercentage > 0U )
2160  *                  {
2161  *                      sprintf( pcWriteBuffer, "%s\t\t%lu\t\t%lu%%\r\n", pxTaskStatusArray[ x ].pcTaskName, pxTaskStatusArray[ x ].ulRunTimeCounter, ulStatsAsPercentage );
2162  *                  }
2163  *                  else
2164  *                  {
2165  *                      // If the percentage is zero here then the task has
2166  *                      // consumed less than 1% of the total run time.
2167  *                      sprintf( pcWriteBuffer, "%s\t\t%lu\t\t<1%%\r\n", pxTaskStatusArray[ x ].pcTaskName, pxTaskStatusArray[ x ].ulRunTimeCounter );
2168  *                  }
2169  *
2170  *                  pcWriteBuffer += strlen( ( char * ) pcWriteBuffer );
2171  *              }
2172  *          }
2173  *
2174  *          // The array is no longer needed, free the memory it consumes.
2175  *          vPortFree( pxTaskStatusArray );
2176  *      }
2177  *  }
2178  *  @endcode
2179  */
2180 #if ( configUSE_TRACE_FACILITY == 1 )
2181     UBaseType_t uxTaskGetSystemState( TaskStatus_t * const pxTaskStatusArray,
2182                                       const UBaseType_t uxArraySize,
2183                                       configRUN_TIME_COUNTER_TYPE * const pulTotalRunTime ) PRIVILEGED_FUNCTION;
2184 #endif
2185 
2186 /**
2187  * task. h
2188  * @code{c}
2189  * void vTaskListTasks( char *pcWriteBuffer, size_t uxBufferLength );
2190  * @endcode
2191  *
2192  * configUSE_TRACE_FACILITY and configUSE_STATS_FORMATTING_FUNCTIONS must
2193  * both be defined as 1 for this function to be available.  See the
2194  * configuration section of the FreeRTOS.org website for more information.
2195  *
2196  * NOTE 1: This function will disable interrupts for its duration.  It is
2197  * not intended for normal application runtime use but as a debug aid.
2198  *
2199  * Lists all the current tasks, along with their current state and stack
2200  * usage high water mark.
2201  *
2202  * Tasks are reported as running ('X'), blocked ('B'), ready ('R'), deleted ('D')
2203  * or suspended ('S').
2204  *
2205  * PLEASE NOTE:
2206  *
2207  * This function is provided for convenience only, and is used by many of the
2208  * demo applications.  Do not consider it to be part of the scheduler.
2209  *
2210  * vTaskListTasks() calls uxTaskGetSystemState(), then formats part of the
2211  * uxTaskGetSystemState() output into a human readable table that displays task
2212  * information in the following format:
2213  * Task Name, Task State, Task Priority, Task Stack High Watermak, Task Number.
2214  *
2215  * The following is a sample output:
2216  * Task A       X       2           67           2
2217  * Task B       R       1           67           3
2218  * IDLE         R       0           67           5
2219  * Tmr Svc      B       6           137          6
2220  *
2221  * Stack usage specified as the number of unused StackType_t words stack can hold
2222  * on top of stack - not the number of bytes.
2223  *
2224  * vTaskListTasks() has a dependency on the snprintf() C library function that might
2225  * bloat the code size, use a lot of stack, and provide different results on
2226  * different platforms.  An alternative, tiny, third party, and limited
2227  * functionality implementation of snprintf() is provided in many of the
2228  * FreeRTOS/Demo sub-directories in a file called printf-stdarg.c (note
2229  * printf-stdarg.c does not provide a full snprintf() implementation!).
2230  *
2231  * It is recommended that production systems call uxTaskGetSystemState()
2232  * directly to get access to raw stats data, rather than indirectly through a
2233  * call to vTaskListTasks().
2234  *
2235  * @param pcWriteBuffer A buffer into which the above mentioned details
2236  * will be written, in ASCII form.  This buffer is assumed to be large
2237  * enough to contain the generated report.  Approximately 40 bytes per
2238  * task should be sufficient.
2239  *
2240  * @param uxBufferLength Length of the pcWriteBuffer.
2241  *
2242  * \defgroup vTaskListTasks vTaskListTasks
2243  * \ingroup TaskUtils
2244  */
2245 #if ( ( configUSE_TRACE_FACILITY == 1 ) && ( configUSE_STATS_FORMATTING_FUNCTIONS > 0 ) )
2246     void vTaskListTasks( char * pcWriteBuffer,
2247                          size_t uxBufferLength ) PRIVILEGED_FUNCTION;
2248 #endif
2249 
2250 /**
2251  * task. h
2252  * @code{c}
2253  * void vTaskList( char *pcWriteBuffer );
2254  * @endcode
2255  *
2256  * configUSE_TRACE_FACILITY and configUSE_STATS_FORMATTING_FUNCTIONS must
2257  * both be defined as 1 for this function to be available.  See the
2258  * configuration section of the FreeRTOS.org website for more information.
2259  *
2260  * WARN: This function assumes that the pcWriteBuffer is of length
2261  * configSTATS_BUFFER_MAX_LENGTH. This function is there only for
2262  * backward compatibility. New applications are recommended to
2263  * use vTaskListTasks and supply the length of the pcWriteBuffer explicitly.
2264  *
2265  * NOTE 1: This function will disable interrupts for its duration.  It is
2266  * not intended for normal application runtime use but as a debug aid.
2267  *
2268  * Lists all the current tasks, along with their current state and stack
2269  * usage high water mark.
2270  *
2271  * Tasks are reported as running ('X'), blocked ('B'), ready ('R'), deleted ('D')
2272  * or suspended ('S').
2273  *
2274  * PLEASE NOTE:
2275  *
2276  * This function is provided for convenience only, and is used by many of the
2277  * demo applications.  Do not consider it to be part of the scheduler.
2278  *
2279  * vTaskList() calls uxTaskGetSystemState(), then formats part of the
2280  * uxTaskGetSystemState() output into a human readable table that displays task
2281  * information in the following format:
2282  * Task Name, Task State, Task Priority, Task Stack High Watermak, Task Number.
2283  *
2284  * The following is a sample output:
2285  * Task A       X       2           67           2
2286  * Task B       R       1           67           3
2287  * IDLE         R       0           67           5
2288  * Tmr Svc      B       6           137          6
2289  *
2290  * Stack usage specified as the number of unused StackType_t words stack can hold
2291  * on top of stack - not the number of bytes.
2292  *
2293  * vTaskList() has a dependency on the snprintf() C library function that might
2294  * bloat the code size, use a lot of stack, and provide different results on
2295  * different platforms.  An alternative, tiny, third party, and limited
2296  * functionality implementation of snprintf() is provided in many of the
2297  * FreeRTOS/Demo sub-directories in a file called printf-stdarg.c (note
2298  * printf-stdarg.c does not provide a full snprintf() implementation!).
2299  *
2300  * It is recommended that production systems call uxTaskGetSystemState()
2301  * directly to get access to raw stats data, rather than indirectly through a
2302  * call to vTaskList().
2303  *
2304  * @param pcWriteBuffer A buffer into which the above mentioned details
2305  * will be written, in ASCII form.  This buffer is assumed to be large
2306  * enough to contain the generated report.  Approximately 40 bytes per
2307  * task should be sufficient.
2308  *
2309  * \defgroup vTaskList vTaskList
2310  * \ingroup TaskUtils
2311  */
2312 #define vTaskList( pcWriteBuffer )    vTaskListTasks( ( pcWriteBuffer ), configSTATS_BUFFER_MAX_LENGTH )
2313 
2314 /**
2315  * task. h
2316  * @code{c}
2317  * void vTaskGetRunTimeStatistics( char *pcWriteBuffer, size_t uxBufferLength );
2318  * @endcode
2319  *
2320  * configGENERATE_RUN_TIME_STATS and configUSE_STATS_FORMATTING_FUNCTIONS
2321  * must both be defined as 1 for this function to be available.  The application
2322  * must also then provide definitions for
2323  * portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() and portGET_RUN_TIME_COUNTER_VALUE()
2324  * to configure a peripheral timer/counter and return the timers current count
2325  * value respectively.  The counter should be at least 10 times the frequency of
2326  * the tick count.
2327  *
2328  * NOTE 1: This function will disable interrupts for its duration.  It is
2329  * not intended for normal application runtime use but as a debug aid.
2330  *
2331  * Setting configGENERATE_RUN_TIME_STATS to 1 will result in a total
2332  * accumulated execution time being stored for each task.  The resolution
2333  * of the accumulated time value depends on the frequency of the timer
2334  * configured by the portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() macro.
2335  * Calling vTaskGetRunTimeStatistics() writes the total execution time of each
2336  * task into a buffer, both as an absolute count value and as a percentage
2337  * of the total system execution time.
2338  *
2339  * NOTE 2:
2340  *
2341  * This function is provided for convenience only, and is used by many of the
2342  * demo applications.  Do not consider it to be part of the scheduler.
2343  *
2344  * vTaskGetRunTimeStatistics() calls uxTaskGetSystemState(), then formats part of
2345  * the uxTaskGetSystemState() output into a human readable table that displays the
2346  * amount of time each task has spent in the Running state in both absolute and
2347  * percentage terms.
2348  *
2349  * vTaskGetRunTimeStatistics() has a dependency on the snprintf() C library function
2350  * that might bloat the code size, use a lot of stack, and provide different
2351  * results on different platforms.  An alternative, tiny, third party, and
2352  * limited functionality implementation of snprintf() is provided in many of the
2353  * FreeRTOS/Demo sub-directories in a file called printf-stdarg.c (note
2354  * printf-stdarg.c does not provide a full snprintf() implementation!).
2355  *
2356  * It is recommended that production systems call uxTaskGetSystemState() directly
2357  * to get access to raw stats data, rather than indirectly through a call to
2358  * vTaskGetRunTimeStatistics().
2359  *
2360  * @param pcWriteBuffer A buffer into which the execution times will be
2361  * written, in ASCII form.  This buffer is assumed to be large enough to
2362  * contain the generated report.  Approximately 40 bytes per task should
2363  * be sufficient.
2364  *
2365  * @param uxBufferLength Length of the pcWriteBuffer.
2366  *
2367  * \defgroup vTaskGetRunTimeStatistics vTaskGetRunTimeStatistics
2368  * \ingroup TaskUtils
2369  */
2370 #if ( ( configGENERATE_RUN_TIME_STATS == 1 ) && ( configUSE_STATS_FORMATTING_FUNCTIONS > 0 ) && ( configUSE_TRACE_FACILITY == 1 ) )
2371     void vTaskGetRunTimeStatistics( char * pcWriteBuffer,
2372                                     size_t uxBufferLength ) PRIVILEGED_FUNCTION;
2373 #endif
2374 
2375 /**
2376  * task. h
2377  * @code{c}
2378  * void vTaskGetRunTimeStats( char *pcWriteBuffer );
2379  * @endcode
2380  *
2381  * configGENERATE_RUN_TIME_STATS and configUSE_STATS_FORMATTING_FUNCTIONS
2382  * must both be defined as 1 for this function to be available.  The application
2383  * must also then provide definitions for
2384  * portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() and portGET_RUN_TIME_COUNTER_VALUE()
2385  * to configure a peripheral timer/counter and return the timers current count
2386  * value respectively.  The counter should be at least 10 times the frequency of
2387  * the tick count.
2388  *
2389  * WARN: This function assumes that the pcWriteBuffer is of length
2390  * configSTATS_BUFFER_MAX_LENGTH. This function is there only for
2391  * backward compatibility. New applications are recommended to use
2392  * vTaskGetRunTimeStatistics and supply the length of the pcWriteBuffer
2393  * explicitly.
2394  *
2395  * NOTE 1: This function will disable interrupts for its duration.  It is
2396  * not intended for normal application runtime use but as a debug aid.
2397  *
2398  * Setting configGENERATE_RUN_TIME_STATS to 1 will result in a total
2399  * accumulated execution time being stored for each task.  The resolution
2400  * of the accumulated time value depends on the frequency of the timer
2401  * configured by the portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() macro.
2402  * Calling vTaskGetRunTimeStats() writes the total execution time of each
2403  * task into a buffer, both as an absolute count value and as a percentage
2404  * of the total system execution time.
2405  *
2406  * NOTE 2:
2407  *
2408  * This function is provided for convenience only, and is used by many of the
2409  * demo applications.  Do not consider it to be part of the scheduler.
2410  *
2411  * vTaskGetRunTimeStats() calls uxTaskGetSystemState(), then formats part of the
2412  * uxTaskGetSystemState() output into a human readable table that displays the
2413  * amount of time each task has spent in the Running state in both absolute and
2414  * percentage terms.
2415  *
2416  * vTaskGetRunTimeStats() has a dependency on the snprintf() C library function
2417  * that might bloat the code size, use a lot of stack, and provide different
2418  * results on different platforms.  An alternative, tiny, third party, and
2419  * limited functionality implementation of snprintf() is provided in many of the
2420  * FreeRTOS/Demo sub-directories in a file called printf-stdarg.c (note
2421  * printf-stdarg.c does not provide a full snprintf() implementation!).
2422  *
2423  * It is recommended that production systems call uxTaskGetSystemState() directly
2424  * to get access to raw stats data, rather than indirectly through a call to
2425  * vTaskGetRunTimeStats().
2426  *
2427  * @param pcWriteBuffer A buffer into which the execution times will be
2428  * written, in ASCII form.  This buffer is assumed to be large enough to
2429  * contain the generated report.  Approximately 40 bytes per task should
2430  * be sufficient.
2431  *
2432  * \defgroup vTaskGetRunTimeStats vTaskGetRunTimeStats
2433  * \ingroup TaskUtils
2434  */
2435 #define vTaskGetRunTimeStats( pcWriteBuffer )    vTaskGetRunTimeStatistics( ( pcWriteBuffer ), configSTATS_BUFFER_MAX_LENGTH )
2436 
2437 /**
2438  * task. h
2439  * @code{c}
2440  * configRUN_TIME_COUNTER_TYPE ulTaskGetRunTimeCounter( const TaskHandle_t xTask );
2441  * configRUN_TIME_COUNTER_TYPE ulTaskGetRunTimePercent( const TaskHandle_t xTask );
2442  * @endcode
2443  *
2444  * configGENERATE_RUN_TIME_STATS must be defined as 1 for these functions to be
2445  * available.  The application must also then provide definitions for
2446  * portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() and
2447  * portGET_RUN_TIME_COUNTER_VALUE() to configure a peripheral timer/counter and
2448  * return the timers current count value respectively.  The counter should be
2449  * at least 10 times the frequency of the tick count.
2450  *
2451  * Setting configGENERATE_RUN_TIME_STATS to 1 will result in a total
2452  * accumulated execution time being stored for each task.  The resolution
2453  * of the accumulated time value depends on the frequency of the timer
2454  * configured by the portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() macro.
2455  * While uxTaskGetSystemState() and vTaskGetRunTimeStats() writes the total
2456  * execution time of each task into a buffer, ulTaskGetRunTimeCounter()
2457  * returns the total execution time of just one task and
2458  * ulTaskGetRunTimePercent() returns the percentage of the CPU time used by
2459  * just one task.
2460  *
2461  * @return The total run time of the given task or the percentage of the total
2462  * run time consumed by the given task.  This is the amount of time the task
2463  * has actually been executing.  The unit of time is dependent on the frequency
2464  * configured using the portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() and
2465  * portGET_RUN_TIME_COUNTER_VALUE() macros.
2466  *
2467  * \defgroup ulTaskGetRunTimeCounter ulTaskGetRunTimeCounter
2468  * \ingroup TaskUtils
2469  */
2470 #if ( configGENERATE_RUN_TIME_STATS == 1 )
2471     configRUN_TIME_COUNTER_TYPE ulTaskGetRunTimeCounter( const TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
2472     configRUN_TIME_COUNTER_TYPE ulTaskGetRunTimePercent( const TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
2473 #endif
2474 
2475 /**
2476  * task. h
2477  * @code{c}
2478  * configRUN_TIME_COUNTER_TYPE ulTaskGetIdleRunTimeCounter( void );
2479  * configRUN_TIME_COUNTER_TYPE ulTaskGetIdleRunTimePercent( void );
2480  * @endcode
2481  *
2482  * configGENERATE_RUN_TIME_STATS must be defined as 1 for these functions to be
2483  * available.  The application must also then provide definitions for
2484  * portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() and
2485  * portGET_RUN_TIME_COUNTER_VALUE() to configure a peripheral timer/counter and
2486  * return the timers current count value respectively.  The counter should be
2487  * at least 10 times the frequency of the tick count.
2488  *
2489  * Setting configGENERATE_RUN_TIME_STATS to 1 will result in a total
2490  * accumulated execution time being stored for each task.  The resolution
2491  * of the accumulated time value depends on the frequency of the timer
2492  * configured by the portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() macro.
2493  * While uxTaskGetSystemState() and vTaskGetRunTimeStats() writes the total
2494  * execution time of each task into a buffer, ulTaskGetIdleRunTimeCounter()
2495  * returns the total execution time of just the idle task and
2496  * ulTaskGetIdleRunTimePercent() returns the percentage of the CPU time used by
2497  * just the idle task.
2498  *
2499  * Note the amount of idle time is only a good measure of the slack time in a
2500  * system if there are no other tasks executing at the idle priority, tickless
2501  * idle is not used, and configIDLE_SHOULD_YIELD is set to 0.
2502  *
2503  * @return The total run time of the idle task or the percentage of the total
2504  * run time consumed by the idle task.  This is the amount of time the
2505  * idle task has actually been executing.  The unit of time is dependent on the
2506  * frequency configured using the portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() and
2507  * portGET_RUN_TIME_COUNTER_VALUE() macros.
2508  *
2509  * \defgroup ulTaskGetIdleRunTimeCounter ulTaskGetIdleRunTimeCounter
2510  * \ingroup TaskUtils
2511  */
2512 #if ( ( configGENERATE_RUN_TIME_STATS == 1 ) && ( INCLUDE_xTaskGetIdleTaskHandle == 1 ) )
2513     configRUN_TIME_COUNTER_TYPE ulTaskGetIdleRunTimeCounter( void ) PRIVILEGED_FUNCTION;
2514     configRUN_TIME_COUNTER_TYPE ulTaskGetIdleRunTimePercent( void ) PRIVILEGED_FUNCTION;
2515 #endif
2516 
2517 /**
2518  * task. h
2519  * @code{c}
2520  * BaseType_t xTaskNotifyIndexed( TaskHandle_t xTaskToNotify, UBaseType_t uxIndexToNotify, uint32_t ulValue, eNotifyAction eAction );
2521  * BaseType_t xTaskNotify( TaskHandle_t xTaskToNotify, uint32_t ulValue, eNotifyAction eAction );
2522  * @endcode
2523  *
2524  * See https://www.FreeRTOS.org/RTOS-task-notifications.html for details.
2525  *
2526  * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for these
2527  * functions to be available.
2528  *
2529  * Sends a direct to task notification to a task, with an optional value and
2530  * action.
2531  *
2532  * Each task has a private array of "notification values" (or 'notifications'),
2533  * each of which is a 32-bit unsigned integer (uint32_t).  The constant
2534  * configTASK_NOTIFICATION_ARRAY_ENTRIES sets the number of indexes in the
2535  * array, and (for backward compatibility) defaults to 1 if left undefined.
2536  * Prior to FreeRTOS V10.4.0 there was only one notification value per task.
2537  *
2538  * Events can be sent to a task using an intermediary object.  Examples of such
2539  * objects are queues, semaphores, mutexes and event groups.  Task notifications
2540  * are a method of sending an event directly to a task without the need for such
2541  * an intermediary object.
2542  *
2543  * A notification sent to a task can optionally perform an action, such as
2544  * update, overwrite or increment one of the task's notification values.  In
2545  * that way task notifications can be used to send data to a task, or be used as
2546  * light weight and fast binary or counting semaphores.
2547  *
2548  * A task can use xTaskNotifyWaitIndexed() or ulTaskNotifyTakeIndexed() to
2549  * [optionally] block to wait for a notification to be pending.  The task does
2550  * not consume any CPU time while it is in the Blocked state.
2551  *
2552  * A notification sent to a task will remain pending until it is cleared by the
2553  * task calling xTaskNotifyWaitIndexed() or ulTaskNotifyTakeIndexed() (or their
2554  * un-indexed equivalents).  If the task was already in the Blocked state to
2555  * wait for a notification when the notification arrives then the task will
2556  * automatically be removed from the Blocked state (unblocked) and the
2557  * notification cleared.
2558  *
2559  * **NOTE** Each notification within the array operates independently - a task
2560  * can only block on one notification within the array at a time and will not be
2561  * unblocked by a notification sent to any other array index.
2562  *
2563  * Backward compatibility information:
2564  * Prior to FreeRTOS V10.4.0 each task had a single "notification value", and
2565  * all task notification API functions operated on that value. Replacing the
2566  * single notification value with an array of notification values necessitated a
2567  * new set of API functions that could address specific notifications within the
2568  * array.  xTaskNotify() is the original API function, and remains backward
2569  * compatible by always operating on the notification value at index 0 in the
2570  * array. Calling xTaskNotify() is equivalent to calling xTaskNotifyIndexed()
2571  * with the uxIndexToNotify parameter set to 0.
2572  *
2573  * @param xTaskToNotify The handle of the task being notified.  The handle to a
2574  * task can be returned from the xTaskCreate() API function used to create the
2575  * task, and the handle of the currently running task can be obtained by calling
2576  * xTaskGetCurrentTaskHandle().
2577  *
2578  * @param uxIndexToNotify The index within the target task's array of
2579  * notification values to which the notification is to be sent.  uxIndexToNotify
2580  * must be less than configTASK_NOTIFICATION_ARRAY_ENTRIES.  xTaskNotify() does
2581  * not have this parameter and always sends notifications to index 0.
2582  *
2583  * @param ulValue Data that can be sent with the notification.  How the data is
2584  * used depends on the value of the eAction parameter.
2585  *
2586  * @param eAction Specifies how the notification updates the task's notification
2587  * value, if at all.  Valid values for eAction are as follows:
2588  *
2589  * eSetBits -
2590  * The target notification value is bitwise ORed with ulValue.
2591  * xTaskNotifyIndexed() always returns pdPASS in this case.
2592  *
2593  * eIncrement -
2594  * The target notification value is incremented.  ulValue is not used and
2595  * xTaskNotifyIndexed() always returns pdPASS in this case.
2596  *
2597  * eSetValueWithOverwrite -
2598  * The target notification value is set to the value of ulValue, even if the
2599  * task being notified had not yet processed the previous notification at the
2600  * same array index (the task already had a notification pending at that index).
2601  * xTaskNotifyIndexed() always returns pdPASS in this case.
2602  *
2603  * eSetValueWithoutOverwrite -
2604  * If the task being notified did not already have a notification pending at the
2605  * same array index then the target notification value is set to ulValue and
2606  * xTaskNotifyIndexed() will return pdPASS.  If the task being notified already
2607  * had a notification pending at the same array index then no action is
2608  * performed and pdFAIL is returned.
2609  *
2610  * eNoAction -
2611  * The task receives a notification at the specified array index without the
2612  * notification value at that index being updated.  ulValue is not used and
2613  * xTaskNotifyIndexed() always returns pdPASS in this case.
2614  *
2615  * pulPreviousNotificationValue -
2616  * Can be used to pass out the subject task's notification value before any
2617  * bits are modified by the notify function.
2618  *
2619  * @return Dependent on the value of eAction.  See the description of the
2620  * eAction parameter.
2621  *
2622  * \defgroup xTaskNotifyIndexed xTaskNotifyIndexed
2623  * \ingroup TaskNotifications
2624  */
2625 BaseType_t xTaskGenericNotify( TaskHandle_t xTaskToNotify,
2626                                UBaseType_t uxIndexToNotify,
2627                                uint32_t ulValue,
2628                                eNotifyAction eAction,
2629                                uint32_t * pulPreviousNotificationValue ) PRIVILEGED_FUNCTION;
2630 #define xTaskNotify( xTaskToNotify, ulValue, eAction ) \
2631     xTaskGenericNotify( ( xTaskToNotify ), ( tskDEFAULT_INDEX_TO_NOTIFY ), ( ulValue ), ( eAction ), NULL )
2632 #define xTaskNotifyIndexed( xTaskToNotify, uxIndexToNotify, ulValue, eAction ) \
2633     xTaskGenericNotify( ( xTaskToNotify ), ( uxIndexToNotify ), ( ulValue ), ( eAction ), NULL )
2634 
2635 /**
2636  * task. h
2637  * @code{c}
2638  * BaseType_t xTaskNotifyAndQueryIndexed( TaskHandle_t xTaskToNotify, UBaseType_t uxIndexToNotify, uint32_t ulValue, eNotifyAction eAction, uint32_t *pulPreviousNotifyValue );
2639  * BaseType_t xTaskNotifyAndQuery( TaskHandle_t xTaskToNotify, uint32_t ulValue, eNotifyAction eAction, uint32_t *pulPreviousNotifyValue );
2640  * @endcode
2641  *
2642  * See https://www.FreeRTOS.org/RTOS-task-notifications.html for details.
2643  *
2644  * xTaskNotifyAndQueryIndexed() performs the same operation as
2645  * xTaskNotifyIndexed() with the addition that it also returns the subject
2646  * task's prior notification value (the notification value at the time the
2647  * function is called rather than when the function returns) in the additional
2648  * pulPreviousNotifyValue parameter.
2649  *
2650  * xTaskNotifyAndQuery() performs the same operation as xTaskNotify() with the
2651  * addition that it also returns the subject task's prior notification value
2652  * (the notification value as it was at the time the function is called, rather
2653  * than when the function returns) in the additional pulPreviousNotifyValue
2654  * parameter.
2655  *
2656  * \defgroup xTaskNotifyAndQueryIndexed xTaskNotifyAndQueryIndexed
2657  * \ingroup TaskNotifications
2658  */
2659 #define xTaskNotifyAndQuery( xTaskToNotify, ulValue, eAction, pulPreviousNotifyValue ) \
2660     xTaskGenericNotify( ( xTaskToNotify ), ( tskDEFAULT_INDEX_TO_NOTIFY ), ( ulValue ), ( eAction ), ( pulPreviousNotifyValue ) )
2661 #define xTaskNotifyAndQueryIndexed( xTaskToNotify, uxIndexToNotify, ulValue, eAction, pulPreviousNotifyValue ) \
2662     xTaskGenericNotify( ( xTaskToNotify ), ( uxIndexToNotify ), ( ulValue ), ( eAction ), ( pulPreviousNotifyValue ) )
2663 
2664 /**
2665  * task. h
2666  * @code{c}
2667  * BaseType_t xTaskNotifyIndexedFromISR( TaskHandle_t xTaskToNotify, UBaseType_t uxIndexToNotify, uint32_t ulValue, eNotifyAction eAction, BaseType_t *pxHigherPriorityTaskWoken );
2668  * BaseType_t xTaskNotifyFromISR( TaskHandle_t xTaskToNotify, uint32_t ulValue, eNotifyAction eAction, BaseType_t *pxHigherPriorityTaskWoken );
2669  * @endcode
2670  *
2671  * See https://www.FreeRTOS.org/RTOS-task-notifications.html for details.
2672  *
2673  * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for these
2674  * functions to be available.
2675  *
2676  * A version of xTaskNotifyIndexed() that can be used from an interrupt service
2677  * routine (ISR).
2678  *
2679  * Each task has a private array of "notification values" (or 'notifications'),
2680  * each of which is a 32-bit unsigned integer (uint32_t).  The constant
2681  * configTASK_NOTIFICATION_ARRAY_ENTRIES sets the number of indexes in the
2682  * array, and (for backward compatibility) defaults to 1 if left undefined.
2683  * Prior to FreeRTOS V10.4.0 there was only one notification value per task.
2684  *
2685  * Events can be sent to a task using an intermediary object.  Examples of such
2686  * objects are queues, semaphores, mutexes and event groups.  Task notifications
2687  * are a method of sending an event directly to a task without the need for such
2688  * an intermediary object.
2689  *
2690  * A notification sent to a task can optionally perform an action, such as
2691  * update, overwrite or increment one of the task's notification values.  In
2692  * that way task notifications can be used to send data to a task, or be used as
2693  * light weight and fast binary or counting semaphores.
2694  *
2695  * A task can use xTaskNotifyWaitIndexed() to [optionally] block to wait for a
2696  * notification to be pending, or ulTaskNotifyTakeIndexed() to [optionally] block
2697  * to wait for a notification value to have a non-zero value.  The task does
2698  * not consume any CPU time while it is in the Blocked state.
2699  *
2700  * A notification sent to a task will remain pending until it is cleared by the
2701  * task calling xTaskNotifyWaitIndexed() or ulTaskNotifyTakeIndexed() (or their
2702  * un-indexed equivalents).  If the task was already in the Blocked state to
2703  * wait for a notification when the notification arrives then the task will
2704  * automatically be removed from the Blocked state (unblocked) and the
2705  * notification cleared.
2706  *
2707  * **NOTE** Each notification within the array operates independently - a task
2708  * can only block on one notification within the array at a time and will not be
2709  * unblocked by a notification sent to any other array index.
2710  *
2711  * Backward compatibility information:
2712  * Prior to FreeRTOS V10.4.0 each task had a single "notification value", and
2713  * all task notification API functions operated on that value. Replacing the
2714  * single notification value with an array of notification values necessitated a
2715  * new set of API functions that could address specific notifications within the
2716  * array.  xTaskNotifyFromISR() is the original API function, and remains
2717  * backward compatible by always operating on the notification value at index 0
2718  * within the array. Calling xTaskNotifyFromISR() is equivalent to calling
2719  * xTaskNotifyIndexedFromISR() with the uxIndexToNotify parameter set to 0.
2720  *
2721  * @param uxIndexToNotify The index within the target task's array of
2722  * notification values to which the notification is to be sent.  uxIndexToNotify
2723  * must be less than configTASK_NOTIFICATION_ARRAY_ENTRIES.  xTaskNotifyFromISR()
2724  * does not have this parameter and always sends notifications to index 0.
2725  *
2726  * @param xTaskToNotify The handle of the task being notified.  The handle to a
2727  * task can be returned from the xTaskCreate() API function used to create the
2728  * task, and the handle of the currently running task can be obtained by calling
2729  * xTaskGetCurrentTaskHandle().
2730  *
2731  * @param ulValue Data that can be sent with the notification.  How the data is
2732  * used depends on the value of the eAction parameter.
2733  *
2734  * @param eAction Specifies how the notification updates the task's notification
2735  * value, if at all.  Valid values for eAction are as follows:
2736  *
2737  * eSetBits -
2738  * The task's notification value is bitwise ORed with ulValue.  xTaskNotify()
2739  * always returns pdPASS in this case.
2740  *
2741  * eIncrement -
2742  * The task's notification value is incremented.  ulValue is not used and
2743  * xTaskNotify() always returns pdPASS in this case.
2744  *
2745  * eSetValueWithOverwrite -
2746  * The task's notification value is set to the value of ulValue, even if the
2747  * task being notified had not yet processed the previous notification (the
2748  * task already had a notification pending).  xTaskNotify() always returns
2749  * pdPASS in this case.
2750  *
2751  * eSetValueWithoutOverwrite -
2752  * If the task being notified did not already have a notification pending then
2753  * the task's notification value is set to ulValue and xTaskNotify() will
2754  * return pdPASS.  If the task being notified already had a notification
2755  * pending then no action is performed and pdFAIL is returned.
2756  *
2757  * eNoAction -
2758  * The task receives a notification without its notification value being
2759  * updated.  ulValue is not used and xTaskNotify() always returns pdPASS in
2760  * this case.
2761  *
2762  * @param pxHigherPriorityTaskWoken  xTaskNotifyFromISR() will set
2763  * *pxHigherPriorityTaskWoken to pdTRUE if sending the notification caused the
2764  * task to which the notification was sent to leave the Blocked state, and the
2765  * unblocked task has a priority higher than the currently running task.  If
2766  * xTaskNotifyFromISR() sets this value to pdTRUE then a context switch should
2767  * be requested before the interrupt is exited.  How a context switch is
2768  * requested from an ISR is dependent on the port - see the documentation page
2769  * for the port in use.
2770  *
2771  * @return Dependent on the value of eAction.  See the description of the
2772  * eAction parameter.
2773  *
2774  * \defgroup xTaskNotifyIndexedFromISR xTaskNotifyIndexedFromISR
2775  * \ingroup TaskNotifications
2776  */
2777 BaseType_t xTaskGenericNotifyFromISR( TaskHandle_t xTaskToNotify,
2778                                       UBaseType_t uxIndexToNotify,
2779                                       uint32_t ulValue,
2780                                       eNotifyAction eAction,
2781                                       uint32_t * pulPreviousNotificationValue,
2782                                       BaseType_t * pxHigherPriorityTaskWoken ) PRIVILEGED_FUNCTION;
2783 #define xTaskNotifyFromISR( xTaskToNotify, ulValue, eAction, pxHigherPriorityTaskWoken ) \
2784     xTaskGenericNotifyFromISR( ( xTaskToNotify ), ( tskDEFAULT_INDEX_TO_NOTIFY ), ( ulValue ), ( eAction ), NULL, ( pxHigherPriorityTaskWoken ) )
2785 #define xTaskNotifyIndexedFromISR( xTaskToNotify, uxIndexToNotify, ulValue, eAction, pxHigherPriorityTaskWoken ) \
2786     xTaskGenericNotifyFromISR( ( xTaskToNotify ), ( uxIndexToNotify ), ( ulValue ), ( eAction ), NULL, ( pxHigherPriorityTaskWoken ) )
2787 
2788 /**
2789  * task. h
2790  * @code{c}
2791  * BaseType_t xTaskNotifyAndQueryIndexedFromISR( TaskHandle_t xTaskToNotify, UBaseType_t uxIndexToNotify, uint32_t ulValue, eNotifyAction eAction, uint32_t *pulPreviousNotificationValue, BaseType_t *pxHigherPriorityTaskWoken );
2792  * BaseType_t xTaskNotifyAndQueryFromISR( TaskHandle_t xTaskToNotify, uint32_t ulValue, eNotifyAction eAction, uint32_t *pulPreviousNotificationValue, BaseType_t *pxHigherPriorityTaskWoken );
2793  * @endcode
2794  *
2795  * See https://www.FreeRTOS.org/RTOS-task-notifications.html for details.
2796  *
2797  * xTaskNotifyAndQueryIndexedFromISR() performs the same operation as
2798  * xTaskNotifyIndexedFromISR() with the addition that it also returns the
2799  * subject task's prior notification value (the notification value at the time
2800  * the function is called rather than at the time the function returns) in the
2801  * additional pulPreviousNotifyValue parameter.
2802  *
2803  * xTaskNotifyAndQueryFromISR() performs the same operation as
2804  * xTaskNotifyFromISR() with the addition that it also returns the subject
2805  * task's prior notification value (the notification value at the time the
2806  * function is called rather than at the time the function returns) in the
2807  * additional pulPreviousNotifyValue parameter.
2808  *
2809  * \defgroup xTaskNotifyAndQueryIndexedFromISR xTaskNotifyAndQueryIndexedFromISR
2810  * \ingroup TaskNotifications
2811  */
2812 #define xTaskNotifyAndQueryIndexedFromISR( xTaskToNotify, uxIndexToNotify, ulValue, eAction, pulPreviousNotificationValue, pxHigherPriorityTaskWoken ) \
2813     xTaskGenericNotifyFromISR( ( xTaskToNotify ), ( uxIndexToNotify ), ( ulValue ), ( eAction ), ( pulPreviousNotificationValue ), ( pxHigherPriorityTaskWoken ) )
2814 #define xTaskNotifyAndQueryFromISR( xTaskToNotify, ulValue, eAction, pulPreviousNotificationValue, pxHigherPriorityTaskWoken ) \
2815     xTaskGenericNotifyFromISR( ( xTaskToNotify ), ( tskDEFAULT_INDEX_TO_NOTIFY ), ( ulValue ), ( eAction ), ( pulPreviousNotificationValue ), ( pxHigherPriorityTaskWoken ) )
2816 
2817 /**
2818  * task. h
2819  * @code{c}
2820  * BaseType_t xTaskNotifyWaitIndexed( UBaseType_t uxIndexToWaitOn, uint32_t ulBitsToClearOnEntry, uint32_t ulBitsToClearOnExit, uint32_t *pulNotificationValue, TickType_t xTicksToWait );
2821  *
2822  * BaseType_t xTaskNotifyWait( uint32_t ulBitsToClearOnEntry, uint32_t ulBitsToClearOnExit, uint32_t *pulNotificationValue, TickType_t xTicksToWait );
2823  * @endcode
2824  *
2825  * Waits for a direct to task notification to be pending at a given index within
2826  * an array of direct to task notifications.
2827  *
2828  * See https://www.FreeRTOS.org/RTOS-task-notifications.html for details.
2829  *
2830  * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for this
2831  * function to be available.
2832  *
2833  * Each task has a private array of "notification values" (or 'notifications'),
2834  * each of which is a 32-bit unsigned integer (uint32_t).  The constant
2835  * configTASK_NOTIFICATION_ARRAY_ENTRIES sets the number of indexes in the
2836  * array, and (for backward compatibility) defaults to 1 if left undefined.
2837  * Prior to FreeRTOS V10.4.0 there was only one notification value per task.
2838  *
2839  * Events can be sent to a task using an intermediary object.  Examples of such
2840  * objects are queues, semaphores, mutexes and event groups.  Task notifications
2841  * are a method of sending an event directly to a task without the need for such
2842  * an intermediary object.
2843  *
2844  * A notification sent to a task can optionally perform an action, such as
2845  * update, overwrite or increment one of the task's notification values.  In
2846  * that way task notifications can be used to send data to a task, or be used as
2847  * light weight and fast binary or counting semaphores.
2848  *
2849  * A notification sent to a task will remain pending until it is cleared by the
2850  * task calling xTaskNotifyWaitIndexed() or ulTaskNotifyTakeIndexed() (or their
2851  * un-indexed equivalents).  If the task was already in the Blocked state to
2852  * wait for a notification when the notification arrives then the task will
2853  * automatically be removed from the Blocked state (unblocked) and the
2854  * notification cleared.
2855  *
2856  * A task can use xTaskNotifyWaitIndexed() to [optionally] block to wait for a
2857  * notification to be pending, or ulTaskNotifyTakeIndexed() to [optionally] block
2858  * to wait for a notification value to have a non-zero value.  The task does
2859  * not consume any CPU time while it is in the Blocked state.
2860  *
2861  * **NOTE** Each notification within the array operates independently - a task
2862  * can only block on one notification within the array at a time and will not be
2863  * unblocked by a notification sent to any other array index.
2864  *
2865  * Backward compatibility information:
2866  * Prior to FreeRTOS V10.4.0 each task had a single "notification value", and
2867  * all task notification API functions operated on that value. Replacing the
2868  * single notification value with an array of notification values necessitated a
2869  * new set of API functions that could address specific notifications within the
2870  * array.  xTaskNotifyWait() is the original API function, and remains backward
2871  * compatible by always operating on the notification value at index 0 in the
2872  * array. Calling xTaskNotifyWait() is equivalent to calling
2873  * xTaskNotifyWaitIndexed() with the uxIndexToWaitOn parameter set to 0.
2874  *
2875  * @param uxIndexToWaitOn The index within the calling task's array of
2876  * notification values on which the calling task will wait for a notification to
2877  * be received.  uxIndexToWaitOn must be less than
2878  * configTASK_NOTIFICATION_ARRAY_ENTRIES.  xTaskNotifyWait() does
2879  * not have this parameter and always waits for notifications on index 0.
2880  *
2881  * @param ulBitsToClearOnEntry Bits that are set in ulBitsToClearOnEntry value
2882  * will be cleared in the calling task's notification value before the task
2883  * checks to see if any notifications are pending, and optionally blocks if no
2884  * notifications are pending.  Setting ulBitsToClearOnEntry to ULONG_MAX (if
2885  * limits.h is included) or 0xffffffffU (if limits.h is not included) will have
2886  * the effect of resetting the task's notification value to 0.  Setting
2887  * ulBitsToClearOnEntry to 0 will leave the task's notification value unchanged.
2888  *
2889  * @param ulBitsToClearOnExit If a notification is pending or received before
2890  * the calling task exits the xTaskNotifyWait() function then the task's
2891  * notification value (see the xTaskNotify() API function) is passed out using
2892  * the pulNotificationValue parameter.  Then any bits that are set in
2893  * ulBitsToClearOnExit will be cleared in the task's notification value (note
2894  * *pulNotificationValue is set before any bits are cleared).  Setting
2895  * ulBitsToClearOnExit to ULONG_MAX (if limits.h is included) or 0xffffffffUL
2896  * (if limits.h is not included) will have the effect of resetting the task's
2897  * notification value to 0 before the function exits.  Setting
2898  * ulBitsToClearOnExit to 0 will leave the task's notification value unchanged
2899  * when the function exits (in which case the value passed out in
2900  * pulNotificationValue will match the task's notification value).
2901  *
2902  * @param pulNotificationValue Used to pass the task's notification value out
2903  * of the function.  Note the value passed out will not be effected by the
2904  * clearing of any bits caused by ulBitsToClearOnExit being non-zero.
2905  *
2906  * @param xTicksToWait The maximum amount of time that the task should wait in
2907  * the Blocked state for a notification to be received, should a notification
2908  * not already be pending when xTaskNotifyWait() was called.  The task
2909  * will not consume any processing time while it is in the Blocked state.  This
2910  * is specified in kernel ticks, the macro pdMS_TO_TICKS( value_in_ms ) can be
2911  * used to convert a time specified in milliseconds to a time specified in
2912  * ticks.
2913  *
2914  * @return If a notification was received (including notifications that were
2915  * already pending when xTaskNotifyWait was called) then pdPASS is
2916  * returned.  Otherwise pdFAIL is returned.
2917  *
2918  * \defgroup xTaskNotifyWaitIndexed xTaskNotifyWaitIndexed
2919  * \ingroup TaskNotifications
2920  */
2921 BaseType_t xTaskGenericNotifyWait( UBaseType_t uxIndexToWaitOn,
2922                                    uint32_t ulBitsToClearOnEntry,
2923                                    uint32_t ulBitsToClearOnExit,
2924                                    uint32_t * pulNotificationValue,
2925                                    TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
2926 #define xTaskNotifyWait( ulBitsToClearOnEntry, ulBitsToClearOnExit, pulNotificationValue, xTicksToWait ) \
2927     xTaskGenericNotifyWait( tskDEFAULT_INDEX_TO_NOTIFY, ( ulBitsToClearOnEntry ), ( ulBitsToClearOnExit ), ( pulNotificationValue ), ( xTicksToWait ) )
2928 #define xTaskNotifyWaitIndexed( uxIndexToWaitOn, ulBitsToClearOnEntry, ulBitsToClearOnExit, pulNotificationValue, xTicksToWait ) \
2929     xTaskGenericNotifyWait( ( uxIndexToWaitOn ), ( ulBitsToClearOnEntry ), ( ulBitsToClearOnExit ), ( pulNotificationValue ), ( xTicksToWait ) )
2930 
2931 /**
2932  * task. h
2933  * @code{c}
2934  * BaseType_t xTaskNotifyGiveIndexed( TaskHandle_t xTaskToNotify, UBaseType_t uxIndexToNotify );
2935  * BaseType_t xTaskNotifyGive( TaskHandle_t xTaskToNotify );
2936  * @endcode
2937  *
2938  * Sends a direct to task notification to a particular index in the target
2939  * task's notification array in a manner similar to giving a counting semaphore.
2940  *
2941  * See https://www.FreeRTOS.org/RTOS-task-notifications.html for more details.
2942  *
2943  * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for these
2944  * macros to be available.
2945  *
2946  * Each task has a private array of "notification values" (or 'notifications'),
2947  * each of which is a 32-bit unsigned integer (uint32_t).  The constant
2948  * configTASK_NOTIFICATION_ARRAY_ENTRIES sets the number of indexes in the
2949  * array, and (for backward compatibility) defaults to 1 if left undefined.
2950  * Prior to FreeRTOS V10.4.0 there was only one notification value per task.
2951  *
2952  * Events can be sent to a task using an intermediary object.  Examples of such
2953  * objects are queues, semaphores, mutexes and event groups.  Task notifications
2954  * are a method of sending an event directly to a task without the need for such
2955  * an intermediary object.
2956  *
2957  * A notification sent to a task can optionally perform an action, such as
2958  * update, overwrite or increment one of the task's notification values.  In
2959  * that way task notifications can be used to send data to a task, or be used as
2960  * light weight and fast binary or counting semaphores.
2961  *
2962  * xTaskNotifyGiveIndexed() is a helper macro intended for use when task
2963  * notifications are used as light weight and faster binary or counting
2964  * semaphore equivalents.  Actual FreeRTOS semaphores are given using the
2965  * xSemaphoreGive() API function, the equivalent action that instead uses a task
2966  * notification is xTaskNotifyGiveIndexed().
2967  *
2968  * When task notifications are being used as a binary or counting semaphore
2969  * equivalent then the task being notified should wait for the notification
2970  * using the ulTaskNotifyTakeIndexed() API function rather than the
2971  * xTaskNotifyWaitIndexed() API function.
2972  *
2973  * **NOTE** Each notification within the array operates independently - a task
2974  * can only block on one notification within the array at a time and will not be
2975  * unblocked by a notification sent to any other array index.
2976  *
2977  * Backward compatibility information:
2978  * Prior to FreeRTOS V10.4.0 each task had a single "notification value", and
2979  * all task notification API functions operated on that value. Replacing the
2980  * single notification value with an array of notification values necessitated a
2981  * new set of API functions that could address specific notifications within the
2982  * array.  xTaskNotifyGive() is the original API function, and remains backward
2983  * compatible by always operating on the notification value at index 0 in the
2984  * array. Calling xTaskNotifyGive() is equivalent to calling
2985  * xTaskNotifyGiveIndexed() with the uxIndexToNotify parameter set to 0.
2986  *
2987  * @param xTaskToNotify The handle of the task being notified.  The handle to a
2988  * task can be returned from the xTaskCreate() API function used to create the
2989  * task, and the handle of the currently running task can be obtained by calling
2990  * xTaskGetCurrentTaskHandle().
2991  *
2992  * @param uxIndexToNotify The index within the target task's array of
2993  * notification values to which the notification is to be sent.  uxIndexToNotify
2994  * must be less than configTASK_NOTIFICATION_ARRAY_ENTRIES.  xTaskNotifyGive()
2995  * does not have this parameter and always sends notifications to index 0.
2996  *
2997  * @return xTaskNotifyGive() is a macro that calls xTaskNotify() with the
2998  * eAction parameter set to eIncrement - so pdPASS is always returned.
2999  *
3000  * \defgroup xTaskNotifyGiveIndexed xTaskNotifyGiveIndexed
3001  * \ingroup TaskNotifications
3002  */
3003 #define xTaskNotifyGive( xTaskToNotify ) \
3004     xTaskGenericNotify( ( xTaskToNotify ), ( tskDEFAULT_INDEX_TO_NOTIFY ), ( 0 ), eIncrement, NULL )
3005 #define xTaskNotifyGiveIndexed( xTaskToNotify, uxIndexToNotify ) \
3006     xTaskGenericNotify( ( xTaskToNotify ), ( uxIndexToNotify ), ( 0 ), eIncrement, NULL )
3007 
3008 /**
3009  * task. h
3010  * @code{c}
3011  * void vTaskNotifyGiveIndexedFromISR( TaskHandle_t xTaskHandle, UBaseType_t uxIndexToNotify, BaseType_t *pxHigherPriorityTaskWoken );
3012  * void vTaskNotifyGiveFromISR( TaskHandle_t xTaskHandle, BaseType_t *pxHigherPriorityTaskWoken );
3013  * @endcode
3014  *
3015  * A version of xTaskNotifyGiveIndexed() that can be called from an interrupt
3016  * service routine (ISR).
3017  *
3018  * See https://www.FreeRTOS.org/RTOS-task-notifications.html for more details.
3019  *
3020  * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for this macro
3021  * to be available.
3022  *
3023  * Each task has a private array of "notification values" (or 'notifications'),
3024  * each of which is a 32-bit unsigned integer (uint32_t).  The constant
3025  * configTASK_NOTIFICATION_ARRAY_ENTRIES sets the number of indexes in the
3026  * array, and (for backward compatibility) defaults to 1 if left undefined.
3027  * Prior to FreeRTOS V10.4.0 there was only one notification value per task.
3028  *
3029  * Events can be sent to a task using an intermediary object.  Examples of such
3030  * objects are queues, semaphores, mutexes and event groups.  Task notifications
3031  * are a method of sending an event directly to a task without the need for such
3032  * an intermediary object.
3033  *
3034  * A notification sent to a task can optionally perform an action, such as
3035  * update, overwrite or increment one of the task's notification values.  In
3036  * that way task notifications can be used to send data to a task, or be used as
3037  * light weight and fast binary or counting semaphores.
3038  *
3039  * vTaskNotifyGiveIndexedFromISR() is intended for use when task notifications
3040  * are used as light weight and faster binary or counting semaphore equivalents.
3041  * Actual FreeRTOS semaphores are given from an ISR using the
3042  * xSemaphoreGiveFromISR() API function, the equivalent action that instead uses
3043  * a task notification is vTaskNotifyGiveIndexedFromISR().
3044  *
3045  * When task notifications are being used as a binary or counting semaphore
3046  * equivalent then the task being notified should wait for the notification
3047  * using the ulTaskNotifyTakeIndexed() API function rather than the
3048  * xTaskNotifyWaitIndexed() API function.
3049  *
3050  * **NOTE** Each notification within the array operates independently - a task
3051  * can only block on one notification within the array at a time and will not be
3052  * unblocked by a notification sent to any other array index.
3053  *
3054  * Backward compatibility information:
3055  * Prior to FreeRTOS V10.4.0 each task had a single "notification value", and
3056  * all task notification API functions operated on that value. Replacing the
3057  * single notification value with an array of notification values necessitated a
3058  * new set of API functions that could address specific notifications within the
3059  * array.  xTaskNotifyFromISR() is the original API function, and remains
3060  * backward compatible by always operating on the notification value at index 0
3061  * within the array. Calling xTaskNotifyGiveFromISR() is equivalent to calling
3062  * xTaskNotifyGiveIndexedFromISR() with the uxIndexToNotify parameter set to 0.
3063  *
3064  * @param xTaskToNotify The handle of the task being notified.  The handle to a
3065  * task can be returned from the xTaskCreate() API function used to create the
3066  * task, and the handle of the currently running task can be obtained by calling
3067  * xTaskGetCurrentTaskHandle().
3068  *
3069  * @param uxIndexToNotify The index within the target task's array of
3070  * notification values to which the notification is to be sent.  uxIndexToNotify
3071  * must be less than configTASK_NOTIFICATION_ARRAY_ENTRIES.
3072  * xTaskNotifyGiveFromISR() does not have this parameter and always sends
3073  * notifications to index 0.
3074  *
3075  * @param pxHigherPriorityTaskWoken  vTaskNotifyGiveFromISR() will set
3076  * *pxHigherPriorityTaskWoken to pdTRUE if sending the notification caused the
3077  * task to which the notification was sent to leave the Blocked state, and the
3078  * unblocked task has a priority higher than the currently running task.  If
3079  * vTaskNotifyGiveFromISR() sets this value to pdTRUE then a context switch
3080  * should be requested before the interrupt is exited.  How a context switch is
3081  * requested from an ISR is dependent on the port - see the documentation page
3082  * for the port in use.
3083  *
3084  * \defgroup vTaskNotifyGiveIndexedFromISR vTaskNotifyGiveIndexedFromISR
3085  * \ingroup TaskNotifications
3086  */
3087 void vTaskGenericNotifyGiveFromISR( TaskHandle_t xTaskToNotify,
3088                                     UBaseType_t uxIndexToNotify,
3089                                     BaseType_t * pxHigherPriorityTaskWoken ) PRIVILEGED_FUNCTION;
3090 #define vTaskNotifyGiveFromISR( xTaskToNotify, pxHigherPriorityTaskWoken ) \
3091     vTaskGenericNotifyGiveFromISR( ( xTaskToNotify ), ( tskDEFAULT_INDEX_TO_NOTIFY ), ( pxHigherPriorityTaskWoken ) )
3092 #define vTaskNotifyGiveIndexedFromISR( xTaskToNotify, uxIndexToNotify, pxHigherPriorityTaskWoken ) \
3093     vTaskGenericNotifyGiveFromISR( ( xTaskToNotify ), ( uxIndexToNotify ), ( pxHigherPriorityTaskWoken ) )
3094 
3095 /**
3096  * task. h
3097  * @code{c}
3098  * uint32_t ulTaskNotifyTakeIndexed( UBaseType_t uxIndexToWaitOn, BaseType_t xClearCountOnExit, TickType_t xTicksToWait );
3099  *
3100  * uint32_t ulTaskNotifyTake( BaseType_t xClearCountOnExit, TickType_t xTicksToWait );
3101  * @endcode
3102  *
3103  * Waits for a direct to task notification on a particular index in the calling
3104  * task's notification array in a manner similar to taking a counting semaphore.
3105  *
3106  * See https://www.FreeRTOS.org/RTOS-task-notifications.html for details.
3107  *
3108  * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for this
3109  * function to be available.
3110  *
3111  * Each task has a private array of "notification values" (or 'notifications'),
3112  * each of which is a 32-bit unsigned integer (uint32_t).  The constant
3113  * configTASK_NOTIFICATION_ARRAY_ENTRIES sets the number of indexes in the
3114  * array, and (for backward compatibility) defaults to 1 if left undefined.
3115  * Prior to FreeRTOS V10.4.0 there was only one notification value per task.
3116  *
3117  * Events can be sent to a task using an intermediary object.  Examples of such
3118  * objects are queues, semaphores, mutexes and event groups.  Task notifications
3119  * are a method of sending an event directly to a task without the need for such
3120  * an intermediary object.
3121  *
3122  * A notification sent to a task can optionally perform an action, such as
3123  * update, overwrite or increment one of the task's notification values.  In
3124  * that way task notifications can be used to send data to a task, or be used as
3125  * light weight and fast binary or counting semaphores.
3126  *
3127  * ulTaskNotifyTakeIndexed() is intended for use when a task notification is
3128  * used as a faster and lighter weight binary or counting semaphore alternative.
3129  * Actual FreeRTOS semaphores are taken using the xSemaphoreTake() API function,
3130  * the equivalent action that instead uses a task notification is
3131  * ulTaskNotifyTakeIndexed().
3132  *
3133  * When a task is using its notification value as a binary or counting semaphore
3134  * other tasks should send notifications to it using the xTaskNotifyGiveIndexed()
3135  * macro, or xTaskNotifyIndex() function with the eAction parameter set to
3136  * eIncrement.
3137  *
3138  * ulTaskNotifyTakeIndexed() can either clear the task's notification value at
3139  * the array index specified by the uxIndexToWaitOn parameter to zero on exit,
3140  * in which case the notification value acts like a binary semaphore, or
3141  * decrement the notification value on exit, in which case the notification
3142  * value acts like a counting semaphore.
3143  *
3144  * A task can use ulTaskNotifyTakeIndexed() to [optionally] block to wait for
3145  * a notification.  The task does not consume any CPU time while it is in the
3146  * Blocked state.
3147  *
3148  * Where as xTaskNotifyWaitIndexed() will return when a notification is pending,
3149  * ulTaskNotifyTakeIndexed() will return when the task's notification value is
3150  * not zero.
3151  *
3152  * **NOTE** Each notification within the array operates independently - a task
3153  * can only block on one notification within the array at a time and will not be
3154  * unblocked by a notification sent to any other array index.
3155  *
3156  * Backward compatibility information:
3157  * Prior to FreeRTOS V10.4.0 each task had a single "notification value", and
3158  * all task notification API functions operated on that value. Replacing the
3159  * single notification value with an array of notification values necessitated a
3160  * new set of API functions that could address specific notifications within the
3161  * array.  ulTaskNotifyTake() is the original API function, and remains backward
3162  * compatible by always operating on the notification value at index 0 in the
3163  * array. Calling ulTaskNotifyTake() is equivalent to calling
3164  * ulTaskNotifyTakeIndexed() with the uxIndexToWaitOn parameter set to 0.
3165  *
3166  * @param uxIndexToWaitOn The index within the calling task's array of
3167  * notification values on which the calling task will wait for a notification to
3168  * be non-zero.  uxIndexToWaitOn must be less than
3169  * configTASK_NOTIFICATION_ARRAY_ENTRIES.  xTaskNotifyTake() does
3170  * not have this parameter and always waits for notifications on index 0.
3171  *
3172  * @param xClearCountOnExit if xClearCountOnExit is pdFALSE then the task's
3173  * notification value is decremented when the function exits.  In this way the
3174  * notification value acts like a counting semaphore.  If xClearCountOnExit is
3175  * not pdFALSE then the task's notification value is cleared to zero when the
3176  * function exits.  In this way the notification value acts like a binary
3177  * semaphore.
3178  *
3179  * @param xTicksToWait The maximum amount of time that the task should wait in
3180  * the Blocked state for the task's notification value to be greater than zero,
3181  * should the count not already be greater than zero when
3182  * ulTaskNotifyTake() was called.  The task will not consume any processing
3183  * time while it is in the Blocked state.  This is specified in kernel ticks,
3184  * the macro pdMS_TO_TICKS( value_in_ms ) can be used to convert a time
3185  * specified in milliseconds to a time specified in ticks.
3186  *
3187  * @return The task's notification count before it is either cleared to zero or
3188  * decremented (see the xClearCountOnExit parameter).
3189  *
3190  * \defgroup ulTaskNotifyTakeIndexed ulTaskNotifyTakeIndexed
3191  * \ingroup TaskNotifications
3192  */
3193 uint32_t ulTaskGenericNotifyTake( UBaseType_t uxIndexToWaitOn,
3194                                   BaseType_t xClearCountOnExit,
3195                                   TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
3196 #define ulTaskNotifyTake( xClearCountOnExit, xTicksToWait ) \
3197     ulTaskGenericNotifyTake( ( tskDEFAULT_INDEX_TO_NOTIFY ), ( xClearCountOnExit ), ( xTicksToWait ) )
3198 #define ulTaskNotifyTakeIndexed( uxIndexToWaitOn, xClearCountOnExit, xTicksToWait ) \
3199     ulTaskGenericNotifyTake( ( uxIndexToWaitOn ), ( xClearCountOnExit ), ( xTicksToWait ) )
3200 
3201 /**
3202  * task. h
3203  * @code{c}
3204  * BaseType_t xTaskNotifyStateClearIndexed( TaskHandle_t xTask, UBaseType_t uxIndexToCLear );
3205  *
3206  * BaseType_t xTaskNotifyStateClear( TaskHandle_t xTask );
3207  * @endcode
3208  *
3209  * See https://www.FreeRTOS.org/RTOS-task-notifications.html for details.
3210  *
3211  * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for these
3212  * functions to be available.
3213  *
3214  * Each task has a private array of "notification values" (or 'notifications'),
3215  * each of which is a 32-bit unsigned integer (uint32_t).  The constant
3216  * configTASK_NOTIFICATION_ARRAY_ENTRIES sets the number of indexes in the
3217  * array, and (for backward compatibility) defaults to 1 if left undefined.
3218  * Prior to FreeRTOS V10.4.0 there was only one notification value per task.
3219  *
3220  * If a notification is sent to an index within the array of notifications then
3221  * the notification at that index is said to be 'pending' until it is read or
3222  * explicitly cleared by the receiving task.  xTaskNotifyStateClearIndexed()
3223  * is the function that clears a pending notification without reading the
3224  * notification value.  The notification value at the same array index is not
3225  * altered.  Set xTask to NULL to clear the notification state of the calling
3226  * task.
3227  *
3228  * Backward compatibility information:
3229  * Prior to FreeRTOS V10.4.0 each task had a single "notification value", and
3230  * all task notification API functions operated on that value. Replacing the
3231  * single notification value with an array of notification values necessitated a
3232  * new set of API functions that could address specific notifications within the
3233  * array.  xTaskNotifyStateClear() is the original API function, and remains
3234  * backward compatible by always operating on the notification value at index 0
3235  * within the array. Calling xTaskNotifyStateClear() is equivalent to calling
3236  * xTaskNotifyStateClearIndexed() with the uxIndexToNotify parameter set to 0.
3237  *
3238  * @param xTask The handle of the RTOS task that will have a notification state
3239  * cleared.  Set xTask to NULL to clear a notification state in the calling
3240  * task.  To obtain a task's handle create the task using xTaskCreate() and
3241  * make use of the pxCreatedTask parameter, or create the task using
3242  * xTaskCreateStatic() and store the returned value, or use the task's name in
3243  * a call to xTaskGetHandle().
3244  *
3245  * @param uxIndexToClear The index within the target task's array of
3246  * notification values to act upon.  For example, setting uxIndexToClear to 1
3247  * will clear the state of the notification at index 1 within the array.
3248  * uxIndexToClear must be less than configTASK_NOTIFICATION_ARRAY_ENTRIES.
3249  * ulTaskNotifyStateClear() does not have this parameter and always acts on the
3250  * notification at index 0.
3251  *
3252  * @return pdTRUE if the task's notification state was set to
3253  * eNotWaitingNotification, otherwise pdFALSE.
3254  *
3255  * \defgroup xTaskNotifyStateClearIndexed xTaskNotifyStateClearIndexed
3256  * \ingroup TaskNotifications
3257  */
3258 BaseType_t xTaskGenericNotifyStateClear( TaskHandle_t xTask,
3259                                          UBaseType_t uxIndexToClear ) PRIVILEGED_FUNCTION;
3260 #define xTaskNotifyStateClear( xTask ) \
3261     xTaskGenericNotifyStateClear( ( xTask ), ( tskDEFAULT_INDEX_TO_NOTIFY ) )
3262 #define xTaskNotifyStateClearIndexed( xTask, uxIndexToClear ) \
3263     xTaskGenericNotifyStateClear( ( xTask ), ( uxIndexToClear ) )
3264 
3265 /**
3266  * task. h
3267  * @code{c}
3268  * uint32_t ulTaskNotifyValueClearIndexed( TaskHandle_t xTask, UBaseType_t uxIndexToClear, uint32_t ulBitsToClear );
3269  *
3270  * uint32_t ulTaskNotifyValueClear( TaskHandle_t xTask, uint32_t ulBitsToClear );
3271  * @endcode
3272  *
3273  * See https://www.FreeRTOS.org/RTOS-task-notifications.html for details.
3274  *
3275  * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for these
3276  * functions to be available.
3277  *
3278  * Each task has a private array of "notification values" (or 'notifications'),
3279  * each of which is a 32-bit unsigned integer (uint32_t).  The constant
3280  * configTASK_NOTIFICATION_ARRAY_ENTRIES sets the number of indexes in the
3281  * array, and (for backward compatibility) defaults to 1 if left undefined.
3282  * Prior to FreeRTOS V10.4.0 there was only one notification value per task.
3283  *
3284  * ulTaskNotifyValueClearIndexed() clears the bits specified by the
3285  * ulBitsToClear bit mask in the notification value at array index uxIndexToClear
3286  * of the task referenced by xTask.
3287  *
3288  * Backward compatibility information:
3289  * Prior to FreeRTOS V10.4.0 each task had a single "notification value", and
3290  * all task notification API functions operated on that value. Replacing the
3291  * single notification value with an array of notification values necessitated a
3292  * new set of API functions that could address specific notifications within the
3293  * array.  ulTaskNotifyValueClear() is the original API function, and remains
3294  * backward compatible by always operating on the notification value at index 0
3295  * within the array. Calling ulTaskNotifyValueClear() is equivalent to calling
3296  * ulTaskNotifyValueClearIndexed() with the uxIndexToClear parameter set to 0.
3297  *
3298  * @param xTask The handle of the RTOS task that will have bits in one of its
3299  * notification values cleared. Set xTask to NULL to clear bits in a
3300  * notification value of the calling task.  To obtain a task's handle create the
3301  * task using xTaskCreate() and make use of the pxCreatedTask parameter, or
3302  * create the task using xTaskCreateStatic() and store the returned value, or
3303  * use the task's name in a call to xTaskGetHandle().
3304  *
3305  * @param uxIndexToClear The index within the target task's array of
3306  * notification values in which to clear the bits.  uxIndexToClear
3307  * must be less than configTASK_NOTIFICATION_ARRAY_ENTRIES.
3308  * ulTaskNotifyValueClear() does not have this parameter and always clears bits
3309  * in the notification value at index 0.
3310  *
3311  * @param ulBitsToClear Bit mask of the bits to clear in the notification value of
3312  * xTask. Set a bit to 1 to clear the corresponding bits in the task's notification
3313  * value. Set ulBitsToClear to 0xffffffff (UINT_MAX on 32-bit architectures) to clear
3314  * the notification value to 0.  Set ulBitsToClear to 0 to query the task's
3315  * notification value without clearing any bits.
3316  *
3317  *
3318  * @return The value of the target task's notification value before the bits
3319  * specified by ulBitsToClear were cleared.
3320  * \defgroup ulTaskNotifyValueClear ulTaskNotifyValueClear
3321  * \ingroup TaskNotifications
3322  */
3323 uint32_t ulTaskGenericNotifyValueClear( TaskHandle_t xTask,
3324                                         UBaseType_t uxIndexToClear,
3325                                         uint32_t ulBitsToClear ) PRIVILEGED_FUNCTION;
3326 #define ulTaskNotifyValueClear( xTask, ulBitsToClear ) \
3327     ulTaskGenericNotifyValueClear( ( xTask ), ( tskDEFAULT_INDEX_TO_NOTIFY ), ( ulBitsToClear ) )
3328 #define ulTaskNotifyValueClearIndexed( xTask, uxIndexToClear, ulBitsToClear ) \
3329     ulTaskGenericNotifyValueClear( ( xTask ), ( uxIndexToClear ), ( ulBitsToClear ) )
3330 
3331 /**
3332  * task.h
3333  * @code{c}
3334  * void vTaskSetTimeOutState( TimeOut_t * const pxTimeOut );
3335  * @endcode
3336  *
3337  * Capture the current time for future use with xTaskCheckForTimeOut().
3338  *
3339  * @param pxTimeOut Pointer to a timeout object into which the current time
3340  * is to be captured.  The captured time includes the tick count and the number
3341  * of times the tick count has overflowed since the system first booted.
3342  * \defgroup vTaskSetTimeOutState vTaskSetTimeOutState
3343  * \ingroup TaskCtrl
3344  */
3345 void vTaskSetTimeOutState( TimeOut_t * const pxTimeOut ) PRIVILEGED_FUNCTION;
3346 
3347 /**
3348  * task.h
3349  * @code{c}
3350  * BaseType_t xTaskCheckForTimeOut( TimeOut_t * const pxTimeOut, TickType_t * const pxTicksToWait );
3351  * @endcode
3352  *
3353  * Determines if pxTicksToWait ticks has passed since a time was captured
3354  * using a call to vTaskSetTimeOutState().  The captured time includes the tick
3355  * count and the number of times the tick count has overflowed.
3356  *
3357  * @param pxTimeOut The time status as captured previously using
3358  * vTaskSetTimeOutState. If the timeout has not yet occurred, it is updated
3359  * to reflect the current time status.
3360  * @param pxTicksToWait The number of ticks to check for timeout i.e. if
3361  * pxTicksToWait ticks have passed since pxTimeOut was last updated (either by
3362  * vTaskSetTimeOutState() or xTaskCheckForTimeOut()), the timeout has occurred.
3363  * If the timeout has not occurred, pxTicksToWait is updated to reflect the
3364  * number of remaining ticks.
3365  *
3366  * @return If timeout has occurred, pdTRUE is returned. Otherwise pdFALSE is
3367  * returned and pxTicksToWait is updated to reflect the number of remaining
3368  * ticks.
3369  *
3370  * @see https://www.FreeRTOS.org/xTaskCheckForTimeOut.html
3371  *
3372  * Example Usage:
3373  * @code{c}
3374  *  // Driver library function used to receive uxWantedBytes from an Rx buffer
3375  *  // that is filled by a UART interrupt. If there are not enough bytes in the
3376  *  // Rx buffer then the task enters the Blocked state until it is notified that
3377  *  // more data has been placed into the buffer. If there is still not enough
3378  *  // data then the task re-enters the Blocked state, and xTaskCheckForTimeOut()
3379  *  // is used to re-calculate the Block time to ensure the total amount of time
3380  *  // spent in the Blocked state does not exceed MAX_TIME_TO_WAIT. This
3381  *  // continues until either the buffer contains at least uxWantedBytes bytes,
3382  *  // or the total amount of time spent in the Blocked state reaches
3383  *  // MAX_TIME_TO_WAIT - at which point the task reads however many bytes are
3384  *  // available up to a maximum of uxWantedBytes.
3385  *
3386  *  size_t xUART_Receive( uint8_t *pucBuffer, size_t uxWantedBytes )
3387  *  {
3388  *  size_t uxReceived = 0;
3389  *  TickType_t xTicksToWait = MAX_TIME_TO_WAIT;
3390  *  TimeOut_t xTimeOut;
3391  *
3392  *      // Initialize xTimeOut.  This records the time at which this function
3393  *      // was entered.
3394  *      vTaskSetTimeOutState( &xTimeOut );
3395  *
3396  *      // Loop until the buffer contains the wanted number of bytes, or a
3397  *      // timeout occurs.
3398  *      while( UART_bytes_in_rx_buffer( pxUARTInstance ) < uxWantedBytes )
3399  *      {
3400  *          // The buffer didn't contain enough data so this task is going to
3401  *          // enter the Blocked state. Adjusting xTicksToWait to account for
3402  *          // any time that has been spent in the Blocked state within this
3403  *          // function so far to ensure the total amount of time spent in the
3404  *          // Blocked state does not exceed MAX_TIME_TO_WAIT.
3405  *          if( xTaskCheckForTimeOut( &xTimeOut, &xTicksToWait ) != pdFALSE )
3406  *          {
3407  *              //Timed out before the wanted number of bytes were available,
3408  *              // exit the loop.
3409  *              break;
3410  *          }
3411  *
3412  *          // Wait for a maximum of xTicksToWait ticks to be notified that the
3413  *          // receive interrupt has placed more data into the buffer.
3414  *          ulTaskNotifyTake( pdTRUE, xTicksToWait );
3415  *      }
3416  *
3417  *      // Attempt to read uxWantedBytes from the receive buffer into pucBuffer.
3418  *      // The actual number of bytes read (which might be less than
3419  *      // uxWantedBytes) is returned.
3420  *      uxReceived = UART_read_from_receive_buffer( pxUARTInstance,
3421  *                                                  pucBuffer,
3422  *                                                  uxWantedBytes );
3423  *
3424  *      return uxReceived;
3425  *  }
3426  * @endcode
3427  * \defgroup xTaskCheckForTimeOut xTaskCheckForTimeOut
3428  * \ingroup TaskCtrl
3429  */
3430 BaseType_t xTaskCheckForTimeOut( TimeOut_t * const pxTimeOut,
3431                                  TickType_t * const pxTicksToWait ) PRIVILEGED_FUNCTION;
3432 
3433 /**
3434  * task.h
3435  * @code{c}
3436  * BaseType_t xTaskCatchUpTicks( TickType_t xTicksToCatchUp );
3437  * @endcode
3438  *
3439  * This function corrects the tick count value after the application code has held
3440  * interrupts disabled for an extended period resulting in tick interrupts having
3441  * been missed.
3442  *
3443  * This function is similar to vTaskStepTick(), however, unlike
3444  * vTaskStepTick(), xTaskCatchUpTicks() may move the tick count forward past a
3445  * time at which a task should be removed from the blocked state.  That means
3446  * tasks may have to be removed from the blocked state as the tick count is
3447  * moved.
3448  *
3449  * @param xTicksToCatchUp The number of tick interrupts that have been missed due to
3450  * interrupts being disabled.  Its value is not computed automatically, so must be
3451  * computed by the application writer.
3452  *
3453  * @return pdTRUE if moving the tick count forward resulted in a task leaving the
3454  * blocked state and a context switch being performed.  Otherwise pdFALSE.
3455  *
3456  * \defgroup xTaskCatchUpTicks xTaskCatchUpTicks
3457  * \ingroup TaskCtrl
3458  */
3459 BaseType_t xTaskCatchUpTicks( TickType_t xTicksToCatchUp ) PRIVILEGED_FUNCTION;
3460 
3461 /**
3462  * task.h
3463  * @code{c}
3464  * void vTaskResetState( void );
3465  * @endcode
3466  *
3467  * This function resets the internal state of the task. It must be called by the
3468  * application before restarting the scheduler.
3469  *
3470  * \defgroup vTaskResetState vTaskResetState
3471  * \ingroup SchedulerControl
3472  */
3473 void vTaskResetState( void ) PRIVILEGED_FUNCTION;
3474 
3475 
3476 /*-----------------------------------------------------------
3477 * SCHEDULER INTERNALS AVAILABLE FOR PORTING PURPOSES
3478 *----------------------------------------------------------*/
3479 
3480 #if ( configNUMBER_OF_CORES == 1 )
3481     #define taskYIELD_WITHIN_API()    portYIELD_WITHIN_API()
3482 #else /* #if ( configNUMBER_OF_CORES == 1 ) */
3483     #define taskYIELD_WITHIN_API()    vTaskYieldWithinAPI()
3484 #endif /* #if ( configNUMBER_OF_CORES == 1 ) */
3485 
3486 /*
3487  * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE.  IT IS ONLY
3488  * INTENDED FOR USE WHEN IMPLEMENTING A PORT OF THE SCHEDULER AND IS
3489  * AN INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.
3490  *
3491  * Called from the real time kernel tick (either preemptive or cooperative),
3492  * this increments the tick count and checks if any tasks that are blocked
3493  * for a finite period required removing from a blocked list and placing on
3494  * a ready list.  If a non-zero value is returned then a context switch is
3495  * required because either:
3496  *   + A task was removed from a blocked list because its timeout had expired,
3497  *     or
3498  *   + Time slicing is in use and there is a task of equal priority to the
3499  *     currently running task.
3500  */
3501 BaseType_t xTaskIncrementTick( void ) PRIVILEGED_FUNCTION;
3502 
3503 /*
3504  * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE.  IT IS AN
3505  * INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.
3506  *
3507  * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED.
3508  *
3509  * Removes the calling task from the ready list and places it both
3510  * on the list of tasks waiting for a particular event, and the
3511  * list of delayed tasks.  The task will be removed from both lists
3512  * and replaced on the ready list should either the event occur (and
3513  * there be no higher priority tasks waiting on the same event) or
3514  * the delay period expires.
3515  *
3516  * The 'unordered' version replaces the event list item value with the
3517  * xItemValue value, and inserts the list item at the end of the list.
3518  *
3519  * The 'ordered' version uses the existing event list item value (which is the
3520  * owning task's priority) to insert the list item into the event list in task
3521  * priority order.
3522  *
3523  * @param pxEventList The list containing tasks that are blocked waiting
3524  * for the event to occur.
3525  *
3526  * @param xItemValue The item value to use for the event list item when the
3527  * event list is not ordered by task priority.
3528  *
3529  * @param xTicksToWait The maximum amount of time that the task should wait
3530  * for the event to occur.  This is specified in kernel ticks, the constant
3531  * portTICK_PERIOD_MS can be used to convert kernel ticks into a real time
3532  * period.
3533  */
3534 void vTaskPlaceOnEventList( List_t * const pxEventList,
3535                             const TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
3536 void vTaskPlaceOnUnorderedEventList( List_t * pxEventList,
3537                                      const TickType_t xItemValue,
3538                                      const TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
3539 
3540 /*
3541  * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE.  IT IS AN
3542  * INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.
3543  *
3544  * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED.
3545  *
3546  * This function performs nearly the same function as vTaskPlaceOnEventList().
3547  * The difference being that this function does not permit tasks to block
3548  * indefinitely, whereas vTaskPlaceOnEventList() does.
3549  *
3550  */
3551 void vTaskPlaceOnEventListRestricted( List_t * const pxEventList,
3552                                       TickType_t xTicksToWait,
3553                                       const BaseType_t xWaitIndefinitely ) PRIVILEGED_FUNCTION;
3554 
3555 /*
3556  * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE.  IT IS AN
3557  * INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.
3558  *
3559  * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED.
3560  *
3561  * Removes a task from both the specified event list and the list of blocked
3562  * tasks, and places it on a ready queue.
3563  *
3564  * xTaskRemoveFromEventList()/vTaskRemoveFromUnorderedEventList() will be called
3565  * if either an event occurs to unblock a task, or the block timeout period
3566  * expires.
3567  *
3568  * xTaskRemoveFromEventList() is used when the event list is in task priority
3569  * order.  It removes the list item from the head of the event list as that will
3570  * have the highest priority owning task of all the tasks on the event list.
3571  * vTaskRemoveFromUnorderedEventList() is used when the event list is not
3572  * ordered and the event list items hold something other than the owning tasks
3573  * priority.  In this case the event list item value is updated to the value
3574  * passed in the xItemValue parameter.
3575  *
3576  * @return pdTRUE if the task being removed has a higher priority than the task
3577  * making the call, otherwise pdFALSE.
3578  */
3579 BaseType_t xTaskRemoveFromEventList( const List_t * const pxEventList ) PRIVILEGED_FUNCTION;
3580 void vTaskRemoveFromUnorderedEventList( ListItem_t * pxEventListItem,
3581                                         const TickType_t xItemValue ) PRIVILEGED_FUNCTION;
3582 
3583 /*
3584  * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE.  IT IS ONLY
3585  * INTENDED FOR USE WHEN IMPLEMENTING A PORT OF THE SCHEDULER AND IS
3586  * AN INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.
3587  *
3588  * Sets the pointer to the current TCB to the TCB of the highest priority task
3589  * that is ready to run.
3590  */
3591 #if ( configNUMBER_OF_CORES == 1 )
3592     portDONT_DISCARD void vTaskSwitchContext( void ) PRIVILEGED_FUNCTION;
3593 #else
3594     portDONT_DISCARD void vTaskSwitchContext( BaseType_t xCoreID ) PRIVILEGED_FUNCTION;
3595 #endif
3596 
3597 /*
3598  * THESE FUNCTIONS MUST NOT BE USED FROM APPLICATION CODE.  THEY ARE USED BY
3599  * THE EVENT BITS MODULE.
3600  */
3601 TickType_t uxTaskResetEventItemValue( void ) PRIVILEGED_FUNCTION;
3602 
3603 /*
3604  * Return the handle of the calling task.
3605  */
3606 TaskHandle_t xTaskGetCurrentTaskHandle( void ) PRIVILEGED_FUNCTION;
3607 
3608 /*
3609  * Return the handle of the task running on specified core.
3610  */
3611 TaskHandle_t xTaskGetCurrentTaskHandleForCore( BaseType_t xCoreID ) PRIVILEGED_FUNCTION;
3612 
3613 /*
3614  * Shortcut used by the queue implementation to prevent unnecessary call to
3615  * taskYIELD();
3616  */
3617 void vTaskMissedYield( void ) PRIVILEGED_FUNCTION;
3618 
3619 /*
3620  * Returns the scheduler state as taskSCHEDULER_RUNNING,
3621  * taskSCHEDULER_NOT_STARTED or taskSCHEDULER_SUSPENDED.
3622  */
3623 BaseType_t xTaskGetSchedulerState( void ) PRIVILEGED_FUNCTION;
3624 
3625 /*
3626  * Raises the priority of the mutex holder to that of the calling task should
3627  * the mutex holder have a priority less than the calling task.
3628  */
3629 BaseType_t xTaskPriorityInherit( TaskHandle_t const pxMutexHolder ) PRIVILEGED_FUNCTION;
3630 
3631 /*
3632  * Set the priority of a task back to its proper priority in the case that it
3633  * inherited a higher priority while it was holding a semaphore.
3634  */
3635 BaseType_t xTaskPriorityDisinherit( TaskHandle_t const pxMutexHolder ) PRIVILEGED_FUNCTION;
3636 
3637 /*
3638  * If a higher priority task attempting to obtain a mutex caused a lower
3639  * priority task to inherit the higher priority task's priority - but the higher
3640  * priority task then timed out without obtaining the mutex, then the lower
3641  * priority task will disinherit the priority again - but only down as far as
3642  * the highest priority task that is still waiting for the mutex (if there were
3643  * more than one task waiting for the mutex).
3644  */
3645 void vTaskPriorityDisinheritAfterTimeout( TaskHandle_t const pxMutexHolder,
3646                                           UBaseType_t uxHighestPriorityWaitingTask ) PRIVILEGED_FUNCTION;
3647 
3648 /*
3649  * Get the uxTaskNumber assigned to the task referenced by the xTask parameter.
3650  */
3651 #if ( configUSE_TRACE_FACILITY == 1 )
3652     UBaseType_t uxTaskGetTaskNumber( TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
3653 #endif
3654 
3655 /*
3656  * Set the uxTaskNumber of the task referenced by the xTask parameter to
3657  * uxHandle.
3658  */
3659 #if ( configUSE_TRACE_FACILITY == 1 )
3660     void vTaskSetTaskNumber( TaskHandle_t xTask,
3661                              const UBaseType_t uxHandle ) PRIVILEGED_FUNCTION;
3662 #endif
3663 
3664 /*
3665  * Only available when configUSE_TICKLESS_IDLE is set to 1.
3666  * If tickless mode is being used, or a low power mode is implemented, then
3667  * the tick interrupt will not execute during idle periods.  When this is the
3668  * case, the tick count value maintained by the scheduler needs to be kept up
3669  * to date with the actual execution time by being skipped forward by a time
3670  * equal to the idle period.
3671  */
3672 #if ( configUSE_TICKLESS_IDLE != 0 )
3673     void vTaskStepTick( TickType_t xTicksToJump ) PRIVILEGED_FUNCTION;
3674 #endif
3675 
3676 /*
3677  * Only available when configUSE_TICKLESS_IDLE is set to 1.
3678  * Provided for use within portSUPPRESS_TICKS_AND_SLEEP() to allow the port
3679  * specific sleep function to determine if it is ok to proceed with the sleep,
3680  * and if it is ok to proceed, if it is ok to sleep indefinitely.
3681  *
3682  * This function is necessary because portSUPPRESS_TICKS_AND_SLEEP() is only
3683  * called with the scheduler suspended, not from within a critical section.  It
3684  * is therefore possible for an interrupt to request a context switch between
3685  * portSUPPRESS_TICKS_AND_SLEEP() and the low power mode actually being
3686  * entered.  eTaskConfirmSleepModeStatus() should be called from a short
3687  * critical section between the timer being stopped and the sleep mode being
3688  * entered to ensure it is ok to proceed into the sleep mode.
3689  */
3690 #if ( configUSE_TICKLESS_IDLE != 0 )
3691     eSleepModeStatus eTaskConfirmSleepModeStatus( void ) PRIVILEGED_FUNCTION;
3692 #endif
3693 
3694 /*
3695  * For internal use only.  Increment the mutex held count when a mutex is
3696  * taken and return the handle of the task that has taken the mutex.
3697  */
3698 TaskHandle_t pvTaskIncrementMutexHeldCount( void ) PRIVILEGED_FUNCTION;
3699 
3700 /*
3701  * For internal use only.  Same as vTaskSetTimeOutState(), but without a critical
3702  * section.
3703  */
3704 void vTaskInternalSetTimeOutState( TimeOut_t * const pxTimeOut ) PRIVILEGED_FUNCTION;
3705 
3706 /*
3707  * For internal use only. Same as portYIELD_WITHIN_API() in single core FreeRTOS.
3708  * For SMP this is not defined by the port.
3709  */
3710 #if ( configNUMBER_OF_CORES > 1 )
3711     void vTaskYieldWithinAPI( void );
3712 #endif
3713 
3714 /*
3715  * This function is only intended for use when implementing a port of the scheduler
3716  * and is only available when portCRITICAL_NESTING_IN_TCB is set to 1 or configNUMBER_OF_CORES
3717  * is greater than 1. This function can be used in the implementation of portENTER_CRITICAL
3718  * if port wants to maintain critical nesting count in TCB in single core FreeRTOS.
3719  * It should be used in the implementation of portENTER_CRITICAL if port is running a
3720  * multiple core FreeRTOS.
3721  */
3722 #if ( ( portCRITICAL_NESTING_IN_TCB == 1 ) || ( configNUMBER_OF_CORES > 1 ) )
3723     void vTaskEnterCritical( void );
3724 #endif
3725 
3726 /*
3727  * This function is only intended for use when implementing a port of the scheduler
3728  * and is only available when portCRITICAL_NESTING_IN_TCB is set to 1 or configNUMBER_OF_CORES
3729  * is greater than 1. This function can be used in the implementation of portEXIT_CRITICAL
3730  * if port wants to maintain critical nesting count in TCB in single core FreeRTOS.
3731  * It should be used in the implementation of portEXIT_CRITICAL if port is running a
3732  * multiple core FreeRTOS.
3733  */
3734 #if ( ( portCRITICAL_NESTING_IN_TCB == 1 ) || ( configNUMBER_OF_CORES > 1 ) )
3735     void vTaskExitCritical( void );
3736 #endif
3737 
3738 /*
3739  * This function is only intended for use when implementing a port of the scheduler
3740  * and is only available when configNUMBER_OF_CORES is greater than 1. This function
3741  * should be used in the implementation of portENTER_CRITICAL_FROM_ISR if port is
3742  * running a multiple core FreeRTOS.
3743  */
3744 #if ( configNUMBER_OF_CORES > 1 )
3745     UBaseType_t vTaskEnterCriticalFromISR( void );
3746 #endif
3747 
3748 /*
3749  * This function is only intended for use when implementing a port of the scheduler
3750  * and is only available when configNUMBER_OF_CORES is greater than 1. This function
3751  * should be used in the implementation of portEXIT_CRITICAL_FROM_ISR if port is
3752  * running a multiple core FreeRTOS.
3753  */
3754 #if ( configNUMBER_OF_CORES > 1 )
3755     void vTaskExitCriticalFromISR( UBaseType_t uxSavedInterruptStatus );
3756 #endif
3757 
3758 #if ( portUSING_MPU_WRAPPERS == 1 )
3759 
3760 /*
3761  * For internal use only.  Get MPU settings associated with a task.
3762  */
3763     xMPU_SETTINGS * xTaskGetMPUSettings( TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
3764 
3765 #endif /* portUSING_MPU_WRAPPERS */
3766 
3767 
3768 #if ( ( portUSING_MPU_WRAPPERS == 1 ) && ( configUSE_MPU_WRAPPERS_V1 == 0 ) && ( configENABLE_ACCESS_CONTROL_LIST == 1 ) )
3769 
3770 /*
3771  * For internal use only.  Grant/Revoke a task's access to a kernel object.
3772  */
3773     void vGrantAccessToKernelObject( TaskHandle_t xExternalTaskHandle,
3774                                      int32_t lExternalKernelObjectHandle ) PRIVILEGED_FUNCTION;
3775     void vRevokeAccessToKernelObject( TaskHandle_t xExternalTaskHandle,
3776                                       int32_t lExternalKernelObjectHandle ) PRIVILEGED_FUNCTION;
3777 
3778 /*
3779  * For internal use only.  Grant/Revoke a task's access to a kernel object.
3780  */
3781     void vPortGrantAccessToKernelObject( TaskHandle_t xInternalTaskHandle,
3782                                          int32_t lInternalIndexOfKernelObject ) PRIVILEGED_FUNCTION;
3783     void vPortRevokeAccessToKernelObject( TaskHandle_t xInternalTaskHandle,
3784                                           int32_t lInternalIndexOfKernelObject ) PRIVILEGED_FUNCTION;
3785 
3786 #endif /* #if ( ( portUSING_MPU_WRAPPERS == 1 ) && ( configUSE_MPU_WRAPPERS_V1 == 0 ) && ( configENABLE_ACCESS_CONTROL_LIST == 1 ) ) */
3787 
3788 /* *INDENT-OFF* */
3789 #ifdef __cplusplus
3790     }
3791 #endif
3792 /* *INDENT-ON* */
3793 #endif /* INC_TASK_H */
3794