diff options
author | Randall Spangler <rspangler@chromium.org> | 2012-06-15 16:39:38 -0700 |
---|---|---|
committer | Gerrit <chrome-bot@google.com> | 2012-06-18 11:48:15 -0700 |
commit | 4aa13dbef989e29518a18a9881858da0dd34d13c (patch) | |
tree | 96f124fb764c6b78d0a7248fe0d440446b0661d2 /common/port80.c | |
parent | b8be40607ef74fa8a91690219437c7519570050b (diff) | |
download | chrome-ec-4aa13dbef989e29518a18a9881858da0dd34d13c.tar.gz |
If port 80 buffer isn't full, only print partial contents
BUG=chromium-os:31902
TEST=manual
1. reboot ec
2. port80; nothing there
3. powerbtn
4. retype port80 repeatedly during boot and see it fill and then scroll
Change-Id: Id227d5debbdd635332ed2f42bc0f163833031b5c
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/25442
Reviewed-by: Vadim Bendebury <vbendeb@chromium.org>
Diffstat (limited to 'common/port80.c')
-rw-r--r-- | common/port80.c | 39 |
1 files changed, 27 insertions, 12 deletions
diff --git a/common/port80.c b/common/port80.c index b879ed2043..64b203e57b 100644 --- a/common/port80.c +++ b/common/port80.c @@ -15,20 +15,22 @@ #define HISTORY_LEN 16 static uint8_t history[HISTORY_LEN]; -static int head; /* Next index to use / oldest previous entry */ +static int writes; /* Number of port 80 writes so far */ static int scroll; void port_80_write(int data) { - /* Note that this currently prints from inside the LPC interrupt + /* + * Note that this currently prints from inside the LPC interrupt * itself. Probably not worth the system overhead to buffer the data * and print it from a task, because we're printing a small amount of - * data and cprintf() doesn't block. */ + * data and cprintf() doesn't block. + */ CPRINTF("%c[%T Port 80: 0x%02x]", scroll ? '\n' : '\r', data); - history[head] = data; - head = (head + 1) & (HISTORY_LEN - 1); + history[writes % ARRAY_SIZE(history)] = data; + writes++; } /*****************************************************************************/ @@ -36,22 +38,35 @@ void port_80_write(int data) static int command_port80(int argc, char **argv) { - int h = head; + int head, tail; int i; - /* 'port80 scroll' toggles whether port 80 output begins with a newline - * (scrolling) or CR (non-scrolling). */ + /* + * 'port80 scroll' toggles whether port 80 output begins with a newline + * (scrolling) or CR (non-scrolling). + */ if (argc > 1 && !strcasecmp(argv[1], "scroll")) { scroll = !scroll; ccprintf("scroll %sabled\n", scroll ? "en" : "dis"); return EC_SUCCESS; } - /* Technically, if a port 80 write comes in while we're printing this, + /* + * Print the port 80 writes so far, clipped to the length of our + * history buffer. + * + * Technically, if a port 80 write comes in while we're printing this, * we could print an incorrect history. Probably not worth the - * complexity to work around that. */ - for (i = 0; i < HISTORY_LEN; i++) - ccprintf(" %02x", history[(h + i) & (HISTORY_LEN - 1)]); + * complexity to work around that. + */ + head = writes; + if (head > ARRAY_SIZE(history)) + tail = head - ARRAY_SIZE(history); + else + tail = 0; + + for (i = tail; i < head; i++) + ccprintf(" %02x", history[i % ARRAY_SIZE(history)]); ccputs(" <--new\n"); return EC_SUCCESS; } |