summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--common/hooks.c9
-rw-r--r--core/cortex-m/ec.lds.S4
-rw-r--r--core/cortex-m/link_defs.h2
-rw-r--r--include/hooks.h1
4 files changed, 16 insertions, 0 deletions
diff --git a/common/hooks.c b/common/hooks.c
index 385f0e0478..a17cf1ade1 100644
--- a/common/hooks.c
+++ b/common/hooks.c
@@ -31,6 +31,7 @@ static const struct hook_ptrs hook_list[] = {
{__hooks_ac_change, __hooks_ac_change_end},
{__hooks_lid_change, __hooks_lid_change_end},
{__hooks_tick, __hooks_tick_end},
+ {__hooks_second, __hooks_second_end},
};
void hook_notify(enum hook_type type)
@@ -64,11 +65,19 @@ void hook_notify(enum hook_type type)
void hook_task(void)
{
+ /* Per-second hook will be called first time through the loop */
+ static uint64_t last_second = -SECOND;
+
while (1) {
uint64_t t = get_time().val;
hook_notify(HOOK_TICK);
+ if (t - last_second >= SECOND) {
+ hook_notify(HOOK_SECOND);
+ last_second = t;
+ }
+
/* Use up the rest of our hook tick interval */
t = get_time().val - t;
if (t < HOOK_TICK_INTERVAL)
diff --git a/core/cortex-m/ec.lds.S b/core/cortex-m/ec.lds.S
index 7097ced5a5..29e63bf4a6 100644
--- a/core/cortex-m/ec.lds.S
+++ b/core/cortex-m/ec.lds.S
@@ -100,6 +100,10 @@ SECTIONS
*(.rodata.HOOK_TICK)
__hooks_tick_end = .;
+ __hooks_second = .;
+ *(.rodata.HOOK_SECOND)
+ __hooks_second_end = .;
+
. = ALIGN(4);
*(.rodata*)
diff --git a/core/cortex-m/link_defs.h b/core/cortex-m/link_defs.h
index 44332c74bc..2b5a4a4d77 100644
--- a/core/cortex-m/link_defs.h
+++ b/core/cortex-m/link_defs.h
@@ -40,6 +40,8 @@ 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[];
+extern const struct hook_data __hooks_second[];
+extern const struct hook_data __hooks_second_end[];
/* Host commands */
extern const struct host_command __hcmds[];
diff --git a/include/hooks.h b/include/hooks.h
index 2c691fb639..6e6c1c8e3c 100644
--- a/include/hooks.h
+++ b/include/hooks.h
@@ -48,6 +48,7 @@ enum hook_type {
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 */
+ HOOK_SECOND, /* Periodic tick, every second */
};
struct hook_data {