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 ).
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. */