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