+/** Convert \a ticks [ticks] to us. */
+INLINE utime_t ticks_to_us(ticks_t ticks)
+{
+#if TIMER_TICKS_PER_SEC < 1000
+ /* Slow timer: avoid rounding down too much. */
+ return ((ticks * 1000) / TIMER_TICKS_PER_SEC) * 1000;
+#else
+ /* Fast timer: avoid overflowing ticks_t. */
+ return (ticks / (TIMER_TICKS_PER_SEC / 1000)) * 1000;
+#endif
+}
+
+/** Convert \a us [us] to hpticks */
+INLINE hptime_t us_to_hptime(utime_t us)
+{
+#if TIMER_HW_HPTICKS_PER_SEC > 10000000UL
+ return us * DIV_ROUND(TIMER_HW_HPTICKS_PER_SEC, 1000000UL);
+#else
+ return (us * ((TIMER_HW_HPTICKS_PER_SEC + 500) / 1000UL) + 500) / 1000UL;
+#endif
+}
+
+/** Convert \a hpticks [hptime] to usec */
+INLINE utime_t hptime_to_us(hptime_t hpticks)
+{
+#if TIMER_HW_HPTICKS_PER_SEC < 100000UL
+ return hpticks * DIV_ROUND(1000000UL, TIMER_HW_HPTICKS_PER_SEC);
+#else
+ return (hpticks * 1000UL) / DIV_ROUND(TIMER_HW_HPTICKS_PER_SEC, 1000UL);
+#endif /* TIMER_HW_HPTICKS_PER_SEC < 100000UL */
+}
+
+
+void timer_init(void);
+void timer_delayTicks(ticks_t delay);
+INLINE void timer_delay(mtime_t delay)
+{
+ timer_delayTicks(ms_to_ticks(delay));
+}
+
+#if !defined(CONFIG_TIMER_DISABLE_UDELAY)
+void timer_busyWait(hptime_t delay);
+void timer_delayHp(hptime_t delay);
+INLINE void timer_udelay(utime_t delay)
+{
+ timer_delayHp(us_to_hptime(delay));
+}
+#endif
+
+#ifndef CONFIG_TIMER_DISABLE_EVENTS
+
+#include <mware/event.h>
+
+/**
+ * The timer driver supports multiple synchronous timers
+ * that can trigger an event when they expire.