9 const millisec_timer_unit_t now,
10 const millisec_timer_unit_t rel) {
11 timer->enabled =
true;
12 timer->set_time = now;
13 timer->expire_time = now + rel;
17 const millisec_timer_unit_t now) {
19 if ((timer->expire_time == timer->set_time) ||
20 (timer->expire_time > timer->set_time &&
21 (now >= timer->expire_time || now < timer->set_time)) ||
22 (timer->expire_time < timer->set_time && now >= timer->expire_time &&
23 now < timer->set_time)) {
24 timer->enabled =
false;
31 const millisec_timer_unit_t now) {
33 if (timer->expire_time == timer->set_time) {
35 }
else if ((timer->expire_time > timer->set_time &&
36 (now >= timer->expire_time || now < timer->set_time)) ||
37 (timer->expire_time < timer->set_time &&
38 now >= timer->expire_time && now < timer->set_time)) {
39 const millisec_timer_unit_t old_expire_time = timer->expire_time;
41 old_expire_time + (old_expire_time - timer->set_time);
42 timer->set_time = old_expire_time;
51 systick_set_clocksource(1 << STK_CSR_CLKSOURCE_LSB);
53 systick_set_reload(ahb_frequency / 1000);
54 systick_counter_enable();
55 systick_interrupt_enable();
void millisec_timer_systick_setup(uint32_t ahb_frequency)
Setup the systick timer.
void millisec_timer_set_rel(millisec_timer *timer, const millisec_timer_unit_t now, const millisec_timer_unit_t rel)
Set timer to expire in the future.
bool millisec_timer_is_expired_repeat(millisec_timer *timer, const millisec_timer_unit_t now)
Check if timer has expired & if so, re-enable for the same interval.
bool millisec_timer_is_expired(millisec_timer *timer, const millisec_timer_unit_t now)
Check if timer has expired & if so, disable it.
Portable millisecond timer.
portable millisecond timer