we are using FreeRTOS on a AT91SAM7 system and have encountered a mysterious behavior of the xTaskGetCurrentTaskHandle() function. We understood that this function will give us back the task handle of the currently running task, wich we like to use to identify in which task we are running to implement thread-save code by allowing recursion. The mystery is that this function gives us all the time random values back! We extected only the values as we got back once we created our tasks by calling xTaskCreate()! What is wrong?
Any help would be appreciated!
Here our code:
//>>> This part makes the function thread save
static xTaskHandle taskhandle=NULL;
static xSemaphoreHandle threadlock=NULL;
vSemaphoreCreateBinary( threadlock );
// waiting 1 ms for Semaphore
if(xSemaphoreTake(threadlock, 1) != pdTRUE) return ERR_TLOCK;
taskhandle=xTaskGetCurrentTaskHandle(); // gives back random values
// do something foo bar
//>>> OK release Threadlock here