Add systick function that checks for passed ticks with correct wrap around

This commit is contained in:
Mario Hüttel 2020-05-02 19:06:42 +02:00
parent 67899c8f02
commit 88062dc8e4
2 changed files with 23 additions and 0 deletions

View File

@ -26,6 +26,7 @@
#define __SYSTICK_H__ #define __SYSTICK_H__
#include <stdint.h> #include <stdint.h>
#include <stdbool.h>
/** /**
* @brief Reload value for the systick timer. * @brief Reload value for the systick timer.
@ -65,4 +66,6 @@ void systick_wait_ms(uint32_t ms);
uint64_t systick_get_global_tick(); uint64_t systick_get_global_tick();
bool systick_ticks_have_passed(uint64_t start_timestamp, uint64_t ticks);
#endif /* __SYSTICK_H__ */ #endif /* __SYSTICK_H__ */

View File

@ -46,6 +46,26 @@ uint64_t systick_get_global_tick()
return global_tick_ms; 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 * @brief Interrupt Handler for SysTick
* *