From d4365c9a7f653f5d81c56424fe04edb4656fd1e2 Mon Sep 17 00:00:00 2001 From: sigsegv7 Date: Fri, 15 Sep 2023 23:34:48 -0400 Subject: kernel: dev: Create hpet_sleep() helper Sleep functions may wrap this helper to simplify their implementation. Signed-off-by: sigsegv7 --- sys/dev/timer/hpet.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'sys/dev/timer/hpet.c') diff --git a/sys/dev/timer/hpet.c b/sys/dev/timer/hpet.c index d276456..ab30f63 100644 --- a/sys/dev/timer/hpet.c +++ b/sys/dev/timer/hpet.c @@ -95,8 +95,8 @@ hpet_write(uint32_t reg, uint64_t val) mmio_write64(addr, val); } -int -hpet_msleep(size_t ms) +static int +hpet_sleep(uint64_t n, uint64_t units) { uint64_t caps; uint32_t period; @@ -112,7 +112,7 @@ hpet_msleep(size_t ms) period = CAP_CLK_PERIOD(caps); counter_val = hpet_read(HPET_REG_MAIN_COUNTER); - ticks = counter_val + (ms * (1000000000000 / period)); + ticks = counter_val + (n * (units / period)); while (hpet_read(HPET_REG_MAIN_COUNTER) < ticks) { spinwait_hint(); @@ -121,6 +121,12 @@ hpet_msleep(size_t ms) return 0; } +int +hpet_msleep(size_t ms) +{ + return hpet_sleep(ms, 1000000000000); +} + int hpet_init(void) { -- cgit v1.2.3