diff options
author | Keith Short <keithshort@chromium.org> | 2021-01-13 15:36:03 -0700 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-01-29 21:57:42 +0000 |
commit | 40b2572cf845020c9380fb7052af5a2d804ac1c9 (patch) | |
tree | a536fe731586f903f2ffb4406793ad606ce5948b | |
parent | 46622826a247f5e2ee3d487861ee9d192bd1086e (diff) | |
download | chrome-ec-40b2572cf845020c9380fb7052af5a2d804ac1c9.tar.gz |
zephyr: add HOOKS task
Enable the HOOKS task so the periodic HOOK_TICK and HOOK_SECONDS are
called.
HOOK_TICK is required by the PWM LED support.
BUG=b:174851299
BRANCH=none
TEST=make buildall, zmake testall
Signed-off-by: Keith Short <keithshort@chromium.org>
Change-Id: Id00f38833d05e32b921d92d2441831058294c994
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2636481
Reviewed-by: Jack Rosenthal <jrosenth@chromium.org>
-rw-r--r-- | zephyr/Kconfig.tasks | 20 | ||||
-rw-r--r-- | zephyr/app/ec/Kconfig | 9 | ||||
-rw-r--r-- | zephyr/projects/volteer/boards/arm/volteer/volteer_defconfig | 6 | ||||
-rw-r--r-- | zephyr/shim/include/config_chip.h | 3 | ||||
-rw-r--r-- | zephyr/shim/include/shimmed_task_id.h | 3 | ||||
-rw-r--r-- | zephyr/shim/include/shimmed_tasks.h | 4 | ||||
-rw-r--r-- | zephyr/shim/src/hooks.c | 37 |
7 files changed, 81 insertions, 1 deletions
diff --git a/zephyr/Kconfig.tasks b/zephyr/Kconfig.tasks index 96795fbe94..bd10d35259 100644 --- a/zephyr/Kconfig.tasks +++ b/zephyr/Kconfig.tasks @@ -68,6 +68,26 @@ config TASK_CHIPSET_STACK_SIZE endif # HAS_TASK_CHIPSET +config HAS_TASK_HOOKS + bool "Hooks task" + default y + help + This required task runs periodic routines connected to the HOOK_TICK + and HOOK_SECOND events. This task is responsible for running + deferred routines. + +if HAS_TASK_HOOKS + +config TASK_HOOKS_STACK_SIZE + hex "Stack size" + default 0x400 + help + The stack size of the hooks task. + + See b/176180736 for checking these stack sizes. + +endif # HAS_TASK_HOOKS + config HAS_TASK_HOSTCMD bool "Host-command task" depends on PLATFORM_EC_HOSTCMD diff --git a/zephyr/app/ec/Kconfig b/zephyr/app/ec/Kconfig index 44f8690f64..eed08f5b8d 100644 --- a/zephyr/app/ec/Kconfig +++ b/zephyr/app/ec/Kconfig @@ -42,6 +42,15 @@ config CROS_EC_ACTIVE_COPY When the active copy name is output to a console, this string will be displayed. +config CROS_EC_HOOK_TICK_INTERVAL + int "The interval time for the HOOK_TICK" + default 250000 + help + Specificies the interval time for the HOOK_TICK, specified in + microseconds. Modules register with HOOK_TICK to be called + periodically by the HOOKS task. The interval must be shorter than + 1 second and is set according the EC chipset's sleep requirements. + # When building for the host, we still need values for the various memory # sizes, though they aren't actually used, so just set some reasonable-looking # values and then ignore them. diff --git a/zephyr/projects/volteer/boards/arm/volteer/volteer_defconfig b/zephyr/projects/volteer/boards/arm/volteer/volteer_defconfig index 7670ba7228..608c7891af 100644 --- a/zephyr/projects/volteer/boards/arm/volteer/volteer_defconfig +++ b/zephyr/projects/volteer/boards/arm/volteer/volteer_defconfig @@ -1,4 +1,6 @@ -# SPDX-License-Identifier: Apache-2.0 +# Copyright 2021 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. # Zephyr Kernel Configuration CONFIG_SOC_SERIES_NPCX7=y @@ -52,3 +54,5 @@ CONFIG_CROS_EC_RW_MEM_OFF=0x40000 # (CONFIG_CROS_EC_FLASH_SIZE - CONFIG_CROS_EC_RW_MEM_OFF - # CONFIG_CROS_EC_RO_MEM_OFF) CONFIG_CROS_EC_RW_SIZE=0x40000 + +CONFIG_CROS_EC_HOOK_TICK_INTERVAL=200000 diff --git a/zephyr/shim/include/config_chip.h b/zephyr/shim/include/config_chip.h index 4d66c158b3..ce9063d4f9 100644 --- a/zephyr/shim/include/config_chip.h +++ b/zephyr/shim/include/config_chip.h @@ -21,6 +21,9 @@ #define CONFIG_ZEPHYR #define CHROMIUM_EC +/* EC chipset configuration */ +#define HOOK_TICK_INTERVAL CONFIG_CROS_EC_HOOK_TICK_INTERVAL + /* Chipset and power configuration */ #ifdef CONFIG_AP_X86_INTEL_CML #define CONFIG_CHIPSET_COMETLAKE diff --git a/zephyr/shim/include/shimmed_task_id.h b/zephyr/shim/include/shimmed_task_id.h index f0999834cc..3b66c03168 100644 --- a/zephyr/shim/include/shimmed_task_id.h +++ b/zephyr/shim/include/shimmed_task_id.h @@ -40,6 +40,9 @@ typedef uint8_t task_id_t; COND_CODE_1(HAS_TASK_MOTIONSENSE, \ (CROS_EC_TASK(MOTIONSENSE, motion_sense_task, 0, \ CONFIG_TASK_MOTIONSENSE_STACK_SIZE)), ()) \ + COND_CODE_1(HAS_TASK_HOOKS, \ + (CROS_EC_TASK(HOOKS, hook_task, 0, \ + CONFIG_TASK_HOOKS_STACK_SIZE)), ()) \ COND_CODE_1(HAS_TASK_HOSTCMD, \ (CROS_EC_TASK(HOSTCMD, host_command_task, 0, \ CONFIG_TASK_HOSTCMD_STACK_SIZE)), ()) \ diff --git a/zephyr/shim/include/shimmed_tasks.h b/zephyr/shim/include/shimmed_tasks.h index 4db1672a30..631b3fcb16 100644 --- a/zephyr/shim/include/shimmed_tasks.h +++ b/zephyr/shim/include/shimmed_tasks.h @@ -18,6 +18,10 @@ #define HAS_TASK_CHIPSET 1 #endif /* CONFIG_HAS_TASK_CHIPSET */ +#ifdef CONFIG_HAS_TASK_HOOKS +#define HAS_TASK_HOOKS 1 +#endif /* CONFIG_HAS_TASK_HOOKS */ + #ifdef CONFIG_HAS_TASK_HOSTCMD #define HAS_TASK_HOSTCMD 1 #define CONFIG_HOSTCMD_EVENTS diff --git a/zephyr/shim/src/hooks.c b/zephyr/shim/src/hooks.c index e4b1ea8791..179f35eef4 100644 --- a/zephyr/shim/src/hooks.c +++ b/zephyr/shim/src/hooks.c @@ -9,6 +9,8 @@ #include "common.h" #include "console.h" #include "hooks.h" +#include "task.h" +#include "timer.h" #define DEFERRED_STACK_SIZE 1024 @@ -90,3 +92,38 @@ void hook_notify(enum hook_type type) for (p = hook_registry[type]; p; p = p->next) p->routine(); } + +void hook_task(void *u) +{ + /* Periodic hooks will be called first time through the loop */ + static uint64_t last_second = -SECOND; + static uint64_t last_tick = -HOOK_TICK_INTERVAL; + + while (1) { + uint64_t t = get_time().val; + int next = 0; + + if (t - last_tick >= HOOK_TICK_INTERVAL) { + hook_notify(HOOK_TICK); + last_tick = t; + } + + if (t - last_second >= SECOND) { + hook_notify(HOOK_SECOND); + last_second = t; + } + + /* Calculate when next tick needs to occur */ + t = get_time().val; + if (last_tick + HOOK_TICK_INTERVAL > t) + next = last_tick + HOOK_TICK_INTERVAL - t; + + /* + * Sleep until next tick, unless we've already exceeded + * HOOK_TICK_INTERVAL. + */ + if (next > 0) + task_wait_event(next); + } +} + |