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

2009-9-5 15:03 2942 4 5 分类: MCU/ 嵌入式

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 */
}

文章评论1条评论)

登录后参与讨论

用户188034 2009-9-13 23:10

翻译一下
相关推荐阅读
用户999308 2011-10-11 10:32
MASK(掩模)、OTP(一次性可编程)、FlashROM的区别
OTP(One Time Programable)是MCU的一种存储器类型MCU按其存储器类型可分为MASK(掩模)ROM、OTP(一次性可编程)ROM、FLASH ROM等类型。MASK ROM的M...
用户999308 2011-08-17 16:49
wireless
今天是玩无线遥控器的第三天,主要的编码芯片有PT2262,ev1527,解码芯片有PT2272....
用户999308 2011-08-06 22:00
VB教程
http://www.enet.com.cn/eschool/video/21hulian_vb/...
用户999308 2011-08-06 21:51
共享一个PIC12F629调光程序
使用MPLIB自带的Hi-tech lite版c编译器编译。不知道为何,Timer0定时中断总有问题,无法用作延时,只好采用实时延时方式,反正MCU也没别的事情好干。延时不是太精确,没仔细去调整。欢迎...
用户999308 2011-05-23 15:51
安规电容X,Y
X电容是用于差模滤波的,即并联于输入的两端.滤除L,N线之间的差模信号;Y电容用于共模滤波,它接于L于地或N于地之间,滤除L对地或N对地的共模信号,(Y电容通常对称使用) 它们都是安规电容. 在交流...
用户999308 2010-07-02 15:41
PT2258的应用(C语言)
#include "regx52.h"#include "PT2258.h"#include "intrins.h"#define uchar unsigned char #define uint  ...
我要评论
1
4
关闭 站长推荐上一条 /3 下一条