加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c – AVR编程,中断处理

发布时间:2020-12-16 05:05:28 所属栏目:百科 来源:网络整理
导读:我开发了一个带有atmega168a-pu和中断的C应用程序.我使用以下中断: ISR(TIMER0_COMPA_vect);ISR(TIMER0_COMPB_vect);ISR (TIMER2_COMPA_vect);ISR(SPI_STC_vect);ISR(TIMER1_COMPA_vect);ISR (PCINT1_vect); 我的代码看起来像 int main(void){///initializa
我开发了一个带有atmega168a-pu和中断的C应用程序.我使用以下中断:
ISR(TIMER0_COMPA_vect);
ISR(TIMER0_COMPB_vect);
ISR (TIMER2_COMPA_vect);
ISR(SPI_STC_vect);
ISR(TIMER1_COMPA_vect);
ISR (PCINT1_vect);

我的代码看起来像

int main(void){
///initialization etc.
   sei();
   while(1){
    ///do some stuff and wait the interrupts
   }
return 0;
}

我想在发生中断时阻止所有其他中断,并在退出中断功能之前启用中断.

您能否在代码片段中解释一下我是如何做到的?

编辑:http://www.nongnu.org/avr-libc/user-manual/optimization.html#optim_code_reorder表示此类使用会导致重新加载问题.

function(){
  cli();
  ..
  sei();
}

解决方法

我在这里发布的上一个答案是基于原始问题,没有提到avr-gcc的重新排序问题.显然,很久以前,我曾与AVR合作,但有一个关于禁用中断的铃声响起

修订了问题的答案

保护中断不被中断

Atmel写了关于数据手册中的中断处理:

When an interrupt occurs,the Global Interrupt Enable I-bit is cleared and all interrupts are disabled.
The user software can write logic one to the I-bit to enable nested interrupts. All enabled
interrupts can then interrupt the current interrupt routine. The I-bit is automatically set when a
Return from Interrupt instruction – RETI – is executed.

因此,您要求的行为已经在硬件中实现.

重新排序问题

我也对这个重新排序问题做了一些调查.显然,这是否是编译器的错误存在巨大的分歧.似乎重新排序的主要风险是中断被禁用的时间比预期的要长.在我的研究期间,我没有找到解决方案,除了解决方案导致更多的负载/存储活动,这是我认为不是一个真正的选择.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读