diff options
-rw-r--r-- | common/timer.c | 18 | ||||
-rw-r--r-- | zephyr/CMakeLists.txt | 1 | ||||
-rw-r--r-- | zephyr/Kconfig | 28 | ||||
-rw-r--r-- | zephyr/shim/include/config_chip.h | 22 | ||||
-rw-r--r-- | zephyr/shim/src/CMakeLists.txt | 1 | ||||
-rw-r--r-- | zephyr/shim/src/hwtimer.c | 29 |
6 files changed, 98 insertions, 1 deletions
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 <kernel.h> /* 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()) { diff --git a/zephyr/CMakeLists.txt b/zephyr/CMakeLists.txt index e13a080bd1..1959486797 100644 --- a/zephyr/CMakeLists.txt +++ b/zephyr/CMakeLists.txt @@ -28,3 +28,4 @@ add_subdirectory_ifdef(CONFIG_PLATFORM_EC "shim/src") # Shimmed modules zephyr_sources_ifdef(CONFIG_PLATFORM_EC "${PLATFORM_EC}/common/util.c") +zephyr_sources_ifdef(CONFIG_PLATFORM_EC_TIMER "${PLATFORM_EC}/common/timer.c") diff --git a/zephyr/Kconfig b/zephyr/Kconfig index e70bb57fc7..e2a5f62ff4 100644 --- a/zephyr/Kconfig +++ b/zephyr/Kconfig @@ -28,4 +28,32 @@ config ZEPHYR This should always be enabled. It's a workaround for config.h not being available in some headers. +menuconfig PLATFORM_EC_TIMER + bool "Enable the EC timer module" + default y + help + Enable compilation of the EC timer module + +if PLATFORM_EC_TIMER + +config PLATFORM_EC_TIMER_CMD_GETTIME + bool "Enable the gettime command" + default y + help + Enable the "gettime" command + +config PLATFORM_EC_TIMER_CMD_TIMERINFO + bool "Enable the timerinfo command" + default y + help + Enable the "timerinfo" command + +config PLATFORM_EC_TIMER_CMD_WAITMS + bool "Enable the waitms command" + default y + help + Enable the "waitms" command + +endif # PLATFORM_EC_TIMER + endif # PLATFORM_EC diff --git a/zephyr/shim/include/config_chip.h b/zephyr/shim/include/config_chip.h index 0929b20031..dc5f14865c 100644 --- a/zephyr/shim/include/config_chip.h +++ b/zephyr/shim/include/config_chip.h @@ -19,4 +19,26 @@ #define CONFIG_ZEPHYR #define CHROMIUM_EC +#ifdef CONFIG_PLATFORM_EC_TIMER +#define CONFIG_HWTIMER_64BIT +#define CONFIG_HW_SPECIFIC_UDELAY +#undef CONFIG_WATCHDOG + +#undef CONFIG_CMD_GETTIME +#ifdef CONFIG_PLATFORM_EC_TIMER_CMD_GETTIME +#define CONFIG_CMD_GETTIME +#endif /* CONFIG_PLATFORM_EC_TIMER_CMD_GETTIME */ + +#undef CONFIG_CMD_TIMERINFO +#ifdef CONFIG_PLATFORM_EC_TIMER_CMD_TIMERINFO +#define CONFIG_CMD_TIMERINFO +#endif /* CONFIG_PLATFORM_EC_TIMER_CMD_TIMERINFO */ + +#undef CONFIG_CMD_WAITMS +#ifdef CONFIG_PLATFORM_EC_TIMER_CMD_WAITMS +#define CONFIG_CMD_WAITMS +#endif /* CONFIG_PLATFORM_EC_TIMER_CMD_TIMERINFO */ + +#endif /* CONFIG_PLATFORM_EC_TIMER */ + #endif /* __CROS_EC_CONFIG_CHIP_H */ diff --git a/zephyr/shim/src/CMakeLists.txt b/zephyr/shim/src/CMakeLists.txt index 0d54d82ad0..5f8eaf88ad 100644 --- a/zephyr/shim/src/CMakeLists.txt +++ b/zephyr/shim/src/CMakeLists.txt @@ -3,3 +3,4 @@ # found in the LICENSE file. zephyr_sources(console.c) +zephyr_sources_ifdef(CONFIG_PLATFORM_EC_TIMER hwtimer.c) diff --git a/zephyr/shim/src/hwtimer.c b/zephyr/shim/src/hwtimer.c new file mode 100644 index 0000000000..85c72c5c59 --- /dev/null +++ b/zephyr/shim/src/hwtimer.c @@ -0,0 +1,29 @@ +/* Copyright 2020 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include <kernel.h> +#include <stdint.h> +#include <zephyr.h> + +#include "hwtimer.h" + +uint64_t __hw_clock_source_read64(void) +{ + return k_ticks_to_us_floor64(k_uptime_ticks()); +} + +uint32_t __hw_clock_event_get(void) +{ + /* + * CrOS EC event deadlines don't quite make sense in Zephyr + * terms. Evaluate what to do about this later... + */ + return 0; +} + +void udelay(unsigned us) +{ + k_busy_wait(us); +} |