Hoe to get the Task Number?

alainm3 wrote on Saturday, March 15, 2014:

Inside vApplicationStackOverflowHook(), I need to get the Task number for error report.
How can I get it from the xTaskHandle?

Thanks, Alain

rtel wrote on Saturday, March 15, 2014:

You can use the function:

UBaseType_t uxTaskGetTaskNumber( TaskHandle_t xTask );

I’m not sure if that is documented as it is intended for internal and tracing use really. configUSE_TRACE_FACILITY must be set to 1 in FreeRTOSConfig.h.

Note if the stack has overflowed then you may find the task handle passed into the hook function is corrupt. In which case you can use the pxCurrentTCB variable to get the handle instead, but you will have to declare it as an extern inside your hook function to make it available.

Finally you could also keep a track of the number of the task that is currently running by defining a trace macro (assuming you are not using the trace macros for anything else). To do that declare a variable in your main.c (or somewhere else suitable) as per:


UBaseType_t uxCurrentTaskNumber = 0;

Then at the bottom of FreeRTOSConfig.h add:


extern UBaseType_t uxCurrentTaskNumber;
#define traceTASK_SWITCHED_IN() uxCurrentTaskNumber = pxCurrentTCB->uxTaskNumber;

then in your hook you can just look at the uxCurrentTaskNumber variable.

Regards.

alainm3 wrote on Sunday, March 16, 2014:

Hi, thanks for the promp reply :slight_smile:

the third option is probably the simplest… BUT…

IT ONLY WORKS with pxCurrentTCB->uxTCBNumber !!!
uxTaskNumber doesn’t seem to be updated and uxTCBNumber is what I get in
pxTaskStatusArray (which serves as reference anyway…)

I has to change UBaseType → portBASE_TYPE → long
I am using 7.6.0 version because I expect trouble with LWIP. And also
because portBASE_TYPE is defined inside portmacro.h wich is not known to
my main.c

NOTE: It’s unfortunate that tskTaskControlBlock is defined only inside
tasks.c, it would be much easier to use in tasks.h. Maybe not safe…
the world isn’t perfect…

thanks,
Alain

Em 15-03-2014 11:54, Real Time Engineers ltd. escreveu:

You can use the function:

UBaseType_t uxTaskGetTaskNumber( TaskHandle_t xTask );

I’m not sure if that is documented as it is intended for internal and
tracing use really. configUSE_TRACE_FACILITY must be set to 1 in
FreeRTOSConfig.h.

Note if the stack has overflowed then you may find the task handle
passed into the hook function is corrupt. In which case you can use
the pxCurrentTCB variable to get the handle instead, but you will have
to declare it as an extern inside your hook function to make it available.

Finally you could also keep a track of the number of the task that is
currently running by defining a trace macro (assuming you are not
using the trace macros for anything else). To do that declare a
variable in your main.c (or somewhere else suitable) as per:

||

UBaseType_t uxCurrentTaskNumber = 0;

Then at the bottom of FreeRTOSConfig.h add:

||

extern UBaseType_t uxCurrentTaskNumber;

define traceTASK_SWITCHED_IN() uxCurrentTaskNumber =
pxCurrentTCB->uxTaskNumber;

then in your hook you can just look at the uxCurrentTaskNumber variable.

Regards.


Hoe to get the Task Number?
https://sourceforge.net/p/freertos/discussion/382005/thread/77ed94e2/?limit=25#b2fe


Sent from sourceforge.net because you indicated interest in
SourceForge.net: Log In to SourceForge.net

To unsubscribe from further messages, please visit
SourceForge.net: Log In to SourceForge.net