1 #include <hal/hwtimer.h>
2 #include <lunaix/spike.h>
4 struct hwtimer_context* current_timer;
7 hwtimer_init(u32_t hertz, void* tick_callback)
9 struct hwtimer_context* hwt_ctx = hwtimer_choose();
11 hwt_ctx->init(hwt_ctx, hertz, tick_callback);
12 hwt_ctx->running_freq = hertz;
14 current_timer = hwt_ctx;
18 hwtimer_base_frequency()
20 return current_timer->base_freq;
24 hwtimer_current_systicks()
26 return current_timer->systicks();
30 hwtimer_to_ticks(u32_t value, int unit)
32 // in case system frequency is less than 1000Hz
33 if (unit != TIME_MS) {
34 return current_timer->running_freq * unit * value;
37 ticks_t freq_ms = current_timer->running_freq / 1000;
39 return freq_ms * value;