Implement zephyr urandom and monotime (#19142)
* implement urandom for Zephyr * add monotime on zephyr Co-authored-by: Jaremy Creechley <jaremy.creechley@panthalassa.com>
This commit is contained in:
parent
bec4900165
commit
6976d18519
2 changed files with 18 additions and 1 deletions
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue