Quality RTOS & Embedded Software

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




Loading

Thread self reference

Posted by Nobody/Anonymous on October 28, 2004
Hi,

How can I get the xTaskHandle for the current running thread?

Regards
Henric


RE: Thread self reference

Posted by Richard on October 28, 2004
Why do you want to do this? Functions such as vTaskSuspend( xTaskHandle) will suspend the currently executing task if NULL is passed in as the parameter. There may be a way around what you are wanting to do like this.

The xTaskHandle is just a pointer to the task control block. It's type is hidden outside of tasks.c though (it is void* outside of tasks.c). You can obtain it by adding the following function to tasks.c (I haven't tried compiling this so watch out for typos):

xTaskHandle xGetCurrentTaskHandle( void )
{
xTaskHandle xReturn;

portENTER_CRITICAL();
xReturn = ( xTaskHandle ) pxCurrentTCB;
portEXIT_CRITICAL();

return xReturn;
}


An alternative and not very nice hack would be to simply declare:

extern volatile void * volatile pxCurrentTCB;

at the top of your application file. pxCurrentTCB will then be the handle to the currently executing task. This may cause a linker warning though and access to the extern variable would have to be only within critical regions so the first method is preferable.

RE: Thread self reference

Posted by Nobody/Anonymous on October 29, 2004
Hi,

Thanks for a great RTOS. I'll try the function xGetCurrentTaskHandle().

The first reason for I need this is that our software is message based, and each message has a sender and a receiver (UML state machines). Thus, I need to know the sender's task handle when creating the message. The second is that the passive objects often use the task handle as an unique reference.

Also, the software is not all new code. It contains lots of old code written for pSOS, OSE, and eCos. Those OSes has a self reference function, and since this functions is used... well, sigh...

Best Regards
Henric

Hello Henric !!! (UML state machines)

Posted by Nobody/Anonymous on November 30, 2004
Hello,
Are u aware of Dr. Miro Samek QF (quantum frame work) or have you tried replacing UML state machines with QF. If so please share u'r experience.


[ 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