aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2017-04-03 10:10:35 -0400
committerKevin O'Connor <kevin@koconnor.net>2017-04-03 10:39:49 -0400
commitfff73c7735618923b865fc93b3187ff323f2a57e (patch)
treed0f5fb0a376bf795b013b97181091dde58d6443a
parente44678ceba9095637af477c3cc6e41c8724c01f4 (diff)
downloadkutter-fff73c7735618923b865fc93b3187ff323f2a57e.tar.gz
kutter-fff73c7735618923b865fc93b3187ff323f2a57e.tar.xz
kutter-fff73c7735618923b865fc93b3187ff323f2a57e.zip
avr: Invert diff in timer checks
Minor optimization on avr. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
-rw-r--r--src/avr/timer.c14
1 files changed, 6 insertions, 8 deletions
diff --git a/src/avr/timer.c b/src/avr/timer.c
index 1c4d03a9..a0acac73 100644
--- a/src/avr/timer.c
+++ b/src/avr/timer.c
@@ -152,8 +152,8 @@ ISR(TIMER1_COMPA_vect)
// Run the next software timer
next = sched_timer_dispatch();
- int16_t diff = next - timer_get();
- if (likely(diff < 0)) {
+ int16_t diff = timer_get() - next;
+ if (likely(diff >= 0)) {
// Another timer is pending - briefly allow irqs to fire
irq_enable();
if (unlikely(TIFR1 & (1<<OCF1B)))
@@ -163,7 +163,7 @@ ISR(TIMER1_COMPA_vect)
continue;
}
- if (likely(diff > TIMER_MIN_TRY_TICKS))
+ if (likely(diff <= -TIMER_MIN_TRY_TICKS))
// Schedule next timer normally
goto done;
@@ -173,8 +173,8 @@ ISR(TIMER1_COMPA_vect)
if (unlikely(TIFR1 & (1<<OCF1B)))
goto force_defer;
irq_disable();
- diff = next - timer_get();
- } while (diff >= 0);
+ diff = timer_get() - next;
+ } while (diff < 0);
}
force_defer:
@@ -182,15 +182,13 @@ force_defer:
irq_disable();
uint16_t now = timer_get();
if ((int16_t)(next - now) < (int16_t)(-timer_from_us(1000)))
- goto fail;
+ shutdown("Rescheduled timer in the past");
timer_repeat_set(now + TIMER_REPEAT_TICKS);
next = now + TIMER_DEFER_REPEAT_TICKS;
done:
timer_set(next);
return;
-fail:
- shutdown("Rescheduled timer in the past");
}
// Periodic background task that temporarily boosts priority of