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 <alecaberg@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/205148
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
This commit is contained in:
Alec Berg
2014-06-21 04:00:57 -07:00
committed by chrome-internal-fetch
parent f8171d72f3
commit d7c19b0236
3 changed files with 15 additions and 2 deletions

View File

@@ -47,6 +47,7 @@ static const char * const channel_names[] = {
"lightbar",
"lpc",
"motionsense",
"pdhostcmd",
"port80",
"pwm",
"spi",

View File

@@ -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");
}
/*

View File

@@ -43,6 +43,7 @@ enum console_channel {
CC_LIGHTBAR,
CC_LPC,
CC_MOTION_SENSE,
CC_PD_HOST_CMD,
CC_PORT80,
CC_PWM,
CC_SPI,