+#define TIMER_TICKS_PER_SEC (TIMER_TICKS_PER_MSEC * 1000)
+
+/*! Number of ticks per microsecond */
+#define TIMER_TICKS_PER_USEC ((TIMER_TICKS_PER_MSEC + 500) / 1000)
+
+
+extern volatile ticks_t _clock;
+
+/*!
+ * \brief Return the system tick counter (expressed in ticks)
+ *
+ * The result is guaranteed to increment monotonically,
+ * but client code must be tolerant with respect to overflows.
+ *
+ * The following code is safe:
+ *
+ * \code
+ * ticks_t tea_start_time = timer_clock();
+ *
+ * boil_water();
+ *
+ * if (timer_clock() - tea_start_time > TEAPOT_DELAY)
+ * printf("Your tea, Sir.\n");
+ * \endcode
+ *
+ * \note This function must disable interrupts on 8/16bit CPUs because the
+ * clock variable is larger than the processor word size and can't
+ * be copied atomically.
+ */
+INLINE ticks_t timer_clock(void)
+{
+ ticks_t result;
+
+ ATOMIC(result = _clock);
+
+ return result;
+}
+
+/*!
+ * Faster version of timer_clock(), to be called only when the timer
+ * interrupt is disabled (DISABLE_INTS) or overridden by a
+ * higher-priority or non-nesting interrupt.
+ *
+ * \sa timer_ticks
+ */
+INLINE ticks_t timer_clock_unlocked(void)
+{
+ return _clock;
+}
+
+
+
+//TODO: take care of slow timers so add convertions for seconds to ticks and viceversa.
+
+/*! Convert \a ms [ms] to ticks */
+INLINE ticks_t ms_to_ticks(mtime_t ms)
+{
+ return ms * TIMER_TICKS_PER_MSEC;
+}
+
+/*! Convert \a us [us] to ticks */
+INLINE ticks_t us_to_ticks(utime_t us)
+{
+#if TIMER_TICKS_PER_MSEC < 10000
+ return (us * TIMER_TICKS_PER_MSEC + 500) / 1000;
+#else
+ return (us * TIMER_TICKS_PER_USEC);
+#endif
+}
+
+/*! Convert \a ticks [ticks] to ms */
+INLINE mtime_t ticks_to_ms(ticks_t ticks)
+{
+ return (ticks + TIMER_TICKS_PER_MSEC / 2) / TIMER_TICKS_PER_MSEC;
+}
+
+/*! Convert \a ticks [ticks] to us */
+INLINE utime_t ticks_to_us(ticks_t ticks)
+{
+#if TIMER_TICKS_PER_USEC > 10
+ return (ticks / TIMER_TICKS_PER_USEC);
+#else
+ return (ticks * 1000 + TIMER_TICKS_PER_MSEC / 2) / TIMER_TICKS_PER_MSEC;
+#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 * ((TIMER_HW_HPTICKS_PER_SEC + 500000UL) / 1000000UL));
+ #else
+ return((us * TIMER_HW_HPTICKS_PER_SEC + 500000UL) / 1000000UL);
+ #endif /* TIMER_HW_HPTICKS_PER_SEC > 10000000UL */
+}
+
+/*! Convert \a hpticks [hptime] to usec */
+INLINE utime_t hptime_to_us(hptime_t hpticks)
+{
+ #if TIMER_HW_HPTICKS_PER_SEC < 100000UL
+ return(hpticks * (1000000UL / TIMER_HW_HPTICKS_PER_SEC));
+ #else
+ return((hpticks * 1000000UL) / TIMER_HW_HPTICKS_PER_SEC);
+ #endif /* TIMER_HW_HPTICKS_PER_SEC < 100000UL */
+}