专栏中心

EEPW首页 > 专栏 > 为什么主函数和中断函数不能调用同一函数?

为什么主函数和中断函数不能调用同一函数?

发布人:mayer 时间:2009-09-07 来源:工程师 发布文章
为什么主函数和中断函数不能调用同一函数?

 

Q. I get the error: function * appears in multiple call graphs: rooted at *
   What does this mean?


A. It means that there is a function which is being called from an interrupt
   and from main code and reentrancy is not supported by the compiler.
   Because the function is not reentrant, it leaves open the possibility
   of it being called from both locations at the same time. There are several
   possible ways to work around this:

1. If the compiler supports the "reentrant" qualifer, then define the function
   with this.

2. ROM space permitting, make two copies of the function but give them different
   names. One is only called by the interrupt, the other only by main code.

3. Rewrite the function such that it doesn't have any local variables or
   parameters. If the function doesn't have these, then it can be called from
   the interrupt and main code at the same time.

4. If you can guarantee that the function will not be called simultaneously, then
   you can use the #pragma interrupt_level directive. This is detailed in the
   user manuals, but in brief it is used like the following:

#pragma interrupt_level 1
void common_func(void)
{
   /* local variable definitions */

   /* code */
}

#pragma interrupt_level 1
void interrupt isr(void)
{
    common_func();
    /* more code */
}


void main(void)
{
   common_func();  /* gets called before interrupts are turned on */
   EI();    /* enable interrupts */
   /* more code */
}

专栏文章内容及配图由作者撰写发布,仅供工程师学习之用,如有侵权或者其他违规问题,请联系本站处理。 联系我们

关键词:

相关推荐

美研制新概念载人小型深潜器

视频 2010-01-14

RTI 和 Kinova 为医疗机器人带来智能连接

德州仪器AMC0106M05:先进的电流和电压检测技术如何实现超精密机器人

美空军计划未来10年采购2000架无人机

视频 2010-01-14

xMEMS发布μCooling微型气冷式全硅主动散热芯片方案

PIC12F635_PIC16F636_PIC12F639 单片机

为何集体围攻比亚迪?

美批准建造首批DD(X)驱逐舰

视频 2010-01-14

AVEVA剑维软件中国智能创新中心成立,加速本土工业智能迭代

人形机器人的产业生态与协同发展探讨

美陆军调整陆航采办计划

视频 2010-01-14

如何利用保护电路轻松消除过压

PIC10F200_Pic10f202_pic10f204_pic10f206 6引脚8位闪存单片机

美研究“多箭一星”发射技术

视频 2010-01-14

PIC10F20X 单片机

PHILIPS单片16_32位微控制器-LPC2292_LPC2294

PIC12C5XX单片机

相较于端到端,VLA给智驾带来了哪些改变?

意法半导体扩展ISO 26262标准车规负载驱动器产品系列

更多 培训课堂
更多 焦点
更多 视频

技术专区