Updated Mar 2025
vTaskGetInfo()
task.h
1void vTaskGetInfo( TaskHandle_t xTask,2 TaskStatus_t *pxTaskStatus,3 BaseType_t xGetFreeStackSpace,4 eTaskState eState );
configUSE_TRACE_FACILITY
vTaskGetInfo()
Whereas uxTaskGetSystemState() populates a TaskStatus_t structure for each task in the system,
vTaskGetInfo()
TaskStatus_t
TaskStatus_t
NOTE: This function is intended for debugging use only as its use results in the scheduler remaining suspended for an extended period.
Parameters:
-
xTask
The handle of the task being queried. Setting xTask to NULL will return information on the calling task.
-
pxTaskStatus
The
structure pointed to byTaskStatus_twill be filled with information about the task referenced by the handle passed in thepxTaskStatusparameter.xTask -
xGetFreeStackSpace
The
structure contains a member to report the stack high water mark of the task being queried. The stack high water mark is the minimum amount of stack space that has ever existed, so the closer the number is to zero the closer the task has come to overflowing its stack. Calculating the stack high water mark takes a relatively long time, and can make the system temporarily unresponsive - so theTaskStatus_tparameter is provided to allow the high water mark checking to be skipped. The high watermark value will only be written to thexGetFreeStackSpacestructure ifTaskStatus_tis not set toxGetFreeStackSpace.pdFALSE -
eState
The
structure contains a member to report the state of the task being queried. Obtaining the task state is not as fast as a simple assignment - so theTaskStatus_tparameter is provided to allow the state information to be omitted from theeStatestructure. To obtain state information then set eState toTaskStatus_t- otherwise the value passed ineInvalidwill be reported as the task state in theeStatestructure.TaskStatus_t
Example usage:
1void vAFunction( void )2{3 TaskHandle_t xHandle;4 TaskStatus_t xTaskDetails;56 /* Obtain the handle of a task from its name. */7 xHandle = xTaskGetHandle( "Task_Name" );89 /* Check the handle is not NULL. */10 configASSERT( xHandle );1112 /* Use the handle to obtain further information about the task. */13 vTaskGetInfo( /* The handle of the task being queried. */14 xHandle,15 /* The TaskStatus_t structure to complete with information16 on xTask. */17 &xTaskDetails,18 /* Include the stack high water mark value in the19 TaskStatus_t structure. */20 pdTRUE,21 /* Include the task state in the TaskStatus_t structure. */22 eInvalid );23}
The TaskStatus_t definition
1typedef struct xTASK_STATUS2{3 /* The handle of the task to which the rest of the information in the4 structure relates. */5 TaskHandle_t xHandle;67 /* A pointer to the task's name. This value will be invalid if the task was8 deleted since the structure was populated! */9 const char *pcTaskName;1011 /* A number unique to the task. */12 UBaseType_t xTaskNumber;1314 /* The state in which the task existed when the structure was populated. */15 eTaskState eCurrentState;1617 /* The priority at which the task was running (may be inherited) when the18 structure was populated. */19 UBaseType_t uxCurrentPriority;2021 /* The priority to which the task will return if the task's current priority22 has been inherited to avoid unbounded priority inversion when obtaining a23 mutex. Only valid if configUSE_MUTEXES is defined as 1 in24 FreeRTOSConfig.h. */25 UBaseType_t uxBasePriority;2627 /* The total run time allocated to the task so far, as defined by the run28 time stats clock. Only valid when configGENERATE_RUN_TIME_STATS is29 defined as 1 in FreeRTOSConfig.h. */30 unsigned long ulRunTimeCounter;3132 /* Points to the lowest address of the task's stack area. */33 StackType_t *pxStackBase;3435 #if ( configRECORD_STACK_HIGH_ADDRESS == 1 )36 /* Points to the top address of the task's stack area. */37 StackType_t * pxTopOfStack;3839 /* Points to the bottom address of the task's stack area. */40 StackType_t * pxEndOfStack;41 #endif4243 /* The minimum amount of stack space that has remained for the task since44 the task was created. The closer this value is to zero the closer the task45 has come to overflowing its stack. */46 configSTACK_DEPTH_TYPE usStackHighWaterMark;47} TaskStatus_t;