pd: use interrupt on Rx retry

After sending a message, we wait for up to 2.7 ms for reply. If we don't
get one, we retry for up to twice. Therefore, a undelivered message
could take up to >8ms. To prevent starving other tasks, let's yield to
other tasks on retries and rely on interrupt to wake us.

BUG=chrome-os-partner:28341
TEST=Plug in zinger on port 0 and C-to-A dongle on port 1. Check that
port 0 drops connection less frequently.
BRANCH=None

Change-Id: If85a70fd1140fef69d79243b198703ce601f8030
Signed-off-by: Vic Yang <victoryang@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/211281
Reviewed-by: Alec Berg <alecaberg@chromium.org>
This commit is contained in:
Vic Yang
2014-08-06 17:52:30 -07:00
committed by chrome-internal-fetch
parent 0d4529c848
commit 5ab558117d
3 changed files with 19 additions and 4 deletions

View File

@@ -531,8 +531,8 @@ void pd_hw_init(int port)
/* Auto-reload value : 16-bit free running counter */
phy->tim_rx->arr = 0xFFFF;
/* Timeout for message receive : 2.7ms */
phy->tim_rx->ccr[2] = 2400000 * 27 / 10000;
/* Timeout for message receive */
phy->tim_rx->ccr[2] = (2400000 / 1000) * USB_PD_RX_TMOUT_US / 1000;
/* Timer ICx input configuration */
if (TIM_CCR_IDX(port) == 1)
phy->tim_rx->ccmr1 |= TIM_CCR_CS << 0;

View File

@@ -334,8 +334,20 @@ static int send_validate_message(int port, uint16_t header,
/* Transmit the packet */
pd_start_tx(port, pd[port].polarity, bit_len);
pd_tx_done(port, pd[port].polarity);
/* starting waiting for GoodCrc */
pd_rx_start(port);
/*
* If we failed the first try, enable interrupt and yield
* to other tasks, so that we don't starve them.
*/
if (r) {
pd_rx_enable_monitoring(port);
/* Message receive timeout is 2.7ms */
if (task_wait_event(USB_PD_RX_TMOUT_US) ==
TASK_EVENT_TIMER)
continue;
} else {
/* starting waiting for GoodCrc */
pd_rx_start(port);
}
/* read the incoming packet if any */
head = analyze_rx(port, payload);
pd_rx_complete(port);

View File

@@ -133,6 +133,9 @@ enum pd_errors {
/* USB Vendor ID assigned to Google Inc. */
#define USB_VID_GOOGLE 0x18d1
/* Timeout for message receive in microseconds */
#define USB_PD_RX_TMOUT_US 2700
/* --- Protocol layer functions --- */
#ifdef CONFIG_USB_PD_DUAL_ROLE