Closed mhx closed 9 years ago
Not so fast, please :-)
Having the fix upstream is always better, that's why I wasn't in a hurry. Just rebased the fork so one gets this fix there, too. Thank you very much for fixing this.
I only closed this pull request as the upstream fix is different from mine :-)
Hmm. With the upstream patch applied I experience lots of interrupt losses with code which seemingly works fine on a real controller. I've opened issue #10 for it.
When an interrupt is detected and queued to be executed after the next statement and the next statement is either CLI or any other instruction that clears the global interrupt flag (OUT SREG, ...), the interrupt handler will still be called /after/ global interrupts have been disabled. This basically means that code that was meant to be uninterruptible (protected by CLI / SEI) can now be interrupted as the RETI will jump back to the first instruction after CLI and will even leave interrupts enabled.
This change aims to fix the problem by checking the current instruction before preparing interrupts. If the instructions will clear the interrupt flag, interrupt preparation will be skipped.
See also: https://savannah.nongnu.org/bugs/index.php?45941