Quality RTOS & Embedded Software

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


get current task name

Posted by Martin Velek on March 5, 2010
Is it possible to get current task name in a user application? In the task.c is stated tskTaskControlBlock.pcTaskName is for debugging only but it is not surrounded by any #if .... #endif. So it exists all the time.
I have tried to do extern tskTCB pxCurrentTCB but the struck tskTCB is defined only in task.c and is not exported.
If possible I would like not to do some kernel hacks(modify kernel files).

Thank you for your help.

RE: get current task name

Posted by Richard Damon on March 5, 2010
The variable is declared static, so it can not be accessed outside that file. if you add a
to FreeRTOSConfig.h then the static will be removed and it will be accessable.

RE: get current task name

Posted by Martin Velek on March 5, 2010
Thanks, but still no success.

line 191: extern tskTCB pxCurrentTCB;

../uEZ_SRC/Source/RTOS/uEZRTOS_FreeRTOS.c:191: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'pxCurrentTCB'
../uEZ_SRC/Source/RTOS/uEZRTOS_FreeRTOS.c:191: error: 'pxCurrentTCB' undeclared (first use in this function)
../uEZ_SRC/Source/RTOS/uEZRTOS_FreeRTOS.c:191: error: (Each undeclared identifier is reported only once
../uEZ_SRC/Source/RTOS/uEZRTOS_FreeRTOS.c:191: error: for each function it appears in.)

I do not want to copy struct tskTCB to uEZRTOS_FreeRTOS.c because the FreeRTOS can change in the future and I would have to maintain two files. Maybe a feature request?

RE: get current task name

Posted by Richard on March 5, 2010
“line 191: extern tskTCB pxCurrentTCB”

I'm not sure what I can add to that, other than it looks like it doesn't know what the tskTCB type is. Is uEZRTOS_FreeRTOS.c the FreeRTOS implementation of the uEZ RTOS abstraction?


RE: get current task name

Posted by Richard Damon on March 5, 2010
The problem is that FreeRTOS hides the definitions of its structures in the c files, for data hiding. A way to fix this and allow selected user files to be able to see the structure information, while still keeping the hiding for most user files, would be to move the structure definition to the header files, but use a preprocessor definition to control whether the structure is defined with details or opaquely. The FreeRTOS files would define this definition, and any use file that for debugging needed it could define it, but the reset get the void* typedef.

I do something like this in the version I use. To help with updating, I didn't remove the definition from the c files, just bracketed it with #if 0 and #endif, that way when I diff the current code with the old, I can detect any changes in the data structures and move the changes over. Perhaps I should clean up how I do this and submit it to Richard as a suggested improvement.

I understand that the current method being used grew out of a need to support a number of somewhat broken C compilers (the embedded market is know for this problem, many chips with smaller market share don't generate enough interest for the manufactures to get a fully working compiler up, so they often don't support the full language). Technically, the technique used invokes undefined behavior, since the prototype used by the user code passes void* pointers, but the functions are declared with struct* pointers, which are not guaranteed by the language to look the same, but for practical purposes will be as long as the machine is inherently "byte addressable", which all the target processors are.

RE: get current task name

Posted by Preet Kang on March 9, 2010
You can add a function :
void getTaskName(char* name)
strcpy(name, pxCurrentTCB->taskname);

at tasks.c and task.h


RE: get current task name

Posted by Martin Velek on March 9, 2010
Thank you Preet,
a similar function exist in my project. However my FreeRTOS upgrade procedure consist of copying files if the new version is declared backward compatible. It is hard to keep track. Currently I have only one line at the end of tasks.c, #include "FreeRTOSExtensions.c" and function prototype is in the FreeRTOS.h. I think that both way are not the right solution to the future.


RE: get current task name

Posted by Preet Kang on March 9, 2010
Try one of these (they both compiled fine on my GCC, but I didn't try to use it):

extern struct tskTaskControlBlock* volatile pxCurrentTCB;
extern volatile void * volatile pxCurrentTCB;


RE: get current task name

Posted by Tyrel Newton on March 10, 2010
I ran into this same problem while I was debugging modifications to a port and I simply added a function like the one Preet mentioned above in both the tasks.c and task.h file. Other than the #include .c file at the end of tasks.c, the only way to cleanly do this is to manually edit tasks.c, since this is where the struct is FULLY defined WITH the task name field. Any other extern struct defintion method should result in a compiler error since it won't know where the task name field is within the structure. So, count me for a vote to either move the struct definition to a header file or add a few struct field get accessor functions to tasks.c and task.h.

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

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

Latest News

FreeRTOS v10.2.1 is available for immediate download. MIT licensed, includes 64-bit RISC-V, NXP Cortex-M33 demo, Nuvoton Cortex-M23 demo & STM32H745 dual core (AMP) demo.

NXP tweet showing LPC5500 (ARMv8-M Cortex-M33) running FreeRTOS.

View a recording of the "OTA Update Security and Reliability" webinar, presented by TI and AWS.


FreeRTOS and other embedded software careers at AWS.

FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Cadence Tensilica Cortes

Espressif ESP32

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

Xilinx Microblaze and Zynq partner