summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJett Rink <jettrink@chromium.org>2019-08-02 16:20:50 -0600
committerCommit Bot <commit-bot@chromium.org>2019-08-20 15:53:16 +0000
commit2a7996a3caf25d358164a48e80723758e8be1fd1 (patch)
treea6dd0682b7ab1c3cc408450137e5f10988cf9da7 /test
parenta1aea89ae15c85d56f52976289a329e7c58bc8f6 (diff)
downloadchrome-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 'test')
-rw-r--r--test/test_config.h12
-rw-r--r--test/usb_prl.c112
-rw-r--r--test/usb_sm_framework_h3.c522
-rw-r--r--test/usb_typec_ctvpd.c154
4 files changed, 372 insertions, 428 deletions
diff --git a/test/test_config.h b/test/test_config.h
index 942c8c8501..1ca557bbef 100644
--- a/test/test_config.h
+++ b/test/test_config.h
@@ -236,8 +236,6 @@ int ncp15wb_calculate_temp(uint16_t adc);
#undef CONFIG_USB_PRL_SM
#undef CONFIG_USB_PE_SM
#undef CONFIG_USB_TYPEC_SM
-#undef CONFIG_SM_NESTING_NUM
-#define CONFIG_SM_NESTING_NUM 3
#define CONFIG_USB_SM_FRAMEWORK
#endif
@@ -246,8 +244,6 @@ int ncp15wb_calculate_temp(uint16_t adc);
#undef CONFIG_USB_PRL_SM
#undef CONFIG_USB_PE_SM
#undef CONFIG_USB_TYPEC_SM
-#undef CONFIG_SM_NESTING_NUM
-#define CONFIG_SM_NESTING_NUM 2
#define CONFIG_USB_SM_FRAMEWORK
#endif
@@ -256,8 +252,6 @@ int ncp15wb_calculate_temp(uint16_t adc);
#undef CONFIG_USB_PRL_SM
#undef CONFIG_USB_PE_SM
#undef CONFIG_USB_TYPEC_SM
-#undef CONFIG_SM_NESTING_NUM
-#define CONFIG_SM_NESTING_NUM 1
#define CONFIG_USB_SM_FRAMEWORK
#endif
@@ -266,14 +260,10 @@ int ncp15wb_calculate_temp(uint16_t adc);
#undef CONFIG_USB_PRL_SM
#undef CONFIG_USB_PE_SM
#undef CONFIG_USB_TYPEC_SM
-#undef CONFIG_SM_NESTING_NUM
-#define CONFIG_SM_NESTING_NUM 0
#define CONFIG_USB_SM_FRAMEWORK
#endif
#if defined(TEST_USB_PRL)
-#undef CONFIG_SM_NESTING_NUM
-#define CONFIG_SM_NESTING_NUM 3
#define CONFIG_USB_PD_PORT_COUNT 2
#define CONFIG_USB_SM_FRAMEWORK
#undef CONFIG_USB_PE_SM
@@ -292,8 +282,6 @@ int ncp15wb_calculate_temp(uint16_t adc);
#else
#define CONFIG_USB_TYPEC_CTVPD
#endif
-#undef CONFIG_SM_NESTING_NUM
-#define CONFIG_SM_NESTING_NUM 3
#define CONFIG_USB_PID 0x5036
#define VPD_HW_VERSION 0x0001
diff --git a/test/usb_prl.c b/test/usb_prl.c
index 36f007b057..0851e0cfc2 100644
--- a/test/usb_prl.c
+++ b/test/usb_prl.c
@@ -20,6 +20,54 @@
#define PORT0 0
#define PORT1 1
+/*
+ * These enum definitions are declared in usb_prl_sm and are private to that
+ * file. If those definitions are re-ordered, then we need to update these
+ * definitions (should be very rare).
+ */
+enum usb_prl_tx_state {
+ PRL_TX_PHY_LAYER_RESET,
+ PRL_TX_WAIT_FOR_MESSAGE_REQUEST,
+ PRL_TX_LAYER_RESET_FOR_TRANSMIT,
+ PRL_TX_WAIT_FOR_PHY_RESPONSE,
+ PRL_TX_SRC_SOURCE_TX,
+ PRL_TX_SNK_START_AMS,
+ PRL_TX_SRC_PENDING,
+ PRL_TX_SNK_PENDING,
+ PRL_TX_DISCARD_MESSAGE,
+};
+
+enum usb_prl_hr_state {
+ PRL_HR_WAIT_FOR_REQUEST,
+ PRL_HR_RESET_LAYER,
+ PRL_HR_WAIT_FOR_PHY_HARD_RESET_COMPLETE,
+ PRL_HR_WAIT_FOR_PE_HARD_RESET_COMPLETE,
+};
+
+enum usb_rch_state {
+ RCH_WAIT_FOR_MESSAGE_FROM_PROTOCOL_LAYER,
+ RCH_PROCESSING_EXTENDED_MESSAGE,
+ RCH_REQUESTING_CHUNK,
+ RCH_WAITING_CHUNK,
+ RCH_REPORT_ERROR,
+};
+
+enum usb_tch_state {
+ TCH_WAIT_FOR_MESSAGE_REQUEST_FROM_PE,
+ TCH_WAIT_FOR_TRANSMISSION_COMPLETE,
+ TCH_CONSTRUCT_CHUNKED_MESSAGE,
+ TCH_SENDING_CHUNKED_MESSAGE,
+ TCH_WAIT_CHUNK_REQUEST,
+ TCH_MESSAGE_RECEIVED,
+};
+
+/* Defined in implementation */
+enum usb_prl_tx_state prl_tx_get_state(const int port);
+enum usb_prl_hr_state prl_hr_get_state(const int port);
+enum usb_rch_state rch_get_state(const int port);
+enum usb_tch_state tch_get_state(const int port);
+
+
static uint32_t test_data[] = {
0x00010203, 0x04050607, 0x08090a0b, 0x0c0d0e0f,
0x10111213, 0x14151617, 0x1819a0b0, 0xc0d0e0f0,
@@ -331,7 +379,7 @@ static int simulate_receive_extended_data(int port,
* Wait for request chunk message
*/
req_timeout = 0;
- while (get_rch_state_id(port) != RCH_REQUESTING_CHUNK &&
+ while (rch_get_state(port) != RCH_REQUESTING_CHUNK &&
req_timeout < 5) {
req_timeout++;
msleep(2);
@@ -675,13 +723,13 @@ static int test_initial_states(void)
enable_prl(port, 1);
- TEST_ASSERT(get_prl_tx_state_id(port) ==
+ TEST_ASSERT(prl_tx_get_state(port) ==
PRL_TX_WAIT_FOR_MESSAGE_REQUEST);
- TEST_ASSERT(get_rch_state_id(port) ==
+ TEST_ASSERT(rch_get_state(port) ==
RCH_WAIT_FOR_MESSAGE_FROM_PROTOCOL_LAYER);
- TEST_ASSERT(get_tch_state_id(port) ==
+ TEST_ASSERT(tch_get_state(port) ==
TCH_WAIT_FOR_MESSAGE_REQUEST_FROM_PE);
- TEST_ASSERT(get_prl_hr_state_id(port) ==
+ TEST_ASSERT(prl_hr_get_state(port) ==
PRL_HR_WAIT_FOR_REQUEST);
return EC_SUCCESS;
@@ -701,7 +749,7 @@ static int test_send_ctrl_msg(void)
task_wake(PD_PORT_TO_TASK_ID(port));
task_wait_event(40 * MSEC);
- TEST_ASSERT(get_prl_tx_state_id(port) ==
+ TEST_ASSERT(prl_tx_get_state(port) ==
PRL_TX_WAIT_FOR_MESSAGE_REQUEST);
TEST_ASSERT(simulate_send_ctrl_msg_request_from_pe(port,
@@ -739,7 +787,7 @@ static int test_send_ctrl_msg_with_retry_and_fail(void)
task_wake(PD_PORT_TO_TASK_ID(port));
task_wait_event(40 * MSEC);
- TEST_ASSERT(get_prl_tx_state_id(port) ==
+ TEST_ASSERT(prl_tx_get_state(port) ==
PRL_TX_WAIT_FOR_MESSAGE_REQUEST);
TEST_ASSERT(simulate_send_ctrl_msg_request_from_pe(port,
@@ -761,7 +809,7 @@ static int test_send_ctrl_msg_with_retry_and_fail(void)
task_wake(PD_PORT_TO_TASK_ID(port));
task_wait_event(40 * MSEC);
- TEST_ASSERT(get_prl_tx_state_id(port) ==
+ TEST_ASSERT(prl_tx_get_state(port) ==
PRL_TX_WAIT_FOR_MESSAGE_REQUEST);
pd_port[port].mock_pe_message_sent = 0;
@@ -801,7 +849,7 @@ static int test_send_ctrl_msg_with_retry_and_success(void)
task_wake(PD_PORT_TO_TASK_ID(port));
task_wait_event(40 * MSEC);
- TEST_ASSERT(get_prl_tx_state_id(port) ==
+ TEST_ASSERT(prl_tx_get_state(port) ==
PRL_TX_WAIT_FOR_MESSAGE_REQUEST);
pd_port[port].mock_got_soft_reset = 0;
@@ -827,7 +875,7 @@ static int test_send_ctrl_msg_with_retry_and_success(void)
task_wake(PD_PORT_TO_TASK_ID(port));
task_wait_event(40 * MSEC);
- TEST_ASSERT(get_prl_tx_state_id(port) ==
+ TEST_ASSERT(prl_tx_get_state(port) ==
PRL_TX_WAIT_FOR_MESSAGE_REQUEST);
pd_port[port].mock_pe_message_sent = 0;
@@ -876,7 +924,7 @@ static int test_send_data_msg(void)
task_wake(PD_PORT_TO_TASK_ID(port));
task_wait_event(40 * MSEC);
- TEST_ASSERT(get_prl_tx_state_id(port) ==
+ TEST_ASSERT(prl_tx_get_state(port) ==
PRL_TX_WAIT_FOR_MESSAGE_REQUEST);
TEST_ASSERT(simulate_send_data_msg_request_from_pe(port,
@@ -913,7 +961,7 @@ static int test_send_data_msg_to_much_data(void)
task_wake(PD_PORT_TO_TASK_ID(port));
task_wait_event(40 * MSEC);
- TEST_ASSERT(get_prl_tx_state_id(port) ==
+ TEST_ASSERT(prl_tx_get_state(port) ==
PRL_TX_WAIT_FOR_MESSAGE_REQUEST);
/* Try to send 29-bytes */
@@ -954,7 +1002,7 @@ static int test_send_extended_data_msg(void)
task_wake(PD_PORT_TO_TASK_ID(port));
task_wait_event(40 * MSEC);
- TEST_ASSERT(get_prl_tx_state_id(port) ==
+ TEST_ASSERT(prl_tx_get_state(port) ==
PRL_TX_WAIT_FOR_MESSAGE_REQUEST);
TEST_ASSERT(simulate_send_extended_data_msg(
@@ -992,7 +1040,7 @@ static int test_receive_soft_reset_msg(void)
task_wake(PD_PORT_TO_TASK_ID(port));
task_wait_event(40 * MSEC);
- TEST_ASSERT(get_rch_state_id(port) ==
+ TEST_ASSERT(rch_get_state(port) ==
RCH_WAIT_FOR_MESSAGE_FROM_PROTOCOL_LAYER);
pd_port[port].mock_got_soft_reset = 0;
@@ -1035,7 +1083,7 @@ static int test_receive_control_msg(void)
task_wake(PD_PORT_TO_TASK_ID(port));
task_wait_event(40 * MSEC);
- TEST_ASSERT(get_rch_state_id(port) ==
+ TEST_ASSERT(rch_get_state(port) ==
RCH_WAIT_FOR_MESSAGE_FROM_PROTOCOL_LAYER);
pd_port[port].mock_got_soft_reset = 0;
@@ -1075,7 +1123,7 @@ static int test_receive_data_msg(void)
task_wake(PD_PORT_TO_TASK_ID(port));
task_wait_event(40 * MSEC);
- TEST_ASSERT(get_rch_state_id(port) ==
+ TEST_ASSERT(rch_get_state(port) ==
RCH_WAIT_FOR_MESSAGE_FROM_PROTOCOL_LAYER);
TEST_ASSERT(simulate_receive_data(port,
PD_DATA_BATTERY_STATUS, i));
@@ -1100,7 +1148,7 @@ static int test_receive_extended_data_msg(void)
task_wake(PD_PORT_TO_TASK_ID(port));
task_wait_event(40 * MSEC);
- TEST_ASSERT(get_rch_state_id(port) ==
+ TEST_ASSERT(rch_get_state(port) ==
RCH_WAIT_FOR_MESSAGE_FROM_PROTOCOL_LAYER);
for (len = 29; len <= 260; len++)
@@ -1125,7 +1173,7 @@ static int test_send_soft_reset_msg(void)
task_wake(PD_PORT_TO_TASK_ID(port));
task_wait_event(40 * MSEC);
- TEST_ASSERT(get_prl_tx_state_id(port) ==
+ TEST_ASSERT(prl_tx_get_state(port) ==
PRL_TX_WAIT_FOR_MESSAGE_REQUEST);
TEST_ASSERT(simulate_send_ctrl_msg_request_from_pe(port,
@@ -1138,7 +1186,7 @@ static int test_send_soft_reset_msg(void)
pd_port[port].msg_tx_id);
inc_tx_id(port);
- TEST_ASSERT(get_prl_tx_state_id(port) ==
+ TEST_ASSERT(prl_tx_get_state(port) ==
PRL_TX_LAYER_RESET_FOR_TRANSMIT);
cycle_through_state_machine(port, 3, 10 * MSEC);
@@ -1167,24 +1215,24 @@ static int test_pe_execute_hard_reset_msg(void)
task_wake(PD_PORT_TO_TASK_ID(port));
task_wait_event(40 * MSEC);
- TEST_ASSERT(get_prl_hr_state_id(port) == PRL_HR_WAIT_FOR_REQUEST);
+ TEST_ASSERT(prl_hr_get_state(port) == PRL_HR_WAIT_FOR_REQUEST);
/* Simulate receiving hard reset from policy engine */
prl_execute_hard_reset(port);
- TEST_ASSERT(get_prl_hr_state_id(port) == PRL_HR_RESET_LAYER);
- TEST_ASSERT(get_prl_tx_state_id(port) ==
+ TEST_ASSERT(prl_hr_get_state(port) == PRL_HR_RESET_LAYER);
+ TEST_ASSERT(prl_tx_get_state(port) ==
PRL_TX_WAIT_FOR_MESSAGE_REQUEST);
cycle_through_state_machine(port, 1, 10 * MSEC);
- TEST_ASSERT(get_prl_hr_state_id(port) ==
+ TEST_ASSERT(prl_hr_get_state(port) ==
PRL_HR_WAIT_FOR_PHY_HARD_RESET_COMPLETE);
cycle_through_state_machine(port, 2, PD_T_PS_HARD_RESET);
TEST_ASSERT(pd_port[port].mock_pe_hard_reset_sent);
- TEST_ASSERT(get_prl_hr_state_id(port) ==
+ TEST_ASSERT(prl_hr_get_state(port) ==
PRL_HR_WAIT_FOR_PE_HARD_RESET_COMPLETE);
/* Simulate policy engine indicating that it is done hard reset */
@@ -1192,7 +1240,7 @@ static int test_pe_execute_hard_reset_msg(void)
cycle_through_state_machine(port, 1, 10 * MSEC);
- TEST_ASSERT(get_prl_hr_state_id(port) == PRL_HR_WAIT_FOR_REQUEST);
+ TEST_ASSERT(prl_hr_get_state(port) == PRL_HR_WAIT_FOR_REQUEST);
enable_prl(port, 0);
@@ -1214,24 +1262,24 @@ static int test_phy_execute_hard_reset_msg(void)
task_wake(PD_PORT_TO_TASK_ID(port));
task_wait_event(40 * MSEC);
- TEST_ASSERT(get_prl_hr_state_id(port) == PRL_HR_WAIT_FOR_REQUEST);
+ TEST_ASSERT(prl_hr_get_state(port) == PRL_HR_WAIT_FOR_REQUEST);
/* Simulate receiving hard reset from port partner */
pd_execute_hard_reset(port);
- TEST_ASSERT(get_prl_hr_state_id(port) == PRL_HR_RESET_LAYER);
- TEST_ASSERT(get_prl_tx_state_id(port) ==
+ TEST_ASSERT(prl_hr_get_state(port) == PRL_HR_RESET_LAYER);
+ TEST_ASSERT(prl_tx_get_state(port) ==
PRL_TX_WAIT_FOR_MESSAGE_REQUEST);
cycle_through_state_machine(port, 1, 10 * MSEC);
- TEST_ASSERT(get_prl_hr_state_id(port) ==
+ TEST_ASSERT(prl_hr_get_state(port) ==
PRL_HR_WAIT_FOR_PE_HARD_RESET_COMPLETE);
cycle_through_state_machine(port, 2, PD_T_PS_HARD_RESET);
TEST_ASSERT(pd_port[port].mock_pe_got_hard_reset);
- TEST_ASSERT(get_prl_hr_state_id(port) ==
+ TEST_ASSERT(prl_hr_get_state(port) ==
PRL_HR_WAIT_FOR_PE_HARD_RESET_COMPLETE);
/* Simulate policy engine indicating that it is done hard reset */
@@ -1239,7 +1287,7 @@ static int test_phy_execute_hard_reset_msg(void)
cycle_through_state_machine(port, 1, 10 * MSEC);
- TEST_ASSERT(get_prl_hr_state_id(port) == PRL_HR_WAIT_FOR_REQUEST);
+ TEST_ASSERT(prl_hr_get_state(port) == PRL_HR_WAIT_FOR_REQUEST);
enable_prl(port, 0);
@@ -1255,7 +1303,7 @@ int pd_task(void *u)
evt = task_wait_event(-1);
tcpc_run(port, evt);
- usbc_protocol_layer(port, evt, pd_port[port].pd_enable);
+ prl_run(port, evt, pd_port[port].pd_enable);
}
return EC_SUCCESS;
diff --git a/test/usb_sm_framework_h3.c b/test/usb_sm_framework_h3.c
index 8976e0b973..f6ecc721ce 100644
--- a/test/usb_sm_framework_h3.c
+++ b/test/usb_sm_framework_h3.c
@@ -113,41 +113,37 @@ enum state_id {
};
#define PORT0 0
-#define TSM_OBJ(port) (SM_OBJ(sm[port]))
struct sm_ {
/* struct sm_obj must be first */
- struct sm_obj obj;
+ struct sm_ctx ctx;
int sv_tmp;
int idx;
- int seq[55];
+ int seq[SEQUENCE_SIZE];
} sm[1];
-#if defined(TEST_USB_SM_FRAMEWORK_H3)
-DECLARE_STATE(sm, test_super_A1, WITH_RUN, WITH_EXIT);
-DECLARE_STATE(sm, test_super_B1, WITH_RUN, WITH_EXIT);
-#endif
-
-#if defined(TEST_USB_SM_FRAMEWORK_H3) || defined(TEST_USB_SM_FRAMEWORK_H2)
-DECLARE_STATE(sm, test_super_A2, WITH_RUN, WITH_EXIT);
-DECLARE_STATE(sm, test_super_B2, WITH_RUN, WITH_EXIT);
-#endif
-
-#if defined(TEST_USB_SM_FRAMEWORK_H3) || defined(TEST_USB_SM_FRAMEWORK_H2) || \
- defined(TEST_USB_SM_FRAMEWORK_H1)
-DECLARE_STATE(sm, test_super_A3, WITH_RUN, WITH_EXIT);
-DECLARE_STATE(sm, test_super_B3, WITH_RUN, WITH_EXIT);
-#endif
-
-DECLARE_STATE(sm, test_A4, WITH_RUN, WITH_EXIT);
-DECLARE_STATE(sm, test_A5, WITH_RUN, WITH_EXIT);
-DECLARE_STATE(sm, test_A6, WITH_RUN, WITH_EXIT);
-DECLARE_STATE(sm, test_A7, WITH_RUN, WITH_EXIT);
+enum state {
+ SM_TEST_SUPER_A1,
+ SM_TEST_SUPER_A2,
+ SM_TEST_SUPER_A3,
+ SM_TEST_SUPER_B1,
+ SM_TEST_SUPER_B2,
+ SM_TEST_SUPER_B3,
+ SM_TEST_A4,
+ SM_TEST_A5,
+ SM_TEST_A6,
+ SM_TEST_A7,
+ SM_TEST_B4,
+ SM_TEST_B5,
+ SM_TEST_B6,
+ SM_TEST_C,
+};
+static const struct usb_state states[];
-DECLARE_STATE(sm, test_B4, WITH_RUN, WITH_EXIT);
-DECLARE_STATE(sm, test_B5, WITH_RUN, WITH_EXIT);
-DECLARE_STATE(sm, test_B6, WITH_RUN, WITH_EXIT);
-DECLARE_STATE(sm, test_C, WITH_RUN, WITH_EXIT);
+static void set_state_sm(const int port, const enum state new_state)
+{
+ set_state(port, &sm[port].ctx, &states[new_state]);
+}
static void clear_seq(int port)
{
@@ -159,494 +155,267 @@ static void clear_seq(int port)
sm[port].seq[i] = 0;
}
-#if defined(TEST_USB_SM_FRAMEWORK_H3)
-static int sm_test_super_A1(int port, enum sm_signal sig)
-{
- int ret;
-
- ret = (*sm_test_super_A1_sig[sig])(port);
- return SM_SUPER(ret, sig, 0);
-}
-
-static int sm_test_super_A1_entry(int port)
+static void sm_test_super_A1_entry(const int port)
{
sm[port].seq[sm[port].idx++] = ENTER_A1;
- return 0;
}
-static int sm_test_super_A1_run(int port)
+static void sm_test_super_A1_run(const int port)
{
sm[port].seq[sm[port].idx++] = RUN_A1;
- return 0;
}
-static int sm_test_super_A1_exit(int port)
+static void sm_test_super_A1_exit(const int port)
{
sm[port].seq[sm[port].idx++] = EXIT_A1;
- return 0;
}
-static int sm_test_super_B1(int port, enum sm_signal sig)
-{
- int ret;
-
- ret = (*sm_test_super_B1_sig[sig])(port);
- return SM_SUPER(ret, sig, 0);
-}
-
-static int sm_test_super_B1_entry(int port)
+static void sm_test_super_B1_entry(const int port)
{
sm[port].seq[sm[port].idx++] = ENTER_B1;
- return 0;
}
-static int sm_test_super_B1_run(int port)
+static void sm_test_super_B1_run(const int port)
{
sm[port].seq[sm[port].idx++] = RUN_B1;
- return 0;
}
-static int sm_test_super_B1_exit(int port)
+static void sm_test_super_B1_exit(const int port)
{
sm[port].seq[sm[port].idx++] = EXIT_B1;
- return 0;
-}
-#endif
-
-#if defined(TEST_USB_SM_FRAMEWORK_H3) || defined(TEST_USB_SM_FRAMEWORK_H2)
-static int sm_test_super_A2(int port, enum sm_signal sig)
-{
- int ret;
-
- ret = (*sm_test_super_A2_sig[sig])(port);
-#if defined(TEST_USB_SM_FRAMEWORK_H3)
- return SM_SUPER(ret, sig, sm_test_super_A1);
-#else
- return SM_SUPER(ret, sig, 0);
-#endif
}
-static int sm_test_super_A2_entry(int port)
+static void sm_test_super_A2_entry(const int port)
{
sm[port].seq[sm[port].idx++] = ENTER_A2;
- return 0;
}
-static int sm_test_super_A2_run(int port)
+static void sm_test_super_A2_run(const int port)
{
sm[port].seq[sm[port].idx++] = RUN_A2;
- return SM_RUN_SUPER;
}
-static int sm_test_super_A2_exit(int port)
+static void sm_test_super_A2_exit(const int port)
{
sm[port].seq[sm[port].idx++] = EXIT_A2;
- return 0;
}
-static int sm_test_super_B2(int port, enum sm_signal sig)
-{
- int ret;
-
- ret = (*sm_test_super_B2_sig[sig])(port);
-#if defined(TEST_USB_SM_FRAMEWORK_H3)
- return SM_SUPER(ret, sig, sm_test_super_B1);
-#else
- return SM_SUPER(ret, sig, 0);
-#endif
-}
-static int sm_test_super_B2_entry(int port)
+static void sm_test_super_B2_entry(const int port)
{
sm[port].seq[sm[port].idx++] = ENTER_B2;
- return 0;
}
-static int sm_test_super_B2_run(int port)
+static void sm_test_super_B2_run(const int port)
{
sm[port].seq[sm[port].idx++] = RUN_B2;
- return SM_RUN_SUPER;
}
-static int sm_test_super_B2_exit(int port)
+static void sm_test_super_B2_exit(const int port)
{
sm[port].seq[sm[port].idx++] = EXIT_B2;
- return 0;
-}
-#endif
-
-#if defined(TEST_USB_SM_FRAMEWORK_H3) || defined(TEST_USB_SM_FRAMEWORK_H2) || \
- defined(TEST_USB_SM_FRAMEWORK_H1)
-static int sm_test_super_A3(int port, enum sm_signal sig)
-{
- int ret;
-
- ret = (*sm_test_super_A3_sig[sig])(port);
-#if defined(TEST_USB_SM_FRAMEWORK_H3) || defined(TEST_USB_SM_FRAMEWORK_H2)
- return SM_SUPER(ret, sig, sm_test_super_A2);
-#else
- return SM_SUPER(ret, sig, 0);
-#endif
}
-static int sm_test_super_A3_entry(int port)
+static void sm_test_super_A3_entry(const int port)
{
sm[port].seq[sm[port].idx++] = ENTER_A3;
- return 0;
}
-static int sm_test_super_A3_run(int port)
+static void sm_test_super_A3_run(const int port)
{
sm[port].seq[sm[port].idx++] = RUN_A3;
-#if defined(TEST_USB_SM_FRAMEWORK_H3) || defined(TEST_USB_SM_FRAMEWORK_H2)
- return SM_RUN_SUPER;
-#else
- return 0;
-#endif
}
-static int sm_test_super_A3_exit(int port)
+static void sm_test_super_A3_exit(const int port)
{
sm[port].seq[sm[port].idx++] = EXIT_A3;
- return 0;
-}
-
-static int sm_test_super_B3(int port, enum sm_signal sig)
-{
- int ret;
-
- ret = (*sm_test_super_B3_sig[sig])(port);
-#if defined(TEST_USB_SM_FRAMEWORK_H3) || defined(TEST_USB_SM_FRAMEWORK_H2)
- return SM_SUPER(ret, sig, sm_test_super_B2);
-#else
- return SM_SUPER(ret, sig, 0);
-#endif
}
-static int sm_test_super_B3_entry(int port)
+static void sm_test_super_B3_entry(const int port)
{
sm[port].seq[sm[port].idx++] = ENTER_B3;
- return 0;
}
-static int sm_test_super_B3_run(int port)
+static void sm_test_super_B3_run(const int port)
{
sm[port].seq[sm[port].idx++] = RUN_B3;
-#if defined(TEST_USB_SM_FRAMEWORK_H3) || defined(TEST_USB_SM_FRAMEWORK_H2)
- return SM_RUN_SUPER;
-#else
- return 0;
-#endif
}
-static int sm_test_super_B3_exit(int port)
+static void sm_test_super_B3_exit(const int port)
{
sm[port].seq[sm[port].idx++] = EXIT_B3;
- return 0;
-}
-#endif
-
-
-static int sm_test_A4(int port, enum sm_signal sig)
-{
- int ret;
-
- ret = (*sm_test_A4_sig[sig])(port);
-#if defined(TEST_USB_SM_FRAMEWORK_H3) || defined(TEST_USB_SM_FRAMEWORK_H2) || \
- defined(TEST_USB_SM_FRAMEWORK_H1)
- return SM_SUPER(ret, sig, sm_test_super_A3);
-#else
- return SM_SUPER(ret, sig, 0);
-#endif
}
-static int sm_test_A4_entry(int port)
+static void sm_test_A4_entry(const int port)
{
sm[port].sv_tmp = 0;
sm[port].seq[sm[port].idx++] = ENTER_A4;
- return 0;
}
-static int sm_test_A4_run(int port)
+static void sm_test_A4_run(const int port)
{
if (sm[port].sv_tmp == 0) {
sm[port].sv_tmp = 1;
sm[port].seq[sm[port].idx++] = RUN_A4;
} else {
- sm_set_state(port, TSM_OBJ(port), sm_test_B4);
- return 0;
+ set_state_sm(port, SM_TEST_B4);
}
-
- return SM_RUN_SUPER;
}
-static int sm_test_A4_exit(int port)
+static void sm_test_A4_exit(const int port)
{
sm[port].seq[sm[port].idx++] = EXIT_A4;
- return 0;
}
-static int sm_test_A5(int port, enum sm_signal sig)
-{
- int ret;
-
- ret = (*sm_test_A5_sig[sig])(port);
-#if defined(TEST_USB_SM_FRAMEWORK_H3) || defined(TEST_USB_SM_FRAMEWORK_H2) || \
- defined(TEST_USB_SM_FRAMEWORK_H1)
- return SM_SUPER(ret, sig, sm_test_super_A3);
-#else
- return SM_SUPER(ret, sig, 0);
-#endif
-}
-static int sm_test_A5_entry(int port)
+static void sm_test_A5_entry(const int port)
{
sm[port].sv_tmp = 0;
sm[port].seq[sm[port].idx++] = ENTER_A5;
- return 0;
}
-static int sm_test_A5_run(int port)
+static void sm_test_A5_run(const int port)
{
if (sm[port].sv_tmp == 0) {
sm[port].sv_tmp = 1;
sm[port].seq[sm[port].idx++] = RUN_A5;
} else {
- sm_set_state(port, TSM_OBJ(port), sm_test_A4);
- return 0;
+ set_state_sm(port, SM_TEST_A4);
}
-
- return SM_RUN_SUPER;
}
-static int sm_test_A5_exit(int port)
+static void sm_test_A5_exit(const int port)
{
sm[port].seq[sm[port].idx++] = EXIT_A5;
- return 0;
}
-static int sm_test_A6(int port, enum sm_signal sig)
-{
- int ret;
-
- ret = (*sm_test_A6_sig[sig])(port);
-#if defined(TEST_USB_SM_FRAMEWORK_H3) || defined(TEST_USB_SM_FRAMEWORK_H2)
- return SM_SUPER(ret, sig, sm_test_super_A2);
-#else
- return SM_SUPER(ret, sig, 0);
-#endif
-}
-static int sm_test_A6_entry(int port)
+static void sm_test_A6_entry(const int port)
{
sm[port].sv_tmp = 0;
sm[port].seq[sm[port].idx++] = ENTER_A6;
- return 0;
}
-static int sm_test_A6_run(int port)
+static void sm_test_A6_run(const int port)
{
if (sm[port].sv_tmp == 0) {
sm[port].sv_tmp = 1;
sm[port].seq[sm[port].idx++] = RUN_A6;
} else {
- sm_set_state(port, TSM_OBJ(port), sm_test_A5);
- return 0;
+ set_state_sm(port, SM_TEST_A5);
}
-
- return SM_RUN_SUPER;
}
-static int sm_test_A6_exit(int port)
+static void sm_test_A6_exit(const int port)
{
sm[port].seq[sm[port].idx++] = EXIT_A6;
- return 0;
-}
-
-static int sm_test_A7(int port, enum sm_signal sig)
-{
- int ret;
-
- ret = (*sm_test_A7_sig[sig])(port);
-#if defined(TEST_USB_SM_FRAMEWORK_H3)
- return SM_SUPER(ret, sig, sm_test_super_A1);
-#else
- return SM_SUPER(ret, sig, 0);
-#endif
}
-static int sm_test_A7_entry(int port)
+static void sm_test_A7_entry(const int port)
{
sm[port].sv_tmp = 0;
sm[port].seq[sm[port].idx++] = ENTER_A7;
- return 0;
}
-static int sm_test_A7_run(int port)
+static void sm_test_A7_run(const int port)
{
if (sm[port].sv_tmp == 0) {
sm[port].sv_tmp = 1;
sm[port].seq[sm[port].idx++] = RUN_A7;
} else {
- sm_set_state(port, TSM_OBJ(port), sm_test_A6);
- return 0;
+ set_state_sm(port, SM_TEST_A6);
}
-
- return SM_RUN_SUPER;
}
-static int sm_test_A7_exit(int port)
+static void sm_test_A7_exit(const int port)
{
sm[port].seq[sm[port].idx++] = EXIT_A7;
- return 0;
-}
-
-static int sm_test_B4(int port, enum sm_signal sig)
-{
- int ret;
-
- ret = (*sm_test_B4_sig[sig])(port);
-#if defined(TEST_USB_SM_FRAMEWORK_H3) || defined(TEST_USB_SM_FRAMEWORK_H2) || \
- defined(TEST_USB_SM_FRAMEWORK_H1)
- return SM_SUPER(ret, sig, sm_test_super_B3);
-#else
- return SM_SUPER(ret, sig, 0);
-#endif
}
-static int sm_test_B4_entry(int port)
+static void sm_test_B4_entry(const int port)
{
sm[port].sv_tmp = 0;
sm[port].seq[sm[port].idx++] = ENTER_B4;
- return 0;
}
-static int sm_test_B4_run(int port)
+static void sm_test_B4_run(const int port)
{
if (sm[port].sv_tmp == 0) {
sm[port].seq[sm[port].idx++] = RUN_B4;
sm[port].sv_tmp = 1;
} else {
- sm_set_state(port, TSM_OBJ(port), sm_test_B5);
- return 0;
+ set_state_sm(port, SM_TEST_B5);
}
-
- return SM_RUN_SUPER;
}
-static int sm_test_B4_exit(int port)
+static void sm_test_B4_exit(const int port)
{
sm[port].seq[sm[port].idx++] = EXIT_B4;
- return 0;
}
-static int sm_test_B5(int port, enum sm_signal sig)
-{
- int ret;
-
- ret = (*sm_test_B5_sig[sig])(port);
-#if defined(TEST_USB_SM_FRAMEWORK_H3) || defined(TEST_USB_SM_FRAMEWORK_H2)
- return SM_SUPER(ret, sig, sm_test_super_B2);
-#else
- return SM_SUPER(ret, sig, 0);
-#endif
-}
-static int sm_test_B5_entry(int port)
+static void sm_test_B5_entry(const int port)
{
sm[port].sv_tmp = 0;
sm[port].seq[sm[port].idx++] = ENTER_B5;
- return 0;
}
-static int sm_test_B5_run(int port)
+static void sm_test_B5_run(const int port)
{
if (sm[port].sv_tmp == 0) {
sm[port].sv_tmp = 1;
sm[port].seq[sm[port].idx++] = RUN_B5;
} else {
- sm_set_state(port, TSM_OBJ(port), sm_test_B6);
- return 0;
+ set_state_sm(port, SM_TEST_B6);
}
-
- return SM_RUN_SUPER;
}
-static int sm_test_B5_exit(int port)
+static void sm_test_B5_exit(const int port)
{
sm[port].seq[sm[port].idx++] = EXIT_B5;
- return 0;
}
-static int sm_test_B6(int port, enum sm_signal sig)
-{
- int ret;
-
- ret = (*sm_test_B6_sig[sig])(port);
-#if defined(TEST_USB_SM_FRAMEWORK_H3)
- return SM_SUPER(ret, sig, sm_test_super_B1);
-#else
- return SM_SUPER(ret, sig, 0);
-#endif
-}
-static int sm_test_B6_entry(int port)
+static void sm_test_B6_entry(const int port)
{
sm[port].sv_tmp = 0;
sm[port].seq[sm[port].idx++] = ENTER_B6;
- return 0;
}
-static int sm_test_B6_run(int port)
+static void sm_test_B6_run(const int port)
{
if (sm[port].sv_tmp == 0) {
sm[port].sv_tmp = 1;
sm[port].seq[sm[port].idx++] = RUN_B6;
} else {
- sm_set_state(port, TSM_OBJ(port), sm_test_C);
- return 0;
+ set_state_sm(port, SM_TEST_C);
}
-
- return SM_RUN_SUPER;
}
-static int sm_test_B6_exit(int port)
+static void sm_test_B6_exit(const int port)
{
sm[port].seq[sm[port].idx++] = EXIT_B6;
- return 0;
-}
-
-static int sm_test_C(int port, enum sm_signal sig)
-{
- int ret;
-
- ret = (*sm_test_C_sig[sig])(port);
- return SM_SUPER(ret, sig, 0);
}
-static int sm_test_C_entry(int port)
+static void sm_test_C_entry(const int port)
{
sm[port].sv_tmp = 0;
sm[port].seq[sm[port].idx++] = ENTER_C;
- return 0;
}
-static int sm_test_C_run(int port)
+static void sm_test_C_run(const int port)
{
if (sm[port].sv_tmp == 0) {
sm[port].seq[sm[port].idx++] = RUN_C;
sm[port].sv_tmp = 1;
} else {
- sm_set_state(port, TSM_OBJ(port), sm_test_A7);
+ set_state_sm(port, SM_TEST_A7);
}
-
- return 0;
}
-static int sm_test_C_exit(int port)
+static void sm_test_C_exit(const int port)
{
sm[port].seq[sm[port].idx++] = EXIT_C;
- return 0;
}
static void run_sm(void)
@@ -655,14 +424,13 @@ static void run_sm(void)
task_wait_event(5 * MSEC);
}
-#if defined(TEST_USB_SM_FRAMEWORK_H0)
-static int test_hierarchy_0(void)
+test_static int test_hierarchy_0(void)
{
int port = PORT0;
int i = 0;
clear_seq(port);
- sm_init_state(port, TSM_OBJ(port), sm_test_A4);
+ set_state_sm(port, SM_TEST_A4);
run_sm();
TEST_EQ(sm[port].seq[i], ENTER_A4, "%d"); ++i;
@@ -728,17 +496,14 @@ static int test_hierarchy_0(void)
return EC_SUCCESS;
}
-#endif
-
-#if defined(TEST_USB_SM_FRAMEWORK_H1)
-static int test_hierarchy_1(void)
+test_static int test_hierarchy_1(void)
{
int port = PORT0;
int i = 0;
clear_seq(port);
- sm_init_state(port, TSM_OBJ(port), sm_test_A4);
+ set_state_sm(port, SM_TEST_A4);
run_sm();
TEST_EQ(sm[port].seq[i], ENTER_A3, "%d"); ++i;
@@ -812,18 +577,15 @@ static int test_hierarchy_1(void)
return EC_SUCCESS;
}
-#endif
-
-#if defined(TEST_USB_SM_FRAMEWORK_H2)
-static int test_hierarchy_2(void)
+test_static int test_hierarchy_2(void)
{
int port = PORT0;
int i = 0;
clear_seq(port);
- sm_init_state(port, TSM_OBJ(port), sm_test_A4);
+ set_state_sm(port, SM_TEST_A4);
run_sm();
TEST_EQ(sm[port].seq[i], ENTER_A2, "%d"); ++i;
@@ -907,17 +669,15 @@ static int test_hierarchy_2(void)
return EC_SUCCESS;
}
-#endif
-#if defined(TEST_USB_SM_FRAMEWORK_H3)
-static int test_hierarchy_3(void)
+test_static int test_hierarchy_3(void)
{
int port = PORT0;
int i = 0;
clear_seq(port);
- sm_init_state(port, TSM_OBJ(port), sm_test_A4);
+ set_state_sm(port, SM_TEST_A4);
run_sm();
TEST_EQ(sm[port].seq[i], ENTER_A1, "%d"); ++i;
@@ -1013,7 +773,125 @@ static int test_hierarchy_3(void)
return EC_SUCCESS;
}
+
+
+#ifdef TEST_USB_SM_FRAMEWORK_H3
+#define TEST_AT_LEAST_3
+#endif
+
+#if defined(TEST_AT_LEAST_3) || defined(TEST_USB_SM_FRAMEWORK_H2)
+#define TEST_AT_LEAST_2
+#endif
+
+#if defined(TEST_AT_LEAST_2) || defined(TEST_USB_SM_FRAMEWORK_H1)
+#define TEST_AT_LEAST_1
+#endif
+
+static const struct usb_state states[] = {
+ [SM_TEST_SUPER_A1] = {
+ .entry = sm_test_super_A1_entry,
+ .run = sm_test_super_A1_run,
+ .exit = sm_test_super_A1_exit,
+ },
+ [SM_TEST_SUPER_A2] = {
+ .entry = sm_test_super_A2_entry,
+ .run = sm_test_super_A2_run,
+ .exit = sm_test_super_A2_exit,
+#ifdef TEST_AT_LEAST_3
+ .parent = &states[SM_TEST_SUPER_A1],
+#endif
+ },
+ [SM_TEST_SUPER_A3] = {
+ .entry = sm_test_super_A3_entry,
+ .run = sm_test_super_A3_run,
+ .exit = sm_test_super_A3_exit,
+#ifdef TEST_AT_LEAST_2
+ .parent = &states[SM_TEST_SUPER_A2],
+#endif
+ },
+ [SM_TEST_SUPER_B1] = {
+ .entry = sm_test_super_B1_entry,
+ .run = sm_test_super_B1_run,
+ .exit = sm_test_super_B1_exit,
+ },
+ [SM_TEST_SUPER_B2] = {
+ .entry = sm_test_super_B2_entry,
+ .run = sm_test_super_B2_run,
+ .exit = sm_test_super_B2_exit,
+#ifdef TEST_AT_LEAST_3
+ .parent = &states[SM_TEST_SUPER_B1],
+#endif
+ },
+ [SM_TEST_SUPER_B3] = {
+ .entry = sm_test_super_B3_entry,
+ .run = sm_test_super_B3_run,
+ .exit = sm_test_super_B3_exit,
+#ifdef TEST_AT_LEAST_2
+ .parent = &states[SM_TEST_SUPER_B2],
#endif
+ },
+ [SM_TEST_A4] = {
+ .entry = sm_test_A4_entry,
+ .run = sm_test_A4_run,
+ .exit = sm_test_A4_exit,
+#ifdef TEST_AT_LEAST_1
+ .parent = &states[SM_TEST_SUPER_A3],
+#endif
+ },
+ [SM_TEST_A5] = {
+ .entry = sm_test_A5_entry,
+ .run = sm_test_A5_run,
+ .exit = sm_test_A5_exit,
+#ifdef TEST_AT_LEAST_1
+ .parent = &states[SM_TEST_SUPER_A3],
+#endif
+ },
+ [SM_TEST_A6] = {
+ .entry = sm_test_A6_entry,
+ .run = sm_test_A6_run,
+ .exit = sm_test_A6_exit,
+#ifdef TEST_AT_LEAST_2
+ .parent = &states[SM_TEST_SUPER_A2],
+#endif
+ },
+ [SM_TEST_A7] = {
+ .entry = sm_test_A7_entry,
+ .run = sm_test_A7_run,
+ .exit = sm_test_A7_exit,
+#ifdef TEST_AT_LEAST_3
+ .parent = &states[SM_TEST_SUPER_A1],
+#endif
+ },
+ [SM_TEST_B4] = {
+ .entry = sm_test_B4_entry,
+ .run = sm_test_B4_run,
+ .exit = sm_test_B4_exit,
+#ifdef TEST_AT_LEAST_1
+ .parent = &states[SM_TEST_SUPER_B3],
+#endif
+ },
+ [SM_TEST_B5] = {
+ .entry = sm_test_B5_entry,
+ .run = sm_test_B5_run,
+ .exit = sm_test_B5_exit,
+#ifdef TEST_AT_LEAST_2
+ .parent = &states[SM_TEST_SUPER_B2],
+#endif
+ },
+ [SM_TEST_B6] = {
+ .entry = sm_test_B6_entry,
+ .run = sm_test_B6_run,
+ .exit = sm_test_B6_exit,
+#ifdef TEST_AT_LEAST_3
+ .parent = &states[SM_TEST_SUPER_B1],
+#endif
+ },
+ [SM_TEST_C] = {
+ .entry = sm_test_C_entry,
+ .run = sm_test_C_run,
+ .exit = sm_test_C_exit,
+ },
+};
int test_task(void *u)
{
@@ -1023,7 +901,7 @@ int test_task(void *u)
/* wait for next event/packet or timeout expiration */
task_wait_event(-1);
/* run state machine */
- sm_run_state_machine(port, TSM_OBJ(port), SM_RUN_SIG);
+ exe_state(port, &sm[port].ctx);
}
return EC_SUCCESS;
diff --git a/test/usb_typec_ctvpd.c b/test/usb_typec_ctvpd.c
index b2a100ad25..2d45b4f882 100644
--- a/test/usb_typec_ctvpd.c
+++ b/test/usb_typec_ctvpd.c
@@ -24,6 +24,36 @@ enum vbus_type {VBUS_0 = 0, VBUS_5 = 5000};
enum vconn_type {VCONN_0 = 0, VCONN_3 = 3000, VCONN_5 = 5000};
enum snk_con_voltage_type {SRC_CON_DEF, SRC_CON_1_5, SRC_CON_3_0};
+/*
+ * These enum definitions are declared in usb_tc_*_sm and are private to that
+ * file. If those definitions are re-ordered, then we need to update these
+ * definitions (should be very rare).
+ */
+enum usb_tc_state {
+ /* Normal States */
+ TC_DISABLED,
+ TC_UNATTACHED_SNK,
+ TC_ATTACH_WAIT_SNK,
+ TC_ATTACHED_SNK,
+ TC_ERROR_RECOVERY,
+ TC_TRY_SNK,
+ TC_UNATTACHED_SRC,
+ TC_ATTACH_WAIT_SRC,
+ TC_TRY_WAIT_SRC,
+ TC_ATTACHED_SRC,
+ TC_CT_TRY_SNK,
+ TC_CT_ATTACH_WAIT_UNSUPPORTED,
+ TC_CT_ATTACHED_UNSUPPORTED,
+ TC_CT_UNATTACHED_UNSUPPORTED,
+ TC_CT_UNATTACHED_VPD,
+ TC_CT_DISABLED_VPD,
+ TC_CT_ATTACHED_VPD,
+ TC_CT_ATTACH_WAIT_VPD,
+};
+
+/* Defined in implementation */
+enum usb_tc_state get_state_tc(const int port);
+
struct pd_port_t {
int host_mode;
int has_vbus;
@@ -39,13 +69,13 @@ uint64_t wait_for_state_change(int port, uint64_t timeout)
{
uint64_t start;
uint64_t wait;
- uint32_t state = get_typec_state_id(port);
+ enum usb_tc_state state = get_state_tc(port);
task_wake(PD_PORT_TO_TASK_ID(port));
wait = get_time().val + timeout;
start = get_time().val;
- while (get_typec_state_id(port) == state && get_time().val < wait)
+ while (get_state_tc(port) == state && get_time().val < wait)
task_wait_event(5 * MSEC);
return get_time().val - start;
@@ -330,7 +360,7 @@ static int test_vpd_host_src_detection(void)
* Host is configured properly and start state is UNATTACHED_SNK
*/
TEST_ASSERT(check_host_ra_rd());
- TEST_ASSERT(get_typec_state_id(port) == TC_UNATTACHED_SNK);
+ TEST_ASSERT(get_state_tc(port) == TC_UNATTACHED_SNK);
/*
* TEST:
@@ -342,7 +372,7 @@ static int test_vpd_host_src_detection(void)
wait_for_state_change(port, 40 * MSEC);
- TEST_ASSERT(get_typec_state_id(port) == TC_ATTACH_WAIT_SNK);
+ TEST_ASSERT(get_state_tc(port) == TC_ATTACH_WAIT_SNK);
/*
* TEST:
@@ -373,7 +403,7 @@ static int test_vpd_host_src_detection(void)
wait_for_state_change(port, 40 * MSEC);
- TEST_ASSERT(get_typec_state_id(port) == TC_UNATTACHED_SNK);
+ TEST_ASSERT(get_state_tc(port) == TC_UNATTACHED_SNK);
return EC_SUCCESS;
}
@@ -394,7 +424,7 @@ static int test_vpd_host_src_detection_vbus(void)
*/
TEST_ASSERT(check_host_ra_rd());
- TEST_ASSERT(get_typec_state_id(port) == TC_UNATTACHED_SNK);
+ TEST_ASSERT(get_state_tc(port) == TC_UNATTACHED_SNK);
/*
* TEST:
@@ -406,7 +436,7 @@ static int test_vpd_host_src_detection_vbus(void)
wait_for_state_change(port, 40 * MSEC);
- TEST_ASSERT(get_typec_state_id(port) == TC_ATTACH_WAIT_SNK);
+ TEST_ASSERT(get_state_tc(port) == TC_ATTACH_WAIT_SNK);
/*
* TEST:
@@ -418,7 +448,7 @@ static int test_vpd_host_src_detection_vbus(void)
wait_for_state_change(port, PD_T_CC_DEBOUNCE + 10 * MSEC);
- TEST_ASSERT(get_typec_state_id(port) == TC_ATTACHED_SNK);
+ TEST_ASSERT(get_state_tc(port) == TC_ATTACHED_SNK);
/*
* TEST:
@@ -429,7 +459,7 @@ static int test_vpd_host_src_detection_vbus(void)
wait_for_state_change(port, 10 * MSEC);
- TEST_ASSERT(get_typec_state_id(port) == TC_UNATTACHED_SNK);
+ TEST_ASSERT(get_state_tc(port) == TC_UNATTACHED_SNK);
return EC_SUCCESS;
}
@@ -450,7 +480,7 @@ static int test_vpd_host_src_detection_vconn(void)
*/
TEST_ASSERT(check_host_ra_rd());
- TEST_ASSERT(get_typec_state_id(port) == TC_UNATTACHED_SNK);
+ TEST_ASSERT(get_state_tc(port) == TC_UNATTACHED_SNK);
/*
* TEST:
@@ -462,7 +492,7 @@ static int test_vpd_host_src_detection_vconn(void)
wait_for_state_change(port, 40 * MSEC);
- TEST_ASSERT(get_typec_state_id(port) == TC_ATTACH_WAIT_SNK);
+ TEST_ASSERT(get_state_tc(port) == TC_ATTACH_WAIT_SNK);
/*
* TEST:
@@ -474,7 +504,7 @@ static int test_vpd_host_src_detection_vconn(void)
wait_for_state_change(port, PD_T_CC_DEBOUNCE + 10 * MSEC);
- TEST_ASSERT(get_typec_state_id(port) == TC_ATTACHED_SNK);
+ TEST_ASSERT(get_state_tc(port) == TC_ATTACHED_SNK);
/* VCONN was detected. Make sure RA is removed */
task_wake(PD_PORT_TO_TASK_ID(port));
@@ -490,7 +520,7 @@ static int test_vpd_host_src_detection_vconn(void)
wait_for_state_change(port, 10 * MSEC);
- TEST_ASSERT(get_typec_state_id(port) == TC_UNATTACHED_SNK);
+ TEST_ASSERT(get_state_tc(port) == TC_UNATTACHED_SNK);
host_disconnect_source();
@@ -540,7 +570,7 @@ static int test_vpd_host_src_detection_message_reception(void)
*/
TEST_ASSERT(check_host_ra_rd());
- TEST_ASSERT(get_typec_state_id(port) == TC_UNATTACHED_SNK);
+ TEST_ASSERT(get_state_tc(port) == TC_UNATTACHED_SNK);
/*
* Transition to ATTACHED_SNK
@@ -550,11 +580,11 @@ static int test_vpd_host_src_detection_message_reception(void)
wait_for_state_change(port, 10 * MSEC);
- TEST_ASSERT(get_typec_state_id(port) == TC_ATTACH_WAIT_SNK);
+ TEST_ASSERT(get_state_tc(port) == TC_ATTACH_WAIT_SNK);
wait_for_state_change(port, PD_T_CC_DEBOUNCE + 20 * MSEC);
- TEST_ASSERT(get_typec_state_id(port) == TC_ATTACHED_SNK);
+ TEST_ASSERT(get_state_tc(port) == TC_ATTACHED_SNK);
/* Run state machines to enable rx monitoring */
task_wake(PD_PORT_TO_TASK_ID(port));
@@ -606,7 +636,7 @@ static int test_vpd_host_src_detection_message_reception(void)
wait_for_state_change(port, 10 * MSEC);
- TEST_ASSERT(get_typec_state_id(port) == TC_UNATTACHED_SNK);
+ TEST_ASSERT(get_state_tc(port) == TC_UNATTACHED_SNK);
host_disconnect_source();
@@ -634,7 +664,7 @@ static int test_ctvpd_behavior_case1(void)
*/
/* 1. DRP and CTVPD are both in the unattached state */
- TEST_ASSERT(get_typec_state_id(port) == TC_UNATTACHED_SNK);
+ TEST_ASSERT(get_state_tc(port) == TC_UNATTACHED_SNK);
/*
* a. DRP alternates between Unattached.SRC and Unattached.SNK
@@ -670,10 +700,10 @@ static int test_ctvpd_behavior_case1(void)
* Charge-Through port’s CC1 and CC2 pins
*/
wait_for_state_change(port, 40 * MSEC);
- TEST_ASSERT(get_typec_state_id(port) == TC_ATTACH_WAIT_SNK);
+ TEST_ASSERT(get_state_tc(port) == TC_ATTACH_WAIT_SNK);
wait_for_state_change(port, PD_T_CC_DEBOUNCE + 40 * MSEC);
- TEST_ASSERT(get_typec_state_id(port) == TC_ATTACHED_SNK);
+ TEST_ASSERT(get_state_tc(port) == TC_ATTACHED_SNK);
TEST_ASSERT(check_ct_ccs_hz());
/*
@@ -702,7 +732,7 @@ static int test_ctvpd_behavior_case1(void)
* d. CTVPD apply Rd on its Charge-Through port’s CC1 and CC2 pins
*/
wait_for_state_change(port, 40 * MSEC);
- TEST_ASSERT(get_typec_state_id(port) == TC_CTUNATTACHED_VPD);
+ TEST_ASSERT(get_state_tc(port) == TC_CT_UNATTACHED_VPD);
/*
* 6. While the CTVPD in CTUnattached.VPD state and the DRP in
@@ -723,32 +753,32 @@ static int test_ctvpd_behavior_case1(void)
TEST_ASSERT(ct_connect_source(CC2, VBUS_0));
wait_for_state_change(port, 40 * MSEC);
- TEST_ASSERT(get_typec_state_id(port) == TC_CTATTACH_WAIT_VPD);
+ TEST_ASSERT(get_state_tc(port) == TC_CT_ATTACH_WAIT_VPD);
/* Remove Power Source */
TEST_ASSERT(ct_disconnect_source());
wait_for_state_change(port, 40 * MSEC);
- TEST_ASSERT(get_typec_state_id(port) == TC_CTUNATTACHED_VPD);
+ TEST_ASSERT(get_state_tc(port) == TC_CT_UNATTACHED_VPD);
/* Attach Sink */
TEST_ASSERT(ct_connect_sink(CC1, SRC_CON_DEF));
wait_for_state_change(port, PD_T_DRP_SNK);
- TEST_ASSERT(get_typec_state_id(port) == TC_CTUNATTACHED_UNSUPPORTED);
+ TEST_ASSERT(get_state_tc(port) == TC_CT_UNATTACHED_UNSUPPORTED);
wait_for_state_change(port, 40 * MSEC);
- TEST_ASSERT(get_typec_state_id(port) == TC_CTATTACH_WAIT_UNSUPPORTED);
+ TEST_ASSERT(get_state_tc(port) == TC_CT_ATTACH_WAIT_UNSUPPORTED);
/* Remove VCONN (Host detach) */
mock_set_vconn(VCONN_0);
wait_for_state_change(port, 40 * MSEC);
- TEST_ASSERT(get_typec_state_id(port) == TC_UNATTACHED_SNK);
+ TEST_ASSERT(get_state_tc(port) == TC_UNATTACHED_SNK);
return EC_SUCCESS;
}
@@ -780,25 +810,25 @@ static int test_ctvpd_behavior_case2(void)
* pins and Rp termination advertising 3.0 A on the Host-side
* port’s CC pin
*/
- TEST_ASSERT(get_typec_state_id(port) == TC_UNATTACHED_SNK);
+ TEST_ASSERT(get_state_tc(port) == TC_UNATTACHED_SNK);
host_connect_source(VBUS_5);
mock_set_vconn(VCONN_3);
wait_for_state_change(port, 40 * MSEC);
- TEST_ASSERT(get_typec_state_id(port) == TC_ATTACH_WAIT_SNK);
+ TEST_ASSERT(get_state_tc(port) == TC_ATTACH_WAIT_SNK);
wait_for_state_change(port, PD_T_CC_DEBOUNCE + 40 * MSEC);
- TEST_ASSERT(get_typec_state_id(port) == TC_ATTACHED_SNK);
+ TEST_ASSERT(get_state_tc(port) == TC_ATTACHED_SNK);
/* Remove Host CC */
mock_set_host_cc_source_voltage(0);
wait_for_state_change(port, 40 * MSEC);
- TEST_ASSERT(get_typec_state_id(port) == TC_CTUNATTACHED_VPD);
+ TEST_ASSERT(get_state_tc(port) == TC_CT_UNATTACHED_VPD);
TEST_ASSERT(check_ct_ccs_rd());
TEST_ASSERT(check_host_rp3a0());
@@ -836,11 +866,11 @@ static int test_ctvpd_behavior_case2(void)
wait_for_state_change(port, 40 * MSEC);
- TEST_ASSERT(get_typec_state_id(port) == TC_CTATTACH_WAIT_VPD);
+ TEST_ASSERT(get_state_tc(port) == TC_CT_ATTACH_WAIT_VPD);
wait_for_state_change(port, PD_T_CC_DEBOUNCE + 40 * MSEC);
- TEST_ASSERT(get_typec_state_id(port) == TC_CTATTACHED_VPD);
+ TEST_ASSERT(get_state_tc(port) == TC_CT_ATTACHED_VPD);
TEST_ASSERT(moch_get_ct_cl_sel() == CT_CC2);
TEST_ASSERT(check_host_cc_open());
TEST_ASSERT(check_ct_ccs_hz());
@@ -870,7 +900,7 @@ static int test_ctvpd_behavior_case2(void)
wait_for_state_change(port, 40 * MSEC);
- TEST_ASSERT(get_typec_state_id(port) == TC_CTDISABLED_VPD);
+ TEST_ASSERT(get_state_tc(port) == TC_CT_DISABLED_VPD);
return EC_SUCCESS;
}
@@ -899,7 +929,7 @@ static int test_ctvpd_behavior_case3(void)
* a. CTVPD has applied Rd on the Charge-Through port’s CC1 and CC2
* pins and Rd on the Host-side port’s CC pin
*/
- TEST_ASSERT(get_typec_state_id(port) == TC_UNATTACHED_SNK);
+ TEST_ASSERT(get_state_tc(port) == TC_UNATTACHED_SNK);
TEST_ASSERT(check_ct_ccs_rd());
TEST_ASSERT(check_host_ra_rd());
@@ -923,7 +953,7 @@ static int test_ctvpd_behavior_case3(void)
* between Unattached.SRC and Unattached.SNK
*/
wait_for_state_change(port, PD_T_CC_DEBOUNCE + 40 * MSEC);
- TEST_ASSERT(get_typec_state_id(port) == TC_UNATTACHED_SRC);
+ TEST_ASSERT(get_state_tc(port) == TC_UNATTACHED_SRC);
/*
* 4. While the CTVPD alternates between Unattached.SRC and
@@ -942,14 +972,14 @@ static int test_ctvpd_behavior_case3(void)
wait_for_state_change(port, 40 * MSEC);
- TEST_ASSERT(get_typec_state_id(port) == TC_ATTACH_WAIT_SRC);
+ TEST_ASSERT(get_state_tc(port) == TC_ATTACH_WAIT_SRC);
/* Remove VBUS */
TEST_ASSERT(ct_disconnect_source());
wait_for_state_change(port, 40 * MSEC);
- TEST_ASSERT(get_typec_state_id(port) == TC_UNATTACHED_SNK);
+ TEST_ASSERT(get_state_tc(port) == TC_UNATTACHED_SNK);
return EC_SUCCESS;
}
@@ -1004,7 +1034,7 @@ static int test_ctvpd_behavior_case4(void)
* b. CTVPD has applied Rd on its Charge-Through port’s CC1 and CC2
* pins and Rd on the Host-side port’s CC pin
*/
- TEST_ASSERT(get_typec_state_id(port) == TC_UNATTACHED_SNK);
+ TEST_ASSERT(get_state_tc(port) == TC_UNATTACHED_SNK);
TEST_ASSERT(check_ct_ccs_rd());
TEST_ASSERT(check_host_ra_rd());
@@ -1038,11 +1068,11 @@ static int test_ctvpd_behavior_case4(void)
wait_for_state_change(port, 40 * MSEC);
- TEST_ASSERT(get_typec_state_id(port) == TC_ATTACH_WAIT_SNK);
+ TEST_ASSERT(get_state_tc(port) == TC_ATTACH_WAIT_SNK);
wait_for_state_change(port, PD_T_CC_DEBOUNCE + 40 * MSEC);
- TEST_ASSERT(get_typec_state_id(port) == TC_ATTACHED_SNK);
+ TEST_ASSERT(get_state_tc(port) == TC_ATTACHED_SNK);
TEST_ASSERT(check_ct_ccs_hz());
/*
@@ -1109,7 +1139,7 @@ static int test_ctvpd_behavior_case4(void)
wait_for_state_change(port, 40 * MSEC);
- TEST_ASSERT(get_typec_state_id(port) == TC_CTUNATTACHED_VPD);
+ TEST_ASSERT(get_state_tc(port) == TC_CT_UNATTACHED_VPD);
TEST_ASSERT(check_ct_ccs_rd());
TEST_ASSERT(check_host_rp3a0());
@@ -1119,16 +1149,16 @@ static int test_ctvpd_behavior_case4(void)
*/
wait_for_state_change(port, PD_T_DRP_SRC + 10 * MSEC);
- TEST_ASSERT(get_typec_state_id(port) == TC_CTUNATTACHED_UNSUPPORTED);
+ TEST_ASSERT(get_state_tc(port) == TC_CT_UNATTACHED_UNSUPPORTED);
wait_for_state_change(port, PD_T_DRP_SRC + 10 * MSEC);
- TEST_ASSERT(get_typec_state_id(port) == TC_CTUNATTACHED_VPD);
+ TEST_ASSERT(get_state_tc(port) == TC_CT_UNATTACHED_VPD);
TEST_ASSERT(ct_connect_source(CC2, VBUS_5));
wait_for_state_change(port, 40 * MSEC);
- TEST_ASSERT(get_typec_state_id(port) == TC_CTATTACH_WAIT_VPD);
+ TEST_ASSERT(get_state_tc(port) == TC_CT_ATTACH_WAIT_VPD);
return EC_SUCCESS;
}
@@ -1159,7 +1189,7 @@ static int test_ctvpd_behavior_case5(void)
* b. CTVPD apply Rd on the Charge-Through port’s CC1 and CC2 pins
* and Rd on the Host-side port’s CC pin
*/
- TEST_ASSERT(get_typec_state_id(port) == TC_UNATTACHED_SNK);
+ TEST_ASSERT(get_state_tc(port) == TC_UNATTACHED_SNK);
TEST_ASSERT(check_ct_ccs_rd());
TEST_ASSERT(check_host_ra_rd());
@@ -1184,7 +1214,7 @@ static int test_ctvpd_behavior_case5(void)
*/
wait_for_state_change(port, PD_T_CC_DEBOUNCE + 40 * MSEC);
- TEST_ASSERT(get_typec_state_id(port) == TC_UNATTACHED_SRC);
+ TEST_ASSERT(get_state_tc(port) == TC_UNATTACHED_SRC);
/* Connect Host With Dead Battery */
host_connect_sink(SRC_CON_DEF);
@@ -1204,11 +1234,11 @@ static int test_ctvpd_behavior_case5(void)
wait_for_state_change(port, 40 * MSEC);
- TEST_ASSERT(get_typec_state_id(port) == TC_ATTACH_WAIT_SRC);
+ TEST_ASSERT(get_state_tc(port) == TC_ATTACH_WAIT_SRC);
wait_for_state_change(port, PD_T_CC_DEBOUNCE + 10 * MSEC);
- TEST_ASSERT(get_typec_state_id(port) == TC_TRY_SNK);
+ TEST_ASSERT(get_state_tc(port) == TC_TRY_SNK);
TEST_ASSERT(check_host_ra_rd());
/* 5. DRP in dead battery condition remains in Unattached.SNK */
@@ -1230,12 +1260,12 @@ static int test_ctvpd_behavior_case5(void)
wait_for_state_change(port, PD_T_TRY_CC_DEBOUNCE +
PD_T_DRP_TRY + 40 * MSEC);
- TEST_ASSERT(get_typec_state_id(port) == TC_TRY_WAIT_SRC);
+ TEST_ASSERT(get_state_tc(port) == TC_TRY_WAIT_SRC);
TEST_ASSERT(check_host_rpusb());
wait_for_state_change(port, 40 * MSEC);
- TEST_ASSERT(get_typec_state_id(port) == TC_ATTACHED_SRC);
+ TEST_ASSERT(get_state_tc(port) == TC_ATTACHED_SRC);
TEST_ASSERT(mock_get_vbus_pass_en());
/*
@@ -1268,7 +1298,7 @@ static int test_ctvpd_behavior_case5(void)
wait_for_state_change(port, 40 * MSEC);
- TEST_ASSERT(get_typec_state_id(port) == TC_UNATTACHED_SNK);
+ TEST_ASSERT(get_state_tc(port) == TC_UNATTACHED_SNK);
return EC_SUCCESS;
}
@@ -1299,7 +1329,7 @@ static int test_ctvpd_behavior_case6(void)
* b. CTVPD has applied Rd on its Charge-Through port’s CC1 and CC2
* pins and Rd on the Host-side port’s CC pin
*/
- TEST_ASSERT(get_typec_state_id(port) == TC_UNATTACHED_SNK);
+ TEST_ASSERT(get_state_tc(port) == TC_UNATTACHED_SNK);
TEST_ASSERT(check_ct_ccs_rd());
TEST_ASSERT(check_host_ra_rd());
@@ -1330,11 +1360,11 @@ static int test_ctvpd_behavior_case6(void)
*/
wait_for_state_change(port, 40 * MSEC);
- TEST_ASSERT(get_typec_state_id(port) == TC_ATTACH_WAIT_SNK);
+ TEST_ASSERT(get_state_tc(port) == TC_ATTACH_WAIT_SNK);
wait_for_state_change(port, PD_T_CC_DEBOUNCE + 40 * MSEC);
- TEST_ASSERT(get_typec_state_id(port) == TC_ATTACHED_SNK);
+ TEST_ASSERT(get_state_tc(port) == TC_ATTACHED_SNK);
TEST_ASSERT(check_ct_ccs_hz());
/*
@@ -1367,7 +1397,7 @@ static int test_ctvpd_behavior_case6(void)
*/
wait_for_state_change(port, 40 * MSEC);
- TEST_ASSERT(get_typec_state_id(port) == TC_CTUNATTACHED_VPD);
+ TEST_ASSERT(get_state_tc(port) == TC_CT_UNATTACHED_VPD);
TEST_ASSERT(check_host_rp3a0());
TEST_ASSERT(mock_get_vbus_pass_en() == 0);
TEST_ASSERT(check_ct_ccs_rd());
@@ -1382,15 +1412,15 @@ static int test_ctvpd_behavior_case6(void)
*/
wait_for_state_change(port, PD_T_DRP_SNK + 40 * MSEC);
- TEST_ASSERT(get_typec_state_id(port) == TC_CTUNATTACHED_UNSUPPORTED);
+ TEST_ASSERT(get_state_tc(port) == TC_CT_UNATTACHED_UNSUPPORTED);
wait_for_state_change(port, PD_T_DRP_SNK + 40 * MSEC);
- TEST_ASSERT(get_typec_state_id(port) == TC_CTUNATTACHED_VPD);
+ TEST_ASSERT(get_state_tc(port) == TC_CT_UNATTACHED_VPD);
wait_for_state_change(port, PD_T_DRP_SNK + 40 * MSEC);
- TEST_ASSERT(get_typec_state_id(port) == TC_CTUNATTACHED_UNSUPPORTED);
+ TEST_ASSERT(get_state_tc(port) == TC_CT_UNATTACHED_UNSUPPORTED);
/*
* 7. CTVPD transitions from CTUnattached.Unsupported to CTTry.SNK
@@ -1409,11 +1439,11 @@ static int test_ctvpd_behavior_case6(void)
wait_for_state_change(port, 40 * MSEC);
- TEST_ASSERT(get_typec_state_id(port) == TC_CTATTACH_WAIT_UNSUPPORTED);
+ TEST_ASSERT(get_state_tc(port) == TC_CT_ATTACH_WAIT_UNSUPPORTED);
wait_for_state_change(port, PD_T_CC_DEBOUNCE + 40 * MSEC);
- TEST_ASSERT(get_typec_state_id(port) == TC_CTTRY_SNK);
+ TEST_ASSERT(get_state_tc(port) == TC_CT_TRY_SNK);
TEST_ASSERT(check_ct_ccs_rd());
/*
@@ -1426,7 +1456,7 @@ static int test_ctvpd_behavior_case6(void)
wait_for_state_change(port, PD_T_DRP_TRY + PD_T_TRY_WAIT + 40 * MSEC);
- TEST_ASSERT(get_typec_state_id(port) == TC_CTATTACHED_UNSUPPORTED);
+ TEST_ASSERT(get_state_tc(port) == TC_CT_ATTACHED_UNSUPPORTED);
/*
* 9. While the CTVPD in CTAttached.Unsupported state, the DRP in
@@ -1455,7 +1485,7 @@ static int test_ctvpd_behavior_case6(void)
wait_for_state_change(port, 40 * MSEC);
- TEST_ASSERT(get_typec_state_id(port) == TC_CTUNATTACHED_VPD);
+ TEST_ASSERT(get_state_tc(port) == TC_CT_UNATTACHED_VPD);
return EC_SUCCESS;
}