FreeRTOS xSemaphoreTakeFromISR() not blocking

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

FreeRTOS xSemaphoreTakeFromISR() not blocking

6,060 次查看
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

…..

}

标签 (1)
0 项奖励
回复
3 回复数

4,343 次查看
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 项奖励
回复

4,343 次查看
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 项奖励
回复

4,343 次查看
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 项奖励
回复