summaryrefslogtreecommitdiff
path: root/board/twinkie/sniffer.c
diff options
context:
space:
mode:
authorVincent Palatin <vpalatin@chromium.org>2014-10-30 14:53:23 -0700
committerchrome-internal-fetch <chrome-internal-fetch@google.com>2014-11-18 18:18:34 +0000
commitc8d7462fcffc1f25d6230734ee6f19a154ebf63a (patch)
treeca422e0820054db2d633f385e601dd86eb664034 /board/twinkie/sniffer.c
parentbacd096372e22d87d7b98d9afc9ae9db91d4e0b9 (diff)
downloadchrome-ec-c8d7462fcffc1f25d6230734ee6f19a154ebf63a.tar.gz
Twinkie: add packet injection capability
Add commands to send PD packets and to tweak individual parameters (TX clock frequency, RX detection threshold, resistors on CCx). Signed-off-by: Vincent Palatin <vpalatin@chromium.org> BRANCH=none BUG=chrome-os-partner:28337 TEST=verify that the PD sniffing is still working by dumping traffic between Zinger and Samus. Connect Twinkie to Zinger, set Rd by using "tw res NONE RD" and see VBUS going to 5V (reading it using "ina 0"). Send a BIST mode 2 request using the following command : tw send 2 0x1043 50000000 and see the other end starting sending BIST. Change-Id: I3c8ddf858435ac1c17a43f59351bbaa69603a209 Reviewed-on: https://chromium-review.googlesource.com/227778 Reviewed-by: Todd Broch <tbroch@chromium.org> Commit-Queue: Vincent Palatin <vpalatin@chromium.org> Tested-by: Vincent Palatin <vpalatin@chromium.org>
Diffstat (limited to 'board/twinkie/sniffer.c')
-rw-r--r--board/twinkie/sniffer.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/board/twinkie/sniffer.c b/board/twinkie/sniffer.c
index 136cc1b01a..e6a0cff0a4 100644
--- a/board/twinkie/sniffer.c
+++ b/board/twinkie/sniffer.c
@@ -299,6 +299,45 @@ void sniffer_task(void)
}
}
+int wait_packet(int pol, uint32_t min_edges, uint32_t timeout_us)
+{
+ stm32_dma_chan_t *chan = dma_get_channel(pol ? DMAC_TIM_RX2
+ : DMAC_TIM_RX1);
+ uint32_t t0 = __hw_clock_source_read();
+ uint32_t c0 = chan->cndtr;
+ uint32_t t_gap = t0;
+ uint32_t c_gap = c0;
+ uint32_t total_edges = 0;
+
+ while (1) {
+ uint32_t t = __hw_clock_source_read();
+ uint32_t c = chan->cndtr;
+ if (t - t0 > timeout_us) /* Timeout */
+ break;
+ if (min_edges) { /* real packet detection */
+ int nb = (int)c_gap - (int)c;
+ if (nb < 0)
+ nb = RX_COUNT - nb;
+ if (nb > 3) { /* NOT IDLE */
+ t_gap = t;
+ c_gap = c;
+ total_edges += nb;
+ } else {
+ if ((t - t_gap) > 20 &&
+ (total_edges - (t - t0)/256) >= min_edges)
+ /* real gap after the packet */
+ break;
+ }
+ }
+ }
+ return (__hw_clock_source_read() - t0 > timeout_us);
+}
+
+void recording_enable(uint8_t mask)
+{
+ /* TODO implement */
+}
+
static int command_sniffer(int argc, char **argv)
{
ccprintf("Seq number:%d Overflows: %d\n", seq, oflow);