diff --git a/stm-firmware/include/reflow-controller/systick.h b/stm-firmware/include/reflow-controller/systick.h index fb7cf2c..5060096 100644 --- a/stm-firmware/include/reflow-controller/systick.h +++ b/stm-firmware/include/reflow-controller/systick.h @@ -26,6 +26,7 @@ #define __SYSTICK_H__ #include +#include /** * @brief Reload value for the systick timer. @@ -65,4 +66,6 @@ void systick_wait_ms(uint32_t ms); uint64_t systick_get_global_tick(); +bool systick_ticks_have_passed(uint64_t start_timestamp, uint64_t ticks); + #endif /* __SYSTICK_H__ */ diff --git a/stm-firmware/systick.c b/stm-firmware/systick.c index 55c68a8..a135d59 100644 --- a/stm-firmware/systick.c +++ b/stm-firmware/systick.c @@ -46,6 +46,26 @@ uint64_t systick_get_global_tick() return global_tick_ms; } +bool systick_ticks_have_passed(uint64_t start_timestamp, uint64_t ticks) +{ + uint64_t end_timestamp = start_timestamp + ticks; + uint64_t current_timestamp = systick_get_global_tick(); + + /* wrap around expected */ + if (end_timestamp < start_timestamp) { + /* Wrap around occured */ + if (current_timestamp < start_timestamp) { + if (current_timestamp >= end_timestamp) + return true; + } + } else { + if (current_timestamp >= end_timestamp) + return true; + } + + return false; +} + /** * @brief Interrupt Handler for SysTick *