diff options
author | Jett Rink <jettrink@chromium.org> | 2019-08-02 16:20:50 -0600 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2019-08-20 15:53:16 +0000 |
commit | 2a7996a3caf25d358164a48e80723758e8be1fd1 (patch) | |
tree | a6dd0682b7ab1c3cc408450137e5f10988cf9da7 /include/usb_tc_sm.h | |
parent | a1aea89ae15c85d56f52976289a329e7c58bc8f6 (diff) | |
download | chrome-ec-2a7996a3caf25d358164a48e80723758e8be1fd1.tar.gz |
usb: update state machine framework
- OBJ is renamed to context (CTX) for current and last state
- State definition now includes its parent (no need for the boiler
plate function that takes in a signal)
- The init_state, set_state, and exe_state have been re-written to take
advantages of new state machine definition. I had to add more logic to
handle hierarchical states fully.
- Explicitly create the USB states at the bottom of the file with all
of the statics. Don't need to use macros (even though I did suggest them)
- Use NULL when we do_nothing instead of calling into a function
- Created a "private" enum in the C file that lists all of the states
in the file, that we can use to refer to a state (it is also the
index into the states array for that state).
- Changed prototype of state function to return void, since we aren't
really using the return value and it cleans up a lot of return 0 that
aren't needed.
- Add const to int port since we can and should
- Moves struct definition to implementation file only to keep
implementation details private. We can access data through accessor if
needed.
BRANCH=none
BUG=none
TEST=all unit tests passes
Change-Id: I482a63e08f7d63022d5102b891a2fac0b0faa46f
Signed-off-by: Jett Rink <jettrink@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1733744
Commit-Queue: Denis Brockus <dbrockus@chromium.org>
Reviewed-by: Denis Brockus <dbrockus@chromium.org>
Diffstat (limited to 'include/usb_tc_sm.h')
-rw-r--r-- | include/usb_tc_sm.h | 90 |
1 files changed, 33 insertions, 57 deletions
diff --git a/include/usb_tc_sm.h b/include/usb_tc_sm.h index 39ba6e026d..c46f449e44 100644 --- a/include/usb_tc_sm.h +++ b/include/usb_tc_sm.h @@ -11,56 +11,11 @@ #include "usb_sm.h" #include "usb_pd_tcpm.h" -enum typec_state_id { - TC_DISABLED, - TC_UNATTACHED_SNK, - TC_ATTACH_WAIT_SNK, - TC_ATTACHED_SNK, -#if !defined(CONFIG_USB_TYPEC_VPD) - TC_ERROR_RECOVERY, - TC_UNATTACHED_SRC, - TC_ATTACH_WAIT_SRC, - TC_ATTACHED_SRC, -#endif -#if !defined(CONFIG_USB_TYPEC_CTVPD) && !defined(CONFIG_USB_TYPEC_VPD) - TC_AUDIO_ACCESSORY, - TC_ORIENTED_DEBUG_ACCESSORY_SRC, - TC_UNORIENTED_DEBUG_ACCESSORY_SRC, - TC_DEBUG_ACCESSORY_SNK, - TC_TRY_SRC, - TC_TRY_WAIT_SNK, - TC_CTUNATTACHED_SNK, - TC_CTATTACHED_SNK, -#endif -#if defined(CONFIG_USB_TYPEC_CTVPD) - TC_CTTRY_SNK, - TC_CTATTACHED_UNSUPPORTED, - TC_CTATTACH_WAIT_UNSUPPORTED, - TC_CTUNATTACHED_UNSUPPORTED, - TC_CTUNATTACHED_VPD, - TC_CTATTACH_WAIT_VPD, - TC_CTATTACHED_VPD, - TC_CTDISABLED_VPD, - TC_TRY_SNK, - TC_TRY_WAIT_SRC, -#endif - /* Number of states. Not an actual state. */ - TC_STATE_COUNT, -}; - -extern const char * const tc_state_names[]; - #define TC_SET_FLAG(port, flag) atomic_or(&tc[port].flags, (flag)) #define TC_CLR_FLAG(port, flag) atomic_clear(&tc[port].flags, (flag)) #define TC_CHK_FLAG(port, flag) (tc[port].flags & (flag)) /* - * TC_OBJ is a convenience macro to access struct sm_obj, which - * must be the first member of struct type_c. - */ -#define TC_OBJ(port) (SM_OBJ(tc[port])) - -/* * Type C supply voltage (mV) * * This is the maximum voltage a sink can request @@ -77,13 +32,6 @@ extern const char * const tc_state_names[]; #define TYPE_C_AUDIO_ACC_CURRENT 500 /* mA */ /** - * Get the id of the current Type-C state - * - * @param port USB-C port number - */ -enum typec_state_id get_typec_state_id(int port); - -/** * Get current data role * * @param port USB-C port number @@ -100,6 +48,23 @@ int tc_get_data_role(int port); int tc_get_power_role(int port); /** + * Get current polarity + * + * @param port USB-C port number + * @return 0 for CC1 as primary, 1 for CC2 as primary + */ +uint8_t tc_get_polarity(int port); + +/** + * Get Power Deliever communication state. If disabled, both protocol and policy + * engine are disabled and should not run. + * + * @param port USB-C port number + * @return 0 if pd is disabled, 1 is pd is enabled + */ +uint8_t tc_get_pd_enabled(int port); + +/** * Set the power role * * @param port USB-C port number @@ -118,6 +83,14 @@ void tc_set_power_role(int port, int role); void set_usb_mux_with_current_data_role(int port); /** + * Get loop timeout value + * + * @param port USB-C port number + * @return time in ms + */ +uint64_t tc_get_timeout(int port); + +/** * Set loop timeout value * * @param port USB-C port number @@ -146,12 +119,8 @@ void set_polarity(int port, int polarity); * TypeC state machine * * @param port USB-C port number - * @param sm_state initial state of the state machine. Must be - * UNATTACHED_SNK or UNATTACHED_SRC, any other - * state id value will be interpreted as - * UNATTACHED_SNK. */ -void tc_state_init(int port, enum typec_state_id start_state); +void tc_state_init(int port); /** * Called by the state machine framework to handle events @@ -162,6 +131,13 @@ void tc_state_init(int port, enum typec_state_id start_state); */ void tc_event_check(int port, int evt); +/** + * Runs the TypeC layer statemachine + * + * @param port USB-C port number + */ +void tc_run(const int port); + #ifdef CONFIG_USB_TYPEC_CTVPD /** * Resets the charge-through support timer. This can be |