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

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

View File

@@ -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
*