summaryrefslogtreecommitdiff
path: root/libhw_cr/host_util.c
diff options
context:
space:
mode:
authorLuke T. Shumaker <lukeshu@lukeshu.com>2025-05-26 14:58:07 -0400
committerLuke T. Shumaker <lukeshu@lukeshu.com>2025-05-26 17:10:36 -0400
commitcf4af09e9a20e9cdaec4b3896eb6d10c27f89eba (patch)
tree016f876531f7dfc822be17f686074f0c859fd508 /libhw_cr/host_util.c
parent42fb27570262b52e2ca889030c621b5f4af76fe1 (diff)
No more (static inline) function bodies in headers
Diffstat (limited to 'libhw_cr/host_util.c')
-rw-r--r--libhw_cr/host_util.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/libhw_cr/host_util.c b/libhw_cr/host_util.c
index 7b3200c..8cacd57 100644
--- a/libhw_cr/host_util.c
+++ b/libhw_cr/host_util.c
@@ -7,6 +7,8 @@
#include <error.h> /* for error(3gnu) */
#include <signal.h> /* for SIGRTMIN, SIGRTMAX */
+#include <libhw/generic/alarmclock.h> /* for {X}S_PER_S */
+
#include "host_util.h"
int host_sigrt_alloc(void) {
@@ -19,3 +21,30 @@ int host_sigrt_alloc(void) {
error(1, 0, "SIGRTMAX exceeded");
return ret;
}
+
+host_us_time_t ns_to_host_us_time(uint64_t time_ns) {
+ host_us_time_t ret;
+ ret.tv_sec = time_ns
+ /NS_PER_S;
+ ret.tv_usec = (time_ns - ((uint64_t)ret.tv_sec)*NS_PER_S)
+ /(NS_PER_S/US_PER_S);
+ return ret;
+}
+
+host_ns_time_t ns_to_host_ns_time(uint64_t time_ns) {
+ host_ns_time_t ret;
+ ret.tv_sec = time_ns
+ /NS_PER_S;
+ ret.tv_nsec = time_ns - ((uint64_t)ret.tv_sec)*NS_PER_S;
+ return ret;
+}
+
+uint64_t ns_from_host_us_time(host_us_time_t host_time) {
+ return (((uint64_t)host_time.tv_sec) * NS_PER_S) +
+ ((uint64_t)host_time.tv_usec * (NS_PER_S/US_PER_S));
+}
+
+uint64_t ns_from_host_ns_time(host_ns_time_t host_time) {
+ return (((uint64_t)host_time.tv_sec) * NS_PER_S) +
+ ((uint64_t)host_time.tv_nsec);
+}