From 4a0b4262d395ec2c46809e1584b2109f3a3d872e Mon Sep 17 00:00:00 2001 From: Randall Spangler Date: Tue, 30 Oct 2012 09:42:58 -0700 Subject: Add tick task Adds a new HOOK_TICK event which is called every 250ms (LM4) or 500ms (STM32). This will be used to consolidate a number of tasks which do small amounts of work infrequently, and previously needed their own task functions. This CL adds the tick task; subsequent CLs will consolidate watchdog and other tasks into tick hooks. BUG=chrome-os-partner:15714 BRANCH=none TEST=taskinfo shows TICK task as lowest priority Change-Id: I9068ee99d56a5bf5c12afd86ad51998c013f4954 Signed-off-by: Randall Spangler Reviewed-on: https://gerrit.chromium.org/gerrit/36908 Reviewed-by: Simon Glass --- board/bds/ec.tasklist | 1 + board/daisy/ec.tasklist | 1 + board/link/ec.tasklist | 1 + board/snow/ec.tasklist | 1 + board/spring/ec.tasklist | 1 + chip/lm4/config.h | 3 +++ chip/stm32/config.h | 3 +++ common/hooks.c | 16 ++++++++++++++++ core/cortex-m/ec.lds.S | 4 ++++ core/cortex-m/link_defs.h | 2 ++ include/hooks.h | 1 + 11 files changed, 34 insertions(+) diff --git a/board/bds/ec.tasklist b/board/bds/ec.tasklist index 2e5408dd5b..2b619f192b 100644 --- a/board/bds/ec.tasklist +++ b/board/bds/ec.tasklist @@ -15,6 +15,7 @@ * 's' is the stack size in bytes; must be a multiple of 8 */ #define CONFIG_TASK_LIST \ + TASK(TICK, hook_task, NULL, TASK_STACK_SIZE) \ TASK(WATCHDOG, watchdog_task, NULL, TASK_STACK_SIZE) \ TASK(LIGHTBAR, lightbar_task, NULL, TASK_STACK_SIZE) \ TASK(CONSOLE, console_task, NULL, TASK_STACK_SIZE) diff --git a/board/daisy/ec.tasklist b/board/daisy/ec.tasklist index dc07f50e26..25c4675852 100644 --- a/board/daisy/ec.tasklist +++ b/board/daisy/ec.tasklist @@ -15,6 +15,7 @@ * 's' is the stack size in bytes; must be a multiple of 8 */ #define CONFIG_TASK_LIST \ + TASK(TICK, hook_task, NULL, TASK_STACK_SIZE) \ TASK(WATCHDOG, watchdog_task, NULL, TASK_STACK_SIZE) \ TASK(VBOOTHASH, vboot_hash_task, NULL, TASK_STACK_SIZE) \ TASK(POWERLED, power_led_task, NULL, TASK_STACK_SIZE) \ diff --git a/board/link/ec.tasklist b/board/link/ec.tasklist index 1bfebe2463..3b32e22540 100644 --- a/board/link/ec.tasklist +++ b/board/link/ec.tasklist @@ -15,6 +15,7 @@ * 's' is the stack size in bytes; must be a multiple of 8 */ #define CONFIG_TASK_LIST \ + TASK(TICK, hook_task, NULL, TASK_STACK_SIZE) \ TASK(WATCHDOG, watchdog_task, NULL, WATCHDOG_TASK_STACK_SIZE) \ TASK(LPC, lpc_task, NULL, TASK_STACK_SIZE) \ TASK(VBOOTHASH, vboot_hash_task, NULL, LARGER_TASK_STACK_SIZE) \ diff --git a/board/snow/ec.tasklist b/board/snow/ec.tasklist index 7c99047a1f..811fa9238a 100644 --- a/board/snow/ec.tasklist +++ b/board/snow/ec.tasklist @@ -15,6 +15,7 @@ * 's' is the stack size in bytes; must be a multiple of 8 */ #define CONFIG_TASK_LIST \ + TASK(TICK, hook_task, NULL, TASK_STACK_SIZE) \ TASK(WATCHDOG, watchdog_task, NULL, 256) \ TASK(VBOOTHASH, vboot_hash_task, NULL, TASK_STACK_SIZE) \ TASK(POWERLED, power_led_task, NULL, 256) \ diff --git a/board/spring/ec.tasklist b/board/spring/ec.tasklist index 1957b14c85..474a5160d3 100644 --- a/board/spring/ec.tasklist +++ b/board/spring/ec.tasklist @@ -15,6 +15,7 @@ * 's' is the stack size in bytes; must be a multiple of 8 */ #define CONFIG_TASK_LIST \ + TASK(TICK, hook_task, NULL, TASK_STACK_SIZE) \ TASK(WATCHDOG, watchdog_task, NULL, 256) \ TASK(VBOOTHASH, vboot_hash_task, NULL, TASK_STACK_SIZE) \ TASK(PMU_TPS65090_CHARGER, pmu_charger_task, NULL, TASK_STACK_SIZE) \ diff --git a/chip/lm4/config.h b/chip/lm4/config.h index 7a39262ba6..aa40382b42 100644 --- a/chip/lm4/config.h +++ b/chip/lm4/config.h @@ -15,6 +15,9 @@ /* Use a bigger console output buffer */ #define CONFIG_UART_TX_BUF_SIZE 8192 +/* Interval between HOOK_TICK notifications */ +#define HOOK_TICK_INTERVAL (250 * MSEC) + /****************************************************************************/ /* Memory mapping */ diff --git a/chip/stm32/config.h b/chip/stm32/config.h index ddd79f39bc..bc7283396a 100644 --- a/chip/stm32/config.h +++ b/chip/stm32/config.h @@ -24,6 +24,9 @@ /* Default task stack size */ #define TASK_STACK_SIZE 488 +/* Interval between HOOK_TICK notifications */ +#define HOOK_TICK_INTERVAL (500 * MSEC) + /* support programming on-chip flash */ #define CONFIG_FLASH diff --git a/common/hooks.c b/common/hooks.c index 81d84b3d00..385f0e0478 100644 --- a/common/hooks.c +++ b/common/hooks.c @@ -7,6 +7,7 @@ #include "hooks.h" #include "link_defs.h" +#include "timer.h" #include "util.h" struct hook_ptrs { @@ -29,6 +30,7 @@ static const struct hook_ptrs hook_list[] = { {__hooks_chipset_shutdown, __hooks_chipset_shutdown_end}, {__hooks_ac_change, __hooks_ac_change_end}, {__hooks_lid_change, __hooks_lid_change_end}, + {__hooks_tick, __hooks_tick_end}, }; void hook_notify(enum hook_type type) @@ -59,3 +61,17 @@ void hook_notify(enum hook_type type) } } } + +void hook_task(void) +{ + while (1) { + uint64_t t = get_time().val; + + hook_notify(HOOK_TICK); + + /* Use up the rest of our hook tick interval */ + t = get_time().val - t; + if (t < HOOK_TICK_INTERVAL) + usleep(HOOK_TICK_INTERVAL - t); + } +} diff --git a/core/cortex-m/ec.lds.S b/core/cortex-m/ec.lds.S index be0e20fdd8..7097ced5a5 100644 --- a/core/cortex-m/ec.lds.S +++ b/core/cortex-m/ec.lds.S @@ -96,6 +96,10 @@ SECTIONS *(.rodata.HOOK_LID_CHANGE) __hooks_lid_change_end = .; + __hooks_tick = .; + *(.rodata.HOOK_TICK) + __hooks_tick_end = .; + . = ALIGN(4); *(.rodata*) diff --git a/core/cortex-m/link_defs.h b/core/cortex-m/link_defs.h index 86c6b0a311..44332c74bc 100644 --- a/core/cortex-m/link_defs.h +++ b/core/cortex-m/link_defs.h @@ -38,6 +38,8 @@ extern const struct hook_data __hooks_ac_change[]; extern const struct hook_data __hooks_ac_change_end[]; extern const struct hook_data __hooks_lid_change[]; extern const struct hook_data __hooks_lid_change_end[]; +extern const struct hook_data __hooks_tick[]; +extern const struct hook_data __hooks_tick_end[]; /* Host commands */ extern const struct host_command __hcmds[]; diff --git a/include/hooks.h b/include/hooks.h index 8124257877..2c691fb639 100644 --- a/include/hooks.h +++ b/include/hooks.h @@ -47,6 +47,7 @@ enum hook_type { HOOK_AC_CHANGE, /* AC power plugged in or removed */ HOOK_LID_CHANGE, /* Lid opened or closed. Based on debounced lid * state, not raw lid GPIO input. */ + HOOK_TICK, /* Periodic tick, every HOOK_TICK_INTERVAL */ }; struct hook_data { -- cgit v1.2.1