diff options
author | Gwendal Grignou <gwendal@chromium.org> | 2015-06-06 23:09:54 -0700 |
---|---|---|
committer | ChromeOS Commit Bot <chromeos-commit-bot@chromium.org> | 2015-06-11 18:27:24 +0000 |
commit | e51399aae80923c6aee8f81a38e7c788f9125dca (patch) | |
tree | 741789b86fa43aacf31e13997b25b1bd9b3bff21 /util | |
parent | e310a2be6272022a90207f5d8227f4536ae0066b (diff) | |
download | chrome-ec-e51399aae80923c6aee8f81a38e7c788f9125dca.tar.gz |
commands: Add EC FIFO commands
Add command to read the sensors events FIFO from the AP:
FIFO_INFO: get information on the FIFO state
FIFO_READ: read and update the consumer pointer
FIFO_FLUSH: insert a flush meta event and force a interrupt.
A new MKBP event is added to tell the host the FIFO needs processing.
BRANCH=smaug
TEST=Test on ryu
BUG=chrome-os-partner:39900
Change-Id: I11c0cf8cdc3087eb9e323f7d6780e6cf3a16257f
Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/276264
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Diffstat (limited to 'util')
-rw-r--r-- | util/ectool.c | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/util/ectool.c b/util/ectool.c index 314ed5b4f0..3faea0ffbe 100644 --- a/util/ectool.c +++ b/util/ectool.c @@ -3221,6 +3221,9 @@ static const struct { MS_SIZES(sensor_range), MS_SIZES(kb_wake_angle), MS_SIZES(data), + MS_SIZES(fifo_flush), + MS_SIZES(fifo_info), + MS_SIZES(fifo_read), }; BUILD_ASSERT(ARRAY_SIZE(ms_command_sizes) == MOTIONSENSE_NUM_CMDS); #undef MS_SIZES @@ -3235,6 +3238,12 @@ static int ms_help(const char *cmd) printf(" %s odr NUM [ODR [ROUNDUP]] - set/get sensor ODR\n", cmd); printf(" %s range NUM [RANGE [ROUNDUP]]- set/get sensor range\n", cmd); printf(" %s kb_wake NUM - set/get KB wake ang\n", cmd); + printf(" %s data NUM - read sensor latest data\n", + cmd); + printf(" %s fifo_info - print fifo info\n", cmd); + printf(" %s fifo_read MAX_DATA - read fifo data\n", cmd); + printf(" %s fifo_flush NUM - trigger fifo interrupt\n", + cmd); return 0; } @@ -3483,6 +3492,92 @@ static int cmd_motionsense(int argc, char **argv) return 0; } + if (argc == 2 && !strcasecmp(argv[1], "fifo_info")) { + param.cmd = MOTIONSENSE_CMD_FIFO_INFO; + rv = ec_command(EC_CMD_MOTION_SENSE_CMD, 2, + ¶m, ms_command_sizes[param.cmd].outsize, + resp, ms_command_sizes[param.cmd].insize); + if (rv < 0) + return rv; + + printf("Size: %d\n", resp->fifo_info.size); + printf("Count: %d\n", resp->fifo_info.count); + printf("Lost: %d\n", resp->fifo_info.lost); + printf("Timestamp:%" PRIx32 "\n", resp->fifo_info.timestamp); + return 0; + } + + if (argc == 3 && !strcasecmp(argv[1], "fifo_read")) { + /* large number to test fragmentation */ + struct { + uint32_t number_data; + struct ec_response_motion_sensor_data data[512]; + } fifo_read_buffer = { + .number_data = -1, + }; + int print_data = 0, max_data = strtol(argv[2], &e, 0); + + if (e && *e) { + fprintf(stderr, "Bad %s arg.\n", argv[2]); + return -1; + } + while (fifo_read_buffer.number_data != 0 && + print_data < max_data) { + struct ec_response_motion_sensor_data *vector; + param.cmd = MOTIONSENSE_CMD_FIFO_READ; + param.fifo_read.max_data_vector = + MIN(ARRAY_SIZE(fifo_read_buffer.data), + max_data - print_data); + + rv = ec_command(EC_CMD_MOTION_SENSE_CMD, 2, + ¶m, + ms_command_sizes[param.cmd].outsize, + &fifo_read_buffer, ec_max_insize); + if (rv < 0) + return rv; + + print_data += fifo_read_buffer.number_data; + for (i = 0; i < fifo_read_buffer.number_data; i++) { + vector = &fifo_read_buffer.data[i]; + if (vector->flags & + (MOTIONSENSE_SENSOR_FLAG_TIMESTAMP | + MOTIONSENSE_SENSOR_FLAG_FLUSH)) { + uint32_t timestamp = 0; + + memcpy(×tamp, vector->data, + sizeof(uint32_t)); + printf("Timestamp:%" PRIx32 "%s\n", + timestamp, + (vector->flags & + MOTIONSENSE_SENSOR_FLAG_FLUSH ? + " - Flush" : "")); + } else { + printf("Sensor %d: %d\t%d\t%d\n", + vector->sensor_num, + vector->data[0], + vector->data[1], + vector->data[2]); + } + } + } + return 0; + } + if (argc == 3 && !strcasecmp(argv[1], "fifo_flush")) { + param.cmd = MOTIONSENSE_CMD_FIFO_FLUSH; + + param.sensor_odr.sensor_num = strtol(argv[2], &e, 0); + if (e && *e) { + fprintf(stderr, "Bad %s arg.\n", argv[2]); + return -1; + } + + rv = ec_command(EC_CMD_MOTION_SENSE_CMD, 1, + ¶m, ms_command_sizes[param.cmd].outsize, + resp, ms_command_sizes[param.cmd].insize); + + return rv < 0 ? rv : 0; + } + return ms_help(argv[0]); } |