From 2fd4b9c5719506793830f8b601bfc893edae1b03 Mon Sep 17 00:00:00 2001 From: Vic Yang Date: Mon, 18 Aug 2014 13:08:43 -0700 Subject: pd: ensure names of PD states are up-to-date As we add more PD states, it's easy to forget to update the names of PD states. This doesn't break any PD functionality so would be hard to discover. However, it can easily confuse us when we are debugging. Add a compile-time assertion to make sure it's updated. BUG=None TEST=Remove one names and check build fails. BRANCH=None Change-Id: I8b503e361b3418835cdf510dd39481eb7d998035 Signed-off-by: Vic Yang Reviewed-on: https://chromium-review.googlesource.com/212885 Reviewed-by: Todd Broch Reviewed-by: Alec Berg --- common/usb_pd_protocol.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/common/usb_pd_protocol.c b/common/usb_pd_protocol.c index 0bf158c790..a8c22d9c69 100644 --- a/common/usb_pd_protocol.c +++ b/common/usb_pd_protocol.c @@ -170,6 +170,9 @@ enum pd_states { PD_STATE_SOFT_RESET, PD_STATE_HARD_RESET, PD_STATE_BIST, + + /* Number of states. Not an actual state. */ + PD_STATE_COUNT, }; enum vdm_states { @@ -1380,6 +1383,8 @@ void pd_task(void) send_bist_cmd(port); bist_mode_2_rx(port); break; + default: + break; } pd[port].last_state = this_state; @@ -1707,6 +1712,7 @@ static int command_pd(int argc, char **argv) "SRC_ACCEPTED", "SRC_TRANSITION", "SRC_READY", "SOFT_RESET", "HARD_RESET", "BIST", }; + BUILD_ASSERT(ARRAY_SIZE(state_names) == PD_STATE_COUNT); ccprintf("Port C%d, %s - Role: %s Polarity: CC%d State: %s\n", port, pd_comm_enabled ? "Enabled" : "Disabled", pd[port].role == PD_ROLE_SOURCE ? "SRC" : "SNK", -- cgit v1.2.1