From 0d4529c8481a8f4e00ea351a63b0d11d0bb9efe2 Mon Sep 17 00:00:00 2001 From: Vic Yang Date: Wed, 6 Aug 2014 16:38:46 -0700 Subject: [PATCH] pd: log state transition and stop logging pings When PD state changes, log the state transition. Also, now that we have the state logged, logging pings doesn't help us anymore, so stop logging them to make console clean. BUG=None TEST=Run on samus_pd. Plug/unplug zinger. Check state is logged and pings are not. BRANCH=None Change-Id: Ib482b3351d9681fbb4bcc2585da58c732428b7af Signed-off-by: Vic Yang Reviewed-on: https://chromium-review.googlesource.com/211262 Reviewed-by: Alec Berg Reviewed-by: Vincent Palatin --- common/usb_pd_protocol.c | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/common/usb_pd_protocol.c b/common/usb_pd_protocol.c index 40aa9430d0..80aeb7b860 100644 --- a/common/usb_pd_protocol.c +++ b/common/usb_pd_protocol.c @@ -214,8 +214,22 @@ static inline void set_state_timeout(int port, static inline void set_state(int port, enum pd_states next_state) { - pd[port].task_state = next_state; + enum pd_states last_state = pd[port].task_state; + set_state_timeout(port, 0, 0); + pd[port].task_state = next_state; + + /* Log state transition, except for toggling between sink and source */ + if (last_state == next_state) + return; +#ifdef CONFIG_USB_PD_DUAL_ROLE + if ((last_state == PD_STATE_SNK_DISCONNECTED && + next_state == PD_STATE_SRC_DISCONNECTED) || + (last_state == PD_STATE_SRC_DISCONNECTED && + next_state == PD_STATE_SNK_DISCONNECTED)) + return; +#endif + CPRINTF("C%d st%d\n", port, next_state); } /* increment message ID counter */ @@ -680,14 +694,16 @@ static void handle_request(int port, uint16_t head, int cnt = PD_HEADER_CNT(head); int p; - if (PD_HEADER_TYPE(head) != 1 || cnt) + if (PD_HEADER_TYPE(head) != PD_CTRL_GOOD_CRC || cnt) send_goodcrc(port, PD_HEADER_ID(head)); - /* dump received packet content */ - CPRINTF("RECV %04x/%d ", head, cnt); - for (p = 0; p < cnt; p++) - CPRINTF("[%d]%08x ", p, payload[p]); - CPRINTF("\n"); + /* dump received packet content (except for ping) */ + if (PD_HEADER_TYPE(head) != PD_CTRL_PING) { + CPRINTF("RECV %04x/%d ", head, cnt); + for (p = 0; p < cnt; p++) + CPRINTF("[%d]%08x ", p, payload[p]); + CPRINTF("\n"); + } /* * If we are in disconnected state, we shouldn't get a request. Do