From d7c19b023687b33eebe5fe429961a13305c71566 Mon Sep 17 00:00:00 2001 From: Alec Berg Date: Sat, 21 Jun 2014 04:00:57 -0700 Subject: samus: add retry mechanism for EC to PD host commands Add a retry mechanism for EC to PD host commands to make the communication channel more robust. BUG=none BRANCH=none TEST=run on system to verify that we don't drop host commands to PD MCU. Change-Id: Ida6f02a149e4dd9e85a5aac21790928b16864104 Signed-off-by: Alec Berg Reviewed-on: https://chromium-review.googlesource.com/205148 Reviewed-by: Vincent Palatin --- common/host_command_pd.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'common/host_command_pd.c') diff --git a/common/host_command_pd.c b/common/host_command_pd.c index a6f6d54720..27bc8265fa 100644 --- a/common/host_command_pd.c +++ b/common/host_command_pd.c @@ -7,11 +7,14 @@ #include "charge_state.h" #include "common.h" +#include "console.h" #include "host_command.h" #include "task.h" #include "timer.h" #include "util.h" +#define CPRINTS(format, args...) cprints(CC_PD_HOST_CMD, format, ## args) + #define TASK_EVENT_EXCHANGE_PD_STATUS TASK_EVENT_CUSTOM(1) static int pd_charger_connected; @@ -25,7 +28,7 @@ static void pd_exchange_status(void) { struct ec_params_pd_status ec_status; struct ec_response_pd_status pd_status; - int rv; + int rv = 0, tries = 0; /* * TODO(crosbug.com/p/29499): Change sending state of charge to @@ -37,13 +40,21 @@ static void pd_exchange_status(void) else ec_status.batt_soc = -1; - rv = pd_host_command(EC_CMD_PD_EXCHANGE_STATUS, 0, &ec_status, + /* Try 3 times to get the PD MCU status. */ + while (tries++ < 3) { + rv = pd_host_command(EC_CMD_PD_EXCHANGE_STATUS, 0, &ec_status, sizeof(struct ec_params_pd_status), &pd_status, sizeof(struct ec_response_pd_status)); + if (rv >= 0) + break; + task_wait_event(500*MSEC); + } if (rv >= 0) pd_charger_connected = pd_status.status & EC_CMD_PD_STATUS_FLAG_CHARGER_CONN; + else + CPRINTS("Host command to PD MCU failed"); } /* -- cgit v1.2.1