core: Don't sleep with pending interrupts
authorJakob Gruber <jakob.gruber@gmail.com>
Wed, 1 Aug 2012 15:01:37 +0000 (17:01 +0200)
committerJakob Gruber <jakob.gruber@gmail.com>
Sun, 5 Aug 2012 11:00:53 +0000 (13:00 +0200)
commitfaf279d6a1ca0de6855269f6e302786202afdf22
treefd90dc133b9af73dc4264d78939d300dcd0cf413
parent8a362b7623ed36cb04b06fbe893e31dbc90f55ef
core: Don't sleep with pending interrupts

This avoids an issue in which we would incorrectly enter a state in
which the CPU was sleeping and interrupts were disabled. It occurred
when an interrupt was raised and a SLEEP instruction processed before
the interrupt could be serviced (due to pending wait).

There are several disadvantages: if somebody adds new code which
switches the CPU to sleeping, there's a good chance of them forgetting
to add this check. Preventing sleep even if the interrupt is masked is
probably harmless but incorrect. Finally, on a real AVR it _is_ possible
to trigger an interrupt and then go to sleep in the next instruction
before the interrupt is serviced.

I'd actually prefer fixing this by moving the CPU interrupt wakeup from
avr_raise_interrupt() to avr_service_interrupts(), but that requires
further changes to avoid sleeping during avr->run() while an interrupt
is about to be serviced.
simavr/sim/sim_core.c