+/**
+ * \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;
+}
+
+/** Convert \a ms [ms] to ticks. */
+INLINE ticks_t ms_to_ticks(mtime_t ms)
+{
+#if TIMER_TICKS_PER_SEC < 1000
+ /* Slow timer: avoid rounding down too much. */
+ return (ms * TIMER_TICKS_PER_SEC) / 1000;
+#else
+ /* Fast timer: don't overflow ticks_t. */
+ return ms * ((TIMER_TICKS_PER_SEC + 500) / 1000);