diff options
-rw-r--r-- | chip/g/usb_console.c | 23 | ||||
-rw-r--r-- | include/config.h | 6 | ||||
-rw-r--r-- | include/usb_console.h | 10 |
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 2d7cd658ee..8d023c54ba 100644 --- a/include/config.h +++ b/include/config.h @@ -2911,6 +2911,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 |