中断是否中断了Arduino的其他中断? [英] Do interrupts interrupt other interrupts on Arduino?

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

问题描述

我有一个 Arduino Uno (很棒的设备!)。它有两个中断;我们称之为 0 1 。我使用 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:


AVR硬件在进入中断向量之前清除SREG中的全局中断标志。因此,正常情况下,处理器中的中断将保持禁用,直到处理程序退出,其中RETI指令(由编译器作为中断处理程序的正常函数结尾的一部分发出)将最终重新启用进一步的中断。因此,中断处理程序通常不嵌套。对于大多数中断处理程序,这是所需的行为,有些甚至是为了防止无限递归中断(如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天全站免登陆