diff options
-rw-r--r-- | common/mock/usb_prl_mock.c | 4 | ||||
-rw-r--r-- | common/usbc/usb_pe_drp_sm.c | 16 | ||||
-rw-r--r-- | common/usbc/usb_prl_sm.c | 17 | ||||
-rw-r--r-- | include/mock/usb_prl_mock.h | 1 | ||||
-rw-r--r-- | include/usb_prl_sm.h | 8 |
5 files changed, 43 insertions, 3 deletions
diff --git a/common/mock/usb_prl_mock.c b/common/mock/usb_prl_mock.c index bf428e6328..9caf63fbf4 100644 --- a/common/mock/usb_prl_mock.c +++ b/common/mock/usb_prl_mock.c @@ -155,6 +155,10 @@ void mock_prl_clear_last_sent_msg(int port) mock_prl_port[port].last_tx_type = TCPC_TX_INVALID; } +timestamp_t prl_get_tcpc_tx_success_ts(int port) +{ + return get_time(); +} void mock_prl_message_sent(int port) { mock_prl_port[port].message_sent = 1; diff --git a/common/usbc/usb_pe_drp_sm.c b/common/usbc/usb_pe_drp_sm.c index 9171b2fb94..e0a364240b 100644 --- a/common/usbc/usb_pe_drp_sm.c +++ b/common/usbc/usb_pe_drp_sm.c @@ -2016,6 +2016,8 @@ static void pe_sender_response_msg_entry(const int port) */ static enum pe_msg_check pe_sender_response_msg_run(const int port) { + timestamp_t tx_success_ts; + uint32_t offset; if (pd_timer_is_disabled(port, PE_TIMER_SENDER_RESPONSE)) { /* Check for Discard */ if (PE_CHK_FLAG(port, PE_FLAGS_MSG_DISCARDED)) { @@ -2034,9 +2036,19 @@ static enum pe_msg_check pe_sender_response_msg_run(const int port) if (PE_CHK_FLAG(port, PE_FLAGS_TX_COMPLETE)) { PE_CLR_FLAG(port, PE_FLAGS_TX_COMPLETE); - /* Initialize and run the SenderResponseTimer */ + /* TCPC TX success time stamp */ + tx_success_ts = prl_get_tcpc_tx_success_ts(port); + /* Calculate the delay from TX success to PE */ + offset = time_since32(tx_success_ts); + + /* + * Initialize and run the SenderResponseTimer by + * offsetting it with TX transmit success time. + * This would remove the effect of the latency from + * propagating the TX status. + */ pd_timer_enable(port, PE_TIMER_SENDER_RESPONSE, - PD_T_SENDER_RESPONSE); + PD_T_SENDER_RESPONSE - offset); return PE_MSG_SEND_COMPLETED; } return PE_MSG_SEND_PENDING; diff --git a/common/usbc/usb_prl_sm.c b/common/usbc/usb_prl_sm.c index b54061b04d..1d77de1aa4 100644 --- a/common/usbc/usb_prl_sm.c +++ b/common/usbc/usb_prl_sm.c @@ -19,7 +19,6 @@ #include "registers.h" #include "system.h" #include "task.h" -#include "timer.h" #include "tcpm/tcpm.h" #include "util.h" #include "usb_charge.h" @@ -415,6 +414,8 @@ GEN_NOT_SUPPORTED(TCH_REPORT_ERROR); #define TCH_REPORT_ERROR TCH_REPORT_ERROR_NOT_SUPPORTED #endif /* !CONFIG_USB_PD_REV30 */ +/* To store the time stamp when TCPC sets TX Complete Success */ +static timestamp_t tcpc_tx_success_ts[CONFIG_USB_PD_PORT_MAX_COUNT]; /* Set the protocol transmit statemachine to a new state. */ static void set_state_prl_tx(const int port, @@ -507,8 +508,22 @@ static void print_current_tch_state(const int port) } #endif /* CONFIG_USB_PD_EXTENDED_MESSAGES */ + +timestamp_t prl_get_tcpc_tx_success_ts(int port) +{ + return tcpc_tx_success_ts[port]; +} + +/* Sets the time stamp when TCPC reports TX success. */ +static void set_tcpc_tx_success_ts(int port) +{ + tcpc_tx_success_ts[port] = get_time(); +} + void pd_transmit_complete(int port, int status) { + if (status == TCPC_TX_COMPLETE_SUCCESS) + set_tcpc_tx_success_ts(port); prl_tx[port].xmit_status = status; } diff --git a/include/mock/usb_prl_mock.h b/include/mock/usb_prl_mock.h index 052b3e7b76..ca5d3c8fc4 100644 --- a/include/mock/usb_prl_mock.h +++ b/include/mock/usb_prl_mock.h @@ -22,6 +22,7 @@ enum pd_ctrl_msg_type mock_prl_get_last_sent_ctrl_msg(int port); enum pd_data_msg_type mock_prl_get_last_sent_data_msg(int port); + void mock_prl_clear_last_sent_msg(int port); void mock_prl_message_sent(int port); diff --git a/include/usb_prl_sm.h b/include/usb_prl_sm.h index afcaa2cfed..0111f54fc1 100644 --- a/include/usb_prl_sm.h +++ b/include/usb_prl_sm.h @@ -11,7 +11,15 @@ #include "usb_pd.h" #include "usb_pd_tcpm.h" #include "usb_sm.h" +#include "timer.h" +/** + * Returns TX success time stamp. + * + * @param port USB-C port number + * @return the time stamp of TCPC tx success. + **/ +timestamp_t prl_get_tcpc_tx_success_ts(int port); /** * Returns true if Protocol Layer State Machine is in run mode |