From 480a1dc59a883251019262147a8c306e98599436 Mon Sep 17 00:00:00 2001 From: Jack Rosenthal Date: Wed, 23 Sep 2020 08:43:26 -0600 Subject: zephyr: shim in the timer module This enables building timer.c in the Zephyr shim. In addition, we provide definitions for the symbols __hw_clock_source_read64 and __hw_clock_event_get defined for Zephyr to provide times to the CrOS EC. The event timer does not make sense for Zephyr code, but we need it defined to prevent link errors (timerinfo uses it). Perhaps the solution to this is to add a new config option (e.g., CONFIG_EVENT_TIMER) which can be used to selectively enable/disable the event timer in the CrOS EC. But punting this work for now and just adding a fake definition. BUG=b:167590251 BRANCH=none TEST=compile for posix-ec, run gettime and timerinfo commands Signed-off-by: Jack Rosenthal Change-Id: I58990a6295625f9c34ec080360470431b46155bd Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2427100 Reviewed-by: Jett Rink --- common/timer.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'common') diff --git a/common/timer.c b/common/timer.c index b4c31360b6..6a210ee9da 100644 --- a/common/timer.c +++ b/common/timer.c @@ -6,6 +6,7 @@ /* Timer module for Chrome EC operating system */ #include "atomic.h" +#include "common.h" #include "console.h" #include "hooks.h" #include "hwtimer.h" @@ -15,6 +16,13 @@ #include "timer.h" #include "watchdog.h" +#ifdef CONFIG_ZEPHYR +#include /* For k_usleep() */ +#else +extern __error("k_usleep() should only be called from Zephyr code") +int32_t k_usleep(int32_t); +#endif /* CONFIG_ZEPHYR */ + #define TIMER_SYSJUMP_TAG 0x4d54 /* "TM" */ /* High 32-bits of the 64-bit timestamp counter. */ @@ -154,7 +162,15 @@ void timer_cancel(task_id_t tskid) void usleep(unsigned us) { uint32_t evt = 0; - uint32_t t0 = __hw_clock_source_read(); + uint32_t t0; + + if (IS_ENABLED(CONFIG_ZEPHYR)) { + while (us) + us = k_usleep(us); + return; + } + + t0 = __hw_clock_source_read(); /* If task scheduling has not started, just delay */ if (!task_start_called()) { -- cgit v1.2.1