Using an ISR - Semaphore to unblock a task

stmiko wrote on Wednesday, May 05, 2010:

Hello,

I´ve got some “problems” with the named topic. I using a task to calculate some date which i get from an ISR.  When the task is blocked with vTaskDelay it works without problems, but i want to start the task only when it get a ready state from the ISR.
This is realized with xSemaphoreGiveFromISR() and in the task with an if - request and xSemaphoreTake(). The problem is, that i can´t stop this task, when it once jumped into the task, which uses the xSemaphoreTake().
In the ISR there is also a context switch with portEND_SWITCHING_ISR() because the unblocked task has the highest priority.

The second problem is, it seems, that after starting the scheduler he goes to the blocked task and don´t stop at the “if - semaphore - request”?

Does any know this problem? I using the Version 5.2.0 of FreeRTOS

Stephan

stmiko wrote on Wednesday, May 05, 2010:

Hello,

according to the first problem, i have found the reason. It has nothing to do with FreeRTOS…
But how can i avoid, that the task will run one time after starting the scheduler?

davedoors wrote on Wednesday, May 05, 2010:

Take the semaphore before entering the task loop.

void atask( void *p )
{
    xSemaphoreTake(sem,0); // dont block
    while(1)
    {
        xSemaphoreTake(sem,max_delay); // now you will block here because the semaphore is not available
        // do something
    }
}

stmiko wrote on Wednesday, May 05, 2010:

Thank you for this information, it works…