summaryrefslogtreecommitdiff
path: root/include/usb_sm.h
diff options
context:
space:
mode:
authorSam Hurst <shurst@google.com>2019-04-18 12:47:52 -0700
committerCommit Bot <commit-bot@chromium.org>2019-07-30 21:25:24 +0000
commit2e3109ec6b964776e7c5bd12f1fc058ca96d33f7 (patch)
tree23ea5eaf67e50094ae683f5d16f09a332a1303c4 /include/usb_sm.h
parentb99b1b10c3f2070e3fbd8d5cb2d0927f04f642ea (diff)
downloadchrome-ec-2e3109ec6b964776e7c5bd12f1fc058ca96d33f7.tar.gz
type-c: USB Type-C State Machine based on Release 1.4 of the spec.
Implements DRP with Accessory, and Try.SRC as detailed in Release 1.4 of the USB Type-C specification. BUG=b:130895206 BRANCH=none TEST=manual Used Atlas device to verify that it could be charged from PD and none PD charges at 5V/3A. Attached USB dock and verifed access to USB Thumb drive. Performed same tests on Hatch Port 0 on Hatch was used to run this CL, merged with PD functionality, on the PD2.0 Compliance tester. All tests pass except for a few physical layer tests. The test report has been added to the bug. Change-Id: Ic4869e20e5b4c2ba6c827d92e40c70f3140f2518 Signed-off-by: Sam Hurst <shurst@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1574667 Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-by: Aseda Aboagye <aaboagye@chromium.org> Tested-by: Sam Hurst <shurst@google.com> Commit-Queue: Sam Hurst <shurst@google.com>
Diffstat (limited to 'include/usb_sm.h')
-rw-r--r--include/usb_sm.h92
1 files changed, 51 insertions, 41 deletions
diff --git a/include/usb_sm.h b/include/usb_sm.h
index 1fd6688a1f..e57cd0b873 100644
--- a/include/usb_sm.h
+++ b/include/usb_sm.h
@@ -8,30 +8,41 @@
#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 \
+#define DECLARE_SM_FUNC_(prefix, name, run, exit) \
+ DECLARE_SM_FUNC_##run(prefix, name); \
+ DECLARE_SM_FUNC_##exit(prefix, name)
+
+#define DECLARE_SM_FUNC_WITH_RUN(prefix, name) static int \
+ prefix##_##name##_run(int port)
+
+#define DECLARE_SM_FUNC_WITH_EXIT(prefix, name) static 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_FUNC_NOOP(prefix, name)
+
+#define DECLARE_SM_SIG_RUN(prefix, name, run) DECLARE_SM_##run(prefix, name)
+#define DECLARE_SM_WITH_RUN(prefix, name) prefix##_##name##_run
+
+#define DECLARE_SM_SIG_EXIT(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
+#define DECLARE_SM_NOOP(prefix, name) sm_do_nothing
/*
* Helper macro for the declaration of states.
*
* @param prefix - prefix of state function name
* @param name - name of state
+ * @param run - if WITH_RUN, generates a run state function name
+ * if NOOP, generates a do nothing function name
* @param exit - if WITH_EXIT, generates an exit state function name
- * if NOOP_EXIT, generates do_nothing_exit function name
+ * if NOOP, generates a do nothing function name
*
* EXAMPLE:
*
- * DECLARE_STATE(tc, test, WITH_EXIT); generates the following:
+ * DECLARE_STATE(tc, test, WITH_RUN, WITH_EXIT); generates the following:
*
- * static unsigned int tc_test(int port, enum signal sig);
+ * static unsigned int tc_test(int port, enum sm_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);
@@ -39,35 +50,33 @@
* tc_test_entry,
* tc_test_run,
* tc_test_exit,
- * get_super_state };
+ * sm_get_super_state };
*
- * DECLARE_STATE(tc, test, NOOP_EXIT); generates the following:
+ * DECLARE_STATE(tc, test, NOOP, NOOP); generates the following:
*
- * static unsigned int tc_test(int port, enum signal sig);
+ * static unsigned int tc_test(int port, enum sm_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 };
+ * sm_do_nothing,
+ * sm_do_nothing,
+ * sm_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); \
+#define DECLARE_STATE(prefix, name, run, exit) \
+static int prefix##_##name(int port, enum sm_signal sig); \
+static int prefix##_##name##_entry(int port); \
+DECLARE_SM_FUNC_(prefix, name, run, exit); \
static const state_sig prefix##_##name##_sig[] = { \
prefix##_##name##_entry, \
-prefix##_##name##_run, \
-DECLARE_SM_SIG_(prefix, name, exit), \
-get_super_state \
+DECLARE_SM_SIG_RUN(prefix, name, run), \
+DECLARE_SM_SIG_EXIT(prefix, name, exit), \
+sm_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)))
-#define RUN_SUPER 1
+#define SM_SUPER(r, sig, s) ((((r) == 0) || ((sig) == SM_ENTRY_SIG) || \
+ ((sig) == SM_EXIT_SIG)) ? 0 : ((uintptr_t)(s)))
+#define SM_RUN_SUPER 1
/* Local state machine states */
enum sm_local_state {
@@ -77,15 +86,15 @@ enum sm_local_state {
};
/* State Machine signals */
-enum signal {
- ENTRY_SIG = 0,
- RUN_SIG,
- EXIT_SIG,
- SUPER_SIG,
+enum sm_signal {
+ SM_ENTRY_SIG = 0,
+ SM_RUN_SIG,
+ SM_EXIT_SIG,
+ SM_SUPER_SIG,
};
-typedef unsigned int (*state_sig)(int port);
-typedef unsigned int (*sm_state)(int port, enum signal sig);
+typedef int (*state_sig)(int port);
+typedef int (*sm_state)(int port, enum sm_signal sig);
struct sm_obj {
sm_state task_state;
@@ -99,7 +108,7 @@ struct sm_obj {
* @param obj State machine object
* @param target Initial state of state machine
*/
-void init_state(int port, struct sm_obj *obj, sm_state target);
+void sm_init_state(int port, struct sm_obj *obj, sm_state target);
/**
* Changes a state machines state
@@ -109,24 +118,25 @@ void init_state(int port, struct sm_obj *obj, sm_state target);
* @param target State to transition to
* @return 0
*/
-int set_state(int port, struct sm_obj *obj, sm_state target);
+int sm_set_state(int port, struct sm_obj *obj, sm_state target);
/**
- * Executes a state machine
+ * Runs a state machine
*
* @param port USB-C port number
* @param obj State machine object
* @param sig State machine signal
*/
-void exe_state(int port, struct sm_obj *obj, enum signal sig);
+void sm_run_state_machine(int port, struct sm_obj *obj, enum sm_signal sig);
/**
- * Substitute this function for states that do not implement an exit state.
+ * Substitute this function for states that do not implement a
+ * run or exit state.
*
* @param port USB-C port number
* @return 0
*/
-unsigned int do_nothing_exit(int port);
+int sm_do_nothing(int port);
/**
* Called by the state machine framework to execute a states super state.
@@ -134,6 +144,6 @@ unsigned int do_nothing_exit(int port);
* @param port USB-C port number
* @return RUN_SUPER
*/
-unsigned int get_super_state(int port);
+int sm_get_super_state(int port);
#endif /* __CROS_EC_USB_SM_H */