Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT




Loading

Hoe to get the Task Number?

Posted by alainm3 on 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


Hoe to get the Task Number?

Posted by rtel on March 15, 2014

You can use the function:

UBaseTypet uxTaskGetTaskNumber( TaskHandlet xTask );

I'm not sure if that is documented as it is intended for internal and tracing use really. configUSETRACEFACILITY 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?

Posted by alainm3 on March 16, 2014

Hi, thanks for the promp reply :)

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 -> portBASETYPE -> long I am using 7.6.0 version because I expect trouble with LWIP. And also because portBASETYPE 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: > > UBaseTypet uxTaskGetTaskNumber( TaskHandlet xTask ); > > I'm not sure if that is documented as it is intended for internal and > tracing use really. configUSETRACEFACILITY 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: > > || > > > UBaseTypet uxCurrentTaskNumber = 0; > > Then at the bottom of FreeRTOSConfig.h add: > > || > > > extern UBaseTypet uxCurrentTaskNumber; > > > define traceTASKSWITCHEDIN() 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 > https://sourceforge.net/p/freertos/discussion/382005/ > > To unsubscribe from further messages, please visit > https://sourceforge.net/auth/subscriptions/ >


[ Back to the top ]    [ About FreeRTOS ]    [ Sitemap ]    [ ]




Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

FreeRTOS kernel V10 is available for immediate download. Now MIT licensed.


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

OpenRTOS and SafeRTOS