--- /dev/null
+#include "clock.h"
+#include "timer.h"
+
+#ifndef CLOCK_TIMER
+#error CLOCK_TIMER must be defined
+#endif
+
+static volatile uint32_t time = 0;
+
+void clock_start()
+{
+ timer_start_hz(CLOCK_TIMER, CLOCK_RATE, 1);
+}
+
+void clock_stop()
+{
+ timer_stop(CLOCK_TIMER);
+}
+
+uint32_t clock_get()
+{
+ cli();
+ uint32_t t = time;
+ sei();
+ return t;
+}
+
+void tick()
+{
+ ++time;
+}
+
+#define SET_CLOCK_CALLBACK(n) TIMER_SET_CALLBACK(n, tick)
+SET_CLOCK_CALLBACK(CLOCK_TIMER)