Skip to content

Commit 914205c

Browse files
Andy Rossnashif
authored andcommitted
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 <[email protected]>
1 parent 5a5d3da commit 914205c

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

include/kernel.h

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2057,6 +2057,17 @@ static inline void *z_impl_k_timer_user_data_get(struct k_timer *timer)
20572057
* @{
20582058
*/
20592059

2060+
/**
2061+
* @brief Get system uptime, in ticks.
2062+
*
2063+
* This routine returns the elapsed time since the system booted, in
2064+
* ticks (c.f. :option:`CONFIG_SYS_CLOCK_TICKS_PER_SEC`), which is the
2065+
* fundamental unit of resolution of kernel timekeeping.
2066+
*
2067+
* @return Current uptime in ticks.
2068+
*/
2069+
__syscall s64_t k_uptime_ticks(void);
2070+
20602071
/**
20612072
* @brief Get system uptime.
20622073
*
@@ -2072,7 +2083,10 @@ static inline void *z_impl_k_timer_user_data_get(struct k_timer *timer)
20722083
*
20732084
* @return Current uptime in milliseconds.
20742085
*/
2075-
__syscall s64_t k_uptime_get(void);
2086+
static inline s64_t k_uptime_get(void)
2087+
{
2088+
return k_ticks_to_ms_floor64(k_uptime_ticks());
2089+
}
20762090

20772091
/**
20782092
* @brief Enable clock always on in tickless kernel

kernel/timeout.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -268,17 +268,17 @@ u32_t z_tick_get_32(void)
268268
#endif
269269
}
270270

271-
s64_t z_impl_k_uptime_get(void)
271+
s64_t z_impl_k_uptime_ticks(void)
272272
{
273-
return k_ticks_to_ms_floor64(z_tick_get());
273+
return z_tick_get();
274274
}
275275

276276
#ifdef CONFIG_USERSPACE
277-
static inline s64_t z_vrfy_k_uptime_get(void)
277+
static inline s64_t z_vrfy_k_uptime_ticks(void)
278278
{
279-
return z_impl_k_uptime_get();
279+
return z_impl_k_uptime_ticks();
280280
}
281-
#include <syscalls/k_uptime_get_mrsh.c>
281+
#include <syscalls/k_uptime_ticks_mrsh.c>
282282
#endif
283283

284284
/* Returns the uptime expiration (relative to an unlocked "now"!) of a

0 commit comments

Comments
 (0)