25 lines
539 B
C
25 lines
539 B
C
#pragma once
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
// Advance to the next tick. Should be called periodically.
|
|
void rt_tick_advance(void);
|
|
|
|
// Return the current tick.
|
|
unsigned long rt_tick_count(void);
|
|
|
|
static inline void rt_tick_elapse(unsigned long *ticks, unsigned long *start_tick)
|
|
{
|
|
const unsigned long now = rt_tick_count();
|
|
const unsigned long elapsed = now - *start_tick;
|
|
const unsigned long prev = *ticks;
|
|
*ticks = (elapsed > prev) ? 0 : (prev - elapsed);
|
|
*start_tick = now;
|
|
}
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|