usbc: wake task on every state transition
Whenever we change state, we should continue to wake the USB statemachine task up until is settles into a steady state were it is waiting/polling on a timer or event. BRANCH=none BUG=b:163152687 TEST=Ran GRL PD3.0 test on Trembyle and did not see any regressions. It did make a few tests pass that were failing before due to timing issues. Signed-off-by: Jett Rink <jettrink@chromium.org> Change-Id: Idc3c1ae8d92a0f6a5cd4b82f9db6d7138d143f77 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2356954 Reviewed-by: Edward Hill <ecgh@chromium.org> Reviewed-by: Diana Z <dzigterman@chromium.org> Commit-Queue: Diana Z <dzigterman@chromium.org>
This commit is contained in:
parent
91a31c82ca
commit
bb20158f5c
|
@ -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);
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue