Board logo

标题: 请版主一定要看,关于中断嵌套! [打印本页]

作者: bozai020141    时间: 2007-5-8 00:26     标题: 请版主一定要看,关于中断嵌套!

为了试验dg128中断嵌套,我编写了如下程序:
设置定时中断0、1、2,默认优先级。进入0定时中断后,我打开1定时中断,关闭2定时中断,并打开全局中断,然后做死循环;1定时中断服务程序每隔5000个定时计数器对PORTB_BIT0位取反;2定时器中断服务程序每隔7000个定时计数器对PORTA_BIT0位取反。
程序结果如我设想那样运行——PORTB_BIT0位不断在做取反运算,PORTA_BIT0位始终不变。
但我让程序运行了一会后,它自动停止了并报错:
FCS Warning (ID 25): writing to reserved register at pc = 0xc021. Value: 0xC0, Memory Address: 0x3FF.
FCS Warning (ID 25): writing to reserved register at pc = 0xc021. Value: 0x0, Memory Address: 0x3FD.
FCS Warning (ID 25): writing to reserved register at pc = 0xc021. Value: 0x0, Memory Address: 0x3FE.
FCS Warning (ID 25): writing to reserved register at pc = 0xc021. Value: 0xC0, Memory Address: 0x3FB.
FCS Warning (ID 25): writing to reserved register at pc = 0xc021. Value: 0x49, Memory Address: 0x3FC.
FCS Warning (ID 25): writing to reserved register at pc = 0xc021. Value: 0x1, Memory Address: 0x3F9.
FCS Warning (ID 25): writing to reserved register at pc = 0xc021. Value: 0x1B, Memory Address: 0x3FA.
FCS Warning (ID 25): writing to reserved register at pc = 0xc021. Value: 0xC0, Memory Address: 0x3F8.
FCS Warning (ID 26): reading from reserved register at pc = 0xc035. Value: 0x0, Memory Address: 0x3F8.
FCS Warning (ID 26): reading from reserved register at pc = 0xc035. Value: 0x0, Memory Address: 0x3F9.
FCS Warning (ID 26): reading from reserved register at pc = 0xc035. Value: 0x0, Memory Address: 0x3FA.
FCS Warning (ID 26): reading from reserved register at pc = 0xc035. Value: 0x0, Memory Address: 0x3FB.
FCS Warning (ID 26): reading from reserved register at pc = 0xc035. Value: 0x0, Memory Address: 0x3FC.
FCS Warning (ID 26): reading from reserved register at pc = 0xc035. Value: 0x0, Memory Address: 0x3FD.
FCS Warning (ID 26): reading from reserved register at pc = 0xc035. Value: 0x0, Memory Address: 0x3FE.
FCS Warning (ID 26): reading from reserved register at pc = 0xc035. Value: 0x0, Memory Address: 0x3FF.
FCS Warning (ID 26): reading from reserved register at pc = 0x1. Value: 0x0, Memory Address: 0x4. MEBI module is affected.
FCS Warning (ID 26): reading from reserved register at pc = 0x1. Value: 0x0, Memory Address: 0x5. MEBI module is affected.
ILLEGAL_BP

请问版主这是怎么回事呢??

其次,版主在以前的帖子中提到,尽量不要用中断嵌套,说太占用资源,这是为什么?
谢谢!
作者: bozai020141    时间: 2007-5-8 00:30

程序如下

#include /* common defines and macros */
#include /* derivative information */
#pragma LINK_INFO DERIVATIVE "mc9s12dg128b"


void Time_Init(void);


void main(void) {
DDRA=0x01;
DDRB=0x01;
Time_Init();

EnableInterrupts;

for(;;) {}

}


void Time_Init(void){
TSCR2=0x07;
TIOS=0xff; //定义time0到time3口为输入捕捉,time4到time7为输出比较
TIE=0x07; //打开time0,time1,time2中断
TSCR1=0x80; //时钟模块使能位;
TFLG1=0xFF; //清除标志位
TC1=TCNT+5000;
TC2=TCNT+7000;
}



#pragma CODE_SEG NON_BANKED
void interrupt 8 time0(void){

TFLG1=0x01; //清除标志位
TIE_C1I=1;
TIE_C2I=0;
EnableInterrupts;
for(;;){
;
}
// TIE_C2I=1;
}

#pragma CODE_SEG NON_BANKED
void interrupt 9 time1(void){
TFLG1=0x02;
TC1=TC1+5000;
PORTB_BIT0=~PORTB_BIT0;

}

#pragma CODE_SEG NON_BANKED
void interrupt 10 time2(void){
TFLG1=0x04;
TC2=TC2+7000;
PORTA_BIT0=~PORTA_BIT0;
}
作者: strongchen    时间: 2007-5-8 09:53

中断嵌套可能使堆栈溢出了。
作者: bozai020141    时间: 2007-5-9 08:37

那如果我一定要用中断嵌套的话,有没有解决办法啊?

还有,版主在以前的帖子中提到,尽量不要用中断嵌套,说太占用资源,这是为什么?

谢谢!

作者: strongchen    时间: 2007-5-9 09:43

每次中断发生时,都会使用大量的堆栈空间用于保存重要寄存器的值和中断服务程序的局部变量。所以,中断嵌套会占用大量的资源,很容易使中断溢出。为什么一定要中断嵌套呢?

如果一定要中断嵌套,第一,可以加大堆栈空间的大小;第二,应该可以知道并控制嵌套的深度,保证堆栈不会溢出。
作者: bozai020141    时间: 2007-5-9 10:47

Thank you very much!
作者: wangnan    时间: 2008-7-12 17:52

楼主这个例子,在timer0中断里面将把timer0中断屏蔽,否则有可能陷入自身嵌套,而你的timer0又是个无法退出的中断,所以导致堆栈溢出!!!

[此贴子已经被作者于2008-7-12 17:58:14编辑过]


作者: fjczd    时间: 2008-12-29 12:08

QUOTE:
以下是引用wangnan在2008-7-12 17:52:00的发言:

楼主这个例子,在timer0中断里面将把timer0中断屏蔽,否则有可能陷入自身嵌套,而你的timer0又是个无法退出的中断,所以导致堆栈溢出!!!

[此贴子已经被作者于2008-7-12 17:58:14编辑过]

用PE生成的也会遇到这样的问题么

我现在就遇到了中断嵌套的问题了,还是没解决


作者: Cathy_fu    时间: 2009-6-10 11:25

我也是遇到了这样的问题哎~还没解决呢~我只用到两个中断就开始报错,运行不下去,怎么解决呢?
作者: strongchen    时间: 2009-6-11 10:34

最好不要中断嵌套。




欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) Powered by Discuz! 7.0.0