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

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

问题描述

我有一个 Arduino Uno(很棒的小设备!).它有两个中断;我们称它们为 01.我使用 attachInterrupt() 将一个处理程序附加到中断 0,将另一个处理程序附加到中断 1: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 指令(由编译器作为中断处理程序的正常功能结尾的一部分发出)最终将重新启用进一步的中断.因此,中断处理程序通常不会嵌套.对于大多数中断处理程序,这是所需的行为,对于某些甚至需要它以防止无限递归中断(如 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天全站免登陆