mirror of https://github.com/Desuuuu/klipper.git
avr: Invert diff in timer checks
Minor optimization on avr. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
e44678ceba
commit
fff73c7735
|
@ -152,8 +152,8 @@ ISR(TIMER1_COMPA_vect)
|
||||||
// Run the next software timer
|
// Run the next software timer
|
||||||
next = sched_timer_dispatch();
|
next = sched_timer_dispatch();
|
||||||
|
|
||||||
int16_t diff = next - timer_get();
|
int16_t diff = timer_get() - next;
|
||||||
if (likely(diff < 0)) {
|
if (likely(diff >= 0)) {
|
||||||
// Another timer is pending - briefly allow irqs to fire
|
// Another timer is pending - briefly allow irqs to fire
|
||||||
irq_enable();
|
irq_enable();
|
||||||
if (unlikely(TIFR1 & (1<<OCF1B)))
|
if (unlikely(TIFR1 & (1<<OCF1B)))
|
||||||
|
@ -163,7 +163,7 @@ ISR(TIMER1_COMPA_vect)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (likely(diff > TIMER_MIN_TRY_TICKS))
|
if (likely(diff <= -TIMER_MIN_TRY_TICKS))
|
||||||
// Schedule next timer normally
|
// Schedule next timer normally
|
||||||
goto done;
|
goto done;
|
||||||
|
|
||||||
|
@ -173,8 +173,8 @@ ISR(TIMER1_COMPA_vect)
|
||||||
if (unlikely(TIFR1 & (1<<OCF1B)))
|
if (unlikely(TIFR1 & (1<<OCF1B)))
|
||||||
goto force_defer;
|
goto force_defer;
|
||||||
irq_disable();
|
irq_disable();
|
||||||
diff = next - timer_get();
|
diff = timer_get() - next;
|
||||||
} while (diff >= 0);
|
} while (diff < 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
force_defer:
|
force_defer:
|
||||||
|
@ -182,15 +182,13 @@ force_defer:
|
||||||
irq_disable();
|
irq_disable();
|
||||||
uint16_t now = timer_get();
|
uint16_t now = timer_get();
|
||||||
if ((int16_t)(next - now) < (int16_t)(-timer_from_us(1000)))
|
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);
|
timer_repeat_set(now + TIMER_REPEAT_TICKS);
|
||||||
next = now + TIMER_DEFER_REPEAT_TICKS;
|
next = now + TIMER_DEFER_REPEAT_TICKS;
|
||||||
|
|
||||||
done:
|
done:
|
||||||
timer_set(next);
|
timer_set(next);
|
||||||
return;
|
return;
|
||||||
fail:
|
|
||||||
shutdown("Rescheduled timer in the past");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Periodic background task that temporarily boosts priority of
|
// Periodic background task that temporarily boosts priority of
|
||||||
|
|
Loading…
Reference in New Issue