mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2025-12-27 18:25:05 +00:00
mcdp28x0: add appstest console command.
Signed-off-by: Todd Broch <tbroch@chromium.org> BRANCH=samus BUG=chrome-os-partner:35939 TEST=manual, with CONFIG_CMD_MCDP in board/hoho/board.h Try appstest commands on hoho and see them work. Change-Id: I0b3f674251f0d7c68ba4958fd3376b7c8d81b13f Reviewed-on: https://chromium-review.googlesource.com/272792 Reviewed-by: Scott Collyer <scollyer@chromium.org> Commit-Queue: Todd Broch <tbroch@chromium.org> Tested-by: Todd Broch <tbroch@chromium.org>
This commit is contained in:
committed by
ChromeOS Commit Bot
parent
0727ac31e8
commit
362ed174eb
@@ -90,6 +90,8 @@ static int tx_serial(const uint8_t *msg, int cnt)
|
||||
if (out_stream_write(&usart_mcdp_out.out, msg, cnt) != cnt)
|
||||
return EC_ERROR_UNKNOWN;
|
||||
|
||||
print_buffer((uint8_t *)msg, cnt);
|
||||
|
||||
if (out_stream_write(&usart_mcdp_out.out, &chksum, 1) != 1)
|
||||
return EC_ERROR_UNKNOWN;
|
||||
|
||||
@@ -163,6 +165,17 @@ int mcdp_get_info(struct mcdp_info *info)
|
||||
}
|
||||
|
||||
#ifdef CONFIG_CMD_MCDP
|
||||
static int rx_serial_ack(void)
|
||||
{
|
||||
if (rx_serial(mcdp_inbuf, 3))
|
||||
return EC_ERROR_UNKNOWN;
|
||||
|
||||
if (mcdp_inbuf[1] != MCDP_CMD_ACK)
|
||||
return EC_ERROR_UNKNOWN;
|
||||
|
||||
return EC_SUCCESS;
|
||||
}
|
||||
|
||||
static int mcdp_get_dev_id(char *dev, uint8_t dev_id, int dev_cnt)
|
||||
{
|
||||
uint8_t msg[2];
|
||||
@@ -180,6 +193,45 @@ static int mcdp_get_dev_id(char *dev, uint8_t dev_id, int dev_cnt)
|
||||
return EC_SUCCESS;
|
||||
}
|
||||
|
||||
static int mcdp_appstest(uint8_t cmd, int paramc, char **paramv)
|
||||
{
|
||||
uint8_t msg[6];
|
||||
char *e;
|
||||
int i;
|
||||
|
||||
/* setup any appstest params */
|
||||
msg[0] = MCDP_CMD_APPSTESTPARAM;
|
||||
for (i = 0; i < paramc; i++) {
|
||||
uint32_t param = strtoi(paramv[i], &e, 10);
|
||||
if (*e)
|
||||
return EC_ERROR_PARAM1;
|
||||
msg[1] = i + 1;
|
||||
msg[2] = (param >> 24) & 0xff;
|
||||
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;
|
||||
|
||||
if (rx_serial_ack())
|
||||
return EC_ERROR_UNKNOWN;
|
||||
}
|
||||
|
||||
msg[0] = MCDP_CMD_APPSTEST;
|
||||
msg[1] = cmd;
|
||||
if (tx_serial(msg, 2))
|
||||
return EC_ERROR_UNKNOWN;
|
||||
|
||||
if (rx_serial_ack())
|
||||
return EC_ERROR_UNKNOWN;
|
||||
|
||||
/* magic */
|
||||
rx_serial(mcdp_inbuf, sizeof(mcdp_inbuf));
|
||||
rx_serial(mcdp_inbuf, sizeof(mcdp_inbuf));
|
||||
|
||||
return EC_SUCCESS;
|
||||
}
|
||||
|
||||
int command_mcdp(int argc, char **argv)
|
||||
{
|
||||
int rv = EC_SUCCESS;
|
||||
@@ -209,6 +261,14 @@ int command_mcdp(int argc, char **argv)
|
||||
rv = mcdp_get_dev_id(dev, dev_id, 32);
|
||||
if (!rv)
|
||||
ccprintf("devid[%d] = %s\n", dev_id, dev);
|
||||
} else if (!strncasecmp(argv[1], "appstest", 4)) {
|
||||
uint8_t cmd = strtoi(argv[2], &e, 10);
|
||||
if (*e)
|
||||
rv = 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;
|
||||
}
|
||||
@@ -217,7 +277,7 @@ int command_mcdp(int argc, char **argv)
|
||||
return rv;
|
||||
}
|
||||
DECLARE_CONSOLE_COMMAND(mcdp, command_mcdp,
|
||||
"info|devid <id>",
|
||||
"info|devid <id>|appstest <cmd> [<params>]",
|
||||
"USB PD",
|
||||
NULL);
|
||||
#endif /* CONFIG_CMD_MCDP */
|
||||
|
||||
@@ -11,8 +11,11 @@
|
||||
#define MCDP_OUTBUF_MAX 16
|
||||
#define MCDP_INBUF_MAX 16
|
||||
|
||||
#define MCDP_CMD_GETINFO 0x40
|
||||
#define MCDP_CMD_GETDEVID 0x30
|
||||
#define MCDP_CMD_GETINFO 0x40
|
||||
#define MCDP_CMD_GETDEVID 0x30
|
||||
#define MCDP_CMD_APPSTEST 0x12
|
||||
#define MCDP_CMD_APPSTESTPARAM 0x11
|
||||
#define MCDP_CMD_ACK 0x0c
|
||||
|
||||
/* packet header (2 bytes: length + cmd) + data + footer (1byte: checksum) */
|
||||
#define MCDP_RSP_LEN(len) (len + 3)
|
||||
|
||||
Reference in New Issue
Block a user