summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarius Schilder <mschilder@google.com>2018-02-23 20:14:46 -0800
committerChromeOS Commit Bot <chromeos-commit-bot@chromium.org>2018-03-14 01:19:51 +0000
commit767daf00789226a5038defa2527f76327ebb1bcc (patch)
tree2379786f6fa93ac11424331624865dd0dd1b49e6
parentaa3a374231cb068bd536d2e38c6b6b425e9b7349 (diff)
downloadchrome-ec-767daf00789226a5038defa2527f76327ebb1bcc.tar.gz
g: add CONFIG_USB_CONSOLE_CRC
This option will cause usb console output to block and also compute a crc32. Signed-off-by: mschilder@google.com TEST=make buildall -j BRANCH=none BUG=none Change-Id: Icf66d5ddbea52008a9c97094e7c83194caa7db79 Reviewed-on: https://chromium-review.googlesource.com/936281 Commit-Ready: Marius Schilder <mschilder@chromium.org> Tested-by: Marius Schilder <mschilder@chromium.org> Reviewed-by: Marius Schilder <mschilder@chromium.org> Reviewed-by: Vadim Bendebury <vbendeb@chromium.org> (cherry picked from commit e5e1b7ea5dbc6a22e14c63ef9a6c4f00cfd1993f) Reviewed-on: https://chromium-review.googlesource.com/949075 Tested-by: Vadim Bendebury <vbendeb@chromium.org> Commit-Queue: Vadim Bendebury <vbendeb@chromium.org>
-rw-r--r--chip/g/usb_console.c23
-rw-r--r--include/config.h6
-rw-r--r--include/usb_console.h10
3 files changed, 39 insertions, 0 deletions
diff --git a/chip/g/usb_console.c b/chip/g/usb_console.c
index f77c34a638..3904c5968a 100644
--- a/chip/g/usb_console.c
+++ b/chip/g/usb_console.c
@@ -6,6 +6,7 @@
#include "common.h"
#include "config.h"
#include "console.h"
+#include "crc.h"
#include "link_defs.h"
#include "printf.h"
#include "queue.h"
@@ -278,6 +279,21 @@ static int usb_wait_console(void)
return EC_SUCCESS;
}
}
+
+#ifdef CONFIG_USB_CONSOLE_CRC
+static uint32_t usb_tx_crc_ctx;
+
+void usb_console_crc_init(void)
+{
+ crc32_ctx_init(&usb_tx_crc_ctx);
+}
+
+uint32_t usb_console_crc(void)
+{
+ return crc32_ctx_result(&usb_tx_crc_ctx);
+}
+#endif
+
static int __tx_char(void *context, int c)
{
struct queue *state =
@@ -286,7 +302,14 @@ static int __tx_char(void *context, int c)
if (c == '\n' && __tx_char(state, '\r'))
return 1;
+#ifdef CONFIG_USB_CONSOLE_CRC
+ crc32_ctx_hash8(&usb_tx_crc_ctx, c);
+
+ while (QUEUE_ADD_UNITS(state, &c, 1) != 1)
+ usleep(500);
+#else
QUEUE_ADD_UNITS(state, &c, 1);
+#endif
return 0;
}
diff --git a/include/config.h b/include/config.h
index a274ab0e30..4831da8824 100644
--- a/include/config.h
+++ b/include/config.h
@@ -2604,6 +2604,12 @@
/* Enable USB serial console module. */
#undef CONFIG_USB_CONSOLE
+/*
+ * Enable USB serial console crc32 computation.
+ * Also makes console output block on overrun.
+ */
+#undef CONFIG_USB_CONSOLE_CRC
+
/* Support USB HID interface. */
#undef CONFIG_USB_HID
diff --git a/include/usb_console.h b/include/usb_console.h
index 08cbbf5491..de538f8ec8 100644
--- a/include/usb_console.h
+++ b/include/usb_console.h
@@ -44,6 +44,16 @@ int usb_putc(int c);
int usb_getc(void);
/**
+ * Reset the usb console output crc32 accumulator.
+ */
+void usb_console_crc_init(void);
+
+/**
+ * Get the current usb console output crc32 accumulator.
+ */
+uint32_t usb_console_crc(void);
+
+/**
* Enable and Disable the USB console.
*
* By default the console is enabled, this should not be a problem since it