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