2 * FreeRTOS SMP Kernel V202110.00
3 * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
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:
12 * The above copyright notice and this permission notice shall be included in all
13 * copies or substantial portions of the Software.
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.
22 * https://www.FreeRTOS.org
23 * https://github.com/FreeRTOS
31 #ifndef INC_FREERTOS_H
32 #error "include FreeRTOS.h must appear in source files before include task.h"
43 /*-----------------------------------------------------------
44 * MACROS AND DEFINITIONS
45 *----------------------------------------------------------*/
47 #define tskKERNEL_VERSION_NUMBER "V10.4.3"
48 #define tskKERNEL_VERSION_MAJOR 10
49 #define tskKERNEL_VERSION_MINOR 4
50 #define tskKERNEL_VERSION_BUILD 3
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 )
60 /* The direct to task notification feature used to have only a single notification
61 * per task. Now there is an array of notifications per task that is dimensioned by
62 * configTASK_NOTIFICATION_ARRAY_ENTRIES. For backward compatibility, any use of the
63 * original direct to task notification defaults to using the first index in the
65 #define tskDEFAULT_INDEX_TO_NOTIFY ( 0 )
70 * Type by which tasks are referenced. For example, a call to xTaskCreate
71 * returns (via a pointer parameter) an TaskHandle_t variable that can then
72 * be used as a parameter to vTaskDelete to delete the task.
74 * \defgroup TaskHandle_t TaskHandle_t
77 struct tskTaskControlBlock; /* The old naming convention is used to prevent breaking kernel aware debuggers. */
78 typedef struct tskTaskControlBlock * TaskHandle_t;
81 * Defines the prototype to which the application task hook function must
84 typedef BaseType_t (* TaskHookFunction_t)( void * );
86 /* Task states returned by eTaskGetState. */
89 eRunning = 0, /* A task is querying the state of itself, so must be running. */
90 eReady, /* The task being queried is in a ready or pending ready list. */
91 eBlocked, /* The task being queried is in the Blocked state. */
92 eSuspended, /* The task being queried is in the Suspended state, or is in the Blocked state with an infinite time out. */
93 eDeleted, /* The task being queried has been deleted, but its TCB has not yet been freed. */
94 eInvalid /* Used as an 'invalid state' value. */
97 /* Actions that can be performed when vTaskNotify() is called. */
100 eNoAction = 0, /* Notify the task without updating its notify value. */
101 eSetBits, /* Set bits in the task's notification value. */
102 eIncrement, /* Increment the task's notification value. */
103 eSetValueWithOverwrite, /* Set the task's notification value to a specific value even if the previous value has not yet been read by the task. */
104 eSetValueWithoutOverwrite /* Set the task's notification value if the previous value has been read by the task. */
108 * Used internally only.
110 typedef struct xTIME_OUT
112 BaseType_t xOverflowCount;
113 TickType_t xTimeOnEntering;
117 * Defines the memory ranges allocated to the task when an MPU is used.
119 typedef struct xMEMORY_REGION
121 void * pvBaseAddress;
122 uint32_t ulLengthInBytes;
123 uint32_t ulParameters;
127 * Parameters required to create an MPU protected task.
129 typedef struct xTASK_PARAMETERS
131 TaskFunction_t pvTaskCode;
132 const char * pcName; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
133 configSTACK_DEPTH_TYPE usStackDepth;
135 UBaseType_t uxPriority;
136 StackType_t * puxStackBuffer;
137 MemoryRegion_t xRegions[ portNUM_CONFIGURABLE_REGIONS ];
138 #if ( ( portUSING_MPU_WRAPPERS == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 1 ) )
139 StaticTask_t * const pxTaskBuffer;
143 /* Used with the uxTaskGetSystemState() function to return the state of each task
145 typedef struct xTASK_STATUS
147 TaskHandle_t xHandle; /* The handle of the task to which the rest of the information in the structure relates. */
148 const char * pcTaskName; /* A pointer to the task's name. This value will be invalid if the task was deleted since the structure was populated! */ /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
149 UBaseType_t xTaskNumber; /* A number unique to the task. */
150 eTaskState eCurrentState; /* The state in which the task existed when the structure was populated. */
151 UBaseType_t uxCurrentPriority; /* The priority at which the task was running (may be inherited) when the structure was populated. */
152 UBaseType_t uxBasePriority; /* The priority to which the task will return if the task's current priority has been inherited to avoid unbounded priority inversion when obtaining a mutex. Only valid if configUSE_MUTEXES is defined as 1 in FreeRTOSConfig.h. */
153 uint32_t ulRunTimeCounter; /* The total run time allocated to the task so far, as defined by the run time stats clock. See https://www.FreeRTOS.org/rtos-run-time-stats.html. Only valid when configGENERATE_RUN_TIME_STATS is defined as 1 in FreeRTOSConfig.h. */
154 StackType_t * pxStackBase; /* Points to the lowest address of the task's stack area. */
155 configSTACK_DEPTH_TYPE usStackHighWaterMark; /* The minimum amount of stack space that has remained for the task since the task was created. The closer this value is to zero the closer the task has come to overflowing its stack. */
156 #if ( ( configUSE_CORE_AFFINITY == 1 ) && ( configNUM_CORES > 1 ) )
157 UBaseType_t uxCoreAffinityMask; /* The core affinity mask for the task */
161 /* Possible return values for eTaskConfirmSleepModeStatus(). */
164 eAbortSleep = 0, /* A task has been made ready or a context switch pended since portSUPPRESS_TICKS_AND_SLEEP() was called - abort entering a sleep mode. */
165 eStandardSleep, /* Enter a sleep mode that will not last any longer than the expected idle time. */
166 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. */
170 * Defines the priority used by the idle task. This must not be modified.
174 #define tskIDLE_PRIORITY ( ( UBaseType_t ) 0U )
177 * Defines affinity to all available cores.
180 #define tskNO_AFFINITY ( ( UBaseType_t ) -1U )
187 * Macro for forcing a context switch.
189 * \defgroup taskYIELD taskYIELD
190 * \ingroup SchedulerControl
192 #define taskYIELD() portYIELD()
197 * Macro to mark the start of a critical code region. Preemptive context
198 * switches cannot occur when in a critical region.
200 * NOTE: This may alter the stack (depending on the portable implementation)
201 * so must be used with care!
203 * \defgroup taskENTER_CRITICAL taskENTER_CRITICAL
204 * \ingroup SchedulerControl
206 #define taskENTER_CRITICAL() portENTER_CRITICAL()
207 #define taskENTER_CRITICAL_FROM_ISR() portSET_INTERRUPT_MASK_FROM_ISR()
212 * Macro to mark the end of a critical code region. Preemptive context
213 * switches cannot occur when in a critical region.
215 * NOTE: This may alter the stack (depending on the portable implementation)
216 * so must be used with care!
218 * \defgroup taskEXIT_CRITICAL taskEXIT_CRITICAL
219 * \ingroup SchedulerControl
221 #define taskEXIT_CRITICAL() portEXIT_CRITICAL()
222 #define taskEXIT_CRITICAL_FROM_ISR( x ) portCLEAR_INTERRUPT_MASK_FROM_ISR( x )
227 * Macro to disable all maskable interrupts.
228 * This also returns what the interrupt state was
229 * upon being called. This state may subsequently
230 * be passed to taskRESTORE_INTERRUPTS().
232 * \defgroup taskDISABLE_INTERRUPTS taskDISABLE_INTERRUPTS
233 * \ingroup SchedulerControl
235 #define taskDISABLE_INTERRUPTS() portDISABLE_INTERRUPTS()
240 * Macro to enable microcontroller interrupts.
242 * \defgroup taskENABLE_INTERRUPTS taskENABLE_INTERRUPTS
243 * \ingroup SchedulerControl
245 #define taskENABLE_INTERRUPTS() portENABLE_INTERRUPTS()
250 * Macro to restore microcontroller interrupts to
253 * \defgroup taskRESTORE_INTERRUPTS taskRESTORE_INTERRUPTS
254 * \ingroup SchedulerControl
256 #define taskRESTORE_INTERRUPTS(ulState) portRESTORE_INTERRUPTS(ulState)
261 * Macro that determines if it is being called from within an ISR
262 * or a task. Returns non-zero if it is in an ISR.
264 * \defgroup taskCHECK_IF_IN_ISR taskCHECK_IF_IN_ISR
265 * \ingroup SchedulerControl
267 #define taskCHECK_IF_IN_ISR() portCHECK_IF_IN_ISR()
269 /* Definitions returned by xTaskGetSchedulerState(). taskSCHEDULER_SUSPENDED is
270 * 0 to generate more optimal code when configASSERT() is defined as the constant
271 * is used in assert() statements. */
272 #define taskSCHEDULER_SUSPENDED ( ( BaseType_t ) 0 )
273 #define taskSCHEDULER_NOT_STARTED ( ( BaseType_t ) 1 )
274 #define taskSCHEDULER_RUNNING ( ( BaseType_t ) 2 )
276 /* Check if core value is valid */
277 #define taskVALID_CORE_ID( xCoreID ) ( ( BaseType_t ) ( ( 0 <= xCoreID ) && ( xCoreID < configNUM_CORES ) ) )
279 /*-----------------------------------------------------------
281 *----------------------------------------------------------*/
286 * BaseType_t xTaskCreate(
287 * TaskFunction_t pxTaskCode,
288 * const char *pcName,
289 * configSTACK_DEPTH_TYPE usStackDepth,
290 * void *pvParameters,
291 * UBaseType_t uxPriority,
292 * TaskHandle_t *pxCreatedTask
296 * Create a new task and add it to the list of tasks that are ready to run.
298 * Internally, within the FreeRTOS implementation, tasks use two blocks of
299 * memory. The first block is used to hold the task's data structures. The
300 * second block is used by the task as its stack. If a task is created using
301 * xTaskCreate() then both blocks of memory are automatically dynamically
302 * allocated inside the xTaskCreate() function. (see
303 * https://www.FreeRTOS.org/a00111.html). If a task is created using
304 * xTaskCreateStatic() then the application writer must provide the required
305 * memory. xTaskCreateStatic() therefore allows a task to be created without
306 * using any dynamic memory allocation.
308 * See xTaskCreateStatic() for a version that does not use any dynamic memory
311 * xTaskCreate() can only be used to create a task that has unrestricted
312 * access to the entire microcontroller memory map. Systems that include MPU
313 * support can alternatively create an MPU constrained task using
314 * xTaskCreateRestricted().
316 * @param pxTaskCode Pointer to the task entry function. Tasks
317 * must be implemented to never return (i.e. continuous loop).
319 * @param pcName A descriptive name for the task. This is mainly used to
320 * facilitate debugging. Max length defined by configMAX_TASK_NAME_LEN - default
323 * @param usStackDepth The size of the task stack specified as the number of
324 * variables the stack can hold - not the number of bytes. For example, if
325 * the stack is 16 bits wide and usStackDepth is defined as 100, 200 bytes
326 * will be allocated for stack storage.
328 * @param pvParameters Pointer that will be used as the parameter for the task
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 ).
337 * @param pxCreatedTask Used to pass back a handle by which the created task
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
345 * // Task to be created.
346 * void vTaskCode( void * pvParameters )
350 * // Task code goes here.
354 * // Function that creates a task.
355 * void vOtherFunction( void )
357 * static uint8_t ucParameterToPass;
358 * TaskHandle_t xHandle = NULL;
360 * // Create the task, storing the handle. Note that the passed parameter ucParameterToPass
361 * // must exist for the lifetime of the task, so in this case is declared static. If it was just an
362 * // an automatic stack variable it might no longer exist, or at least have been corrupted, by the time
363 * // the new task attempts to access it.
364 * xTaskCreate( vTaskCode, "NAME", STACK_SIZE, &ucParameterToPass, tskIDLE_PRIORITY, &xHandle );
365 * configASSERT( xHandle );
367 * // Use the handle to delete the task.
368 * if( xHandle != NULL )
370 * vTaskDelete( xHandle );
374 * \defgroup xTaskCreate xTaskCreate
377 #if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
378 BaseType_t xTaskCreate( TaskFunction_t pxTaskCode,
379 const char * const pcName, /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
380 const configSTACK_DEPTH_TYPE usStackDepth,
381 void * const pvParameters,
382 UBaseType_t uxPriority,
383 TaskHandle_t * const pxCreatedTask ) PRIVILEGED_FUNCTION;
386 #if ( ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) && ( configNUM_CORES > 1 ) && ( configUSE_CORE_AFFINITY == 1 ) )
387 BaseType_t xTaskCreateAffinitySet( TaskFunction_t pxTaskCode,
388 const char * const pcName, /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
389 const configSTACK_DEPTH_TYPE usStackDepth,
390 void * const pvParameters,
391 UBaseType_t uxPriority,
392 UBaseType_t uxCoreAffinityMask,
393 TaskHandle_t * const pxCreatedTask ) PRIVILEGED_FUNCTION;
399 * TaskHandle_t xTaskCreateStatic( TaskFunction_t pxTaskCode,
400 * const char *pcName,
401 * uint32_t ulStackDepth,
402 * void *pvParameters,
403 * UBaseType_t uxPriority,
404 * StackType_t *puxStackBuffer,
405 * StaticTask_t *pxTaskBuffer );
408 * Create a new task and add it to the list of tasks that are ready to run.
410 * Internally, within the FreeRTOS implementation, tasks use two blocks of
411 * memory. The first block is used to hold the task's data structures. The
412 * second block is used by the task as its stack. If a task is created using
413 * xTaskCreate() then both blocks of memory are automatically dynamically
414 * allocated inside the xTaskCreate() function. (see
415 * https://www.FreeRTOS.org/a00111.html). If a task is created using
416 * xTaskCreateStatic() then the application writer must provide the required
417 * memory. xTaskCreateStatic() therefore allows a task to be created without
418 * using any dynamic memory allocation.
420 * @param pxTaskCode Pointer to the task entry function. Tasks
421 * must be implemented to never return (i.e. continuous loop).
423 * @param pcName A descriptive name for the task. This is mainly used to
424 * facilitate debugging. The maximum length of the string is defined by
425 * configMAX_TASK_NAME_LEN in FreeRTOSConfig.h.
427 * @param ulStackDepth The size of the task stack specified as the number of
428 * variables the stack can hold - not the number of bytes. For example, if
429 * the stack is 32-bits wide and ulStackDepth is defined as 100 then 400 bytes
430 * will be allocated for stack storage.
432 * @param pvParameters Pointer that will be used as the parameter for the task
435 * @param uxPriority The priority at which the task will run.
437 * @param puxStackBuffer Must point to a StackType_t array that has at least
438 * ulStackDepth indexes - the array will then be used as the task's stack,
439 * removing the need for the stack to be allocated dynamically.
441 * @param pxTaskBuffer Must point to a variable of type StaticTask_t, which will
442 * then be used to hold the task's data structures, removing the need for the
443 * memory to be allocated dynamically.
445 * @return If neither puxStackBuffer nor pxTaskBuffer are NULL, then the task
446 * will be created and a handle to the created task is returned. If either
447 * puxStackBuffer or pxTaskBuffer are NULL then the task will not be created and
453 * // Dimensions of the buffer that the task being created will use as its stack.
454 * // NOTE: This is the number of words the stack will hold, not the number of
455 * // bytes. For example, if each stack item is 32-bits, and this is set to 100,
456 * // then 400 bytes (100 * 32-bits) will be allocated.
457 #define STACK_SIZE 200
459 * // Structure that will hold the TCB of the task being created.
460 * StaticTask_t xTaskBuffer;
462 * // Buffer that the task being created will use as its stack. Note this is
463 * // an array of StackType_t variables. The size of StackType_t is dependent on
465 * StackType_t xStack[ STACK_SIZE ];
467 * // Function that implements the task being created.
468 * void vTaskCode( void * pvParameters )
470 * // The parameter value is expected to be 1 as 1 is passed in the
471 * // pvParameters value in the call to xTaskCreateStatic().
472 * configASSERT( ( uint32_t ) pvParameters == 1UL );
476 * // Task code goes here.
480 * // Function that creates a task.
481 * void vOtherFunction( void )
483 * TaskHandle_t xHandle = NULL;
485 * // Create the task without using any dynamic memory allocation.
486 * xHandle = xTaskCreateStatic(
487 * vTaskCode, // Function that implements the task.
488 * "NAME", // Text name for the task.
489 * STACK_SIZE, // Stack size in words, not bytes.
490 * ( void * ) 1, // Parameter passed into the task.
491 * tskIDLE_PRIORITY,// Priority at which the task is created.
492 * xStack, // Array to use as the task's stack.
493 * &xTaskBuffer ); // Variable to hold the task's data structure.
495 * // puxStackBuffer and pxTaskBuffer were not NULL, so the task will have
496 * // been created, and xHandle will be the task's handle. Use the handle
497 * // to suspend the task.
498 * vTaskSuspend( xHandle );
501 * \defgroup xTaskCreateStatic xTaskCreateStatic
504 #if ( configSUPPORT_STATIC_ALLOCATION == 1 )
505 TaskHandle_t xTaskCreateStatic( TaskFunction_t pxTaskCode,
506 const char * const pcName, /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
507 const uint32_t ulStackDepth,
508 void * const pvParameters,
509 UBaseType_t uxPriority,
510 StackType_t * const puxStackBuffer,
511 StaticTask_t * const pxTaskBuffer ) PRIVILEGED_FUNCTION;
512 #endif /* configSUPPORT_STATIC_ALLOCATION */
514 #if ( ( configSUPPORT_STATIC_ALLOCATION == 1 ) && ( configNUM_CORES > 1 ) && ( configUSE_CORE_AFFINITY == 1 ) )
515 TaskHandle_t xTaskCreateStaticAffinitySet( TaskFunction_t pxTaskCode,
516 const char * const pcName, /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
517 const uint32_t ulStackDepth,
518 void * const pvParameters,
519 UBaseType_t uxPriority,
520 StackType_t * const puxStackBuffer,
521 StaticTask_t * const pxTaskBuffer,
522 UBaseType_t uxCoreAffinityMask ) PRIVILEGED_FUNCTION;
528 * BaseType_t xTaskCreateRestricted( TaskParameters_t *pxTaskDefinition, TaskHandle_t *pxCreatedTask );
531 * Only available when configSUPPORT_DYNAMIC_ALLOCATION is set to 1.
533 * xTaskCreateRestricted() should only be used in systems that include an MPU
536 * Create a new task and add it to the list of tasks that are ready to run.
537 * The function parameters define the memory regions and associated access
538 * permissions allocated to the task.
540 * See xTaskCreateRestrictedStatic() for a version that does not use any
541 * dynamic memory allocation.
543 * @param pxTaskDefinition Pointer to a structure that contains a member
544 * for each of the normal xTaskCreate() parameters (see the xTaskCreate() API
545 * documentation) plus an optional stack buffer and the memory region
548 * @param pxCreatedTask Used to pass back a handle by which the created task
551 * @return pdPASS if the task was successfully created and added to a ready
552 * list, otherwise an error code defined in the file projdefs.h
556 * // Create an TaskParameters_t structure that defines the task to be created.
557 * static const TaskParameters_t xCheckTaskParameters =
559 * vATask, // pvTaskCode - the function that implements the task.
560 * "ATask", // pcName - just a text name for the task to assist debugging.
561 * 100, // usStackDepth - the stack size DEFINED IN WORDS.
562 * NULL, // pvParameters - passed into the task function as the function parameters.
563 * ( 1UL | portPRIVILEGE_BIT ),// uxPriority - task priority, set the portPRIVILEGE_BIT if the task should run in a privileged state.
564 * cStackBuffer,// puxStackBuffer - the buffer to be used as the task stack.
566 * // xRegions - Allocate up to three separate memory regions for access by
567 * // the task, with appropriate access permissions. Different processors have
568 * // different memory alignment requirements - refer to the FreeRTOS documentation
569 * // for full information.
571 * // Base address Length Parameters
572 * { cReadWriteArray, 32, portMPU_REGION_READ_WRITE },
573 * { cReadOnlyArray, 32, portMPU_REGION_READ_ONLY },
574 * { cPrivilegedOnlyAccessArray, 128, portMPU_REGION_PRIVILEGED_READ_WRITE }
580 * TaskHandle_t xHandle;
582 * // Create a task from the const structure defined above. The task handle
583 * // is requested (the second parameter is not NULL) but in this case just for
584 * // demonstration purposes as its not actually used.
585 * xTaskCreateRestricted( &xRegTest1Parameters, &xHandle );
587 * // Start the scheduler.
588 * vTaskStartScheduler();
590 * // Will only get here if there was insufficient memory to create the idle
591 * // and/or timer task.
595 * \defgroup xTaskCreateRestricted xTaskCreateRestricted
598 #if ( portUSING_MPU_WRAPPERS == 1 )
599 BaseType_t xTaskCreateRestricted( const TaskParameters_t * const pxTaskDefinition,
600 TaskHandle_t * pxCreatedTask ) PRIVILEGED_FUNCTION;
603 #if ( ( portUSING_MPU_WRAPPERS == 1 ) && ( configNUM_CORES > 1 ) && ( configUSE_CORE_AFFINITY == 1 ) )
604 BaseType_t xTaskCreateRestrictedAffinitySet( const TaskParameters_t * const pxTaskDefinition,
605 UBaseType_t uxCoreAffinityMask,
606 TaskHandle_t * pxCreatedTask ) PRIVILEGED_FUNCTION;
612 * BaseType_t xTaskCreateRestrictedStatic( TaskParameters_t *pxTaskDefinition, TaskHandle_t *pxCreatedTask );
615 * Only available when configSUPPORT_STATIC_ALLOCATION is set to 1.
617 * xTaskCreateRestrictedStatic() should only be used in systems that include an
618 * MPU implementation.
620 * Internally, within the FreeRTOS implementation, tasks use two blocks of
621 * memory. The first block is used to hold the task's data structures. The
622 * second block is used by the task as its stack. If a task is created using
623 * xTaskCreateRestricted() then the stack is provided by the application writer,
624 * and the memory used to hold the task's data structure is automatically
625 * dynamically allocated inside the xTaskCreateRestricted() function. If a task
626 * is created using xTaskCreateRestrictedStatic() then the application writer
627 * must provide the memory used to hold the task's data structures too.
628 * xTaskCreateRestrictedStatic() therefore allows a memory protected task to be
629 * created without using any dynamic memory allocation.
631 * @param pxTaskDefinition Pointer to a structure that contains a member
632 * for each of the normal xTaskCreate() parameters (see the xTaskCreate() API
633 * documentation) plus an optional stack buffer and the memory region
634 * definitions. If configSUPPORT_STATIC_ALLOCATION is set to 1 the structure
635 * contains an additional member, which is used to point to a variable of type
636 * StaticTask_t - which is then used to hold the task's data structure.
638 * @param pxCreatedTask Used to pass back a handle by which the created task
641 * @return pdPASS if the task was successfully created and added to a ready
642 * list, otherwise an error code defined in the file projdefs.h
646 * // Create an TaskParameters_t structure that defines the task to be created.
647 * // The StaticTask_t variable is only included in the structure when
648 * // configSUPPORT_STATIC_ALLOCATION is set to 1. The PRIVILEGED_DATA macro can
649 * // be used to force the variable into the RTOS kernel's privileged data area.
650 * static PRIVILEGED_DATA StaticTask_t xTaskBuffer;
651 * static const TaskParameters_t xCheckTaskParameters =
653 * vATask, // pvTaskCode - the function that implements the task.
654 * "ATask", // pcName - just a text name for the task to assist debugging.
655 * 100, // usStackDepth - the stack size DEFINED IN WORDS.
656 * NULL, // pvParameters - passed into the task function as the function parameters.
657 * ( 1UL | portPRIVILEGE_BIT ),// uxPriority - task priority, set the portPRIVILEGE_BIT if the task should run in a privileged state.
658 * cStackBuffer,// puxStackBuffer - the buffer to be used as the task stack.
660 * // xRegions - Allocate up to three separate memory regions for access by
661 * // the task, with appropriate access permissions. Different processors have
662 * // different memory alignment requirements - refer to the FreeRTOS documentation
663 * // for full information.
665 * // Base address Length Parameters
666 * { cReadWriteArray, 32, portMPU_REGION_READ_WRITE },
667 * { cReadOnlyArray, 32, portMPU_REGION_READ_ONLY },
668 * { cPrivilegedOnlyAccessArray, 128, portMPU_REGION_PRIVILEGED_READ_WRITE }
671 * &xTaskBuffer; // Holds the task's data structure.
676 * TaskHandle_t xHandle;
678 * // Create a task from the const structure defined above. The task handle
679 * // is requested (the second parameter is not NULL) but in this case just for
680 * // demonstration purposes as its not actually used.
681 * xTaskCreateRestricted( &xRegTest1Parameters, &xHandle );
683 * // Start the scheduler.
684 * vTaskStartScheduler();
686 * // Will only get here if there was insufficient memory to create the idle
687 * // and/or timer task.
691 * \defgroup xTaskCreateRestrictedStatic xTaskCreateRestrictedStatic
694 #if ( ( portUSING_MPU_WRAPPERS == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 1 ) )
695 BaseType_t xTaskCreateRestrictedStatic( const TaskParameters_t * const pxTaskDefinition,
696 TaskHandle_t * pxCreatedTask ) PRIVILEGED_FUNCTION;
699 #if ( ( portUSING_MPU_WRAPPERS == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 1 ) && ( configNUM_CORES > 1 ) && ( configUSE_CORE_AFFINITY == 1 ) )
700 BaseType_t xTaskCreateRestrictedStaticAffinitySet( const TaskParameters_t * const pxTaskDefinition,
701 UBaseType_t uxCoreAffinityMask,
702 TaskHandle_t * pxCreatedTask ) PRIVILEGED_FUNCTION;
708 * void vTaskAllocateMPURegions( TaskHandle_t xTask, const MemoryRegion_t * const pxRegions );
711 * Memory regions are assigned to a restricted task when the task is created by
712 * a call to xTaskCreateRestricted(). These regions can be redefined using
713 * vTaskAllocateMPURegions().
715 * @param xTask The handle of the task being updated.
717 * @param xRegions A pointer to a MemoryRegion_t structure that contains the
718 * new memory region definitions.
722 * // Define an array of MemoryRegion_t structures that configures an MPU region
723 * // allowing read/write access for 1024 bytes starting at the beginning of the
724 * // ucOneKByte array. The other two of the maximum 3 definable regions are
725 * // unused so set to zero.
726 * static const MemoryRegion_t xAltRegions[ portNUM_CONFIGURABLE_REGIONS ] =
728 * // Base address Length Parameters
729 * { ucOneKByte, 1024, portMPU_REGION_READ_WRITE },
734 * void vATask( void *pvParameters )
736 * // This task was created such that it has access to certain regions of
737 * // memory as defined by the MPU configuration. At some point it is
738 * // desired that these MPU regions are replaced with that defined in the
739 * // xAltRegions const struct above. Use a call to vTaskAllocateMPURegions()
740 * // for this purpose. NULL is used as the task handle to indicate that this
741 * // function should modify the MPU regions of the calling task.
742 * vTaskAllocateMPURegions( NULL, xAltRegions );
744 * // Now the task can continue its function, but from this point on can only
745 * // access its stack and the ucOneKByte array (unless any other statically
746 * // defined or shared regions have been declared elsewhere).
749 * \defgroup xTaskCreateRestricted xTaskCreateRestricted
752 void vTaskAllocateMPURegions( TaskHandle_t xTask,
753 const MemoryRegion_t * const pxRegions ) PRIVILEGED_FUNCTION;
758 * void vTaskDelete( TaskHandle_t xTaskToDelete );
761 * INCLUDE_vTaskDelete must be defined as 1 for this function to be available.
762 * See the configuration section for more information.
764 * Remove a task from the RTOS real time kernel's management. The task being
765 * deleted will be removed from all ready, blocked, suspended and event lists.
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
774 * See the demo application file death.c for sample code that utilises
777 * @param xTaskToDelete The handle of the task to be deleted. Passing NULL will
778 * cause the calling task to be deleted.
782 * void vOtherFunction( void )
784 * TaskHandle_t xHandle;
786 * // Create the task, storing the handle.
787 * xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
789 * // Use the handle to delete the task.
790 * vTaskDelete( xHandle );
793 * \defgroup vTaskDelete vTaskDelete
796 void vTaskDelete( TaskHandle_t xTaskToDelete ) PRIVILEGED_FUNCTION;
798 /*-----------------------------------------------------------
800 *----------------------------------------------------------*/
805 * void vTaskDelay( const TickType_t xTicksToDelay );
808 * Delay a task for a given number of ticks. The actual time that the
809 * task remains blocked depends on the tick rate. The constant
810 * portTICK_PERIOD_MS can be used to calculate real time from the tick
811 * rate - with the resolution of one tick period.
813 * INCLUDE_vTaskDelay must be defined as 1 for this function to be available.
814 * See the configuration section for more information.
817 * vTaskDelay() specifies a time at which the task wishes to unblock relative to
818 * the time at which vTaskDelay() is called. For example, specifying a block
819 * period of 100 ticks will cause the task to unblock 100 ticks after
820 * vTaskDelay() is called. vTaskDelay() does not therefore provide a good method
821 * of controlling the frequency of a periodic task as the path taken through the
822 * code, as well as other task and interrupt activity, will effect the frequency
823 * at which vTaskDelay() gets called and therefore the time at which the task
824 * next executes. See xTaskDelayUntil() for an alternative API function designed
825 * to facilitate fixed frequency execution. It does this by specifying an
826 * absolute time (rather than a relative time) at which the calling task should
829 * @param xTicksToDelay The amount of time, in tick periods, that
830 * the calling task should block.
834 * void vTaskFunction( void * pvParameters )
836 * // Block for 500ms.
837 * const TickType_t xDelay = 500 / portTICK_PERIOD_MS;
841 * // Simply toggle the LED every 500ms, blocking between each toggle.
843 * vTaskDelay( xDelay );
847 * \defgroup vTaskDelay vTaskDelay
850 void vTaskDelay( const TickType_t xTicksToDelay ) PRIVILEGED_FUNCTION;
855 * BaseType_t xTaskDelayUntil( TickType_t *pxPreviousWakeTime, const TickType_t xTimeIncrement );
858 * INCLUDE_xTaskDelayUntil must be defined as 1 for this function to be available.
859 * See the configuration section for more information.
861 * Delay a task until a specified time. This function can be used by periodic
862 * tasks to ensure a constant execution frequency.
864 * This function differs from vTaskDelay () in one important aspect: vTaskDelay () will
865 * cause a task to block for the specified number of ticks from the time vTaskDelay () is
866 * called. It is therefore difficult to use vTaskDelay () by itself to generate a fixed
867 * execution frequency as the time between a task starting to execute and that task
868 * calling vTaskDelay () may not be fixed [the task may take a different path though the
869 * code between calls, or may get interrupted or preempted a different number of times
870 * each time it executes].
872 * Whereas vTaskDelay () specifies a wake time relative to the time at which the function
873 * is called, xTaskDelayUntil () specifies the absolute (exact) time at which it wishes to
876 * The macro pdMS_TO_TICKS() can be used to calculate the number of ticks from a
877 * time specified in milliseconds with a resolution of one tick period.
879 * @param pxPreviousWakeTime Pointer to a variable that holds the time at which the
880 * task was last unblocked. The variable must be initialised with the current time
881 * prior to its first use (see the example below). Following this the variable is
882 * automatically updated within xTaskDelayUntil ().
884 * @param xTimeIncrement The cycle time period. The task will be unblocked at
885 * time *pxPreviousWakeTime + xTimeIncrement. Calling xTaskDelayUntil with the
886 * same xTimeIncrement parameter value will cause the task to execute with
887 * a fixed interface period.
889 * @return Value which can be used to check whether the task was actually delayed.
890 * Will be pdTRUE if the task way delayed and pdFALSE otherwise. A task will not
891 * be delayed if the next expected wake time is in the past.
895 * // Perform an action every 10 ticks.
896 * void vTaskFunction( void * pvParameters )
898 * TickType_t xLastWakeTime;
899 * const TickType_t xFrequency = 10;
900 * BaseType_t xWasDelayed;
902 * // Initialise the xLastWakeTime variable with the current time.
903 * xLastWakeTime = xTaskGetTickCount ();
906 * // Wait for the next cycle.
907 * xWasDelayed = xTaskDelayUntil( &xLastWakeTime, xFrequency );
909 * // Perform action here. xWasDelayed value can be used to determine
910 * // whether a deadline was missed if the code here took too long.
914 * \defgroup xTaskDelayUntil xTaskDelayUntil
917 BaseType_t xTaskDelayUntil( TickType_t * const pxPreviousWakeTime,
918 const TickType_t xTimeIncrement ) PRIVILEGED_FUNCTION;
921 * vTaskDelayUntil() is the older version of xTaskDelayUntil() and does not
924 #define vTaskDelayUntil( pxPreviousWakeTime, xTimeIncrement ) \
926 ( void ) xTaskDelayUntil( pxPreviousWakeTime, xTimeIncrement ); \
933 * BaseType_t xTaskAbortDelay( TaskHandle_t xTask );
936 * INCLUDE_xTaskAbortDelay must be defined as 1 in FreeRTOSConfig.h for this
937 * function to be available.
939 * A task will enter the Blocked state when it is waiting for an event. The
940 * event it is waiting for can be a temporal event (waiting for a time), such
941 * as when vTaskDelay() is called, or an event on an object, such as when
942 * xQueueReceive() or ulTaskNotifyTake() is called. If the handle of a task
943 * that is in the Blocked state is used in a call to xTaskAbortDelay() then the
944 * task will leave the Blocked state, and return from whichever function call
945 * placed the task into the Blocked state.
947 * There is no 'FromISR' version of this function as an interrupt would need to
948 * know which object a task was blocked on in order to know which actions to
949 * take. For example, if the task was blocked on a queue the interrupt handler
950 * would then need to know if the queue was locked.
952 * @param xTask The handle of the task to remove from the Blocked state.
954 * @return If the task referenced by xTask was not in the Blocked state then
955 * pdFAIL is returned. Otherwise pdPASS is returned.
957 * \defgroup xTaskAbortDelay xTaskAbortDelay
960 BaseType_t xTaskAbortDelay( TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
965 * UBaseType_t uxTaskPriorityGet( const TaskHandle_t xTask );
968 * INCLUDE_uxTaskPriorityGet must be defined as 1 for this function to be available.
969 * See the configuration section for more information.
971 * Obtain the priority of any task.
973 * @param xTask Handle of the task to be queried. Passing a NULL
974 * handle results in the priority of the calling task being returned.
976 * @return The priority of xTask.
980 * void vAFunction( void )
982 * TaskHandle_t xHandle;
984 * // Create a task, storing the handle.
985 * xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
989 * // Use the handle to obtain the priority of the created task.
990 * // It was created with tskIDLE_PRIORITY, but may have changed
992 * if( uxTaskPriorityGet( xHandle ) != tskIDLE_PRIORITY )
994 * // The task has changed it's priority.
999 * // Is our priority higher than the created task?
1000 * if( uxTaskPriorityGet( xHandle ) < uxTaskPriorityGet( NULL ) )
1002 * // Our priority (obtained using NULL handle) is higher.
1006 * \defgroup uxTaskPriorityGet uxTaskPriorityGet
1009 UBaseType_t uxTaskPriorityGet( const TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
1014 * UBaseType_t uxTaskPriorityGetFromISR( const TaskHandle_t xTask );
1017 * A version of uxTaskPriorityGet() that can be used from an ISR.
1019 UBaseType_t uxTaskPriorityGetFromISR( const TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
1024 * eTaskState eTaskGetState( TaskHandle_t xTask );
1027 * INCLUDE_eTaskGetState must be defined as 1 for this function to be available.
1028 * See the configuration section for more information.
1030 * Obtain the state of any task. States are encoded by the eTaskState
1033 * @param xTask Handle of the task to be queried.
1035 * @return The state of xTask at the time the function was called. Note the
1036 * state of the task might change between the function being called, and the
1037 * functions return value being tested by the calling task.
1039 eTaskState eTaskGetState( TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
1044 * void vTaskGetInfo( TaskHandle_t xTask, TaskStatus_t *pxTaskStatus, BaseType_t xGetFreeStackSpace, eTaskState eState );
1047 * configUSE_TRACE_FACILITY must be defined as 1 for this function to be
1048 * available. See the configuration section for more information.
1050 * Populates a TaskStatus_t structure with information about a task.
1052 * @param xTask Handle of the task being queried. If xTask is NULL then
1053 * information will be returned about the calling task.
1055 * @param pxTaskStatus A pointer to the TaskStatus_t structure that will be
1056 * filled with information about the task referenced by the handle passed using
1057 * the xTask parameter.
1059 * @xGetFreeStackSpace The TaskStatus_t structure contains a member to report
1060 * the stack high water mark of the task being queried. Calculating the stack
1061 * high water mark takes a relatively long time, and can make the system
1062 * temporarily unresponsive - so the xGetFreeStackSpace parameter is provided to
1063 * allow the high water mark checking to be skipped. The high watermark value
1064 * will only be written to the TaskStatus_t structure if xGetFreeStackSpace is
1065 * not set to pdFALSE;
1067 * @param eState The TaskStatus_t structure contains a member to report the
1068 * state of the task being queried. Obtaining the task state is not as fast as
1069 * a simple assignment - so the eState parameter is provided to allow the state
1070 * information to be omitted from the TaskStatus_t structure. To obtain state
1071 * information then set eState to eInvalid - otherwise the value passed in
1072 * eState will be reported as the task state in the TaskStatus_t structure.
1076 * void vAFunction( void )
1078 * TaskHandle_t xHandle;
1079 * TaskStatus_t xTaskDetails;
1081 * // Obtain the handle of a task from its name.
1082 * xHandle = xTaskGetHandle( "Task_Name" );
1084 * // Check the handle is not NULL.
1085 * configASSERT( xHandle );
1087 * // Use the handle to obtain further information about the task.
1088 * vTaskGetInfo( xHandle,
1090 * pdTRUE, // Include the high water mark in xTaskDetails.
1091 * eInvalid ); // Include the task state in xTaskDetails.
1094 * \defgroup vTaskGetInfo vTaskGetInfo
1097 void vTaskGetInfo( TaskHandle_t xTask,
1098 TaskStatus_t * pxTaskStatus,
1099 BaseType_t xGetFreeStackSpace,
1100 eTaskState eState ) PRIVILEGED_FUNCTION;
1105 * void vTaskPrioritySet( TaskHandle_t xTask, UBaseType_t uxNewPriority );
1108 * INCLUDE_vTaskPrioritySet must be defined as 1 for this function to be available.
1109 * See the configuration section for more information.
1111 * Set the priority of any task.
1113 * A context switch will occur before the function returns if the priority
1114 * being set is higher than the currently executing task.
1116 * @param xTask Handle to the task for which the priority is being set.
1117 * Passing a NULL handle results in the priority of the calling task being set.
1119 * @param uxNewPriority The priority to which the task will be set.
1123 * void vAFunction( void )
1125 * TaskHandle_t xHandle;
1127 * // Create a task, storing the handle.
1128 * xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
1132 * // Use the handle to raise the priority of the created task.
1133 * vTaskPrioritySet( xHandle, tskIDLE_PRIORITY + 1 );
1137 * // Use a NULL handle to raise our priority to the same value.
1138 * vTaskPrioritySet( NULL, tskIDLE_PRIORITY + 1 );
1141 * \defgroup vTaskPrioritySet vTaskPrioritySet
1144 void vTaskPrioritySet( TaskHandle_t xTask,
1145 UBaseType_t uxNewPriority ) PRIVILEGED_FUNCTION;
1150 * void vTaskSuspend( TaskHandle_t xTaskToSuspend );
1153 * INCLUDE_vTaskSuspend must be defined as 1 for this function to be available.
1154 * See the configuration section for more information.
1156 * Suspend any task. When suspended a task will never get any microcontroller
1157 * processing time, no matter what its priority.
1159 * Calls to vTaskSuspend are not accumulative -
1160 * i.e. calling vTaskSuspend () twice on the same task still only requires one
1161 * call to vTaskResume () to ready the suspended task.
1163 * @param xTaskToSuspend Handle to the task being suspended. Passing a NULL
1164 * handle will cause the calling task to be suspended.
1168 * void vAFunction( void )
1170 * TaskHandle_t xHandle;
1172 * // Create a task, storing the handle.
1173 * xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
1177 * // Use the handle to suspend the created task.
1178 * vTaskSuspend( xHandle );
1182 * // The created task will not run during this period, unless
1183 * // another task calls vTaskResume( xHandle ).
1188 * // Suspend ourselves.
1189 * vTaskSuspend( NULL );
1191 * // We cannot get here unless another task calls vTaskResume
1192 * // with our handle as the parameter.
1195 * \defgroup vTaskSuspend vTaskSuspend
1198 void vTaskSuspend( TaskHandle_t xTaskToSuspend ) PRIVILEGED_FUNCTION;
1203 * void vTaskResume( TaskHandle_t xTaskToResume );
1206 * INCLUDE_vTaskSuspend must be defined as 1 for this function to be available.
1207 * See the configuration section for more information.
1209 * Resumes a suspended task.
1211 * A task that has been suspended by one or more calls to vTaskSuspend ()
1212 * will be made available for running again by a single call to
1215 * @param xTaskToResume Handle to the task being readied.
1219 * void vAFunction( void )
1221 * TaskHandle_t xHandle;
1223 * // Create a task, storing the handle.
1224 * xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &xHandle );
1228 * // Use the handle to suspend the created task.
1229 * vTaskSuspend( xHandle );
1233 * // The created task will not run during this period, unless
1234 * // another task calls vTaskResume( xHandle ).
1239 * // Resume the suspended task ourselves.
1240 * vTaskResume( xHandle );
1242 * // The created task will once again get microcontroller processing
1243 * // time in accordance with its priority within the system.
1246 * \defgroup vTaskResume vTaskResume
1249 void vTaskResume( TaskHandle_t xTaskToResume ) PRIVILEGED_FUNCTION;
1254 * void xTaskResumeFromISR( TaskHandle_t xTaskToResume );
1257 * INCLUDE_xTaskResumeFromISR must be defined as 1 for this function to be
1258 * available. See the configuration section for more information.
1260 * An implementation of vTaskResume() that can be called from within an ISR.
1262 * A task that has been suspended by one or more calls to vTaskSuspend ()
1263 * will be made available for running again by a single call to
1264 * xTaskResumeFromISR ().
1266 * xTaskResumeFromISR() should not be used to synchronise a task with an
1267 * interrupt if there is a chance that the interrupt could arrive prior to the
1268 * task being suspended - as this can lead to interrupts being missed. Use of a
1269 * semaphore as a synchronisation mechanism would avoid this eventuality.
1271 * @param xTaskToResume Handle to the task being readied.
1273 * @return pdTRUE if resuming the task should result in a context switch,
1274 * otherwise pdFALSE. This is used by the ISR to determine if a context switch
1275 * may be required following the ISR.
1277 * \defgroup vTaskResumeFromISR vTaskResumeFromISR
1280 BaseType_t xTaskResumeFromISR( TaskHandle_t xTaskToResume ) PRIVILEGED_FUNCTION;
1282 #if ( configUSE_CORE_AFFINITY == 1)
1284 * @brief Sets the core affinity mask for a task.
1286 * It sets the cores on which a task can run. configUSE_CORE_AFFINITY must
1287 * be defined as 1 for this function to be available.
1289 * @param xTask The handle of the task to set the core affinity mask for.
1290 * Passing NULL will set the core affinity mask for the calling task.
1292 * @param uxCoreAffinityMask A bitwise value that indicates the cores on
1293 * which the task can run. Cores are numbered from 0 to configNUM_CORES - 1.
1294 * For example, to ensure that a task can run on core 0 and core 1, set
1295 * uxCoreAffinityMask to 0x03.
1299 * // The function that creates task.
1300 * void vAFunction( void )
1302 * TaskHandle_t xHandle;
1303 * UBaseType_t uxCoreAffinityMask;
1305 * // Create a task, storing the handle.
1306 * xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &( xHandle ) );
1308 * // Define the core affinity mask such that this task can only run
1309 * // on core 0 and core 2.
1310 * uxCoreAffinityMask = ( ( 1 << 0 ) | ( 1 << 2 ) );
1312 * //Set the core affinity mask for the task.
1313 * vTaskCoreAffinitySet( xHandle, uxCoreAffinityMask );
1316 void vTaskCoreAffinitySet( const TaskHandle_t xTask, UBaseType_t uxCoreAffinityMask );
1319 #if ( configUSE_CORE_AFFINITY == 1)
1321 * @brief Gets the core affinity mask for a task.
1323 * configUSE_CORE_AFFINITY must be defined as 1 for this function to be
1326 * @param xTask The handle of the task to get the core affinity mask for.
1327 * Passing NULL will get the core affinity mask for the calling task.
1329 * @return The core affinity mask which is a bitwise value that indicates
1330 * the cores on which a task can run. Cores are numbered from 0 to
1331 * configNUM_CORES - 1. For example, if a task can run on core 0 and core 1,
1332 * the core affinity mask is 0x03.
1336 * // Task handle of the networking task - it is populated elsewhere.
1337 * TaskHandle_t xNetworkingTaskHandle;
1339 * void vAFunction( void )
1341 * TaskHandle_t xHandle;
1342 * UBaseType_t uxNetworkingCoreAffinityMask;
1344 * // Create a task, storing the handle.
1345 * xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, &( xHandle ) );
1347 * //Get the core affinity mask for the networking task.
1348 * uxNetworkingCoreAffinityMask = vTaskCoreAffinityGet( xNetworkingTaskHandle );
1350 * // Here is a hypothetical scenario, just for the example. Assume that we
1351 * // have 2 cores - Core 0 and core 1. We want to pin the application task to
1352 * // the core different than the networking task to ensure that the
1353 * // application task does not interfere with networking.
1354 * if( ( uxNetworkingCoreAffinityMask & ( 1 << 0 ) ) != 0 )
1356 * // The networking task can run on core 0, pin our task to core 1.
1357 * vTaskCoreAffinitySet( xHandle, ( 1 << 1 ) );
1361 * // Otherwise, pin our task to core 0.
1362 * vTaskCoreAffinitySet( xHandle, ( 1 << 0 ) );
1366 UBaseType_t vTaskCoreAffinityGet( const TaskHandle_t xTask );
1370 * @brief Disables preemption for a task.
1372 * @param xTask The handle of the task to disable preemption. Passing NULL
1373 * disables preemption for the calling task.
1377 * void vTaskCode( void *pvParameters )
1379 * // Silence warnings about unused parameters.
1380 * ( void ) pvParameters;
1384 * // ... Perform some function here.
1386 * // Disable preemption for this task.
1387 * vTaskPreemptionDisable( NULL );
1389 * // The task will not be preempted when it is executing in this portion ...
1391 * // ... until the preemption is enabled again.
1392 * vTaskPreemptionEnable( NULL );
1394 * // The task can be preempted when it is executing in this portion.
1398 void vTaskPreemptionDisable( const TaskHandle_t xTask );
1401 * @brief Enables preemption for a task.
1403 * @param xTask The handle of the task to enable preemption. Passing NULL
1404 * enables preemption for the calling task.
1408 * void vTaskCode( void *pvParameters )
1410 * // Silence warnings about unused parameters.
1411 * ( void ) pvParameters;
1415 * // ... Perform some function here.
1417 * // Disable preemption for this task.
1418 * vTaskPreemptionDisable( NULL );
1420 * // The task will not be preempted when it is executing in this portion ...
1422 * // ... until the preemption is enabled again.
1423 * vTaskPreemptionEnable( NULL );
1425 * // The task can be preempted when it is executing in this portion.
1429 void vTaskPreemptionEnable( const TaskHandle_t xTask );
1431 /*-----------------------------------------------------------
1433 *----------------------------------------------------------*/
1438 * void vTaskStartScheduler( void );
1441 * Starts the real time kernel tick processing. After calling the kernel
1442 * has control over which tasks are executed and when.
1444 * See the demo application file main.c for an example of creating
1445 * tasks and starting the kernel.
1449 * void vAFunction( void )
1451 * // Create at least one task before starting the kernel.
1452 * xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
1454 * // Start the real time kernel with preemption.
1455 * vTaskStartScheduler ();
1457 * // Will not get here unless a task calls vTaskEndScheduler ()
1461 * \defgroup vTaskStartScheduler vTaskStartScheduler
1462 * \ingroup SchedulerControl
1464 void vTaskStartScheduler( void ) PRIVILEGED_FUNCTION;
1469 * void vTaskEndScheduler( void );
1472 * NOTE: At the time of writing only the x86 real mode port, which runs on a PC
1473 * in place of DOS, implements this function.
1475 * Stops the real time kernel tick. All created tasks will be automatically
1476 * deleted and multitasking (either preemptive or cooperative) will
1477 * stop. Execution then resumes from the point where vTaskStartScheduler ()
1478 * was called, as if vTaskStartScheduler () had just returned.
1480 * See the demo application file main. c in the demo/PC directory for an
1481 * example that uses vTaskEndScheduler ().
1483 * vTaskEndScheduler () requires an exit function to be defined within the
1484 * portable layer (see vPortEndScheduler () in port. c for the PC port). This
1485 * performs hardware specific operations such as stopping the kernel tick.
1487 * vTaskEndScheduler () will cause all of the resources allocated by the
1488 * kernel to be freed - but will not free resources allocated by application
1493 * void vTaskCode( void * pvParameters )
1497 * // Task code goes here.
1499 * // At some point we want to end the real time kernel processing
1501 * vTaskEndScheduler ();
1505 * void vAFunction( void )
1507 * // Create at least one task before starting the kernel.
1508 * xTaskCreate( vTaskCode, "NAME", STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
1510 * // Start the real time kernel with preemption.
1511 * vTaskStartScheduler ();
1513 * // Will only get here when the vTaskCode () task has called
1514 * // vTaskEndScheduler (). When we get here we are back to single task
1519 * \defgroup vTaskEndScheduler vTaskEndScheduler
1520 * \ingroup SchedulerControl
1522 void vTaskEndScheduler( void ) PRIVILEGED_FUNCTION;
1527 * void vTaskSuspendAll( void );
1530 * Suspends the scheduler without disabling interrupts. Context switches will
1531 * not occur while the scheduler is suspended.
1533 * After calling vTaskSuspendAll () the calling task will continue to execute
1534 * without risk of being swapped out until a call to xTaskResumeAll () has been
1537 * API functions that have the potential to cause a context switch (for example,
1538 * xTaskDelayUntil(), xQueueSend(), etc.) must not be called while the scheduler
1543 * void vTask1( void * pvParameters )
1547 * // Task code goes here.
1551 * // At some point the task wants to perform a long operation during
1552 * // which it does not want to get swapped out. It cannot use
1553 * // taskENTER_CRITICAL ()/taskEXIT_CRITICAL () as the length of the
1554 * // operation may cause interrupts to be missed - including the
1557 * // Prevent the real time kernel swapping out the task.
1558 * vTaskSuspendAll ();
1560 * // Perform the operation here. There is no need to use critical
1561 * // sections as we have all the microcontroller processing time.
1562 * // During this time interrupts will still operate and the kernel
1563 * // tick count will be maintained.
1567 * // The operation is complete. Restart the kernel.
1568 * xTaskResumeAll ();
1572 * \defgroup vTaskSuspendAll vTaskSuspendAll
1573 * \ingroup SchedulerControl
1575 void vTaskSuspendAll( void ) PRIVILEGED_FUNCTION;
1580 * BaseType_t xTaskResumeAll( void );
1583 * Resumes scheduler activity after it was suspended by a call to
1584 * vTaskSuspendAll().
1586 * xTaskResumeAll() only resumes the scheduler. It does not unsuspend tasks
1587 * that were previously suspended by a call to vTaskSuspend().
1589 * @return If resuming the scheduler caused a context switch then pdTRUE is
1590 * returned, otherwise pdFALSE is returned.
1594 * void vTask1( void * pvParameters )
1598 * // Task code goes here.
1602 * // At some point the task wants to perform a long operation during
1603 * // which it does not want to get swapped out. It cannot use
1604 * // taskENTER_CRITICAL ()/taskEXIT_CRITICAL () as the length of the
1605 * // operation may cause interrupts to be missed - including the
1608 * // Prevent the real time kernel swapping out the task.
1609 * vTaskSuspendAll ();
1611 * // Perform the operation here. There is no need to use critical
1612 * // sections as we have all the microcontroller processing time.
1613 * // During this time interrupts will still operate and the real
1614 * // time kernel tick count will be maintained.
1618 * // The operation is complete. Restart the kernel. We want to force
1619 * // a context switch - but there is no point if resuming the scheduler
1620 * // caused a context switch already.
1621 * if( !xTaskResumeAll () )
1628 * \defgroup xTaskResumeAll xTaskResumeAll
1629 * \ingroup SchedulerControl
1631 BaseType_t xTaskResumeAll( void ) PRIVILEGED_FUNCTION;
1633 /*-----------------------------------------------------------
1635 *----------------------------------------------------------*/
1639 * <PRE>TickType_t xTaskGetTickCount( void );</PRE>
1641 * @return The count of ticks since vTaskStartScheduler was called.
1643 * \defgroup xTaskGetTickCount xTaskGetTickCount
1644 * \ingroup TaskUtils
1646 TickType_t xTaskGetTickCount( void ) PRIVILEGED_FUNCTION;
1650 * <PRE>TickType_t xTaskGetTickCountFromISR( void );</PRE>
1652 * @return The count of ticks since vTaskStartScheduler was called.
1654 * This is a version of xTaskGetTickCount() that is safe to be called from an
1655 * ISR - provided that TickType_t is the natural word size of the
1656 * microcontroller being used or interrupt nesting is either not supported or
1659 * \defgroup xTaskGetTickCountFromISR xTaskGetTickCountFromISR
1660 * \ingroup TaskUtils
1662 TickType_t xTaskGetTickCountFromISR( void ) PRIVILEGED_FUNCTION;
1666 * <PRE>uint16_t uxTaskGetNumberOfTasks( void );</PRE>
1668 * @return The number of tasks that the real time kernel is currently managing.
1669 * This includes all ready, blocked and suspended tasks. A task that
1670 * has been deleted but not yet freed by the idle task will also be
1671 * included in the count.
1673 * \defgroup uxTaskGetNumberOfTasks uxTaskGetNumberOfTasks
1674 * \ingroup TaskUtils
1676 UBaseType_t uxTaskGetNumberOfTasks( void ) PRIVILEGED_FUNCTION;
1680 * <PRE>char *pcTaskGetName( TaskHandle_t xTaskToQuery );</PRE>
1682 * @return The text (human readable) name of the task referenced by the handle
1683 * xTaskToQuery. A task can query its own name by either passing in its own
1684 * handle, or by setting xTaskToQuery to NULL.
1686 * \defgroup pcTaskGetName pcTaskGetName
1687 * \ingroup TaskUtils
1689 char * pcTaskGetName( TaskHandle_t xTaskToQuery ) PRIVILEGED_FUNCTION; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
1693 * <PRE>TaskHandle_t xTaskGetHandle( const char *pcNameToQuery );</PRE>
1695 * NOTE: This function takes a relatively long time to complete and should be
1698 * @return The handle of the task that has the human readable name pcNameToQuery.
1699 * NULL is returned if no matching name is found. INCLUDE_xTaskGetHandle
1700 * must be set to 1 in FreeRTOSConfig.h for pcTaskGetHandle() to be available.
1702 * \defgroup pcTaskGetHandle pcTaskGetHandle
1703 * \ingroup TaskUtils
1705 TaskHandle_t xTaskGetHandle( const char * pcNameToQuery ) PRIVILEGED_FUNCTION; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
1709 * <PRE>UBaseType_t uxTaskGetStackHighWaterMark( TaskHandle_t xTask );</PRE>
1711 * INCLUDE_uxTaskGetStackHighWaterMark must be set to 1 in FreeRTOSConfig.h for
1712 * this function to be available.
1714 * Returns the high water mark of the stack associated with xTask. That is,
1715 * the minimum free stack space there has been (in words, so on a 32 bit machine
1716 * a value of 1 means 4 bytes) since the task started. The smaller the returned
1717 * number the closer the task has come to overflowing its stack.
1719 * uxTaskGetStackHighWaterMark() and uxTaskGetStackHighWaterMark2() are the
1720 * same except for their return type. Using configSTACK_DEPTH_TYPE allows the
1721 * user to determine the return type. It gets around the problem of the value
1722 * overflowing on 8-bit types without breaking backward compatibility for
1723 * applications that expect an 8-bit return type.
1725 * @param xTask Handle of the task associated with the stack to be checked.
1726 * Set xTask to NULL to check the stack of the calling task.
1728 * @return The smallest amount of free stack space there has been (in words, so
1729 * actual spaces on the stack rather than bytes) since the task referenced by
1730 * xTask was created.
1732 UBaseType_t uxTaskGetStackHighWaterMark( TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
1736 * <PRE>configSTACK_DEPTH_TYPE uxTaskGetStackHighWaterMark2( TaskHandle_t xTask );</PRE>
1738 * INCLUDE_uxTaskGetStackHighWaterMark2 must be set to 1 in FreeRTOSConfig.h for
1739 * this function to be available.
1741 * Returns the high water mark of the stack associated with xTask. That is,
1742 * the minimum free stack space there has been (in words, so on a 32 bit machine
1743 * a value of 1 means 4 bytes) since the task started. The smaller the returned
1744 * number the closer the task has come to overflowing its stack.
1746 * uxTaskGetStackHighWaterMark() and uxTaskGetStackHighWaterMark2() are the
1747 * same except for their return type. Using configSTACK_DEPTH_TYPE allows the
1748 * user to determine the return type. It gets around the problem of the value
1749 * overflowing on 8-bit types without breaking backward compatibility for
1750 * applications that expect an 8-bit return type.
1752 * @param xTask Handle of the task associated with the stack to be checked.
1753 * Set xTask to NULL to check the stack of the calling task.
1755 * @return The smallest amount of free stack space there has been (in words, so
1756 * actual spaces on the stack rather than bytes) since the task referenced by
1757 * xTask was created.
1759 configSTACK_DEPTH_TYPE uxTaskGetStackHighWaterMark2( TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
1761 /* When using trace macros it is sometimes necessary to include task.h before
1762 * FreeRTOS.h. When this is done TaskHookFunction_t will not yet have been defined,
1763 * so the following two prototypes will cause a compilation error. This can be
1764 * fixed by simply guarding against the inclusion of these two prototypes unless
1765 * they are explicitly required by the configUSE_APPLICATION_TASK_TAG configuration
1767 #ifdef configUSE_APPLICATION_TASK_TAG
1768 #if configUSE_APPLICATION_TASK_TAG == 1
1773 * void vTaskSetApplicationTaskTag( TaskHandle_t xTask, TaskHookFunction_t pxHookFunction );
1776 * Sets pxHookFunction to be the task hook function used by the task xTask.
1777 * Passing xTask as NULL has the effect of setting the calling tasks hook
1780 void vTaskSetApplicationTaskTag( TaskHandle_t xTask,
1781 TaskHookFunction_t pxHookFunction ) PRIVILEGED_FUNCTION;
1786 * void xTaskGetApplicationTaskTag( TaskHandle_t xTask );
1789 * Returns the pxHookFunction value assigned to the task xTask. Do not
1790 * call from an interrupt service routine - call
1791 * xTaskGetApplicationTaskTagFromISR() instead.
1793 TaskHookFunction_t xTaskGetApplicationTaskTag( TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
1798 * void xTaskGetApplicationTaskTagFromISR( TaskHandle_t xTask );
1801 * Returns the pxHookFunction value assigned to the task xTask. Can
1802 * be called from an interrupt service routine.
1804 TaskHookFunction_t xTaskGetApplicationTaskTagFromISR( TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
1805 #endif /* configUSE_APPLICATION_TASK_TAG ==1 */
1806 #endif /* ifdef configUSE_APPLICATION_TASK_TAG */
1808 #if ( configNUM_THREAD_LOCAL_STORAGE_POINTERS > 0 )
1810 /* Each task contains an array of pointers that is dimensioned by the
1811 * configNUM_THREAD_LOCAL_STORAGE_POINTERS setting in FreeRTOSConfig.h. The
1812 * kernel does not use the pointers itself, so the application writer can use
1813 * the pointers for any purpose they wish. The following two functions are
1814 * used to set and query a pointer respectively. */
1815 void vTaskSetThreadLocalStoragePointer( TaskHandle_t xTaskToSet,
1817 void * pvValue ) PRIVILEGED_FUNCTION;
1818 void * pvTaskGetThreadLocalStoragePointer( TaskHandle_t xTaskToQuery,
1819 BaseType_t xIndex ) PRIVILEGED_FUNCTION;
1823 #if ( configCHECK_FOR_STACK_OVERFLOW > 0 )
1827 * <pre>void vApplicationStackOverflowHook( TaskHandle_t xTask char *pcTaskName); </pre>
1829 * The application stack overflow hook is called when a stack overflow is detected for a task.
1831 * Details on stack overflow detection can be found here: https://www.FreeRTOS.org/Stacks-and-stack-overflow-checking.html
1833 * @param xTask the task that just exceeded its stack boundaries.
1834 * @param pcTaskName A character string containing the name of the offending task.
1836 void vApplicationStackOverflowHook( TaskHandle_t xTask,
1837 char * pcTaskName );
1841 #if ( configUSE_TICK_HOOK > 0 )
1844 * <pre>void vApplicationTickHook( void ); </pre>
1846 * This hook function is called in the system tick handler after any OS work is completed.
1848 void vApplicationTickHook( void ); /*lint !e526 Symbol not defined as it is an application callback. */
1852 #if ( configSUPPORT_STATIC_ALLOCATION == 1 )
1855 * <pre>void vApplicationGetIdleTaskMemory( StaticTask_t ** ppxIdleTaskTCBBuffer, StackType_t ** ppxIdleTaskStackBuffer, uint32_t *pulIdleTaskStackSize ) </pre>
1857 * This function is used to provide a statically allocated block of memory to FreeRTOS to hold the Idle Task TCB. This function is required when
1858 * configSUPPORT_STATIC_ALLOCATION is set. For more information see this URI: https://www.FreeRTOS.org/a00110.html#configSUPPORT_STATIC_ALLOCATION
1860 * @param ppxIdleTaskTCBBuffer A handle to a statically allocated TCB buffer
1861 * @param ppxIdleTaskStackBuffer A handle to a statically allocated Stack buffer for the idle task
1862 * @param pulIdleTaskStackSize A pointer to the number of elements that will fit in the allocated stack buffer
1864 void vApplicationGetIdleTaskMemory( StaticTask_t ** ppxIdleTaskTCBBuffer,
1865 StackType_t ** ppxIdleTaskStackBuffer,
1866 uint32_t * pulIdleTaskStackSize ); /*lint !e526 Symbol not defined as it is an application callback. */
1872 * BaseType_t xTaskCallApplicationTaskHook( TaskHandle_t xTask, void *pvParameter );
1875 * Calls the hook function associated with xTask. Passing xTask as NULL has
1876 * the effect of calling the Running tasks (the calling task) hook function.
1878 * pvParameter is passed to the hook function for the task to interpret as it
1879 * wants. The return value is the value returned by the task hook function
1880 * registered by the user.
1882 BaseType_t xTaskCallApplicationTaskHook( TaskHandle_t xTask,
1883 void * pvParameter ) PRIVILEGED_FUNCTION;
1886 * xTaskGetIdleTaskHandle() is only available if
1887 * INCLUDE_xTaskGetIdleTaskHandle is set to 1 in FreeRTOSConfig.h.
1889 * Simply returns a pointer to the array of idle task handles.
1890 * It is not valid to call xTaskGetIdleTaskHandle() before the scheduler has been started.
1892 TaskHandle_t *xTaskGetIdleTaskHandle( void ) PRIVILEGED_FUNCTION;
1895 * configUSE_TRACE_FACILITY must be defined as 1 in FreeRTOSConfig.h for
1896 * uxTaskGetSystemState() to be available.
1898 * uxTaskGetSystemState() populates an TaskStatus_t structure for each task in
1899 * the system. TaskStatus_t structures contain, among other things, members
1900 * for the task handle, task name, task priority, task state, and total amount
1901 * of run time consumed by the task. See the TaskStatus_t structure
1902 * definition in this file for the full member list.
1904 * NOTE: This function is intended for debugging use only as its use results in
1905 * the scheduler remaining suspended for an extended period.
1907 * @param pxTaskStatusArray A pointer to an array of TaskStatus_t structures.
1908 * The array must contain at least one TaskStatus_t structure for each task
1909 * that is under the control of the RTOS. The number of tasks under the control
1910 * of the RTOS can be determined using the uxTaskGetNumberOfTasks() API function.
1912 * @param uxArraySize The size of the array pointed to by the pxTaskStatusArray
1913 * parameter. The size is specified as the number of indexes in the array, or
1914 * the number of TaskStatus_t structures contained in the array, not by the
1915 * number of bytes in the array.
1917 * @param pulTotalRunTime If configGENERATE_RUN_TIME_STATS is set to 1 in
1918 * FreeRTOSConfig.h then *pulTotalRunTime is set by uxTaskGetSystemState() to the
1919 * total run time (as defined by the run time stats clock, see
1920 * https://www.FreeRTOS.org/rtos-run-time-stats.html) since the target booted.
1921 * pulTotalRunTime can be set to NULL to omit the total run time information.
1923 * @return The number of TaskStatus_t structures that were populated by
1924 * uxTaskGetSystemState(). This should equal the number returned by the
1925 * uxTaskGetNumberOfTasks() API function, but will be zero if the value passed
1926 * in the uxArraySize parameter was too small.
1930 * // This example demonstrates how a human readable table of run time stats
1931 * // information is generated from raw data provided by uxTaskGetSystemState().
1932 * // The human readable table is written to pcWriteBuffer
1933 * void vTaskGetRunTimeStats( char *pcWriteBuffer )
1935 * TaskStatus_t *pxTaskStatusArray;
1936 * volatile UBaseType_t uxArraySize, x;
1937 * uint32_t ulTotalRunTime, ulStatsAsPercentage;
1939 * // Make sure the write buffer does not contain a string.
1940 * pcWriteBuffer = 0x00;
1942 * // Take a snapshot of the number of tasks in case it changes while this
1943 * // function is executing.
1944 * uxArraySize = uxTaskGetNumberOfTasks();
1946 * // Allocate a TaskStatus_t structure for each task. An array could be
1947 * // allocated statically at compile time.
1948 * pxTaskStatusArray = pvPortMalloc( uxArraySize * sizeof( TaskStatus_t ) );
1950 * if( pxTaskStatusArray != NULL )
1952 * // Generate raw status information about each task.
1953 * uxArraySize = uxTaskGetSystemState( pxTaskStatusArray, uxArraySize, &ulTotalRunTime );
1955 * // For percentage calculations.
1956 * ulTotalRunTime /= 100UL;
1958 * // Avoid divide by zero errors.
1959 * if( ulTotalRunTime > 0 )
1961 * // For each populated position in the pxTaskStatusArray array,
1962 * // format the raw data as human readable ASCII data
1963 * for( x = 0; x < uxArraySize; x++ )
1965 * // What percentage of the total run time has the task used?
1966 * // This will always be rounded down to the nearest integer.
1967 * // ulTotalRunTimeDiv100 has already been divided by 100.
1968 * ulStatsAsPercentage = pxTaskStatusArray[ x ].ulRunTimeCounter / ulTotalRunTime;
1970 * if( ulStatsAsPercentage > 0UL )
1972 * sprintf( pcWriteBuffer, "%s\t\t%lu\t\t%lu%%\r\n", pxTaskStatusArray[ x ].pcTaskName, pxTaskStatusArray[ x ].ulRunTimeCounter, ulStatsAsPercentage );
1976 * // If the percentage is zero here then the task has
1977 * // consumed less than 1% of the total run time.
1978 * sprintf( pcWriteBuffer, "%s\t\t%lu\t\t<1%%\r\n", pxTaskStatusArray[ x ].pcTaskName, pxTaskStatusArray[ x ].ulRunTimeCounter );
1981 * pcWriteBuffer += strlen( ( char * ) pcWriteBuffer );
1985 * // The array is no longer needed, free the memory it consumes.
1986 * vPortFree( pxTaskStatusArray );
1991 UBaseType_t uxTaskGetSystemState( TaskStatus_t * const pxTaskStatusArray,
1992 const UBaseType_t uxArraySize,
1993 uint32_t * const pulTotalRunTime ) PRIVILEGED_FUNCTION;
1997 * <PRE>void vTaskList( char *pcWriteBuffer );</PRE>
1999 * configUSE_TRACE_FACILITY and configUSE_STATS_FORMATTING_FUNCTIONS must
2000 * both be defined as 1 for this function to be available. See the
2001 * configuration section of the FreeRTOS.org website for more information.
2003 * NOTE 1: This function will disable interrupts for its duration. It is
2004 * not intended for normal application runtime use but as a debug aid.
2006 * Lists all the current tasks, along with their current state and stack
2007 * usage high water mark.
2009 * Tasks are reported as blocked ('B'), ready ('R'), deleted ('D') or
2014 * This function is provided for convenience only, and is used by many of the
2015 * demo applications. Do not consider it to be part of the scheduler.
2017 * vTaskList() calls uxTaskGetSystemState(), then formats part of the
2018 * uxTaskGetSystemState() output into a human readable table that displays task:
2019 * names, states, priority, stack usage and task number.
2020 * Stack usage specified as the number of unused StackType_t words stack can hold
2021 * on top of stack - not the number of bytes.
2023 * vTaskList() has a dependency on the sprintf() C library function that might
2024 * bloat the code size, use a lot of stack, and provide different results on
2025 * different platforms. An alternative, tiny, third party, and limited
2026 * functionality implementation of sprintf() is provided in many of the
2027 * FreeRTOS/Demo sub-directories in a file called printf-stdarg.c (note
2028 * printf-stdarg.c does not provide a full snprintf() implementation!).
2030 * It is recommended that production systems call uxTaskGetSystemState()
2031 * directly to get access to raw stats data, rather than indirectly through a
2032 * call to vTaskList().
2034 * @param pcWriteBuffer A buffer into which the above mentioned details
2035 * will be written, in ASCII form. This buffer is assumed to be large
2036 * enough to contain the generated report. Approximately 40 bytes per
2037 * task should be sufficient.
2039 * \defgroup vTaskList vTaskList
2040 * \ingroup TaskUtils
2042 void vTaskList( char * pcWriteBuffer ) PRIVILEGED_FUNCTION; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
2046 * <PRE>void vTaskGetRunTimeStats( char *pcWriteBuffer );</PRE>
2048 * configGENERATE_RUN_TIME_STATS and configUSE_STATS_FORMATTING_FUNCTIONS
2049 * must both be defined as 1 for this function to be available. The application
2050 * must also then provide definitions for
2051 * portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() and portGET_RUN_TIME_COUNTER_VALUE()
2052 * to configure a peripheral timer/counter and return the timers current count
2053 * value respectively. The counter should be at least 10 times the frequency of
2056 * NOTE 1: This function will disable interrupts for its duration. It is
2057 * not intended for normal application runtime use but as a debug aid.
2059 * Setting configGENERATE_RUN_TIME_STATS to 1 will result in a total
2060 * accumulated execution time being stored for each task. The resolution
2061 * of the accumulated time value depends on the frequency of the timer
2062 * configured by the portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() macro.
2063 * Calling vTaskGetRunTimeStats() writes the total execution time of each
2064 * task into a buffer, both as an absolute count value and as a percentage
2065 * of the total system execution time.
2069 * This function is provided for convenience only, and is used by many of the
2070 * demo applications. Do not consider it to be part of the scheduler.
2072 * vTaskGetRunTimeStats() calls uxTaskGetSystemState(), then formats part of the
2073 * uxTaskGetSystemState() output into a human readable table that displays the
2074 * amount of time each task has spent in the Running state in both absolute and
2077 * vTaskGetRunTimeStats() has a dependency on the sprintf() C library function
2078 * that might bloat the code size, use a lot of stack, and provide different
2079 * results on different platforms. An alternative, tiny, third party, and
2080 * limited functionality implementation of sprintf() is provided in many of the
2081 * FreeRTOS/Demo sub-directories in a file called printf-stdarg.c (note
2082 * printf-stdarg.c does not provide a full snprintf() implementation!).
2084 * It is recommended that production systems call uxTaskGetSystemState() directly
2085 * to get access to raw stats data, rather than indirectly through a call to
2086 * vTaskGetRunTimeStats().
2088 * @param pcWriteBuffer A buffer into which the execution times will be
2089 * written, in ASCII form. This buffer is assumed to be large enough to
2090 * contain the generated report. Approximately 40 bytes per task should
2093 * \defgroup vTaskGetRunTimeStats vTaskGetRunTimeStats
2094 * \ingroup TaskUtils
2096 void vTaskGetRunTimeStats( char * pcWriteBuffer ) PRIVILEGED_FUNCTION; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
2100 * <PRE>uint32_t ulTaskGetIdleRunTimeCounter( void );</PRE>
2102 * configGENERATE_RUN_TIME_STATS and configUSE_STATS_FORMATTING_FUNCTIONS
2103 * must both be defined as 1 for this function to be available. The application
2104 * must also then provide definitions for
2105 * portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() and portGET_RUN_TIME_COUNTER_VALUE()
2106 * to configure a peripheral timer/counter and return the timers current count
2107 * value respectively. The counter should be at least 10 times the frequency of
2110 * Setting configGENERATE_RUN_TIME_STATS to 1 will result in a total
2111 * accumulated execution time being stored for each task. The resolution
2112 * of the accumulated time value depends on the frequency of the timer
2113 * configured by the portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() macro.
2114 * While uxTaskGetSystemState() and vTaskGetRunTimeStats() writes the total
2115 * execution time of each task into a buffer, ulTaskGetIdleRunTimeCounter()
2116 * returns the total execution time of just the idle task.
2118 * @return The total run time of the idle task. This is the amount of time the
2119 * idle task has actually been executing. The unit of time is dependent on the
2120 * frequency configured using the portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() and
2121 * portGET_RUN_TIME_COUNTER_VALUE() macros.
2123 * \defgroup ulTaskGetIdleRunTimeCounter ulTaskGetIdleRunTimeCounter
2124 * \ingroup TaskUtils
2126 uint32_t ulTaskGetIdleRunTimeCounter( void ) PRIVILEGED_FUNCTION;
2130 * <PRE>BaseType_t xTaskNotifyIndexed( TaskHandle_t xTaskToNotify, UBaseType_t uxIndexToNotify, uint32_t ulValue, eNotifyAction eAction );</PRE>
2131 * <PRE>BaseType_t xTaskNotify( TaskHandle_t xTaskToNotify, uint32_t ulValue, eNotifyAction eAction );</PRE>
2133 * See https://www.FreeRTOS.org/RTOS-task-notifications.html for details.
2135 * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for these
2136 * functions to be available.
2138 * Sends a direct to task notification to a task, with an optional value and
2141 * Each task has a private array of "notification values" (or 'notifications'),
2142 * each of which is a 32-bit unsigned integer (uint32_t). The constant
2143 * configTASK_NOTIFICATION_ARRAY_ENTRIES sets the number of indexes in the
2144 * array, and (for backward compatibility) defaults to 1 if left undefined.
2145 * Prior to FreeRTOS V10.4.0 there was only one notification value per task.
2147 * Events can be sent to a task using an intermediary object. Examples of such
2148 * objects are queues, semaphores, mutexes and event groups. Task notifications
2149 * are a method of sending an event directly to a task without the need for such
2150 * an intermediary object.
2152 * A notification sent to a task can optionally perform an action, such as
2153 * update, overwrite or increment one of the task's notification values. In
2154 * that way task notifications can be used to send data to a task, or be used as
2155 * light weight and fast binary or counting semaphores.
2157 * A task can use xTaskNotifyWaitIndexed() or ulTaskNotifyTakeIndexed() to
2158 * [optionally] block to wait for a notification to be pending. The task does
2159 * not consume any CPU time while it is in the Blocked state.
2161 * A notification sent to a task will remain pending until it is cleared by the
2162 * task calling xTaskNotifyWaitIndexed() or ulTaskNotifyTakeIndexed() (or their
2163 * un-indexed equivalents). If the task was already in the Blocked state to
2164 * wait for a notification when the notification arrives then the task will
2165 * automatically be removed from the Blocked state (unblocked) and the
2166 * notification cleared.
2168 * **NOTE** Each notification within the array operates independently - a task
2169 * can only block on one notification within the array at a time and will not be
2170 * unblocked by a notification sent to any other array index.
2172 * Backward compatibility information:
2173 * Prior to FreeRTOS V10.4.0 each task had a single "notification value", and
2174 * all task notification API functions operated on that value. Replacing the
2175 * single notification value with an array of notification values necessitated a
2176 * new set of API functions that could address specific notifications within the
2177 * array. xTaskNotify() is the original API function, and remains backward
2178 * compatible by always operating on the notification value at index 0 in the
2179 * array. Calling xTaskNotify() is equivalent to calling xTaskNotifyIndexed()
2180 * with the uxIndexToNotify parameter set to 0.
2182 * @param xTaskToNotify The handle of the task being notified. The handle to a
2183 * task can be returned from the xTaskCreate() API function used to create the
2184 * task, and the handle of the currently running task can be obtained by calling
2185 * xTaskGetCurrentTaskHandle().
2187 * @param uxIndexToNotify The index within the target task's array of
2188 * notification values to which the notification is to be sent. uxIndexToNotify
2189 * must be less than configTASK_NOTIFICATION_ARRAY_ENTRIES. xTaskNotify() does
2190 * not have this parameter and always sends notifications to index 0.
2192 * @param ulValue Data that can be sent with the notification. How the data is
2193 * used depends on the value of the eAction parameter.
2195 * @param eAction Specifies how the notification updates the task's notification
2196 * value, if at all. Valid values for eAction are as follows:
2199 * The target notification value is bitwise ORed with ulValue.
2200 * xTaskNotifyIndexed() always returns pdPASS in this case.
2203 * The target notification value is incremented. ulValue is not used and
2204 * xTaskNotifyIndexed() always returns pdPASS in this case.
2206 * eSetValueWithOverwrite -
2207 * The target notification value is set to the value of ulValue, even if the
2208 * task being notified had not yet processed the previous notification at the
2209 * same array index (the task already had a notification pending at that index).
2210 * xTaskNotifyIndexed() always returns pdPASS in this case.
2212 * eSetValueWithoutOverwrite -
2213 * If the task being notified did not already have a notification pending at the
2214 * same array index then the target notification value is set to ulValue and
2215 * xTaskNotifyIndexed() will return pdPASS. If the task being notified already
2216 * had a notification pending at the same array index then no action is
2217 * performed and pdFAIL is returned.
2220 * The task receives a notification at the specified array index without the
2221 * notification value at that index being updated. ulValue is not used and
2222 * xTaskNotifyIndexed() always returns pdPASS in this case.
2224 * pulPreviousNotificationValue -
2225 * Can be used to pass out the subject task's notification value before any
2226 * bits are modified by the notify function.
2228 * @return Dependent on the value of eAction. See the description of the
2229 * eAction parameter.
2231 * \defgroup xTaskNotifyIndexed xTaskNotifyIndexed
2232 * \ingroup TaskNotifications
2234 BaseType_t xTaskGenericNotify( TaskHandle_t xTaskToNotify,
2235 UBaseType_t uxIndexToNotify,
2237 eNotifyAction eAction,
2238 uint32_t * pulPreviousNotificationValue ) PRIVILEGED_FUNCTION;
2239 #define xTaskNotify( xTaskToNotify, ulValue, eAction ) \
2240 xTaskGenericNotify( ( xTaskToNotify ), ( tskDEFAULT_INDEX_TO_NOTIFY ), ( ulValue ), ( eAction ), NULL )
2241 #define xTaskNotifyIndexed( xTaskToNotify, uxIndexToNotify, ulValue, eAction ) \
2242 xTaskGenericNotify( ( xTaskToNotify ), ( uxIndexToNotify ), ( ulValue ), ( eAction ), NULL )
2246 * <PRE>BaseType_t xTaskNotifyAndQueryIndexed( TaskHandle_t xTaskToNotify, UBaseType_t uxIndexToNotify, uint32_t ulValue, eNotifyAction eAction, uint32_t *pulPreviousNotifyValue );</PRE>
2247 * <PRE>BaseType_t xTaskNotifyAndQuery( TaskHandle_t xTaskToNotify, uint32_t ulValue, eNotifyAction eAction, uint32_t *pulPreviousNotifyValue );</PRE>
2249 * See https://www.FreeRTOS.org/RTOS-task-notifications.html for details.
2251 * xTaskNotifyAndQueryIndexed() performs the same operation as
2252 * xTaskNotifyIndexed() with the addition that it also returns the subject
2253 * task's prior notification value (the notification value at the time the
2254 * function is called rather than when the function returns) in the additional
2255 * pulPreviousNotifyValue parameter.
2257 * xTaskNotifyAndQuery() performs the same operation as xTaskNotify() with the
2258 * addition that it also returns the subject task's prior notification value
2259 * (the notification value as it was at the time the function is called, rather
2260 * than when the function returns) in the additional pulPreviousNotifyValue
2263 * \defgroup xTaskNotifyAndQueryIndexed xTaskNotifyAndQueryIndexed
2264 * \ingroup TaskNotifications
2266 #define xTaskNotifyAndQuery( xTaskToNotify, ulValue, eAction, pulPreviousNotifyValue ) \
2267 xTaskGenericNotify( ( xTaskToNotify ), ( tskDEFAULT_INDEX_TO_NOTIFY ), ( ulValue ), ( eAction ), ( pulPreviousNotifyValue ) )
2268 #define xTaskNotifyAndQueryIndexed( xTaskToNotify, uxIndexToNotify, ulValue, eAction, pulPreviousNotifyValue ) \
2269 xTaskGenericNotify( ( xTaskToNotify ), ( uxIndexToNotify ), ( ulValue ), ( eAction ), ( pulPreviousNotifyValue ) )
2273 * <PRE>BaseType_t xTaskNotifyIndexedFromISR( TaskHandle_t xTaskToNotify, UBaseType_t uxIndexToNotify, uint32_t ulValue, eNotifyAction eAction, BaseType_t *pxHigherPriorityTaskWoken );</PRE>
2274 * <PRE>BaseType_t xTaskNotifyFromISR( TaskHandle_t xTaskToNotify, uint32_t ulValue, eNotifyAction eAction, BaseType_t *pxHigherPriorityTaskWoken );</PRE>
2276 * See https://www.FreeRTOS.org/RTOS-task-notifications.html for details.
2278 * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for these
2279 * functions to be available.
2281 * A version of xTaskNotifyIndexed() that can be used from an interrupt service
2284 * Each task has a private array of "notification values" (or 'notifications'),
2285 * each of which is a 32-bit unsigned integer (uint32_t). The constant
2286 * configTASK_NOTIFICATION_ARRAY_ENTRIES sets the number of indexes in the
2287 * array, and (for backward compatibility) defaults to 1 if left undefined.
2288 * Prior to FreeRTOS V10.4.0 there was only one notification value per task.
2290 * Events can be sent to a task using an intermediary object. Examples of such
2291 * objects are queues, semaphores, mutexes and event groups. Task notifications
2292 * are a method of sending an event directly to a task without the need for such
2293 * an intermediary object.
2295 * A notification sent to a task can optionally perform an action, such as
2296 * update, overwrite or increment one of the task's notification values. In
2297 * that way task notifications can be used to send data to a task, or be used as
2298 * light weight and fast binary or counting semaphores.
2300 * A task can use xTaskNotifyWaitIndexed() to [optionally] block to wait for a
2301 * notification to be pending, or ulTaskNotifyTakeIndexed() to [optionally] block
2302 * to wait for a notification value to have a non-zero value. The task does
2303 * not consume any CPU time while it is in the Blocked state.
2305 * A notification sent to a task will remain pending until it is cleared by the
2306 * task calling xTaskNotifyWaitIndexed() or ulTaskNotifyTakeIndexed() (or their
2307 * un-indexed equivalents). If the task was already in the Blocked state to
2308 * wait for a notification when the notification arrives then the task will
2309 * automatically be removed from the Blocked state (unblocked) and the
2310 * notification cleared.
2312 * **NOTE** Each notification within the array operates independently - a task
2313 * can only block on one notification within the array at a time and will not be
2314 * unblocked by a notification sent to any other array index.
2316 * Backward compatibility information:
2317 * Prior to FreeRTOS V10.4.0 each task had a single "notification value", and
2318 * all task notification API functions operated on that value. Replacing the
2319 * single notification value with an array of notification values necessitated a
2320 * new set of API functions that could address specific notifications within the
2321 * array. xTaskNotifyFromISR() is the original API function, and remains
2322 * backward compatible by always operating on the notification value at index 0
2323 * within the array. Calling xTaskNotifyFromISR() is equivalent to calling
2324 * xTaskNotifyIndexedFromISR() with the uxIndexToNotify parameter set to 0.
2326 * @param uxIndexToNotify The index within the target task's array of
2327 * notification values to which the notification is to be sent. uxIndexToNotify
2328 * must be less than configTASK_NOTIFICATION_ARRAY_ENTRIES. xTaskNotifyFromISR()
2329 * does not have this parameter and always sends notifications to index 0.
2331 * @param xTaskToNotify The handle of the task being notified. The handle to a
2332 * task can be returned from the xTaskCreate() API function used to create the
2333 * task, and the handle of the currently running task can be obtained by calling
2334 * xTaskGetCurrentTaskHandle().
2336 * @param ulValue Data that can be sent with the notification. How the data is
2337 * used depends on the value of the eAction parameter.
2339 * @param eAction Specifies how the notification updates the task's notification
2340 * value, if at all. Valid values for eAction are as follows:
2343 * The task's notification value is bitwise ORed with ulValue. xTaskNotify()
2344 * always returns pdPASS in this case.
2347 * The task's notification value is incremented. ulValue is not used and
2348 * xTaskNotify() always returns pdPASS in this case.
2350 * eSetValueWithOverwrite -
2351 * The task's notification value is set to the value of ulValue, even if the
2352 * task being notified had not yet processed the previous notification (the
2353 * task already had a notification pending). xTaskNotify() always returns
2354 * pdPASS in this case.
2356 * eSetValueWithoutOverwrite -
2357 * If the task being notified did not already have a notification pending then
2358 * the task's notification value is set to ulValue and xTaskNotify() will
2359 * return pdPASS. If the task being notified already had a notification
2360 * pending then no action is performed and pdFAIL is returned.
2363 * The task receives a notification without its notification value being
2364 * updated. ulValue is not used and xTaskNotify() always returns pdPASS in
2367 * @param pxHigherPriorityTaskWoken xTaskNotifyFromISR() will set
2368 * *pxHigherPriorityTaskWoken to pdTRUE if sending the notification caused the
2369 * task to which the notification was sent to leave the Blocked state, and the
2370 * unblocked task has a priority higher than the currently running task. If
2371 * xTaskNotifyFromISR() sets this value to pdTRUE then a context switch should
2372 * be requested before the interrupt is exited. How a context switch is
2373 * requested from an ISR is dependent on the port - see the documentation page
2374 * for the port in use.
2376 * @return Dependent on the value of eAction. See the description of the
2377 * eAction parameter.
2379 * \defgroup xTaskNotifyIndexedFromISR xTaskNotifyIndexedFromISR
2380 * \ingroup TaskNotifications
2382 BaseType_t xTaskGenericNotifyFromISR( TaskHandle_t xTaskToNotify,
2383 UBaseType_t uxIndexToNotify,
2385 eNotifyAction eAction,
2386 uint32_t * pulPreviousNotificationValue,
2387 BaseType_t * pxHigherPriorityTaskWoken ) PRIVILEGED_FUNCTION;
2388 #define xTaskNotifyFromISR( xTaskToNotify, ulValue, eAction, pxHigherPriorityTaskWoken ) \
2389 xTaskGenericNotifyFromISR( ( xTaskToNotify ), ( tskDEFAULT_INDEX_TO_NOTIFY ), ( ulValue ), ( eAction ), NULL, ( pxHigherPriorityTaskWoken ) )
2390 #define xTaskNotifyIndexedFromISR( xTaskToNotify, uxIndexToNotify, ulValue, eAction, pxHigherPriorityTaskWoken ) \
2391 xTaskGenericNotifyFromISR( ( xTaskToNotify ), ( uxIndexToNotify ), ( ulValue ), ( eAction ), NULL, ( pxHigherPriorityTaskWoken ) )
2395 * <PRE>BaseType_t xTaskNotifyAndQueryIndexedFromISR( TaskHandle_t xTaskToNotify, UBaseType_t uxIndexToNotify, uint32_t ulValue, eNotifyAction eAction, uint32_t *pulPreviousNotificationValue, BaseType_t *pxHigherPriorityTaskWoken );</PRE>
2396 * <PRE>BaseType_t xTaskNotifyAndQueryFromISR( TaskHandle_t xTaskToNotify, uint32_t ulValue, eNotifyAction eAction, uint32_t *pulPreviousNotificationValue, BaseType_t *pxHigherPriorityTaskWoken );</PRE>
2398 * See https://www.FreeRTOS.org/RTOS-task-notifications.html for details.
2400 * xTaskNotifyAndQueryIndexedFromISR() performs the same operation as
2401 * xTaskNotifyIndexedFromISR() with the addition that it also returns the
2402 * subject task's prior notification value (the notification value at the time
2403 * the function is called rather than at the time the function returns) in the
2404 * additional pulPreviousNotifyValue parameter.
2406 * xTaskNotifyAndQueryFromISR() performs the same operation as
2407 * xTaskNotifyFromISR() with the addition that it also returns the subject
2408 * task's prior notification value (the notification value at the time the
2409 * function is called rather than at the time the function returns) in the
2410 * additional pulPreviousNotifyValue parameter.
2412 * \defgroup xTaskNotifyAndQueryIndexedFromISR xTaskNotifyAndQueryIndexedFromISR
2413 * \ingroup TaskNotifications
2415 #define xTaskNotifyAndQueryIndexedFromISR( xTaskToNotify, uxIndexToNotify, ulValue, eAction, pulPreviousNotificationValue, pxHigherPriorityTaskWoken ) \
2416 xTaskGenericNotifyFromISR( ( xTaskToNotify ), ( uxIndexToNotify ), ( ulValue ), ( eAction ), ( pulPreviousNotificationValue ), ( pxHigherPriorityTaskWoken ) )
2417 #define xTaskNotifyAndQueryFromISR( xTaskToNotify, ulValue, eAction, pulPreviousNotificationValue, pxHigherPriorityTaskWoken ) \
2418 xTaskGenericNotifyFromISR( ( xTaskToNotify ), ( tskDEFAULT_INDEX_TO_NOTIFY ), ( ulValue ), ( eAction ), ( pulPreviousNotificationValue ), ( pxHigherPriorityTaskWoken ) )
2423 * BaseType_t xTaskNotifyWaitIndexed( UBaseType_t uxIndexToWaitOn, uint32_t ulBitsToClearOnEntry, uint32_t ulBitsToClearOnExit, uint32_t *pulNotificationValue, TickType_t xTicksToWait );
2425 * BaseType_t xTaskNotifyWait( uint32_t ulBitsToClearOnEntry, uint32_t ulBitsToClearOnExit, uint32_t *pulNotificationValue, TickType_t xTicksToWait );
2428 * Waits for a direct to task notification to be pending at a given index within
2429 * an array of direct to task notifications.
2431 * See https://www.FreeRTOS.org/RTOS-task-notifications.html for details.
2433 * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for this
2434 * function to be available.
2436 * Each task has a private array of "notification values" (or 'notifications'),
2437 * each of which is a 32-bit unsigned integer (uint32_t). The constant
2438 * configTASK_NOTIFICATION_ARRAY_ENTRIES sets the number of indexes in the
2439 * array, and (for backward compatibility) defaults to 1 if left undefined.
2440 * Prior to FreeRTOS V10.4.0 there was only one notification value per task.
2442 * Events can be sent to a task using an intermediary object. Examples of such
2443 * objects are queues, semaphores, mutexes and event groups. Task notifications
2444 * are a method of sending an event directly to a task without the need for such
2445 * an intermediary object.
2447 * A notification sent to a task can optionally perform an action, such as
2448 * update, overwrite or increment one of the task's notification values. In
2449 * that way task notifications can be used to send data to a task, or be used as
2450 * light weight and fast binary or counting semaphores.
2452 * A notification sent to a task will remain pending until it is cleared by the
2453 * task calling xTaskNotifyWaitIndexed() or ulTaskNotifyTakeIndexed() (or their
2454 * un-indexed equivalents). If the task was already in the Blocked state to
2455 * wait for a notification when the notification arrives then the task will
2456 * automatically be removed from the Blocked state (unblocked) and the
2457 * notification cleared.
2459 * A task can use xTaskNotifyWaitIndexed() to [optionally] block to wait for a
2460 * notification to be pending, or ulTaskNotifyTakeIndexed() to [optionally] block
2461 * to wait for a notification value to have a non-zero value. The task does
2462 * not consume any CPU time while it is in the Blocked state.
2464 * **NOTE** Each notification within the array operates independently - a task
2465 * can only block on one notification within the array at a time and will not be
2466 * unblocked by a notification sent to any other array index.
2468 * Backward compatibility information:
2469 * Prior to FreeRTOS V10.4.0 each task had a single "notification value", and
2470 * all task notification API functions operated on that value. Replacing the
2471 * single notification value with an array of notification values necessitated a
2472 * new set of API functions that could address specific notifications within the
2473 * array. xTaskNotifyWait() is the original API function, and remains backward
2474 * compatible by always operating on the notification value at index 0 in the
2475 * array. Calling xTaskNotifyWait() is equivalent to calling
2476 * xTaskNotifyWaitIndexed() with the uxIndexToWaitOn parameter set to 0.
2478 * @param uxIndexToWaitOn The index within the calling task's array of
2479 * notification values on which the calling task will wait for a notification to
2480 * be received. uxIndexToWaitOn must be less than
2481 * configTASK_NOTIFICATION_ARRAY_ENTRIES. xTaskNotifyWait() does
2482 * not have this parameter and always waits for notifications on index 0.
2484 * @param ulBitsToClearOnEntry Bits that are set in ulBitsToClearOnEntry value
2485 * will be cleared in the calling task's notification value before the task
2486 * checks to see if any notifications are pending, and optionally blocks if no
2487 * notifications are pending. Setting ulBitsToClearOnEntry to ULONG_MAX (if
2488 * limits.h is included) or 0xffffffffUL (if limits.h is not included) will have
2489 * the effect of resetting the task's notification value to 0. Setting
2490 * ulBitsToClearOnEntry to 0 will leave the task's notification value unchanged.
2492 * @param ulBitsToClearOnExit If a notification is pending or received before
2493 * the calling task exits the xTaskNotifyWait() function then the task's
2494 * notification value (see the xTaskNotify() API function) is passed out using
2495 * the pulNotificationValue parameter. Then any bits that are set in
2496 * ulBitsToClearOnExit will be cleared in the task's notification value (note
2497 * *pulNotificationValue is set before any bits are cleared). Setting
2498 * ulBitsToClearOnExit to ULONG_MAX (if limits.h is included) or 0xffffffffUL
2499 * (if limits.h is not included) will have the effect of resetting the task's
2500 * notification value to 0 before the function exits. Setting
2501 * ulBitsToClearOnExit to 0 will leave the task's notification value unchanged
2502 * when the function exits (in which case the value passed out in
2503 * pulNotificationValue will match the task's notification value).
2505 * @param pulNotificationValue Used to pass the task's notification value out
2506 * of the function. Note the value passed out will not be effected by the
2507 * clearing of any bits caused by ulBitsToClearOnExit being non-zero.
2509 * @param xTicksToWait The maximum amount of time that the task should wait in
2510 * the Blocked state for a notification to be received, should a notification
2511 * not already be pending when xTaskNotifyWait() was called. The task
2512 * will not consume any processing time while it is in the Blocked state. This
2513 * is specified in kernel ticks, the macro pdMS_TO_TICKS( value_in_ms ) can be
2514 * used to convert a time specified in milliseconds to a time specified in
2517 * @return If a notification was received (including notifications that were
2518 * already pending when xTaskNotifyWait was called) then pdPASS is
2519 * returned. Otherwise pdFAIL is returned.
2521 * \defgroup xTaskNotifyWaitIndexed xTaskNotifyWaitIndexed
2522 * \ingroup TaskNotifications
2524 BaseType_t xTaskGenericNotifyWait( UBaseType_t uxIndexToWaitOn,
2525 uint32_t ulBitsToClearOnEntry,
2526 uint32_t ulBitsToClearOnExit,
2527 uint32_t * pulNotificationValue,
2528 TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
2529 #define xTaskNotifyWait( ulBitsToClearOnEntry, ulBitsToClearOnExit, pulNotificationValue, xTicksToWait ) \
2530 xTaskGenericNotifyWait( tskDEFAULT_INDEX_TO_NOTIFY, ( ulBitsToClearOnEntry ), ( ulBitsToClearOnExit ), ( pulNotificationValue ), ( xTicksToWait ) )
2531 #define xTaskNotifyWaitIndexed( uxIndexToWaitOn, ulBitsToClearOnEntry, ulBitsToClearOnExit, pulNotificationValue, xTicksToWait ) \
2532 xTaskGenericNotifyWait( ( uxIndexToWaitOn ), ( ulBitsToClearOnEntry ), ( ulBitsToClearOnExit ), ( pulNotificationValue ), ( xTicksToWait ) )
2536 * <PRE>BaseType_t xTaskNotifyGiveIndexed( TaskHandle_t xTaskToNotify, UBaseType_t uxIndexToNotify );</PRE>
2537 * <PRE>BaseType_t xTaskNotifyGive( TaskHandle_t xTaskToNotify );</PRE>
2539 * Sends a direct to task notification to a particular index in the target
2540 * task's notification array in a manner similar to giving a counting semaphore.
2542 * See https://www.FreeRTOS.org/RTOS-task-notifications.html for more details.
2544 * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for these
2545 * macros to be available.
2547 * Each task has a private array of "notification values" (or 'notifications'),
2548 * each of which is a 32-bit unsigned integer (uint32_t). The constant
2549 * configTASK_NOTIFICATION_ARRAY_ENTRIES sets the number of indexes in the
2550 * array, and (for backward compatibility) defaults to 1 if left undefined.
2551 * Prior to FreeRTOS V10.4.0 there was only one notification value per task.
2553 * Events can be sent to a task using an intermediary object. Examples of such
2554 * objects are queues, semaphores, mutexes and event groups. Task notifications
2555 * are a method of sending an event directly to a task without the need for such
2556 * an intermediary object.
2558 * A notification sent to a task can optionally perform an action, such as
2559 * update, overwrite or increment one of the task's notification values. In
2560 * that way task notifications can be used to send data to a task, or be used as
2561 * light weight and fast binary or counting semaphores.
2563 * xTaskNotifyGiveIndexed() is a helper macro intended for use when task
2564 * notifications are used as light weight and faster binary or counting
2565 * semaphore equivalents. Actual FreeRTOS semaphores are given using the
2566 * xSemaphoreGive() API function, the equivalent action that instead uses a task
2567 * notification is xTaskNotifyGiveIndexed().
2569 * When task notifications are being used as a binary or counting semaphore
2570 * equivalent then the task being notified should wait for the notification
2571 * using the ulTaskNotificationTakeIndexed() API function rather than the
2572 * xTaskNotifyWaitIndexed() API function.
2574 * **NOTE** Each notification within the array operates independently - a task
2575 * can only block on one notification within the array at a time and will not be
2576 * unblocked by a notification sent to any other array index.
2578 * Backward compatibility information:
2579 * Prior to FreeRTOS V10.4.0 each task had a single "notification value", and
2580 * all task notification API functions operated on that value. Replacing the
2581 * single notification value with an array of notification values necessitated a
2582 * new set of API functions that could address specific notifications within the
2583 * array. xTaskNotifyGive() is the original API function, and remains backward
2584 * compatible by always operating on the notification value at index 0 in the
2585 * array. Calling xTaskNotifyGive() is equivalent to calling
2586 * xTaskNotifyGiveIndexed() with the uxIndexToNotify parameter set to 0.
2588 * @param xTaskToNotify The handle of the task being notified. The handle to a
2589 * task can be returned from the xTaskCreate() API function used to create the
2590 * task, and the handle of the currently running task can be obtained by calling
2591 * xTaskGetCurrentTaskHandle().
2593 * @param uxIndexToNotify The index within the target task's array of
2594 * notification values to which the notification is to be sent. uxIndexToNotify
2595 * must be less than configTASK_NOTIFICATION_ARRAY_ENTRIES. xTaskNotifyGive()
2596 * does not have this parameter and always sends notifications to index 0.
2598 * @return xTaskNotifyGive() is a macro that calls xTaskNotify() with the
2599 * eAction parameter set to eIncrement - so pdPASS is always returned.
2601 * \defgroup xTaskNotifyGiveIndexed xTaskNotifyGiveIndexed
2602 * \ingroup TaskNotifications
2604 #define xTaskNotifyGive( xTaskToNotify ) \
2605 xTaskGenericNotify( ( xTaskToNotify ), ( tskDEFAULT_INDEX_TO_NOTIFY ), ( 0 ), eIncrement, NULL )
2606 #define xTaskNotifyGiveIndexed( xTaskToNotify, uxIndexToNotify ) \
2607 xTaskGenericNotify( ( xTaskToNotify ), ( uxIndexToNotify ), ( 0 ), eIncrement, NULL )
2611 * <PRE>void vTaskNotifyGiveIndexedFromISR( TaskHandle_t xTaskHandle, UBaseType_t uxIndexToNotify, BaseType_t *pxHigherPriorityTaskWoken );</PRE>
2612 * <PRE>void vTaskNotifyGiveFromISR( TaskHandle_t xTaskHandle, BaseType_t *pxHigherPriorityTaskWoken );</PRE>
2614 * A version of xTaskNotifyGiveIndexed() that can be called from an interrupt
2615 * service routine (ISR).
2617 * See https://www.FreeRTOS.org/RTOS-task-notifications.html for more details.
2619 * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for this macro
2622 * Each task has a private array of "notification values" (or 'notifications'),
2623 * each of which is a 32-bit unsigned integer (uint32_t). The constant
2624 * configTASK_NOTIFICATION_ARRAY_ENTRIES sets the number of indexes in the
2625 * array, and (for backward compatibility) defaults to 1 if left undefined.
2626 * Prior to FreeRTOS V10.4.0 there was only one notification value per task.
2628 * Events can be sent to a task using an intermediary object. Examples of such
2629 * objects are queues, semaphores, mutexes and event groups. Task notifications
2630 * are a method of sending an event directly to a task without the need for such
2631 * an intermediary object.
2633 * A notification sent to a task can optionally perform an action, such as
2634 * update, overwrite or increment one of the task's notification values. In
2635 * that way task notifications can be used to send data to a task, or be used as
2636 * light weight and fast binary or counting semaphores.
2638 * vTaskNotifyGiveIndexedFromISR() is intended for use when task notifications
2639 * are used as light weight and faster binary or counting semaphore equivalents.
2640 * Actual FreeRTOS semaphores are given from an ISR using the
2641 * xSemaphoreGiveFromISR() API function, the equivalent action that instead uses
2642 * a task notification is vTaskNotifyGiveIndexedFromISR().
2644 * When task notifications are being used as a binary or counting semaphore
2645 * equivalent then the task being notified should wait for the notification
2646 * using the ulTaskNotificationTakeIndexed() API function rather than the
2647 * xTaskNotifyWaitIndexed() API function.
2649 * **NOTE** Each notification within the array operates independently - a task
2650 * can only block on one notification within the array at a time and will not be
2651 * unblocked by a notification sent to any other array index.
2653 * Backward compatibility information:
2654 * Prior to FreeRTOS V10.4.0 each task had a single "notification value", and
2655 * all task notification API functions operated on that value. Replacing the
2656 * single notification value with an array of notification values necessitated a
2657 * new set of API functions that could address specific notifications within the
2658 * array. xTaskNotifyFromISR() is the original API function, and remains
2659 * backward compatible by always operating on the notification value at index 0
2660 * within the array. Calling xTaskNotifyGiveFromISR() is equivalent to calling
2661 * xTaskNotifyGiveIndexedFromISR() with the uxIndexToNotify parameter set to 0.
2663 * @param xTaskToNotify The handle of the task being notified. The handle to a
2664 * task can be returned from the xTaskCreate() API function used to create the
2665 * task, and the handle of the currently running task can be obtained by calling
2666 * xTaskGetCurrentTaskHandle().
2668 * @param uxIndexToNotify The index within the target task's array of
2669 * notification values to which the notification is to be sent. uxIndexToNotify
2670 * must be less than configTASK_NOTIFICATION_ARRAY_ENTRIES.
2671 * xTaskNotifyGiveFromISR() does not have this parameter and always sends
2672 * notifications to index 0.
2674 * @param pxHigherPriorityTaskWoken vTaskNotifyGiveFromISR() will set
2675 * *pxHigherPriorityTaskWoken to pdTRUE if sending the notification caused the
2676 * task to which the notification was sent to leave the Blocked state, and the
2677 * unblocked task has a priority higher than the currently running task. If
2678 * vTaskNotifyGiveFromISR() sets this value to pdTRUE then a context switch
2679 * should be requested before the interrupt is exited. How a context switch is
2680 * requested from an ISR is dependent on the port - see the documentation page
2681 * for the port in use.
2683 * \defgroup vTaskNotifyGiveIndexedFromISR vTaskNotifyGiveIndexedFromISR
2684 * \ingroup TaskNotifications
2686 void vTaskGenericNotifyGiveFromISR( TaskHandle_t xTaskToNotify,
2687 UBaseType_t uxIndexToNotify,
2688 BaseType_t * pxHigherPriorityTaskWoken ) PRIVILEGED_FUNCTION;
2689 #define vTaskNotifyGiveFromISR( xTaskToNotify, pxHigherPriorityTaskWoken ) \
2690 vTaskGenericNotifyGiveFromISR( ( xTaskToNotify ), ( tskDEFAULT_INDEX_TO_NOTIFY ), ( pxHigherPriorityTaskWoken ) );
2691 #define vTaskNotifyGiveIndexedFromISR( xTaskToNotify, uxIndexToNotify, pxHigherPriorityTaskWoken ) \
2692 vTaskGenericNotifyGiveFromISR( ( xTaskToNotify ), ( uxIndexToNotify ), ( pxHigherPriorityTaskWoken ) );
2697 * uint32_t ulTaskNotifyTakeIndexed( UBaseType_t uxIndexToWaitOn, BaseType_t xClearCountOnExit, TickType_t xTicksToWait );
2699 * uint32_t ulTaskNotifyTake( BaseType_t xClearCountOnExit, TickType_t xTicksToWait );
2702 * Waits for a direct to task notification on a particular index in the calling
2703 * task's notification array in a manner similar to taking a counting semaphore.
2705 * See https://www.FreeRTOS.org/RTOS-task-notifications.html for details.
2707 * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for this
2708 * function to be available.
2710 * Each task has a private array of "notification values" (or 'notifications'),
2711 * each of which is a 32-bit unsigned integer (uint32_t). The constant
2712 * configTASK_NOTIFICATION_ARRAY_ENTRIES sets the number of indexes in the
2713 * array, and (for backward compatibility) defaults to 1 if left undefined.
2714 * Prior to FreeRTOS V10.4.0 there was only one notification value per task.
2716 * Events can be sent to a task using an intermediary object. Examples of such
2717 * objects are queues, semaphores, mutexes and event groups. Task notifications
2718 * are a method of sending an event directly to a task without the need for such
2719 * an intermediary object.
2721 * A notification sent to a task can optionally perform an action, such as
2722 * update, overwrite or increment one of the task's notification values. In
2723 * that way task notifications can be used to send data to a task, or be used as
2724 * light weight and fast binary or counting semaphores.
2726 * ulTaskNotifyTakeIndexed() is intended for use when a task notification is
2727 * used as a faster and lighter weight binary or counting semaphore alternative.
2728 * Actual FreeRTOS semaphores are taken using the xSemaphoreTake() API function,
2729 * the equivalent action that instead uses a task notification is
2730 * ulTaskNotifyTakeIndexed().
2732 * When a task is using its notification value as a binary or counting semaphore
2733 * other tasks should send notifications to it using the xTaskNotifyGiveIndexed()
2734 * macro, or xTaskNotifyIndex() function with the eAction parameter set to
2737 * ulTaskNotifyTakeIndexed() can either clear the task's notification value at
2738 * the array index specified by the uxIndexToWaitOn parameter to zero on exit,
2739 * in which case the notification value acts like a binary semaphore, or
2740 * decrement the notification value on exit, in which case the notification
2741 * value acts like a counting semaphore.
2743 * A task can use ulTaskNotifyTakeIndexed() to [optionally] block to wait for
2744 * a notification. The task does not consume any CPU time while it is in the
2747 * Where as xTaskNotifyWaitIndexed() will return when a notification is pending,
2748 * ulTaskNotifyTakeIndexed() will return when the task's notification value is
2751 * **NOTE** Each notification within the array operates independently - a task
2752 * can only block on one notification within the array at a time and will not be
2753 * unblocked by a notification sent to any other array index.
2755 * Backward compatibility information:
2756 * Prior to FreeRTOS V10.4.0 each task had a single "notification value", and
2757 * all task notification API functions operated on that value. Replacing the
2758 * single notification value with an array of notification values necessitated a
2759 * new set of API functions that could address specific notifications within the
2760 * array. ulTaskNotifyTake() is the original API function, and remains backward
2761 * compatible by always operating on the notification value at index 0 in the
2762 * array. Calling ulTaskNotifyTake() is equivalent to calling
2763 * ulTaskNotifyTakeIndexed() with the uxIndexToWaitOn parameter set to 0.
2765 * @param uxIndexToWaitOn The index within the calling task's array of
2766 * notification values on which the calling task will wait for a notification to
2767 * be non-zero. uxIndexToWaitOn must be less than
2768 * configTASK_NOTIFICATION_ARRAY_ENTRIES. xTaskNotifyTake() does
2769 * not have this parameter and always waits for notifications on index 0.
2771 * @param xClearCountOnExit if xClearCountOnExit is pdFALSE then the task's
2772 * notification value is decremented when the function exits. In this way the
2773 * notification value acts like a counting semaphore. If xClearCountOnExit is
2774 * not pdFALSE then the task's notification value is cleared to zero when the
2775 * function exits. In this way the notification value acts like a binary
2778 * @param xTicksToWait The maximum amount of time that the task should wait in
2779 * the Blocked state for the task's notification value to be greater than zero,
2780 * should the count not already be greater than zero when
2781 * ulTaskNotifyTake() was called. The task will not consume any processing
2782 * time while it is in the Blocked state. This is specified in kernel ticks,
2783 * the macro pdMS_TO_TICKS( value_in_ms ) can be used to convert a time
2784 * specified in milliseconds to a time specified in ticks.
2786 * @return The task's notification count before it is either cleared to zero or
2787 * decremented (see the xClearCountOnExit parameter).
2789 * \defgroup ulTaskNotifyTakeIndexed ulTaskNotifyTakeIndexed
2790 * \ingroup TaskNotifications
2792 uint32_t ulTaskGenericNotifyTake( UBaseType_t uxIndexToWaitOn,
2793 BaseType_t xClearCountOnExit,
2794 TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
2795 #define ulTaskNotifyTake( xClearCountOnExit, xTicksToWait ) \
2796 ulTaskGenericNotifyTake( ( tskDEFAULT_INDEX_TO_NOTIFY ), ( xClearCountOnExit ), ( xTicksToWait ) )
2797 #define ulTaskNotifyTakeIndexed( uxIndexToWaitOn, xClearCountOnExit, xTicksToWait ) \
2798 ulTaskGenericNotifyTake( ( uxIndexToWaitOn ), ( xClearCountOnExit ), ( xTicksToWait ) )
2803 * BaseType_t xTaskNotifyStateClearIndexed( TaskHandle_t xTask, UBaseType_t uxIndexToCLear );
2805 * BaseType_t xTaskNotifyStateClear( TaskHandle_t xTask );
2808 * See https://www.FreeRTOS.org/RTOS-task-notifications.html for details.
2810 * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for these
2811 * functions to be available.
2813 * Each task has a private array of "notification values" (or 'notifications'),
2814 * each of which is a 32-bit unsigned integer (uint32_t). The constant
2815 * configTASK_NOTIFICATION_ARRAY_ENTRIES sets the number of indexes in the
2816 * array, and (for backward compatibility) defaults to 1 if left undefined.
2817 * Prior to FreeRTOS V10.4.0 there was only one notification value per task.
2819 * If a notification is sent to an index within the array of notifications then
2820 * the notification at that index is said to be 'pending' until it is read or
2821 * explicitly cleared by the receiving task. xTaskNotifyStateClearIndexed()
2822 * is the function that clears a pending notification without reading the
2823 * notification value. The notification value at the same array index is not
2824 * altered. Set xTask to NULL to clear the notification state of the calling
2827 * Backward compatibility information:
2828 * Prior to FreeRTOS V10.4.0 each task had a single "notification value", and
2829 * all task notification API functions operated on that value. Replacing the
2830 * single notification value with an array of notification values necessitated a
2831 * new set of API functions that could address specific notifications within the
2832 * array. xTaskNotifyStateClear() is the original API function, and remains
2833 * backward compatible by always operating on the notification value at index 0
2834 * within the array. Calling xTaskNotifyStateClear() is equivalent to calling
2835 * xTaskNotifyStateClearIndexed() with the uxIndexToNotify parameter set to 0.
2837 * @param xTask The handle of the RTOS task that will have a notification state
2838 * cleared. Set xTask to NULL to clear a notification state in the calling
2839 * task. To obtain a task's handle create the task using xTaskCreate() and
2840 * make use of the pxCreatedTask parameter, or create the task using
2841 * xTaskCreateStatic() and store the returned value, or use the task's name in
2842 * a call to xTaskGetHandle().
2844 * @param uxIndexToClear The index within the target task's array of
2845 * notification values to act upon. For example, setting uxIndexToClear to 1
2846 * will clear the state of the notification at index 1 within the array.
2847 * uxIndexToClear must be less than configTASK_NOTIFICATION_ARRAY_ENTRIES.
2848 * ulTaskNotifyStateClear() does not have this parameter and always acts on the
2849 * notification at index 0.
2851 * @return pdTRUE if the task's notification state was set to
2852 * eNotWaitingNotification, otherwise pdFALSE.
2854 * \defgroup xTaskNotifyStateClearIndexed xTaskNotifyStateClearIndexed
2855 * \ingroup TaskNotifications
2857 BaseType_t xTaskGenericNotifyStateClear( TaskHandle_t xTask,
2858 UBaseType_t uxIndexToClear ) PRIVILEGED_FUNCTION;
2859 #define xTaskNotifyStateClear( xTask ) \
2860 xTaskGenericNotifyStateClear( ( xTask ), ( tskDEFAULT_INDEX_TO_NOTIFY ) )
2861 #define xTaskNotifyStateClearIndexed( xTask, uxIndexToClear ) \
2862 xTaskGenericNotifyStateClear( ( xTask ), ( uxIndexToClear ) )
2867 * uint32_t ulTaskNotifyValueClearIndexed( TaskHandle_t xTask, UBaseType_t uxIndexToClear, uint32_t ulBitsToClear );
2869 * uint32_t ulTaskNotifyValueClear( TaskHandle_t xTask, uint32_t ulBitsToClear );
2872 * See https://www.FreeRTOS.org/RTOS-task-notifications.html for details.
2874 * configUSE_TASK_NOTIFICATIONS must be undefined or defined as 1 for these
2875 * functions to be available.
2877 * Each task has a private array of "notification values" (or 'notifications'),
2878 * each of which is a 32-bit unsigned integer (uint32_t). The constant
2879 * configTASK_NOTIFICATION_ARRAY_ENTRIES sets the number of indexes in the
2880 * array, and (for backward compatibility) defaults to 1 if left undefined.
2881 * Prior to FreeRTOS V10.4.0 there was only one notification value per task.
2883 * ulTaskNotifyValueClearIndexed() clears the bits specified by the
2884 * ulBitsToClear bit mask in the notification value at array index uxIndexToClear
2885 * of the task referenced by xTask.
2887 * Backward compatibility information:
2888 * Prior to FreeRTOS V10.4.0 each task had a single "notification value", and
2889 * all task notification API functions operated on that value. Replacing the
2890 * single notification value with an array of notification values necessitated a
2891 * new set of API functions that could address specific notifications within the
2892 * array. ulTaskNotifyValueClear() is the original API function, and remains
2893 * backward compatible by always operating on the notification value at index 0
2894 * within the array. Calling ulTaskNotifyValueClear() is equivalent to calling
2895 * ulTaskNotifyValueClearIndexed() with the uxIndexToClear parameter set to 0.
2897 * @param xTask The handle of the RTOS task that will have bits in one of its
2898 * notification values cleared. Set xTask to NULL to clear bits in a
2899 * notification value of the calling task. To obtain a task's handle create the
2900 * task using xTaskCreate() and make use of the pxCreatedTask parameter, or
2901 * create the task using xTaskCreateStatic() and store the returned value, or
2902 * use the task's name in a call to xTaskGetHandle().
2904 * @param uxIndexToClear The index within the target task's array of
2905 * notification values in which to clear the bits. uxIndexToClear
2906 * must be less than configTASK_NOTIFICATION_ARRAY_ENTRIES.
2907 * ulTaskNotifyValueClear() does not have this parameter and always clears bits
2908 * in the notification value at index 0.
2910 * @param ulBitsToClear Bit mask of the bits to clear in the notification value of
2911 * xTask. Set a bit to 1 to clear the corresponding bits in the task's notification
2912 * value. Set ulBitsToClear to 0xffffffff (UINT_MAX on 32-bit architectures) to clear
2913 * the notification value to 0. Set ulBitsToClear to 0 to query the task's
2914 * notification value without clearing any bits.
2917 * @return The value of the target task's notification value before the bits
2918 * specified by ulBitsToClear were cleared.
2919 * \defgroup ulTaskNotifyValueClear ulTaskNotifyValueClear
2920 * \ingroup TaskNotifications
2922 uint32_t ulTaskGenericNotifyValueClear( TaskHandle_t xTask,
2923 UBaseType_t uxIndexToClear,
2924 uint32_t ulBitsToClear ) PRIVILEGED_FUNCTION;
2925 #define ulTaskNotifyValueClear( xTask, ulBitsToClear ) \
2926 ulTaskGenericNotifyValueClear( ( xTask ), ( tskDEFAULT_INDEX_TO_NOTIFY ), ( ulBitsToClear ) )
2927 #define ulTaskNotifyValueClearIndexed( xTask, uxIndexToClear, ulBitsToClear ) \
2928 ulTaskGenericNotifyValueClear( ( xTask ), ( uxIndexToClear ), ( ulBitsToClear ) )
2933 * void vTaskSetTimeOutState( TimeOut_t * const pxTimeOut );
2936 * Capture the current time for future use with xTaskCheckForTimeOut().
2938 * @param pxTimeOut Pointer to a timeout object into which the current time
2939 * is to be captured. The captured time includes the tick count and the number
2940 * of times the tick count has overflowed since the system first booted.
2941 * \defgroup vTaskSetTimeOutState vTaskSetTimeOutState
2944 void vTaskSetTimeOutState( TimeOut_t * const pxTimeOut ) PRIVILEGED_FUNCTION;
2949 * BaseType_t xTaskCheckForTimeOut( TimeOut_t * const pxTimeOut, TickType_t * const pxTicksToWait );
2952 * Determines if pxTicksToWait ticks has passed since a time was captured
2953 * using a call to vTaskSetTimeOutState(). The captured time includes the tick
2954 * count and the number of times the tick count has overflowed.
2956 * @param pxTimeOut The time status as captured previously using
2957 * vTaskSetTimeOutState. If the timeout has not yet occurred, it is updated
2958 * to reflect the current time status.
2959 * @param pxTicksToWait The number of ticks to check for timeout i.e. if
2960 * pxTicksToWait ticks have passed since pxTimeOut was last updated (either by
2961 * vTaskSetTimeOutState() or xTaskCheckForTimeOut()), the timeout has occurred.
2962 * If the timeout has not occurred, pxTicksToWait is updated to reflect the
2963 * number of remaining ticks.
2965 * @return If timeout has occurred, pdTRUE is returned. Otherwise pdFALSE is
2966 * returned and pxTicksToWait is updated to reflect the number of remaining
2969 * @see https://www.FreeRTOS.org/xTaskCheckForTimeOut.html
2973 * // Driver library function used to receive uxWantedBytes from an Rx buffer
2974 * // that is filled by a UART interrupt. If there are not enough bytes in the
2975 * // Rx buffer then the task enters the Blocked state until it is notified that
2976 * // more data has been placed into the buffer. If there is still not enough
2977 * // data then the task re-enters the Blocked state, and xTaskCheckForTimeOut()
2978 * // is used to re-calculate the Block time to ensure the total amount of time
2979 * // spent in the Blocked state does not exceed MAX_TIME_TO_WAIT. This
2980 * // continues until either the buffer contains at least uxWantedBytes bytes,
2981 * // or the total amount of time spent in the Blocked state reaches
2982 * // MAX_TIME_TO_WAIT – at which point the task reads however many bytes are
2983 * // available up to a maximum of uxWantedBytes.
2985 * size_t xUART_Receive( uint8_t *pucBuffer, size_t uxWantedBytes )
2987 * size_t uxReceived = 0;
2988 * TickType_t xTicksToWait = MAX_TIME_TO_WAIT;
2989 * TimeOut_t xTimeOut;
2991 * // Initialize xTimeOut. This records the time at which this function
2993 * vTaskSetTimeOutState( &xTimeOut );
2995 * // Loop until the buffer contains the wanted number of bytes, or a
2996 * // timeout occurs.
2997 * while( UART_bytes_in_rx_buffer( pxUARTInstance ) < uxWantedBytes )
2999 * // The buffer didn't contain enough data so this task is going to
3000 * // enter the Blocked state. Adjusting xTicksToWait to account for
3001 * // any time that has been spent in the Blocked state within this
3002 * // function so far to ensure the total amount of time spent in the
3003 * // Blocked state does not exceed MAX_TIME_TO_WAIT.
3004 * if( xTaskCheckForTimeOut( &xTimeOut, &xTicksToWait ) != pdFALSE )
3006 * //Timed out before the wanted number of bytes were available,
3011 * // Wait for a maximum of xTicksToWait ticks to be notified that the
3012 * // receive interrupt has placed more data into the buffer.
3013 * ulTaskNotifyTake( pdTRUE, xTicksToWait );
3016 * // Attempt to read uxWantedBytes from the receive buffer into pucBuffer.
3017 * // The actual number of bytes read (which might be less than
3018 * // uxWantedBytes) is returned.
3019 * uxReceived = UART_read_from_receive_buffer( pxUARTInstance,
3023 * return uxReceived;
3026 * \defgroup xTaskCheckForTimeOut xTaskCheckForTimeOut
3029 BaseType_t xTaskCheckForTimeOut( TimeOut_t * const pxTimeOut,
3030 TickType_t * const pxTicksToWait ) PRIVILEGED_FUNCTION;
3035 * BaseType_t xTaskCatchUpTicks( TickType_t xTicksToCatchUp );
3038 * This function corrects the tick count value after the application code has held
3039 * interrupts disabled for an extended period resulting in tick interrupts having
3042 * This function is similar to vTaskStepTick(), however, unlike
3043 * vTaskStepTick(), xTaskCatchUpTicks() may move the tick count forward past a
3044 * time at which a task should be removed from the blocked state. That means
3045 * tasks may have to be removed from the blocked state as the tick count is
3048 * @param xTicksToCatchUp The number of tick interrupts that have been missed due to
3049 * interrupts being disabled. Its value is not computed automatically, so must be
3050 * computed by the application writer.
3052 * @return pdTRUE if moving the tick count forward resulted in a task leaving the
3053 * blocked state and a context switch being performed. Otherwise pdFALSE.
3055 * \defgroup xTaskCatchUpTicks xTaskCatchUpTicks
3058 BaseType_t xTaskCatchUpTicks( TickType_t xTicksToCatchUp ) PRIVILEGED_FUNCTION;
3061 /*-----------------------------------------------------------
3062 * SCHEDULER INTERNALS AVAILABLE FOR PORTING PURPOSES
3063 *----------------------------------------------------------*/
3066 * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS ONLY
3067 * INTENDED FOR USE WHEN IMPLEMENTING A PORT OF THE SCHEDULER AND IS
3068 * AN INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.
3070 * Called from the real time kernel tick (either preemptive or cooperative),
3071 * this increments the tick count and checks if any tasks that are blocked
3072 * for a finite period required removing from a blocked list and placing on
3073 * a ready list. If a non-zero value is returned then a context switch is
3074 * required because either:
3075 * + A task was removed from a blocked list because its timeout had expired,
3077 * + Time slicing is in use and there is a task of equal priority to the
3078 * currently running task.
3080 BaseType_t xTaskIncrementTick( void ) PRIVILEGED_FUNCTION;
3083 * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS AN
3084 * INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.
3086 * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED.
3088 * Removes the calling task from the ready list and places it both
3089 * on the list of tasks waiting for a particular event, and the
3090 * list of delayed tasks. The task will be removed from both lists
3091 * and replaced on the ready list should either the event occur (and
3092 * there be no higher priority tasks waiting on the same event) or
3093 * the delay period expires.
3095 * The 'unordered' version replaces the event list item value with the
3096 * xItemValue value, and inserts the list item at the end of the list.
3098 * The 'ordered' version uses the existing event list item value (which is the
3099 * owning task's priority) to insert the list item into the event list in task
3102 * @param pxEventList The list containing tasks that are blocked waiting
3103 * for the event to occur.
3105 * @param xItemValue The item value to use for the event list item when the
3106 * event list is not ordered by task priority.
3108 * @param xTicksToWait The maximum amount of time that the task should wait
3109 * for the event to occur. This is specified in kernel ticks, the constant
3110 * portTICK_PERIOD_MS can be used to convert kernel ticks into a real time
3113 void vTaskPlaceOnEventList( List_t * const pxEventList,
3114 const TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
3115 void vTaskPlaceOnUnorderedEventList( List_t * pxEventList,
3116 const TickType_t xItemValue,
3117 const TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
3120 * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS AN
3121 * INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.
3123 * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED.
3125 * This function performs nearly the same function as vTaskPlaceOnEventList().
3126 * The difference being that this function does not permit tasks to block
3127 * indefinitely, whereas vTaskPlaceOnEventList() does.
3130 void vTaskPlaceOnEventListRestricted( List_t * const pxEventList,
3131 TickType_t xTicksToWait,
3132 const BaseType_t xWaitIndefinitely ) PRIVILEGED_FUNCTION;
3135 * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS AN
3136 * INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.
3138 * THIS FUNCTION MUST BE CALLED WITH INTERRUPTS DISABLED.
3140 * Removes a task from both the specified event list and the list of blocked
3141 * tasks, and places it on a ready queue.
3143 * xTaskRemoveFromEventList()/vTaskRemoveFromUnorderedEventList() will be called
3144 * if either an event occurs to unblock a task, or the block timeout period
3147 * xTaskRemoveFromEventList() is used when the event list is in task priority
3148 * order. It removes the list item from the head of the event list as that will
3149 * have the highest priority owning task of all the tasks on the event list.
3150 * vTaskRemoveFromUnorderedEventList() is used when the event list is not
3151 * ordered and the event list items hold something other than the owning tasks
3152 * priority. In this case the event list item value is updated to the value
3153 * passed in the xItemValue parameter.
3155 * @return pdTRUE if the task being removed has a higher priority than the task
3156 * making the call, otherwise pdFALSE.
3158 BaseType_t xTaskRemoveFromEventList( const List_t * const pxEventList ) PRIVILEGED_FUNCTION;
3159 void vTaskRemoveFromUnorderedEventList( ListItem_t * pxEventListItem,
3160 const TickType_t xItemValue ) PRIVILEGED_FUNCTION;
3163 * THIS FUNCTION MUST NOT BE USED FROM APPLICATION CODE. IT IS ONLY
3164 * INTENDED FOR USE WHEN IMPLEMENTING A PORT OF THE SCHEDULER AND IS
3165 * AN INTERFACE WHICH IS FOR THE EXCLUSIVE USE OF THE SCHEDULER.
3167 * Sets the pointer to the current TCB to the TCB of the highest priority task
3168 * that is ready to run.
3170 portDONT_DISCARD void vTaskSwitchContext( BaseType_t xCoreID ) PRIVILEGED_FUNCTION;
3173 * THESE FUNCTIONS MUST NOT BE USED FROM APPLICATION CODE. THEY ARE USED BY
3174 * THE EVENT BITS MODULE.
3176 TickType_t uxTaskResetEventItemValue( void ) PRIVILEGED_FUNCTION;
3179 * Return the handle of the calling task.
3181 TaskHandle_t xTaskGetCurrentTaskHandle( void ) PRIVILEGED_FUNCTION;
3184 * Return the handle of the task running on specified core.
3186 TaskHandle_t xTaskGetCurrentTaskHandleCPU( UBaseType_t xCoreID ) PRIVILEGED_FUNCTION;
3189 * Shortcut used by the queue implementation to prevent unnecessary call to
3192 void vTaskMissedYield( void ) PRIVILEGED_FUNCTION;
3195 * Returns the scheduler state as taskSCHEDULER_RUNNING,
3196 * taskSCHEDULER_NOT_STARTED or taskSCHEDULER_SUSPENDED.
3198 BaseType_t xTaskGetSchedulerState( void ) PRIVILEGED_FUNCTION;
3201 * Raises the priority of the mutex holder to that of the calling task should
3202 * the mutex holder have a priority less than the calling task.
3204 BaseType_t xTaskPriorityInherit( TaskHandle_t const pxMutexHolder ) PRIVILEGED_FUNCTION;
3207 * Set the priority of a task back to its proper priority in the case that it
3208 * inherited a higher priority while it was holding a semaphore.
3210 BaseType_t xTaskPriorityDisinherit( TaskHandle_t const pxMutexHolder ) PRIVILEGED_FUNCTION;
3213 * If a higher priority task attempting to obtain a mutex caused a lower
3214 * priority task to inherit the higher priority task's priority - but the higher
3215 * priority task then timed out without obtaining the mutex, then the lower
3216 * priority task will disinherit the priority again - but only down as far as
3217 * the highest priority task that is still waiting for the mutex (if there were
3218 * more than one task waiting for the mutex).
3220 void vTaskPriorityDisinheritAfterTimeout( TaskHandle_t const pxMutexHolder,
3221 UBaseType_t uxHighestPriorityWaitingTask ) PRIVILEGED_FUNCTION;
3224 * Get the uxTCBNumber assigned to the task referenced by the xTask parameter.
3226 UBaseType_t uxTaskGetTaskNumber( TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
3229 * Set the uxTaskNumber of the task referenced by the xTask parameter to
3232 void vTaskSetTaskNumber( TaskHandle_t xTask,
3233 const UBaseType_t uxHandle ) PRIVILEGED_FUNCTION;
3236 * Only available when configUSE_TICKLESS_IDLE is set to 1.
3237 * If tickless mode is being used, or a low power mode is implemented, then
3238 * the tick interrupt will not execute during idle periods. When this is the
3239 * case, the tick count value maintained by the scheduler needs to be kept up
3240 * to date with the actual execution time by being skipped forward by a time
3241 * equal to the idle period.
3243 void vTaskStepTick( const TickType_t xTicksToJump ) PRIVILEGED_FUNCTION;
3246 * Only available when configUSE_TICKLESS_IDLE is set to 1.
3247 * Provided for use within portSUPPRESS_TICKS_AND_SLEEP() to allow the port
3248 * specific sleep function to determine if it is ok to proceed with the sleep,
3249 * and if it is ok to proceed, if it is ok to sleep indefinitely.
3251 * This function is necessary because portSUPPRESS_TICKS_AND_SLEEP() is only
3252 * called with the scheduler suspended, not from within a critical section. It
3253 * is therefore possible for an interrupt to request a context switch between
3254 * portSUPPRESS_TICKS_AND_SLEEP() and the low power mode actually being
3255 * entered. eTaskConfirmSleepModeStatus() should be called from a short
3256 * critical section between the timer being stopped and the sleep mode being
3257 * entered to ensure it is ok to proceed into the sleep mode.
3259 eSleepModeStatus eTaskConfirmSleepModeStatus( void ) PRIVILEGED_FUNCTION;
3262 * For internal use only. Increment the mutex held count when a mutex is
3263 * taken and return the handle of the task that has taken the mutex.
3265 TaskHandle_t pvTaskIncrementMutexHeldCount( void ) PRIVILEGED_FUNCTION;
3268 * For internal use only. Same as vTaskSetTimeOutState(), but without a critical
3271 void vTaskInternalSetTimeOutState( TimeOut_t * const pxTimeOut ) PRIVILEGED_FUNCTION;
3274 * For internal use only. Same as portYIELD_WITHIN_API() in single core FreeRTOS.
3275 * For SMP this is not defined by the port.
3277 void vTaskYieldWithinAPI( void );
3284 #endif /* INC_TASK_H */