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