From d2c5e22944f7eeff4b6fd3c535c76fcbce25e22e Mon Sep 17 00:00:00 2001 From: Vincent Palatin Date: Thu, 1 May 2014 14:56:05 -0700 Subject: pd: more robust reception Ensure that we finish reception if and only if we started it whatever other events happened. Signed-off-by: Vincent Palatin BRANCH=none BUG=chrome-os-partner:28332 TEST=Connect Zinger to Firefly, request higher voltage and ensure that Firefly was still getting the Pings after several hours. Change-Id: Ie99984aeb4c565be39d349457dbd2813203b3f5b Reviewed-on: https://chromium-review.googlesource.com/197946 Reviewed-by: Alec Berg Commit-Queue: Vincent Palatin Tested-by: Vincent Palatin --- chip/stm32/usb_pd_phy.c | 6 ++++++ common/usb_pd_protocol.c | 7 ++----- include/usb_pd.h | 7 +++++++ 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/chip/stm32/usb_pd_phy.c b/chip/stm32/usb_pd_phy.c index 4417cd3f54..4a4e63b51b 100644 --- a/chip/stm32/usb_pd_phy.c +++ b/chip/stm32/usb_pd_phy.c @@ -349,6 +349,12 @@ void pd_rx_complete(void) dma_disable(DMAC_TIM_RX); } +int pd_rx_started(void) +{ + /* is the sampling timer running ? */ + return STM32_TIM_CR1(TIM_RX) & 1; +} + void pd_rx_enable_monitoring(void) { /* clear comparator external interrupt */ diff --git a/common/usb_pd_protocol.c b/common/usb_pd_protocol.c index af68874984..442cccce2d 100644 --- a/common/usb_pd_protocol.c +++ b/common/usb_pd_protocol.c @@ -631,7 +631,6 @@ void pd_task(void) void *ctxt = pd_hw_init(); uint32_t payload[7]; int timeout = 10*MSEC; - uint32_t evt; int cc1_volt, cc2_volt; int res; @@ -644,9 +643,9 @@ void pd_task(void) /* Verify board specific health status : current, voltages... */ pd_board_checks(); /* wait for next event/packet or timeout expiration */ - evt = task_wait_event(timeout); + task_wait_event(timeout); /* incoming packet ? */ - if (evt & PD_EVENT_RX) { + if (pd_rx_started()) { head = analyze_rx(payload); pd_rx_complete(); if (head > 0) @@ -795,8 +794,6 @@ static int command_pd(int argc, char **argv) if (!strcasecmp(argv[1], "tx")) { pd_task_state = PD_STATE_SNK_DISCOVERY; task_wake(TASK_ID_PD); - } else if (!strcasecmp(argv[1], "rx")) { - pd_rx_event(); } else if (!strcasecmp(argv[1], "bist")) { pd_task_state = PD_STATE_BIST; task_wake(TASK_ID_PD); diff --git a/include/usb_pd.h b/include/usb_pd.h index e11d712800..84d98dff9b 100644 --- a/include/usb_pd.h +++ b/include/usb_pd.h @@ -255,6 +255,13 @@ void pd_start_tx(void *ctxt, int polarity, int bit_len); */ void pd_tx_done(int polarity); +/** + * Check whether the PD reception is started. + * + * @return true if the reception is on-going. + */ +int pd_rx_started(void); + /* Callback when the hardware has detected an incoming packet */ void pd_rx_event(void); /* Start sampling the CC line for reception */ -- cgit v1.2.1