diff options
author | Sam Hurst <shurst@google.com> | 2019-05-22 14:13:40 -0700 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2019-06-05 21:43:03 +0000 |
commit | d76c396bf65e912c2aa2ca1e905daa74996cdb27 (patch) | |
tree | c34654adeebeb793d548215c2eaf6f4f4ba3bdfe /include/usb_sm.h | |
parent | 184701a33a0f77dfbe38d231d05741db1f8ddbc6 (diff) | |
download | chrome-ec-d76c396bf65e912c2aa2ca1e905daa74996cdb27.tar.gz |
chocodile_vpdmcu: Firmware refactoring
Move code in header files into c source files.
BUG=b:133341676
BRANCH=none
TEST=manual
Charge-Through was tested on an Atlas running a DRP USB-C/PD state
machine with CTUnattached.SNK and CTAttached.SNK states.
Change-Id: Ib1b51a778b937e02908f0bc8866bc91a39831163
Signed-off-by: Sam Hurst <shurst@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1626036
Reviewed-by: Jett Rink <jettrink@chromium.org>
Commit-Queue: Sam Hurst <shurst@google.com>
Tested-by: Sam Hurst <shurst@google.com>
Diffstat (limited to 'include/usb_sm.h')
-rw-r--r-- | include/usb_sm.h | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/include/usb_sm.h b/include/usb_sm.h index 15de5f9ef4..1fd6688a1f 100644 --- a/include/usb_sm.h +++ b/include/usb_sm.h @@ -8,6 +8,62 @@ #ifndef __CROS_EC_USB_SM_H #define __CROS_EC_USB_SM_H +#define DECLARE_SM_FUNC_(prefix, name, exit) \ + DECLARE_SM_FUNC_##exit(prefix, name) +#define DECLARE_SM_FUNC_WITH_EXIT(prefix, name) static unsigned int \ + prefix##_##name##_exit(int port) +#define DECLARE_SM_FUNC_NOOP_EXIT(prefix, name) + +#define DECLARE_SM_SIG_(prefix, name, exit) DECLARE_SM_##exit(prefix, name) +#define DECLARE_SM_WITH_EXIT(prefix, name) prefix##_##name##_exit +#define DECLARE_SM_NOOP_EXIT(prefix, name) do_nothing_exit + + +/* + * Helper macro for the declaration of states. + * + * @param prefix - prefix of state function name + * @param name - name of state + * @param exit - if WITH_EXIT, generates an exit state function name + * if NOOP_EXIT, generates do_nothing_exit function name + * + * EXAMPLE: + * + * DECLARE_STATE(tc, test, WITH_EXIT); generates the following: + * + * static unsigned int tc_test(int port, enum signal sig); + * static unsigned int tc_test_entry(int port); + * static unsigned int tc_test_run(int port); + * static unsigned int tc_test_exit(int port); + * static const state_sig tc_test_sig[] = { + * tc_test_entry, + * tc_test_run, + * tc_test_exit, + * get_super_state }; + * + * DECLARE_STATE(tc, test, NOOP_EXIT); generates the following: + * + * static unsigned int tc_test(int port, enum signal sig); + * static unsigned int tc_test_entry(int port); + * static unsigned int tc_test_run(int port); + * static const state_sig tc_test_sig[] = { + * tc_test_entry, + * tc_test_run, + * do_nothing_exit, + * get_super_state }; + */ +#define DECLARE_STATE(prefix, name, exit) \ +static unsigned int prefix##_##name(int port, enum signal sig); \ +static unsigned int prefix##_##name##_entry(int port); \ +static unsigned int prefix##_##name##_run(int port); \ +DECLARE_SM_FUNC_(prefix, name, exit); \ +static const state_sig prefix##_##name##_sig[] = { \ +prefix##_##name##_entry, \ +prefix##_##name##_run, \ +DECLARE_SM_SIG_(prefix, name, exit), \ +get_super_state \ +} + #define SM_OBJ(smo) ((struct sm_obj *)&smo) #define SUPER(r, sig, s) ((((r) == 0) || ((sig) == ENTRY_SIG) || \ ((sig) == EXIT_SIG)) ? 0 : ((uintptr_t)(s))) @@ -64,4 +120,20 @@ int set_state(int port, struct sm_obj *obj, sm_state target); */ void exe_state(int port, struct sm_obj *obj, enum signal sig); +/** + * Substitute this function for states that do not implement an exit state. + * + * @param port USB-C port number + * @return 0 + */ +unsigned int do_nothing_exit(int port); + +/** + * Called by the state machine framework to execute a states super state. + * + * @param port USB-C port number + * @return RUN_SUPER + */ +unsigned int get_super_state(int port); + #endif /* __CROS_EC_USB_SM_H */ |