aboutsummaryrefslogtreecommitdiffstats
path: root/src/avr/timer.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/avr/timer.c')
-rw-r--r--src/avr/timer.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/avr/timer.c b/src/avr/timer.c
index 7b5facca..e96b88bf 100644
--- a/src/avr/timer.c
+++ b/src/avr/timer.c
@@ -25,6 +25,15 @@ timer_from_us(uint32_t us)
return us * (F_CPU / 1000000);
}
+// Return true if time1 is before time2. Always use this function to
+// compare times as regular C comparisons can fail if the counter
+// rolls over.
+uint8_t
+timer_is_before(uint32_t time1, uint32_t time2)
+{
+ return (int32_t)(time1 - time2) < 0;
+}
+
static inline uint16_t
timer_get(void)
{