Systick: Add function to calculate uptime in days, hours, minutes, and seconds from global tick
This commit is contained in:
parent
43b4fd1e77
commit
0cdc7448e4
@ -71,6 +71,8 @@ void systick_wait_ms(uint32_t ms);
|
|||||||
|
|
||||||
uint64_t systick_get_global_tick();
|
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);
|
bool systick_ticks_have_passed(uint64_t start_timestamp, uint64_t ticks);
|
||||||
|
|
||||||
#endif /* __SYSTICK_H__ */
|
#endif /* __SYSTICK_H__ */
|
||||||
|
@ -53,6 +53,35 @@ uint64_t systick_get_global_tick()
|
|||||||
return temp;
|
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)
|
bool __attribute__((optimize("O3"))) systick_ticks_have_passed(uint64_t start_timestamp, uint64_t ticks)
|
||||||
{
|
{
|
||||||
uint64_t end_timestamp = start_timestamp + ticks;
|
uint64_t end_timestamp = start_timestamp + ticks;
|
||||||
|
Loading…
Reference in New Issue
Block a user