Using eTaskGetState and vTaskGetInfo to debug?

I was wondering if it was possible or a good/bad idea to use either eTaskGetState or vTaskGetInfo to verify if a task is working as expected or if there are any conflicts between task threads? If so, what are the different use cases between eTaskGetState and vTaskGetInfo?

Many thanks in advance!

Would you please elaborate on what you want to verify? TaskStatus_t structure contains the following members:

typedef struct xTASK_STATUS
    TaskHandle_t xHandle; 
    const char * pcTaskName;
    UBaseType_t xTaskNumber;
    eTaskState eCurrentState;
    UBaseType_t uxCurrentPriority;
    UBaseType_t uxBasePriority
    configRUN_TIME_COUNTER_TYPE ulRunTimeCounter;
    StackType_t * pxStackBase;
    #if ( ( portSTACK_GROWTH > 0 ) || ( configRECORD_STACK_HIGH_ADDRESS == 1 ) )
        StackType_t * pxTopOfStack;
        StackType_t * pxEndOfStack;
    configSTACK_DEPTH_TYPE usStackHighWaterMark;
    #if ( ( configUSE_CORE_AFFINITY == 1 ) && ( configNUMBER_OF_CORES > 1 ) )
        UBaseType_t uxCoreAffinityMask;
} TaskStatus_t;

Do you want to look at the ulRunTimeCounter member and ensure that the task is getting CPU cycles? If so, that should be okay.

Another way to implement system health check is using Watchdog. Watchdog is a HW unit which requires regular patting from software to avoid tripping/resetting the system. You create a high priority monitoring task which regularly checks that every task in the system is making progress and then pats the Watchdog. If it detects any stuck task, it does not pat the Watchdog and then Watchdog trips/resets the system. You can use event groups to track task progress where each task keeps setting a bit as long as it is making progress.

1 Like

Originally I was thinking something supper basic, like what state the task was in. And that is still a question I have, can either of these be used to debug using printf or something to see what state a task is current in? Then my next question would be what usecase would using Watchdog have? How does it differ from checking state? Would I be correct in assuming that ulRunTimeCounter can be used to check for task starvation? Many thanks in advance!

You can do so - nothing prevents you printing the state of a task. Note that a task’s state may change between when it is queried and when it is printed.

You can use ulRunTimeCounter to find starvation for a task but that assumes that the task checking for starvation is still running. What if all the tasks are stuck (lets say deadlock)? The HW watchdog enables you to reset the system in such scenarios.