From 914205ca85a2e941a2b0e0dc11bcf8cf34930efc Mon Sep 17 00:00:00 2001 From: Andy Ross Date: Tue, 10 Mar 2020 15:26:38 -0700 Subject: [PATCH] kernel/timeout: Add k_uptime_ticks() API Add a call to get the system tick count as an official API (and redefine the existing millisecond API in terms of it). Sophisticated applications need to be able to count ticks directly, and the newer timeout API supports that. Uptime should too, for symmetry. Signed-off-by: Andy Ross --- include/kernel.h | 16 +++++++++++++++- kernel/timeout.c | 10 +++++----- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/include/kernel.h b/include/kernel.h index e9691db95a2..e7be91cc23e 100644 --- a/include/kernel.h +++ b/include/kernel.h @@ -2057,6 +2057,17 @@ static inline void *z_impl_k_timer_user_data_get(struct k_timer *timer) * @{ */ +/** + * @brief Get system uptime, in ticks. + * + * This routine returns the elapsed time since the system booted, in + * ticks (c.f. :option:`CONFIG_SYS_CLOCK_TICKS_PER_SEC`), which is the + * fundamental unit of resolution of kernel timekeeping. + * + * @return Current uptime in ticks. + */ +__syscall s64_t k_uptime_ticks(void); + /** * @brief Get system uptime. * @@ -2072,7 +2083,10 @@ static inline void *z_impl_k_timer_user_data_get(struct k_timer *timer) * * @return Current uptime in milliseconds. */ -__syscall s64_t k_uptime_get(void); +static inline s64_t k_uptime_get(void) +{ + return k_ticks_to_ms_floor64(k_uptime_ticks()); +} /** * @brief Enable clock always on in tickless kernel diff --git a/kernel/timeout.c b/kernel/timeout.c index cd797abdbce..eb1418000ff 100644 --- a/kernel/timeout.c +++ b/kernel/timeout.c @@ -268,17 +268,17 @@ u32_t z_tick_get_32(void) #endif } -s64_t z_impl_k_uptime_get(void) +s64_t z_impl_k_uptime_ticks(void) { - return k_ticks_to_ms_floor64(z_tick_get()); + return z_tick_get(); } #ifdef CONFIG_USERSPACE -static inline s64_t z_vrfy_k_uptime_get(void) +static inline s64_t z_vrfy_k_uptime_ticks(void) { - return z_impl_k_uptime_get(); + return z_impl_k_uptime_ticks(); } -#include +#include #endif /* Returns the uptime expiration (relative to an unlocked "now"!) of a