diff options
author | Todd Broch <tbroch@chromium.org> | 2015-06-09 17:06:11 -0700 |
---|---|---|
committer | ChromeOS Commit Bot <chromeos-commit-bot@chromium.org> | 2015-06-11 05:40:11 +0000 |
commit | e310a2be6272022a90207f5d8227f4536ae0066b (patch) | |
tree | 18203f745a2f32c9ee181a7350d564f866caf785 | |
parent | 4aee90d5594863fc390e73dc880fb328cf4bfbd3 (diff) | |
download | chrome-ec-e310a2be6272022a90207f5d8227f4536ae0066b.tar.gz |
mcdp28x0: Add more useful error codes.
BRANCH=samus
BUG=none
TEST=compiles
Signed-off-by: Todd Broch <tbroch@chromium.org>
Change-Id: Id925acbafcb49dbf503f666a7edb79b7eb25fecd
Reviewed-on: https://chromium-review.googlesource.com/276554
Reviewed-by: Alec Berg <alecaberg@chromium.org>
Commit-Queue: Todd Broch <tbroch@chromium.org>
Tested-by: Todd Broch <tbroch@chromium.org>
-rw-r--r-- | driver/mcdp28x0.c | 81 | ||||
-rw-r--r-- | driver/mcdp28x0.h | 10 |
2 files changed, 60 insertions, 31 deletions
diff --git a/driver/mcdp28x0.c b/driver/mcdp28x0.c index 552d2dc474..216d271737 100644 --- a/driver/mcdp28x0.c +++ b/driver/mcdp28x0.c @@ -93,17 +93,17 @@ static int tx_serial(const uint8_t *msg, int cnt) uint8_t chksum = compute_checksum(cnt + 2, msg, cnt); if (queue_add_unit(&usart_mcdp_tx_queue, &out) != 1) - return EC_ERROR_UNKNOWN; + return MCDP_ERROR_TX_CNT; if (queue_add_units(&usart_mcdp_tx_queue, msg, cnt) != cnt) - return EC_ERROR_UNKNOWN; + return MCDP_ERROR_TX_BODY; print_buffer((uint8_t *)msg, cnt); if (queue_add_unit(&usart_mcdp_tx_queue, &chksum) != 1) - return EC_ERROR_UNKNOWN; + return MCDP_ERROR_TX_CHKSUM; - return EC_SUCCESS; + return MCDP_SUCCESS; } /** @@ -142,20 +142,26 @@ static int rx_serial(uint8_t *msg, int cnt) cnt = msg[0]; if (msg[cnt-1] != compute_checksum(0, msg, cnt-1)) - return EC_ERROR_UNKNOWN; + return MCDP_ERROR_CHKSUM; + + if (read != cnt) { + CPRINTF("rx_serial: read bytes %d != %d cnt\n", read, cnt); + return MCDP_ERROR_RX_BYTES; + } - return !(read == cnt); + return MCDP_SUCCESS; } static int rx_serial_ack(void) { - if (rx_serial(mcdp_inbuf, 3)) - return EC_ERROR_UNKNOWN; + int rv = rx_serial(mcdp_inbuf, 3); + if (rv) + return rv; if (mcdp_inbuf[1] != MCDP_CMD_ACK) - return EC_ERROR_UNKNOWN; + return MCDP_ERROR_RX_ACK; - return EC_SUCCESS; + return rv; } void mcdp_enable(void) @@ -171,33 +177,38 @@ void mcdp_disable(void) int mcdp_get_info(struct mcdp_info *info) { const uint8_t msg[2] = {MCDP_CMD_APPSTEST, 0x28}; + int rv = tx_serial(msg, sizeof(msg)); - if (tx_serial(msg, sizeof(msg))) - return EC_ERROR_UNKNOWN; + if (rv) + return rv; - if (rx_serial_ack()) - return EC_ERROR_UNKNOWN; + rv = rx_serial_ack(); + if (rv) + return rv; /* chksum is unreliable ... don't check */ rx_serial(mcdp_inbuf, MCDP_RSP_LEN(MCDP_LEN_GETINFO)); memcpy(info, &mcdp_inbuf[2], MCDP_LEN_GETINFO); - return EC_SUCCESS; + return rv; } #ifdef CONFIG_CMD_MCDP static int mcdp_get_dev_id(char *dev, uint8_t dev_id, int dev_cnt) { uint8_t msg[2]; + int rv; msg[0] = MCDP_CMD_GETDEVID; msg[1] = dev_id; - if (tx_serial(msg, sizeof(msg))) - return EC_ERROR_UNKNOWN; + rv = tx_serial(msg, sizeof(msg)); + if (rv) + return rv; - if (rx_serial(mcdp_inbuf, sizeof(mcdp_inbuf))) - return EC_ERROR_UNKNOWN; + rv = rx_serial(mcdp_inbuf, sizeof(mcdp_inbuf)); + if (rv) + return rv; memcpy(dev, &mcdp_inbuf[2], mcdp_inbuf[0] - 3); dev[mcdp_inbuf[0] - 3] = '\0'; @@ -209,6 +220,7 @@ static int mcdp_appstest(uint8_t cmd, int paramc, char **paramv) uint8_t msg[6]; char *e; int i; + int rv = MCDP_SUCCESS; /* setup any appstest params */ msg[0] = MCDP_CMD_APPSTESTPARAM; @@ -221,20 +233,24 @@ static int mcdp_appstest(uint8_t cmd, int paramc, char **paramv) msg[3] = (param >> 16) & 0xff; msg[4] = (param >> 8) & 0xff; msg[5] = (param >> 0) & 0xff; - if (tx_serial(msg, sizeof(msg))) - return EC_ERROR_UNKNOWN; + rv = tx_serial(msg, sizeof(msg)); + if (rv) + return rv; - if (rx_serial_ack()) - return EC_ERROR_UNKNOWN; + rv = rx_serial_ack(); + if (rv) + return rv; } msg[0] = MCDP_CMD_APPSTEST; msg[1] = cmd; - if (tx_serial(msg, 2)) - return EC_ERROR_UNKNOWN; + rv = tx_serial(msg, 2); + if (rv) + return rv; - if (rx_serial_ack()) - return EC_ERROR_UNKNOWN; + rv = rx_serial_ack(); + if (rv) + return rv; /* magic */ rx_serial(mcdp_inbuf, sizeof(mcdp_inbuf)); @@ -267,7 +283,7 @@ int command_mcdp(int argc, char **argv) uint8_t dev_id = strtoi(argv[2], &e, 10); char dev[32]; if (*e) - rv = EC_ERROR_PARAM2; + return EC_ERROR_PARAM2; else rv = mcdp_get_dev_id(dev, dev_id, 32); if (!rv) @@ -275,17 +291,20 @@ int command_mcdp(int argc, char **argv) } else if (!strncasecmp(argv[1], "appstest", 4)) { uint8_t cmd = strtoi(argv[2], &e, 10); if (*e) - rv = EC_ERROR_PARAM2; + return EC_ERROR_PARAM2; else rv = mcdp_appstest(cmd, argc - 3, &argv[3]); if (!rv) ccprintf("appstest[%d] completed\n", cmd); } else { - rv = EC_ERROR_PARAM1; + return EC_ERROR_PARAM1; } mcdp_disable(); - return rv; + if (rv) + ccprintf("mcdp_error:%d\n", rv); + + return EC_SUCCESS; } DECLARE_CONSOLE_COMMAND(mcdp, command_mcdp, "info|devid <id>|appstest <cmd> [<params>]", diff --git a/driver/mcdp28x0.h b/driver/mcdp28x0.h index 0273a12301..9c48cab32f 100644 --- a/driver/mcdp28x0.h +++ b/driver/mcdp28x0.h @@ -21,6 +21,16 @@ #define MCDP_RSP_LEN(len) (len + 3) #define MCDP_LEN_GETINFO 12 +/* List of common error codes that can be returned */ +enum mcdp_error_list { + MCDP_SUCCESS = 0, + MCDP_ERROR_TX_CNT, + MCDP_ERROR_TX_BODY, + MCDP_ERROR_TX_CHKSUM, + MCDP_ERROR_CHKSUM, + MCDP_ERROR_RX_BYTES, + MCDP_ERROR_RX_ACK, +}; /** * Enable mcdp driver. |