不要中断中断对Arduino的其他中断? [英] Do interrupts interrupt other interrupts on Arduino?

查看:1601
本文介绍了不要中断中断对Arduino的其他中断?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Arduino的乌诺(真棒小装置!)。它有两个中断;我们姑且称之为 0 1 即可。我附加处理程序中断0和一个不同中断1,使用 attachInterrupt():<一href=\"http://www.arduino.cc/en/Reference/AttachInterrupt\">http://www.arduino.cc/en/Reference/AttachInterrupt.

I have an Arduino Uno (awesome little device!). It has two interrupts; let's call them 0 and 1. I attach a handler to interrupt 0 and a different one to interrupt 1, using attachInterrupt() : http://www.arduino.cc/en/Reference/AttachInterrupt.

中断 0,将触发并调用它的处理程序,它做一些数字运算。如果中断 0 的处理程序仍在执行时中断的 1 被触发时,会发生什么?

Interrupt 0 is triggered and it calls its handler, which does some number crunching. If interrupt 0's handler is still executing when interrupt 1 is triggered, what will happen?

将中断 1 中断中断 0 或将中断的 1 等到中断 0 的处理程序是执行完毕?

Will interrupt 1 interrupt interrupt 0, or will interrupt 1 wait until interrupt 0's handler is done executing?

请注意,这个问题具体涉及的Arduino。

Please note that this question specifically relates to Arduino.

推荐答案

在Arduino的(又名AVR)的硬件,嵌套中断不会发生,除非你故意创造条件让它发生。

On Arduino (aka AVR) hardware, nested interrupts don't happen unless you intentionally create the conditions to allow it to happen.

从AVR-lib目录下:

From avr-lib:

AVR的硬件清零SREG的全局中断标志进入一个中断向量。因此,一般的中断将保持在处理程序中禁用,直到处理程序退出,其中,RETI指令(即由编译器发出的正常功能尾声的中断处理程序的一部分),最终将重新启用进一步中断。出于这个原因,中断处理程序通常不嵌套。对于大多数的中断处理程序,这是所期望的行为,对一些人来说是为了甚至需​​要prevent无限递归中断(如UART中断,或电平触发外部中断)。在极少数情况下,尽管它可能会希望尽早在中断处理程序中重新启用全局中断标志,为了不推迟任何其他中断超过绝对需要。这可以用一个SEI()指令就在中断处理程序的开始做,但是这仍然让编译器生成的函数序幕禁用全局中断运行里面几条指令。

The AVR hardware clears the global interrupt flag in SREG before entering an interrupt vector. Thus, normally interrupts will remain disabled inside the handler until the handler exits, where the RETI instruction (that is emitted by the compiler as part of the normal function epilogue for an interrupt handler) will eventually re-enable further interrupts. For that reason, interrupt handlers normally do not nest. For most interrupt handlers, this is the desired behaviour, for some it is even required in order to prevent infinitely recursive interrupts (like UART interrupts, or level-triggered external interrupts). In rare circumstances though it might be desired to re-enable the global interrupt flag as early as possible in the interrupt handler, in order to not defer any other interrupt more than absolutely needed. This could be done using an sei() instruction right at the beginning of the interrupt handler, but this still leaves few instructions inside the compiler-generated function prologue to run with global interrupts disabled.

(来源: http://linux.die.net/man/3/avr_interrupts

这篇关于不要中断中断对Arduino的其他中断?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆