Quality RTOS & Embedded Software

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


Loading

how can I get the TCB imformation from the task handle?

Posted by yc0284 on October 19, 2017

~~~ TaskHandle_t task1,task2,task3;

void main_blinky( void ) {

    srand(time(NULL));
	xTaskCreate( SPEEDTEST, "Task 1", 100, NULL, 3, (TaskHandle_t*)&task1 );
	xTaskCreate( ROOM, "Task 2", 100, NULL, 2, (TaskHandle_t*)&task2 );
	xTaskCreate( Power, "Task 3", 100, NULL, 1, (TaskHandle_t*)&task3 );
	vTaskStartScheduler();

	CheckNextRun();
for( ;; );

}

static void CheckNextRun(void) {

taskENTER_CRITICAL();
printf("**************Address1=%p\n  ***************",*task3->xStateListItem.pvContainer );
fflush( stdout );
printf("**************Address2=%u\n  ***************",&(pxReadyTasks[*task3->uxPriority]) );
fflush( stdout );

// if ( task3->xStateListItem.pvContainer==&(pxReadyTasks[task3->uxPriority]) ) // {period=Period_3};

taskEXIT_CRITICAL();

} ~~~

I tired to check if the pvContainer is point to the pxReadyTasksLists[ ], it shows three errors :

  1. pxReadyTasksLists' undeclared (first use in this function) main_blinky.c

  2. request for member 'uxPriority' in something not a structure or union

  3. request for member 'xStateListItem' in something not a structure or union

How should I declare the pxReadyTasksLists? as extern? How can I get the TCB imformation from the task handle?

Thanks!


how can I get the TCB imformation from the task handle?

Posted by rtel on October 19, 2017

You can't, not directly anyway. The task handle is a pointer to the TCB structure, but it is deliberately kept opaque because you should not access the TCB directly. The TCB is an internal data structure and could, potentially, change at any time between FreeRTOS versions.

There are some functions that allow you to obtain task state information though. This link lists all (?) the task utility functions (it's possibly not completely up to date), one of which is vTaskGetInfo() (http://www.freertos.org/vTaskGetInfo.html ).


how can I get the TCB imformation from the task handle?

Posted by heinbali01 on October 19, 2017

Just a few more tips. You wrote :

~~~ vTaskStartScheduler(); CheckNextRun(); ~~~

Note that vTaskStartScheduler() starts the scheduler, and the first task will become active. CheckNextRun() will never get called.

You also wrote:

~~~ taskENTERCRITICAL(); printf( "xn" ); fflush( stdout ); taskEXITCRITICAL(); ~~~

I am not sure how your printf() and fflush() have been implemented, but chances are that they don't like the critical section. A critical section means that all interrupts are temporarily disabled.

Remember that you can also temporarily suspend the scheduler, while still allowing for interrupts.

And if you use a critical secion, do the absolute minimum, like e.g. :

~~~ void *container, *address;

taskENTER_CRITICAL();
{
    /* Do as little as possible. */
    container = task3->xStateListItem.pvContainer;
    address = &(pxReadyTasks[*task3->uxPriority]);
}
taskEXIT_CRITICAL();
/* Now printf the information obtained. */

~~~

Good luck


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


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

Latest News

Version 10.1.0 of the FreeRTOS kernel is available for immediate download. MIT licensed.

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


Careers

FreeRTOS and other embedded software careers at AWS.



FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Espressif ESP32

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Renesas

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