freertos xSemaphoreTake stuck

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

freertos xSemaphoreTake stuck

2,191 Views
zohargolan
Contributor III

Hi All,

 

I have a problem with the MCU On eclipse freeRtos component.

I am using k20fx512 device with the MCU On Eclipse component on KDS 3.0.0.

the freeRtos version is v8.2.0.

I have a periodic hardware interrupt which is pulsing every ~20 ms. This interrupt is giving a semaphore using

xSemaphoreGiveFromIsr

 

In the back end I have a task which is waiting for this semaphore in a for loop.

 

for (;;)

 

if(xSemaphoreTake(SemaphoreName, (TickType_t) 25) != pdTRUE)

 

     "Missed a frame interrupt.\n");

 

else

     ...

     task body

 

 

This mechanism is working perfectly until something happens and the task is not processing the task body anymore.

The interrupt is still working and when the semaphore is given in the ISR, it is returning an error, because it is already given.

the semaphore take just missed and the semaphore is still waiting endlessly.

 

Please advise

Zohar

Labels (1)
0 Kudos
2 Replies

956 Views
danielchen
NXP TechSupport
NXP TechSupport

Hi Zohar:

Please refer to the following example to use xSempaphoreGiveFromISR()

void vISR(void *pvParameters)

{

    BaseType_t xHigherPriorityTaskWoken = pdFALSE;

    /*The event has occurr3d, use teh semaphore to unblock the task so the task can process the event*/

    xSemaphoreGiveFromISR(xSemaphore, &HigherPriorityTaskWoken);

    /* Clear the interrupt here */

   /* */

    portYIELD_FROM_ISR(xHigherPriorityTaskWoken);

}

    /*Define a task that performs an action each time an interrupt occurs. */

void vATask(void * pvParameters)

{

    /*it is assumed the semaphore has already been created outside of this task*/

    for (;;)

    {

        /*wait for the next event*/

        if ( xSemaphoreTake(xSemaphore, portMAX_DELAY) == pdTURE)

            /* The event has occurred, process it here*/

            ......

            /*Processing is complete, return to wait for the next event*/

    }

}

Regards

Daniel

0 Kudos

956 Views
zohargolan
Contributor III

Thank you Daniel,

This is exactly how I am using the interrupt

Zohar

0 Kudos