1 #include <lunaix/spike.h>
2 #include <lunaix/time.h>
4 #include <hal/hwtimer.h>
6 const struct hwtimer* systimer;
9 hwtimer_base_frequency()
12 return systimer->base_freq;
16 hwtimer_current_systicks()
19 return systimer->systicks();
23 hwtimer_to_ticks(u32_t value, int unit)
26 // in case system frequency is less than 1000Hz
27 if (unit != TIME_MS) {
28 return systimer->running_freq * unit * value;
31 ticks_t freq_ms = systimer->running_freq / 1000;
33 return freq_ms * value;
37 __hwtimer_ioctl(struct device* dev, u32_t req, va_list args)
39 struct hwtimer* hwt = (struct hwtimer*)dev->underlay;
52 hwtimer_init(u32_t hertz, void* tick_callback)
54 struct hwtimer* hwt_ctx = hwtimer_choose();
56 hwt_ctx->init(hwt_ctx, hertz, tick_callback);
57 hwt_ctx->running_freq = hertz;
61 struct device* timerdev = device_allocsys(NULL, hwt_ctx);
63 timerdev->ops.exec_cmd = __hwtimer_ioctl;
65 register_device(timerdev, &hwt_ctx->class, hwt_ctx->name);