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