FreeRTOS xSemaphoreTakeFromISR() not blocking

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

FreeRTOS xSemaphoreTakeFromISR() not blocking

4,137 Views
momirpartalo
Contributor I

I am using FreeRTOS from the Kinetis SDK 1.3.0. A snippet of my code is provided below. Why is the second call to xSemaphoreTakeFromISR()  not blocking and not waiting for xSemaphoreGiveFromISR() to release the binary semaphore? If I disable xSemaphoreGiveFromISR() from within IRQHandler_A(), my code within IRQHandler_B() will still move to the next instruction.

 

void IRQHandler_A(void)

{

…..

xSemaphoreGiveFromISR(Sem, NULL);  

…..

}

 

void IRQHandler_B(void)

{

static bool once = true;

                if(once)

                {

                               xSemaphoreTakeFromISR(Sem, NULL);  // first time

                               once = false;

                }

…..

xSemaphoreTakeFromISR(Sem, NULL);

// next instruction

…..

}

Labels (1)
0 Kudos
3 Replies

2,420 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi, Momir,

From instinct, it seems that xSemaphoreTakeFromISR() should not appear in an interrupt service routine as Erich said, how about creating a task, and put the xSemaphoreTakeFromISR() in a forever loop in the task.

I am not sure if the xSemaphoreTakeFromISR() can appear in an ISR, it is only my opinion, pls refer to the FreeRTOS website:

FreeRTOS - Market leading RTOS (Real Time Operating System) for embedded systems with Internet of Th...

Hope it can help you.

BR

XiangJun Rong

0 Kudos

2,420 Views
BlackNight
NXP Employee
NXP Employee

FYI, the *FromISR() functions should be called only from an interrupt service routines.

From a task the xSemaphoreTake() API has to be called.

Erich

0 Kudos

2,420 Views
BlackNight
NXP Employee
NXP Employee

Hi Momir,

see This page describes the xSemaphoreTakeFromISR() RTOS API function . Taking a semaphore in an interrupt is not (and should not!) block. Blocking in a semaphore would be a very, very bad thing anyway.

If you need to know if the semaphore was available, you can check the return value of xSemaphoreTakeFromISR() (see above lik to the documentation).

I hope this helps,

Erich

0 Kudos