Add systick function that checks for passed ticks with correct wrap around
This commit is contained in:
parent
67899c8f02
commit
88062dc8e4
@ -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__ */
|
||||||
|
@ -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
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user