diff options
-rw-r--r-- | common/usb_pd_protocol.c | 2 | ||||
-rw-r--r-- | common/usbc/usb_sm.c | 9 | ||||
-rw-r--r-- | common/usbc/usb_tc_drp_acc_trysrc_sm.c | 1 | ||||
-rw-r--r-- | include/usb_pd.h | 9 | ||||
-rw-r--r-- | test/usb_prl_old.c | 4 | ||||
-rw-r--r-- | test/usb_typec_ctvpd.c | 26 |
6 files changed, 25 insertions, 26 deletions
diff --git a/common/usb_pd_protocol.c b/common/usb_pd_protocol.c index 06ef2b630a..71343f1334 100644 --- a/common/usb_pd_protocol.c +++ b/common/usb_pd_protocol.c @@ -3125,7 +3125,7 @@ void pd_task(void *u) evt = task_wait_event(timeout); #ifdef CONFIG_USB_PD_TCPC_LOW_POWER - if (evt & PD_EXIT_LOW_POWER_EVENT_MASK) + if (evt & (PD_EXIT_LOW_POWER_EVENT_MASK | TASK_EVENT_WAKE)) exit_low_power_mode(port); if (evt & PD_EVENT_DEVICE_ACCESSED) handle_device_access(port); diff --git a/common/usbc/usb_sm.c b/common/usbc/usb_sm.c index 99bed2b1bb..04b7193c0f 100644 --- a/common/usbc/usb_sm.c +++ b/common/usbc/usb_sm.c @@ -6,6 +6,7 @@ #include "common.h" #include "console.h" #include "stdbool.h" +#include "task.h" #include "usb_pd.h" #include "usb_sm.h" #include "util.h" @@ -159,6 +160,14 @@ void set_state(const int port, struct sm_ctx *const ctx, * any remaining parent states. */ internal->running = false; + + /* + * Since we are changing states, we want to ensure that we process the + * next state's run method as soon as we can to ensure that we don't + * delay important processing until the next task interval. + */ + if (IS_ENABLED(HAS_TASK_PD_C0)) + task_wake(PD_PORT_TO_TASK_ID(port)); } /* diff --git a/common/usbc/usb_tc_drp_acc_trysrc_sm.c b/common/usbc/usb_tc_drp_acc_trysrc_sm.c index 58a2cdcefb..47a3f0fc63 100644 --- a/common/usbc/usb_tc_drp_acc_trysrc_sm.c +++ b/common/usbc/usb_tc_drp_acc_trysrc_sm.c @@ -1439,6 +1439,7 @@ void tc_event_check(int port, int evt) if (evt & PD_EXIT_LOW_POWER_EVENT_MASK) TC_SET_FLAG(port, TC_FLAGS_CHECK_CONNECTION); + if (evt & PD_EVENT_DEVICE_ACCESSED) handle_device_access(port); diff --git a/include/usb_pd.h b/include/usb_pd.h index bdadab0aae..5ab722de73 100644 --- a/include/usb_pd.h +++ b/include/usb_pd.h @@ -19,20 +19,18 @@ /* PD Host command timeout */ #define PD_HOST_COMMAND_TIMEOUT_US SECOND -#ifdef CONFIG_USB_PD_PORT_MAX_COUNT /* * Define PD_PORT_TO_TASK_ID() and TASK_ID_TO_PD_PORT() macros to * go between PD port number and task ID. Assume that TASK_ID_PD_C0 is the * lowest task ID and IDs are on a continuous range. */ -#ifdef HAS_TASK_PD_C0 +#if defined(HAS_TASK_PD_C0) && defined(CONFIG_USB_PD_PORT_MAX_COUNT) #define PD_PORT_TO_TASK_ID(port) (TASK_ID_PD_C0 + (port)) #define TASK_ID_TO_PD_PORT(id) ((id) - TASK_ID_PD_C0) #else #define PD_PORT_TO_TASK_ID(port) -1 /* stub task ID */ #define TASK_ID_TO_PD_PORT(id) 0 -#endif /* HAS_TASK_PD_C0 */ -#endif /* CONFIG_USB_PD_PORT_MAX_COUNT */ +#endif /* CONFIG_USB_PD_PORT_MAX_COUNT && HAS_TASK_PD_C0 */ enum pd_rx_errors { PD_RX_ERR_INVAL = -1, /* Invalid packet */ @@ -75,8 +73,7 @@ enum pd_rx_errors { #define PD_EXIT_LOW_POWER_EVENT_MASK \ (PD_EVENT_CC | \ PD_EVENT_UPDATE_DUAL_ROLE | \ - PD_EVENT_POWER_STATE_CHANGE | \ - TASK_EVENT_WAKE) + PD_EVENT_POWER_STATE_CHANGE) /* --- PD data message helpers --- */ #define PDO_MAX_OBJECTS 7 diff --git a/test/usb_prl_old.c b/test/usb_prl_old.c index af87195fb9..d1aa0ba649 100644 --- a/test/usb_prl_old.c +++ b/test/usb_prl_old.c @@ -509,10 +509,6 @@ static int simulate_send_ctrl_msg_request_from_pe(int port, prl_send_ctrl_msg(port, type, msg_type); cycle_through_state_machine(port, 1, MSEC); - /* Soft reset takes another iteration through the state machine */ - if (msg_type == PD_CTRL_SOFT_RESET) - cycle_through_state_machine(port, 1, MSEC); - return verify_ctrl_msg_transmission(port, msg_type); } diff --git a/test/usb_typec_ctvpd.c b/test/usb_typec_ctvpd.c index 1340c7a093..d46e68e40d 100644 --- a/test/usb_typec_ctvpd.c +++ b/test/usb_typec_ctvpd.c @@ -460,10 +460,10 @@ static int test_vpd_host_src_detection_vbus(void) host_connect_source(VBUS_0); - wait_for_state_change(port, 10 * MSEC); - - TEST_ASSERT(get_state_tc(port) == TC_UNATTACHED_SNK); - + /* + * The state changes from UNATTACHED_SNK to ATTACH_WAIT_SNK immediately + * if Rp is detected. + */ wait_for_state_change(port, 10 * MSEC); TEST_ASSERT(get_state_tc(port) == TC_ATTACH_WAIT_SNK); @@ -523,11 +523,12 @@ static int test_vpd_host_src_detection_vconn(void) * Host Port VCONN Removed */ + mock_set_host_cc_source_voltage(0); mock_set_vconn(VCONN_0); wait_for_state_change(port, 10 * MSEC); - TEST_ASSERT(get_state_tc(port) == TC_UNATTACHED_SNK); + TEST_EQ(get_state_tc(port), TC_UNATTACHED_SNK, "%d"); host_disconnect_source(); @@ -639,13 +640,12 @@ static int test_vpd_host_src_detection_message_reception(void) * Host Port VBUS Removed */ - host_connect_source(VBUS_0); + host_disconnect_source(); wait_for_state_change(port, 100 * MSEC); TEST_EQ(get_state_tc(port), TC_UNATTACHED_SNK, "%d"); - host_disconnect_source(); return EC_SUCCESS; } @@ -760,32 +760,28 @@ 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_state_tc(port) == TC_CT_ATTACH_WAIT_VPD); + TEST_EQ(get_state_tc(port), TC_CT_ATTACH_WAIT_VPD, "%d"); /* Remove Power Source */ TEST_ASSERT(ct_disconnect_source()); wait_for_state_change(port, 40 * MSEC); - TEST_ASSERT(get_state_tc(port) == TC_CT_UNATTACHED_VPD); + TEST_EQ(get_state_tc(port), TC_CT_UNATTACHED_VPD, "%d"); /* Attach Sink */ TEST_ASSERT(ct_connect_sink(CC1, SRC_CON_DEF)); - wait_for_state_change(port, PD_T_DRP_SNK); - - TEST_ASSERT(get_state_tc(port) == TC_CT_UNATTACHED_UNSUPPORTED); - wait_for_state_change(port, 40 * MSEC); - TEST_ASSERT(get_state_tc(port) == TC_CT_ATTACH_WAIT_UNSUPPORTED); + TEST_EQ(get_state_tc(port), TC_CT_ATTACH_WAIT_UNSUPPORTED, "%d"); /* Remove VCONN (Host detach) */ mock_set_vconn(VCONN_0); wait_for_state_change(port, 40 * MSEC); - TEST_ASSERT(get_state_tc(port) == TC_UNATTACHED_SNK); + TEST_EQ(get_state_tc(port), TC_UNATTACHED_SNK, "%d"); return EC_SUCCESS; } |