安全检测,如果从ISR调用功能? [英] Safely detect, if function is called from an ISR?
问题描述
如果有包含必要信息的寄存器,我已经查阅了参考手册。
例如,我试图检测是否根据中断活动位寄存器(IABR)寄存器从ISR(我使用SysTick-ISR)调用。如果ISR处于活动状态,该寄存器应为!= 0。但值为0x00000000。这意味着没有中断是有效的。除了这个测试,我在参考手册中检查了NVIC和SC寄存器,搜索包含必要标志的寄存器,但没有找到一个。
有人知道一个合适的注册/机制为我的问题?
您需要测试 VECTACTIVE >中断控制状态注册
我使用以下内容:
//!在中断模式下测试
inline bool isInterrupt()
{
return(SCB-> ICSR& SCB_ICSR_VECTACTIVE_Msk)!= 0;
}
SCM和SCB_ICSR_VECTACTIVE_Msk在CMSIS(core_cm3.h)中定义,其中想象会间接地包含部分特定头(lpc17xx.h或类似的我猜)。我正在使用C ++,包括C中的stdbool.h会给你一个bool类型,或者改为你自己的一个int r typedef。
例如:
void somefunction(char ch)
{
if(isInterrupt())
{
//如果ISR
发送(ch,NO_WAIT),请勿阻止;
}
else
{
send(ch,TIMEOUT);
}
}
如果需要一个解决方案,架构考虑如下:
int interrupt_nest_count = 0;
#define ENTER_ISR()interrupt_nest_count ++
#define EXIT_ISR()interrupt_nest_count--
#define IN_ISR()(interrupt_nest_count!= 0)
void isrA()
{
ENTER_ISR();
somefunction('a');
EXIT_ISR();
}
void isrB()
{
ENTER_ISR();
somefunction('b');
EXIT_ISR();
}
void somefunction(char ch)
{
if(IN_ISR())
{
//如果ISR不要阻止
send(ch,NO_WAIT);
}
else
{
send(ch,TIMEOUT);
}
}
但问题是指安全检测中断上下文,这依赖于添加到所有 ISR的输入/输出宏。
I'm developing software for an ARM Cortex M3 (NXP LPC1769) microncontroller. At the moment I'm searching for a mechansim to detect if my function is called within an ISR. I asume that I have to check a register. Based on this information I would like to call difficult functions.
I already checked the reference manual, if there is a register containing the necessary information.
For example I tried to detect if I'm called from an ISR (I used SysTick-ISR) based on the "Interrupt Active Bit Register" (IABR) register. This register should be != 0 if an ISR is active. But the value was 0x00000000. This implies that no interrupt is active. Besides this test I checked the NVIC and SC register in the reference manual searching for a register containing the necessary flag but I didn't found one.
Does anybody know a suitable register / mechanism for my problem?
You need to test the VECTACTIVE field of the Interrupt Control State Register.
I use the following:
//! Test if in interrupt mode
inline bool isInterrupt()
{
return (SCB->ICSR & SCB_ICSR_VECTACTIVE_Msk) != 0 ;
}
SCM and SCB_ICSR_VECTACTIVE_Msk are defined in the CMSIS (core_cm3.h), which I imagine would be included indirectly by toye part specific header (lpc17xx.h or similar I guess). I am using C++, including stdbool.h in C will get you a bool type, or change to an int r typedef of your own.
It is then used thus for example:
void somefunction( char ch )
{
if( isInterrupt() )
{
// Do not block if ISR
send( ch, NO_WAIT ) ;
}
else
{
send( ch, TIMEOUT ) ;
}
}
If a solution is required that assumes no knowledge of the architecture consider the following:
int interrupt_nest_count = 0 ;
#define ENTER_ISR() interrupt_nest_count++
#define EXIT_ISR() interrupt_nest_count--
#define IN_ISR() (interrupt_nest_count != 0)
void isrA()
{
ENTER_ISR() ;
somefunction( 'a' ) ;
EXIT_ISR() ;
}
void isrB()
{
ENTER_ISR() ;
somefunction( 'b' ) ;
EXIT_ISR() ;
}
void somefunction( char ch )
{
if( IN_ISR() )
{
// Do not block if ISR
send( ch, NO_WAIT ) ;
}
else
{
send( ch, TIMEOUT ) ;
}
}
However the question refers to safely detecting the interrupt context, and this relies on the enter/exit macros being added to all ISRs.
这篇关于安全检测,如果从ISR调用功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!