Quality RTOS & Embedded Software

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




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) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.

Latest News:

FreeRTOS V9.0.0 is now available for download.


Free TCP/IP and file system demos for the RTOS


Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

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

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

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

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists