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