I am trying to get a tasks name by using the pcTaskGetName function.
I tried from within the task with NULL as parameter and also from elsewhere with the tasks handle as a parameter, but i always get back a pointer to “main”.
What do you mean you get a pointer to “main”? The string “main”, or the
main() function? Do you have task that is called “main”?
Are you calling this after the scheduler has been started?
The code for pcTaskGetName() is very simple, as below, step into it in
the debugger to see what it is doing.
char *pcTaskGetName( TaskHandle_t xTaskToQuery )
{
TCB_t *pxTCB;
/* If null is passed in here then the name of the calling task is being
queried. */
pxTCB = prvGetTCBFromHandle( xTaskToQuery );
configASSERT( pxTCB );
return &( pxTCB->pcTaskName[ 0 ] );
}
pcTaskGetName( NULL ) will return the name of the task that is currently active.
So if you call pcTaskGetName( NULL ) from a task whose name is "main", it is logical that it returns that string.
Didn’t you create your task with xTaskCreate( pvFunction, "main", xxx) ?
If the idle-task would call pcTaskGetName( NULL ), it would see "IDLE"
Or if your task would call pcTaskGetName( xIdleTaskHandle ), it would also receive the string “IDLE”
( NB. TaskHandle_t xIdleTaskHandle is declared static in tasks.c, so you can not easily try that )