Jeremy

语言EN

freeRTOS API Reference

Update: 2026-07-01

1.Task

Task Creation


// Create a new task and add it to the list of tasks that are ready to run.
BaseType_t xTaskCreate( TaskFunction_t pvTaskCode,
                         const char * const pcName,
                         const configSTACK_DEPTH_TYPE uxStackDepth,
                         void *pvParameters,
                         UBaseType_t uxPriority,
                         TaskHandle_t *pxCreatedTask
                       );

// Create a new task and add it to the list of tasks that are ready to run.
TaskHandle_t xTaskCreateStatic( TaskFunction_t pxTaskCode,
                                 const char * const pcName,
                                 const uint32_t ulStackDepth,
                                 void * const pvParameters,
                                 UBaseType_t uxPriority,
                                 StackType_t * const puxStackBuffer,
                                 StaticTask_t * const pxTaskBuffer );

/**
 * Create a new Memory Protection Unit (MPU) restricted task and add it to the list of tasks that are ready to run.
 */
BaseType_t xTaskCreateRestrictedStatic( TaskParameters_t *pxTaskDefinition,
                                        TaskHandle_t *pxCreatedTask );


// Remove a task from the RTOS kernels management. The task being deleted will be removed from all ready, blocked, suspended and event lists.
void vTaskDelete( TaskHandle_t xTask );

Task Control


// Delay a task for a given number of ticks. The actual time that the task remains blocked depends on the tick rate.
void vTaskDelay( const TickType_t xTicksToDelay );

// Delay a task until a specified time.
void vTaskDelayUntil( TickType_t *pxPreviousWakeTime,
                      const TickType_t xTimeIncrement );

UBaseType_t uxTaskPriorityGet( const TaskHandle_t xTask );

void vTaskPrioritySet( TaskHandle_t xTask,
                       UBaseType_t uxNewPriority );

// Suspend any task. When suspended a task will never get any microcontroller processing time, no matter what its priority.
void vTaskSuspend( TaskHandle_t xTaskToSuspend );

// Resumes a suspended task.
void vTaskResume( TaskHandle_t xTaskToResume );

// A function to resume a suspended task that can be called from within an ISR.
BaseType_t xTaskResumeFromISR( TaskHandle_t xTaskToResume );

// Forces a task to leave the Blocked state, and enter the Ready state, even if the event the task was in the Blocked state to wait for has not occurred, and any specified timeout has not expired.
BaseType_t xTaskAbortDelay( TaskHandle_t xTask );

// Obtain the priority of any task. This function is safe to use from within an interrupt service routine (ISR).
UBaseType_t uxTaskPriorityGetFromISR( const TaskHandle_t xTask );

// Obtain the base priority of any task.
UBaseType_t uxTaskBasePriorityGet( const TaskHandle_t xTask );

// Obtain the base priority of any task.
UBaseType_t uxTaskBasePriorityGetFromISR( const TaskHandle_t xTask );

Task Utilities


UBaseType_t uxTaskGetSystemState(
                       TaskStatus_t * const pxTaskStatusArray,
                       const UBaseType_t uxArraySize,
                       unsigned long * const pulTotalRunTime );

void vTaskGetInfo( TaskHandle_t xTask,
                   TaskStatus_t *pxTaskStatus,
                   BaseType_t xGetFreeStackSpace,
                   eTaskState eState );

TaskHookFunction_t xTaskGetApplicationTaskTag( TaskHandle_t xTask );
TaskHookFunction_t xTaskGetApplicationTaskTagFromISR( TaskHandle_t xTask );


UBaseType_t uxTaskGetStackHighWaterMark
 ( TaskHandle_t xTask );

configSTACK_DEPTH_TYPE uxTaskGetStackHighWaterMark2
 ( TaskHandle_t xTask );


BaseType_t xTaskCallApplicationTaskHook(
                                         TaskHandle_t xTask,
                                         void *pvParameter );

void vTaskSetApplicationTaskTag(
                                 TaskHandle_t xTask,
                                 TaskHookFunction_t pxTagValue );

void vTaskSetThreadLocalStoragePointer( TaskHandle_t xTaskToSet,
                                        BaseType_t xIndex,
                                        void *pvValue )

void *pvTaskGetThreadLocalStoragePointer(
                                 TaskHandle_t xTaskToQuery,
                                 BaseType_t xIndex );

void vTaskSetTimeOutState( TimeOut_t * const pxTimeOut );

BaseType_t xTaskCheckForTimeOut( TimeOut_t * const pxTimeOut,
                                 TickType_t * const pxTicksToWait );

eSleepModeStatus eTaskConfirmSleepModeStatus( void );

2. RTOS kernel control


// The taskENTER_CRITICAL() and taskEXIT_CRITICAL() macros provide a basic critical section implementation that works by simply disabling interrupts, either globally, or up to a specific interrupt priority level. See the vTaskSuspendAll() RTOS API function for information on creating a critical section without disabling interrupts.
void taskENTER_CRITICAL( void );
void taskEXIT_CRITICAL( void );

// The taskENTER_CRITICAL_FROM_ISR() and taskEXIT_CRITICAL_FROM_ISR() macros provide a basic critical section implementation that works by simply disabling interrupts, either globally, or up to a specific interrupt priority level.
UBaseType_t taskENTER_CRITICAL_FROM_ISR( void );
void taskEXIT_CRITICAL_FROM_ISR( UBaseType_t uxSavedInterruptStatus );

// Starts the RTOS scheduler. After calling the RTOS kernel has control over which tasks are executed and when.
void vTaskStartScheduler( void );

// Stops the RTOS kernel tick.
void vTaskEndScheduler( void );

// Suspends the scheduler.
void vTaskSuspendAll( void );

// Resumes the scheduler after it was suspended using a call to vTaskSuspendAll().
BaseType_t xTaskResumeAll( void );

void vTaskStepTick( TickType_t xTicksToJump );

BaseType_t xTaskCatchUpTicks( TickType_t xTicksToCatchUp );

Direct to task notifications


// ulTaskNotifyTake() and ulTaskNotifyTakeIndexed() are equivalent macros - the only difference being ulTaskNotifyTakeIndexed() can operate on any task notification within the array and ulTaskNotifyTake() always operates on the task notification at array index 0.
BaseType_t xTaskNotifyGive( TaskHandle_t xTaskToNotify );

BaseType_t xTaskNotifyGiveIndexed( TaskHandle_t xTaskToNotify,
                                  UBaseType_t uxIndexToNotify );

// Versions of xTaskNotifyGive() and xTaskNotifyGiveIndexed() that can be used from an interrupt service routine (ISR).
void vTaskNotifyGiveFromISR( TaskHandle_t xTaskToNotify,
                             BaseType_t *pxHigherPriorityTaskWoken );

void vTaskNotifyGiveIndexedFromISR( TaskHandle_t xTaskHandle,
                                    UBaseType_t uxIndexToNotify,
                                    BaseType_t *pxHigherPriorityTaskWoken );

uint32_t ulTaskNotifyTake( BaseType_t xClearCountOnExit,
                           TickType_t xTicksToWait );

uint32_t ulTaskNotifyTakeIndexed( UBaseType_t uxIndexToWaitOn,
                                  BaseType_t xClearCountOnExit,
                                  TickType_t xTicksToWait );

BaseType_t xTaskNotify( TaskHandle_t xTaskToNotify,
                        uint32_t ulValue,
                        eNotifyAction eAction );

BaseType_t xTaskNotifyIndexed( TaskHandle_t xTaskToNotify,
                              UBaseType_t uxIndexToNotify,
                              uint32_t ulValue,
                              eNotifyAction eAction );

// xTaskNotifyAndQueryIndexed() performs the same operation as xTaskNotifyIndexed() with the addition that it also returns the target task's prior notification value
BaseType_t xTaskNotifyAndQuery( TaskHandle_t xTaskToNotify,
                                uint32_t ulValue,
                                eNotifyAction eAction,
                                uint32_t *pulPreviousNotifyValue );

BaseType_t xTaskNotifyAndQueryIndexed( TaskHandle_t xTaskToNotify,
                                      UBaseType_t uxIndexToNotify,
                                      uint32_t ulValue,
                                      eNotifyAction eAction,
                                      uint32_t *pulPreviousNotifyValue );

BaseType_t xTaskNotifyAndQueryFromISR(
                    TaskHandle_t xTaskToNotify,
                    uint32_t ulValue,
                    eNotifyAction eAction,
                    uint32_t *pulPreviousNotifyValue,
                    BaseType_t *pxHigherPriorityTaskWoken );

BaseType_t xTaskNotifyAndQueryIndexedFromISR(
                    TaskHandle_t xTaskToNotify,
                    UBaseType_t uxIndexToNotify
                    uint32_t ulValue,
                    eNotifyAction eAction,
                    uint32_t *pulPreviousNotifyValue,
                    BaseType_t *pxHigherPriorityTaskWoken );


 BaseType_t xTaskNotifyFromISR( TaskHandle_t xTaskToNotify,
                                uint32_t ulValue,
                                eNotifyAction eAction,
                                BaseType_t *pxHigherPriorityTaskWoken );

 BaseType_t xTaskNotifyIndexedFromISR( TaskHandle_t xTaskToNotify,
                                       UBaseType_t uxIndexToNotify,
                                       uint32_t ulValue,
                                       eNotifyAction eAction,
                                       BaseType_t *pxHigherPriorityTaskWoken );


// xTaskNotifyWait() waits, with an optional timeout, for the calling task to receive a notification. If the receiving RTOS task was already Blocked waiting for a notification when the notification it is waiting for arrives the receiving RTOS task will be removed from the Blocked state and the notification cleared.
BaseType_t xTaskNotifyWait( uint32_t ulBitsToClearOnEntry,
                            uint32_t ulBitsToClearOnExit,
                            uint32_t *pulNotificationValue,
                            TickType_t xTicksToWait );

BaseType_t xTaskNotifyWaitIndexed( UBaseType_t uxIndexToWaitOn,
                                  uint32_t ulBitsToClearOnEntry,
                                  uint32_t ulBitsToClearOnExit,
                                  uint32_t *pulNotificationValue,
                                  TickType_t xTicksToWait );

// If a notification is sent to an index within the array of notifications then the notification at that index is said to be 'pending' until the task reads its notification value or explicitly clears the notification state to 'not pending' by calling xTaskNotifyStateClear().

BaseType_t xTaskNotifyStateClear( TaskHandle_t xTask );

BaseType_t xTaskNotifyStateClearIndexed( TaskHandle_t xTask,
                                         UBaseType_t uxIndexToClear );


uint32_t ulTaskNotifyValueClear( TaskHandle_t xTask,
                                 uint32_t ulBitsToClear );

uint32_t ulTaskNotifyValueClearIndexed( TaskHandle_t xTask,
                                        UBaseType_t uxIndexToClear,
                                        uint32_t ulBitsToClear );