+#include <cfg/debug.h>
+#include <cfg/compiler.h>
+#include <appconfig.h>
+
+
+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;
+}
+