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