Systick: Add function to calculate uptime in days, hours, minutes, and seconds from global tick

This commit is contained in:
Mario Hüttel 2020-06-14 13:35:47 +02:00
parent 43b4fd1e77
commit 0cdc7448e4
2 changed files with 31 additions and 0 deletions

View File

@ -71,6 +71,8 @@ void systick_wait_ms(uint32_t ms);
uint64_t systick_get_global_tick();
void systick_get_uptime_from_tick(uint32_t *days, uint32_t *hours, uint32_t *minutes, uint32_t *seconds);
bool systick_ticks_have_passed(uint64_t start_timestamp, uint64_t ticks);
#endif /* __SYSTICK_H__ */

View File

@ -53,6 +53,35 @@ uint64_t systick_get_global_tick()
return temp;
}
void systick_get_uptime_from_tick(uint32_t *days, uint32_t *hours, uint32_t *minutes, uint32_t *seconds)
{
uint64_t tick_secs;
uint32_t secs;
uint32_t mins;
uint32_t hs;
uint32_t ds;
tick_secs = systick_get_global_tick() / 1000;
secs = tick_secs % 60;
tick_secs /= 60;
mins = tick_secs % 60;
tick_secs /= 60;
hs = tick_secs % 60;
tick_secs /= 24;
ds = tick_secs;
if (days)
*days = ds;
if (hours)
*hours = hs;
if (minutes)
*minutes = mins;
if (seconds)
*seconds = secs;
}
bool __attribute__((optimize("O3"))) systick_ticks_have_passed(uint64_t start_timestamp, uint64_t ticks)
{
uint64_t end_timestamp = start_timestamp + ticks;