33#ifndef MILLISEC_TIMER_H
34#define MILLISEC_TIMER_H
44#include <libopencm3/cm3/systick.h>
47typedef uint32_t millisec_timer_unit_t;
57 millisec_timer_unit_t set_time;
58 millisec_timer_unit_t expire_time;
69 const millisec_timer_unit_t now,
70 const millisec_timer_unit_t rel);
79 const millisec_timer_unit_t now);
90 const millisec_timer_unit_t now);
92#if defined(__ARM_ARCH) || defined(__AVR)
93#pragma GCC diagnostic ignored "-Wunused-variable"
94#pragma GCC diagnostic push
102#pragma GCC diagnostic pop
111#define MILLISEC_TIMER_SYSTICK_IT \
112 void sys_tick_handler(void) { MILLISEC_TIMER_NOW++; }
128#define MILLISEC_TIMER_AVR_TIMER0_ISR \
129 ISR(TIMER0_COMPA_vect) { MILLISEC_TIMER_NOW++; }
138#define millisec_timer_avr_timer0_setup_16MHz() \
142 TIMSK0 |= 1 << OCIE0A
static uint32_t MILLISEC_TIMER_NOW
A counter that increments every millisecond.
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.
struct __millisec_timer millisec_timer
portable millisecond timer
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