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

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.
Martin

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
#define portREMOVE_STATIC_QUALIFIER
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?

Regards.

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

Preet

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.

Martin

RE: get current task name

Posted by Preet Kang on March 9, 2010
Martin,
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;

Preet

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 ]    [ 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