diff options
author | Vincent Palatin <vpalatin@chromium.org> | 2014-10-30 10:42:11 -0700 |
---|---|---|
committer | chrome-internal-fetch <chrome-internal-fetch@google.com> | 2014-11-10 20:43:06 +0000 |
commit | d92b5b61f762ff004828987efc0e94421e8e5569 (patch) | |
tree | 2e059bd1ee423740b2df8d7309c049f66a438daa /board/twinkie | |
parent | 8a9d0cae28c77be4ce1013802ea6f8713b3e5033 (diff) | |
download | chrome-ec-d92b5b61f762ff004828987efc0e94421e8e5569.tar.gz |
twinkie: add LEDs for traffic
When PD traffic is seen on CC1 / CC2, turn on respectively the green LED
and the red LED.
When the samples are properly exported through USB without overrun, the
blue LED is lightly blinking.
Signed-off-by: Vincent Palatin <vpalatin@chromium.org>
BRANCH=none
BUG=none
TEST=plug a Zinger into a power sink through the Twinkie and see it
blinking in a different color depending on the plug polarity.
Change-Id: Icde9de5c807045d4df725e702690246367bcfd1d
Reviewed-on: https://chromium-review.googlesource.com/226590
Reviewed-by: Todd Broch <tbroch@chromium.org>
Reviewed-by: Alec Berg <alecaberg@chromium.org>
Commit-Queue: Vincent Palatin <vpalatin@chromium.org>
Tested-by: Vincent Palatin <vpalatin@chromium.org>
Diffstat (limited to 'board/twinkie')
-rw-r--r-- | board/twinkie/sniffer.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/board/twinkie/sniffer.c b/board/twinkie/sniffer.c index a4e4f6f16e..136cc1b01a 100644 --- a/board/twinkie/sniffer.c +++ b/board/twinkie/sniffer.c @@ -43,6 +43,27 @@ static usb_uint ep_buf[2][EP_BUF_SIZE / 2] __usb_ram; /* USB Buffers not used, ready to be filled */ static volatile uint32_t free_usb = 3; +static inline void led_set_activity(int ch) +{ + static int accumul[2]; + static uint32_t last_ts[2]; + uint32_t now = __hw_clock_source_read(); + int delta = now - last_ts[ch]; + last_ts[ch] = now; + accumul[ch] = MAX(0, accumul[ch] + (30000 - delta)); + gpio_set_level(ch ? GPIO_LED_R_L : GPIO_LED_G_L, !accumul[ch]); +} + +static inline void led_set_record(void) +{ + gpio_set_level(GPIO_LED_B_L, 0); +} + +static inline void led_reset_record(void) +{ + gpio_set_level(GPIO_LED_B_L, 1); +} + /* USB descriptors */ const struct usb_interface_descriptor USB_IFACE_DESC(USB_IFACE_VENDOR) = { .bLength = USB_DT_INTERFACE_SIZE, @@ -138,9 +159,12 @@ void tim_rx1_handler(uint32_t stat) if (filled_dma & next) { oflow++; sample_seq[idx] |= 0x8000; + } else { + led_set_record(); } filled_dma |= mask; dma->ifcr = STM32_DMA_ISR_ALL(DMAC_TIM_RX1); + led_set_activity(0); } void tim_rx2_handler(uint32_t stat) @@ -156,9 +180,12 @@ void tim_rx2_handler(uint32_t stat) if (filled_dma & next) { oflow++; sample_seq[idx] |= 0x8000; + } else { + led_set_record(); } filled_dma |= mask; dma->ifcr = STM32_DMA_ISR_ALL(DMAC_TIM_RX2); + led_set_activity(1); } void tim_dma_handler(void) @@ -268,6 +295,7 @@ void sniffer_task(void) u = !u; atomic_clear((uint32_t *)&filled_dma, 1 << d); } + led_reset_record(); } } |