there doesn’t seem to be a simple function to obtain the ulRunTimeCounter of a task, although it has to be enabled via configGENERATE_RUN_TIME_STATS.
The only two ways this can be used is via vTaskGetInfo() and uxTaskGetSystemState().
Would it be possible to add the function TaskGetRunTimeCounter(TaskHandle_t xTask) similar to TaskGetIdleRunTimeCounter()?
Would it help if I submit a PR for this?
You could always just add a function to your user application to retrieve the ulRunTimeCounter. I didn’t check this code at all, but it should be pretty close to working.
uint32_t TaskGetRunTimeCounter( TaskHandle_t xTask )
uint32_t ulRunTimeCounter = 0;
/* xTask is NULL then get the state of the calling task. */
pxTCB = prvGetTCBFromHandle( xTask );
#if ( configGENERATE_RUN_TIME_STATS == 1 )
ulRunTimeCounter = pxTCB->ulRunTimeCounter;
These functions are all hidden in task.c.
task.c has a special way to add additional functions to it for user customization.
First add to your FreeRTOSConfig.h
#define configINCLUDE_FREERTOS_TASK_C_ADDITIONS_H 1
Then create a file freertos_tasks_c_additions.h somewhere on your include path (likely the same directory that FreeRTOSConfig.h is) which has the code you want added to task.c
Note, that even though this file ends in .h, treat it like a .c file, but DON’T add it as a file to compile in the project (it will get compiled as part of task.c)
I generally define another header file, something like mytask.h which I include ih freertos_task_c_additions.h and my files that use the additions, as a location to put the function prototypes for my new additions.
Since freertos_task_c_additions.h is compiled as part of the task.c file, it has access to all of the internals to task.c