gpt4 book ai didi

embedded - Arduino 上的中断会中断其他中断吗?

转载 作者:行者123 更新时间:2023-12-02 10:56:32 24 4
gpt4 key购买 nike

我有一个Arduino Uno (很棒的小设备!)。它有两个中断;我们将它们称为01。我使用 attachInterrupt() 将一个处理程序附加到中断 0,并将另一个处理程序附加到中断 1:http://www.arduino.cc/en/Reference/AttachInterrupt .

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

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

请注意,这个问题具体与 Arduino 有关。

最佳答案

在 Arduino(又名 AVR)硬件上,嵌套中断不会发生,除非您有意创建允许其发生的条件。

来自 avr-lib:

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)

关于embedded - Arduino 上的中断会中断其他中断吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5111393/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com