sys_clock: Fix unsafe tick count usage
The system tick count is a 64 bit quantity that gets updated from
interrupt context, meaning that it's dangerously non-atomic and has to
be locked. The core kernel clock code did this right.
But the value was also exposed to the rest of the universe as a global
variable, and virtually nothing else was doing this correctly. Even
in the timer ISRs themselves, the interrupts may be themselves
preempted (most of our architectures support nested interrupts) by
code that wants to set timeouts and inspect system uptime.
Define a z_tick_{get,set}() API, eliminate the old variable, and make
sure everyone uses the right mechanism.
Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
diff --git a/include/sys_clock.h b/include/sys_clock.h
index 3a6bdae..abcda46 100644
--- a/include/sys_clock.h
+++ b/include/sys_clock.h
@@ -185,7 +185,32 @@
* @} end defgroup clock_apis
*/
-extern volatile u64_t _sys_clock_tick_count;
+/**
+ *
+ * @brief Return the lower part of the current system tick count
+ *
+ * @return the current system tick count
+ *
+ */
+u32_t z_tick_get_32(void);
+
+/**
+ *
+ * @brief Return the current system tick count
+ *
+ * @return the current system tick count
+ *
+ */
+s64_t z_tick_get(void);
+
+/**
+ *
+ * @brief Sets the current system tick count
+ *
+ * @param ticks Ticks since system start
+ *
+ */
+void z_tick_set(s64_t ticks);
/* timeouts */