simulator: fix timer overflow problem

Next-interrupt-time calculations were made in 16-bit registers but
moved to 32-bit ones for convenience.  But they forgot to round off
at 16-bits.  Force the round-off so we do not wait forever.
This commit is contained in:
Phil Hord 2013-10-29 07:52:23 -04:00 committed by Markus Hitter
parent 1e2824d56b
commit 18ea439788
1 changed files with 2 additions and 2 deletions

View File

@ -115,13 +115,13 @@ void sim_setTimer() {
//-- Calculate time in clock ticks until next timer events //-- Calculate time in clock ticks until next timer events
if (TIMSK1 & MASK(OCIE1A)) { if (TIMSK1 & MASK(OCIE1A)) {
sim_debug("Timer1 Interrupt A: Enabled"); sim_debug("Timer1 Interrupt A: Enabled");
nextA = OCR1A - now; nextA = (OCR1A - now) & 0xFFFF ;
// 0 = No timer; 1-0x10000 = time until next occurrence // 0 = No timer; 1-0x10000 = time until next occurrence
if ( ! nextA) nextA = 0x10000; if ( ! nextA) nextA = 0x10000;
} }
if (TIMSK1 & MASK(OCIE1B)) { if (TIMSK1 & MASK(OCIE1B)) {
sim_debug("Timer1 Interrupt B: Enabled"); sim_debug("Timer1 Interrupt B: Enabled");
nextB = OCR1B - now; nextB = (OCR1B - now) & 0xFFFF;
// 0 = No timer; 1-0x10000 = time until next occurrence // 0 = No timer; 1-0x10000 = time until next occurrence
if ( ! nextB) nextB = 0x10000; if ( ! nextB) nextB = 0x10000;
} }