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

yc0284 wrote on Thursday, October 19, 2017:

TaskHandle_t task1,task2,task3;

void main_blinky( void )

		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 );

	for( ;; );


static void CheckNextRun(void)

	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};


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?


rtel wrote on Thursday, 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()
( ).

heinbali01 wrote on Thursday, October 19, 2017:

Just a few more tips. You wrote :


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

You also wrote:

    printf( "x\n" );
    fflush( stdout );

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;

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

Good luck