pxCurrentTCB->uxTaskNumber always zero.

bdouram wrote on Tuesday, October 15, 2019:

Working with the trace macros, I came across documentation that says pxCurrentTCB-> uxTaskNumber would give me the number of the task to create or was running on the CPU.

I have read the docs and search in forum, but i have not found anything that could help me in this situation.

I set the trace setting

#define configUSE_TRACE_FACILITY		1

And I defined the macros, including this header bellow at the bottom of FreeRTOSConfig.h:

#include "FreeRTOS.h"


#define traceTASK_CREATE(xTask) taskCreated((int) pxCurrentTCB-> uxTaskNumber)
#define traceTASK_SWITCHED_IN() taskIn((int) pxCurrentTCB-> uxTaskNumber)


However, in debugging any task, the value contained in** pxCurrentTCB-> uxTaskNumber** is always 0 and the value that was supposed to be in uxTaskNumber, for example, 2, is in uxTCBNumber, not uxTaskNumber.

Below are the screenshots of pxCurrentTCB in debug mode on Eclipse IDE.

What i’m doing wrong in this case? Thanks.

rtel wrote on Tuesday, October 15, 2019:

I suspect this is because uxTCBNumber is the value you actually want,
and that uxTaskNumber is set by the Percepio trace macros (the ones that
generate trace output for FreeRTOS+Trace/Tracealyzer). Which
documentation says uxTaskNumber is used? If it is incorrect we can get
it updated.

Had the same problem.

uxTCBNumber is statically defined and no access interface provided.

tasks.h says :

  • Get the uxTCBNumber assigned to the task referenced by the xTask parameter.
    UBaseType_t uxTaskGetTaskNumber( TaskHandle_t xTask ) PRIVILEGED_FUNCTION;

uxReturn = pxTCB->uxTaskNumber; ← NOT uxTCBNumber soooo confusing !!

Need :
UBaseType_t uxTaskGetTCBNumber( TaskHandle_t xTask )

What do you need the TCB number for? Can you use vTaskGetInfo? In any case, the documentation in task.h should be updated.

This PR updates the documentation - Update documentation of uxTaskGetTaskNumber function by aggarg · Pull Request #460 · FreeRTOS/FreeRTOS-Kernel · GitHub