From 05f51137831bc3711ba80f52ad0586ae247ee7d3 Mon Sep 17 00:00:00 2001 From: Adam Wujek <adam.wujek@cern.ch> Date: Fri, 19 Feb 2016 11:50:34 +0100 Subject: [PATCH] userspace/libwr: add functions get_monotonic_* Add function get_monotonic_tics and get_monotonic_sec to the libwr to keep them in the one place. Signed-off-by: Adam Wujek <adam.wujek@cern.ch> --- userspace/libwr/include/libwr/util.h | 4 ++++ userspace/libwr/util.c | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/userspace/libwr/include/libwr/util.h b/userspace/libwr/include/libwr/util.h index a4703dfad..5dfe4ff33 100644 --- a/userspace/libwr/include/libwr/util.h +++ b/userspace/libwr/include/libwr/util.h @@ -8,5 +8,9 @@ void shw_udelay_init(void); void shw_udelay(uint32_t microseconds); +/* get monotonic number of useconds */ +uint64_t get_monotonic_tics(void); +/* get monotonic number of seconds */ +time_t get_monotonic_sec(void); #endif /* __LIBWR_HW_UTIL_H */ diff --git a/userspace/libwr/util.c b/userspace/libwr/util.c index 2cb9df3cf..50145ad68 100644 --- a/userspace/libwr/util.c +++ b/userspace/libwr/util.c @@ -52,3 +52,21 @@ void shw_udelay(uint32_t microseconds) for (i = 0; i < loops_per_msec * microseconds / 1000; i++) ; } + +/* get monotonic number of useconds */ +uint64_t get_monotonic_tics(void) +{ + struct timespec tv; + clock_gettime(CLOCK_MONOTONIC, &tv); + + return (uint64_t) tv.tv_sec * 1000000ULL + + (uint64_t) (tv.tv_nsec / 1000); +} + +/* get monotonic number of seconds */ +time_t get_monotonic_sec(void) +{ + struct timespec tv; + clock_gettime(CLOCK_MONOTONIC, &tv); + return tv.tv_sec; +} -- GitLab