summary refs log tree commit diff stats
path: root/lib/std/monotimes.nim
diff options
context:
space:
mode:
authorJaremy Creechley <creechley@gmail.com>2021-11-14 03:49:30 -0800
committerGitHub <noreply@github.com>2021-11-14 12:49:30 +0100
commit6976d18519d102c9cc857a84a4b10b009c1e1a38 (patch)
tree83dc40e9c9809ffe39fa70a7b3247b31c27c2158 /lib/std/monotimes.nim
parentbec490016548e73f01317736ff8863f9ce6aab31 (diff)
downloadNim-6976d18519d102c9cc857a84a4b10b009c1e1a38.tar.gz
Implement zephyr urandom and monotime (#19142)
* implement urandom for Zephyr

* add monotime on zephyr

Co-authored-by: Jaremy Creechley <jaremy.creechley@panthalassa.com>
Diffstat (limited to 'lib/std/monotimes.nim')
-rw-r--r--lib/std/monotimes.nim7
1 files changed, 7 insertions, 0 deletions
diff --git a/lib/std/monotimes.nim b/lib/std/monotimes.nim
index bd078d7c0..5c67a5d4c 100644
--- a/lib/std/monotimes.nim
+++ b/lib/std/monotimes.nim
@@ -76,6 +76,10 @@ when defined(js):
 elif defined(posix) and not defined(osx):
   import posix
 
+when defined(zephyr):
+  proc k_uptime_ticks(): int64 {.importc: "k_uptime_ticks", header: "<kernel.h>".}
+  proc k_ticks_to_ns_floor64(ticks: int64): int64 {.importc: "k_ticks_to_ns_floor64", header: "<kernel.h>".}
+
 elif defined(windows):
   proc QueryPerformanceCounter(res: var uint64) {.
     importc: "QueryPerformanceCounter", stdcall, dynlib: "kernel32".}
@@ -98,6 +102,9 @@ proc getMonoTime*(): MonoTime {.tags: [TimeEffect].} =
     mach_timebase_info(machAbsoluteTimeFreq)
     result = MonoTime(ticks: ticks * machAbsoluteTimeFreq.numer div
       machAbsoluteTimeFreq.denom)
+  elif defined(zephyr):
+    let ticks = k_ticks_to_ns_floor64(k_uptime_ticks())
+    result = MonoTime(ticks: ticks)
   elif defined(posix):
     var ts: Timespec
     discard clock_gettime(CLOCK_MONOTONIC, ts)