summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorSam Hurst <shurst@google.com>2019-08-01 09:09:10 -0700
committerCommit Bot <commit-bot@chromium.org>2019-09-10 09:24:36 +0000
commitc32c1ae24c398679edae807f9c1620eb91377003 (patch)
treef284f214e47729345cdd2d9c25add31a7449e7a0 /test
parent16ce272e65cae34ad1b0ad3e8a301e6e307ed49c (diff)
downloadchrome-ec-c32c1ae24c398679edae807f9c1620eb91377003.tar.gz
pd: USB Power Delivery State Machine based on Revision 3.0 of the spec.
Adds Power Delivery to the TypeC state machine as detailed in Revision 3.0, Version 1.2 of the specification. This CL passes the PD2.0 compliance tests and has been tested on several devices. Some areas such as handling Electronically Marked Cable information, creation of PIDs, and Host commands will be addressed in later CLs. BUG=b:130895206 BRANCH=none TEST=manual 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. Atlas was verified to work with Apple, Amazon, StarTech, MKDGO and several other generic docks. Atlas was verified to work with Google's and Apple's CTVPD. Signed-off-by: Sam Hurst <shurst@chromium.org> Change-Id: Ia5e1988b0d81ec4cf9a7175e273197bd5a0865e4 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1737899 Reviewed-by: Jett Rink <jettrink@chromium.org> Reviewed-by: Denis Brockus <dbrockus@chromium.org> Tested-by: Jett Rink <jettrink@chromium.org> Commit-Queue: Denis Brockus <dbrockus@chromium.org>
Diffstat (limited to 'test')
-rw-r--r--test/usb_prl.c34
1 files changed, 19 insertions, 15 deletions
diff --git a/test/usb_prl.c b/test/usb_prl.c
index eab20be46f..0bbcb1412d 100644
--- a/test/usb_prl.c
+++ b/test/usb_prl.c
@@ -102,7 +102,7 @@ static struct pd_prl {
int mock_pe_error;
int mock_pe_hard_reset_sent;
int mock_pe_got_hard_reset;
- int mock_pe_pass_up_message;
+ int mock_pe_message_received;
int mock_got_soft_reset;
} pd_port[CONFIG_USB_PD_PORT_COUNT];
@@ -114,6 +114,7 @@ static void init_port(int port, int rev)
pd_port[port].data_role = PD_ROLE_UFP;
pd_port[port].msg_tx_id = 0;
pd_port[port].msg_rx_id = 0;
+
tcpm_init(port);
tcpm_set_polarity(port, 0);
tcpm_set_rx_enable(port, 0);
@@ -224,7 +225,7 @@ static int verify_data_reception(int port, uint16_t header, int len)
if (pd_port[port].mock_pe_error >= 0)
return 0;
- if (!pd_port[port].mock_pe_pass_up_message)
+ if (!pd_port[port].mock_pe_message_received)
return 0;
if (emsg[port].header != header)
@@ -255,7 +256,7 @@ static int verify_chunk_data_reception(int port, uint16_t header, int len)
if (pd_port[port].mock_got_soft_reset)
return 0;
- if (!pd_port[port].mock_pe_pass_up_message)
+ if (!pd_port[port].mock_pe_message_received)
return 0;
if (pd_port[port].mock_pe_error >= 0)
@@ -282,7 +283,7 @@ static int simulate_receive_data(int port, enum pd_data_msg_type msg_type,
nw, pd_port[port].rev, 0);
pd_port[port].mock_pe_error = -1;
- pd_port[port].mock_pe_pass_up_message = 0;
+ pd_port[port].mock_pe_message_received = 0;
emsg[port].header = 0;
emsg[port].len = 0;
memset(emsg[port].buf, 0, 260);
@@ -322,7 +323,7 @@ static int simulate_receive_extended_data(int port,
int req_timeout;
pd_port[port].mock_pe_error = -1;
- pd_port[port].mock_pe_pass_up_message = 0;
+ pd_port[port].mock_pe_message_received = 0;
emsg[port].header = 0;
emsg[port].len = 0;
memset(emsg[port].buf, 0, 260);
@@ -354,7 +355,7 @@ static int simulate_receive_extended_data(int port,
if (pd_port[port].mock_pe_error >= 0)
return 0;
- if (pd_port[port].mock_pe_pass_up_message)
+ if (pd_port[port].mock_pe_message_received)
return 0;
if (emsg[port].len != 0)
@@ -699,9 +700,9 @@ void pe_got_hard_reset(int port)
pd_port[port].mock_pe_got_hard_reset = 1;
}
-void pe_pass_up_message(int port)
+void pe_message_received(int port)
{
- pd_port[port].mock_pe_pass_up_message = 1;
+ pd_port[port].mock_pe_message_received = 1;
}
void pe_message_sent(int port)
@@ -719,12 +720,14 @@ void pe_got_soft_reset(int port)
pd_port[port].mock_got_soft_reset = 1;
}
-static int test_initial_states(void)
+static int test_prl_reset(void)
{
int port = PORT0;
enable_prl(port, 1);
+ prl_reset(port);
+
TEST_ASSERT(prl_tx_get_state(port) ==
PRL_TX_WAIT_FOR_MESSAGE_REQUEST);
TEST_ASSERT(rch_get_state(port) ==
@@ -733,6 +736,7 @@ static int test_initial_states(void)
TCH_WAIT_FOR_MESSAGE_REQUEST_FROM_PE);
TEST_ASSERT(prl_hr_get_state(port) ==
PRL_HR_WAIT_FOR_REQUEST);
+ enable_prl(port, 0);
return EC_SUCCESS;
}
@@ -1047,7 +1051,7 @@ static int test_receive_soft_reset_msg(void)
pd_port[port].mock_got_soft_reset = 0;
pd_port[port].mock_pe_error = -1;
- pd_port[port].mock_pe_pass_up_message = 0;
+ pd_port[port].mock_pe_message_received = 0;
TEST_ASSERT(simulate_receive_ctrl_msg(port, PD_CTRL_SOFT_RESET));
@@ -1058,7 +1062,7 @@ static int test_receive_soft_reset_msg(void)
TEST_ASSERT(pd_port[port].mock_got_soft_reset);
TEST_ASSERT(pd_port[port].mock_pe_error < 0);
- TEST_ASSERT(pd_port[port].mock_pe_pass_up_message);
+ TEST_ASSERT(pd_port[port].mock_pe_message_received);
TEST_ASSERT(expected_header == emsg[port].header);
TEST_ASSERT(emsg[port].len == 0);
@@ -1090,7 +1094,7 @@ static int test_receive_control_msg(void)
pd_port[port].mock_got_soft_reset = 0;
pd_port[port].mock_pe_error = -1;
- pd_port[port].mock_pe_pass_up_message = 0;
+ pd_port[port].mock_pe_message_received = 0;
TEST_ASSERT(simulate_receive_ctrl_msg(port, PD_CTRL_DR_SWAP));
@@ -1101,7 +1105,7 @@ static int test_receive_control_msg(void)
TEST_ASSERT(!pd_port[port].mock_got_soft_reset);
TEST_ASSERT(pd_port[port].mock_pe_error < 0);
- TEST_ASSERT(pd_port[port].mock_pe_pass_up_message);
+ TEST_ASSERT(pd_port[port].mock_pe_message_received);
TEST_ASSERT(expected_header == emsg[port].header);
TEST_ASSERT(emsg[port].len == 0);
@@ -1317,7 +1321,7 @@ void run_test(void)
/* Test PD 2.0 Protocol */
init_port(PORT0, PD_REV20);
- RUN_TEST(test_initial_states);
+ RUN_TEST(test_prl_reset);
RUN_TEST(test_send_ctrl_msg);
RUN_TEST(test_send_ctrl_msg_with_retry_and_fail);
RUN_TEST(test_send_ctrl_msg_with_retry_and_success);
@@ -1334,7 +1338,7 @@ void run_test(void)
/* Test PD 3.0 Protocol */
init_port(PORT0, PD_REV30);
- RUN_TEST(test_initial_states);
+ RUN_TEST(test_prl_reset);
RUN_TEST(test_send_ctrl_msg);
RUN_TEST(test_send_ctrl_msg_with_retry_and_fail);
RUN_TEST(test_send_ctrl_msg_with_retry_and_success);