diff options
author | Randall Spangler <rspangler@chromium.org> | 2013-03-29 16:34:02 -0700 |
---|---|---|
committer | ChromeBot <chrome-bot@google.com> | 2013-04-02 14:12:55 -0700 |
commit | 5966f22a8a1928583943b57fc22e72f85d69d079 (patch) | |
tree | e49232c6d5368219faa63cae0ec5e01a4866f837 /include | |
parent | 97bf36c9d3ad3d96ad6dea7cd6e6f3e164297c43 (diff) | |
download | chrome-ec-5966f22a8a1928583943b57fc22e72f85d69d079.tar.gz |
Add support for calling deferred functions
This is a cleaner way of deferring work from interrupt-time to
task-time without requiring a task for each module which needs this.
Replaces/supersedes delayed hook notification, which didn't scale well
(since every function would have needed to be its own hook type).
BUG=chrome-os-partner:18473
BRANCH=none
TEST=boot system. plug/unplug AC power; notifies the host properly
Change-Id: I50263fe1ce37e74c1ef8db3671379098997102ed
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/46953
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
Diffstat (limited to 'include')
-rw-r--r-- | include/hooks.h | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/include/hooks.h b/include/hooks.h index c07877feca..6a6bd797cc 100644 --- a/include/hooks.h +++ b/include/hooks.h @@ -124,6 +124,11 @@ struct hook_data { }; /** + * Initialize the hooks library. + */ +void hook_init(void); + +/** * Call all the hook routines of a specified type. * * @param type Type of hook routines to call. @@ -131,6 +136,23 @@ struct hook_data { void hook_notify(enum hook_type type); /** + * Start a timer to call a deferred routine. + * + * The routine will be called after at least the specified delay, in the + * context of the hook task. + * + * @param routine Routine to call; must have been declared with + * DECLARE_DEFERRED(). + * @param us Delay in microseconds until routine will be called. + * If the routine is already pending, subsequent calls + * will change the delay. Pass us=0 to call as soon as + * possible, or -1 to cancel the deferred call. + * + * @return non-zero if error. + */ +int hook_call_deferred(void (*routine)(void), int us); + +/** * Register a hook routine. * * @param hooktype Type of hook for routine (enum hook_type) @@ -146,4 +168,23 @@ void hook_notify(enum hook_type type); __attribute__((section(".rodata." #hooktype))) \ = {routine, priority} + +struct deferred_data { + /* Deferred function pointer */ + void (*routine)(void); +}; + +/** + * Register a deferred function call. + * + * Note that if you declare a bunch of these, you may need to override + * DEFERRABLE_MAX_COUNT in your board.h. + * + * @param routine Function pointer, with prototype void routine(void) + */ +#define DECLARE_DEFERRED(routine) \ + const struct deferred_data __deferred_##routine \ + __attribute__((section(".rodata.deferred"))) \ + = {routine} + #endif /* __CROS_EC_HOOKS_H */ |