From 32225b18b0a8ea30669799b3dd426fe050471acf Mon Sep 17 00:00:00 2001 From: Vincent Palatin Date: Wed, 4 Oct 2017 17:20:25 +0200 Subject: [EXPERIMENTAL] Add packetized console mode Add hooks to provide console commands and read their answers in a 'packetized' fashion, ie it's the command is in a single delimited in a single packet and doesn't need to be extracted from a flow of console characters. Signed-off-by: Vincent Palatin BRANCH=twinkie BUG=none TEST=with the following CLs, use the console with the packetized USB endpoint on Twinkie. Change-Id: Ie02db092af6f6f37c1d575bf5746183a64baafd1 Reviewed-on: https://chromium-review.googlesource.com/702423 Tested-by: Vincent Palatin Trybot-Ready: Vincent Palatin Commit-Queue: Vincent Palatin Reviewed-by: Vincent Palatin --- common/console.c | 4 ++++ common/console_output.c | 21 +++++++++++++++++++++ include/config.h | 3 +++ include/console.h | 11 +++++++++++ 4 files changed, 39 insertions(+) diff --git a/common/console.c b/common/console.c index bb4195d584..23562b00b5 100644 --- a/common/console.c +++ b/common/console.c @@ -656,6 +656,10 @@ void console_task(void) while (1) { int c; +#ifdef CONFIG_CONSOLE_PACKETS + if (console_packet_get_command(input_buf)) + console_packet_send_response(handle_command(input_buf)); +#endif /* CONFIG_CONSOLE_PACKETS */ while (1) { c = uart_getc(); diff --git a/common/console_output.c b/common/console_output.c index 7354ea4392..4067377a6a 100644 --- a/common/console_output.c +++ b/common/console_output.c @@ -46,6 +46,10 @@ int cputs(enum console_channel channel, const char *outstr) if (!(CC_MASK(channel) & channel_mask)) return EC_SUCCESS; +#ifdef CONFIG_CONSOLE_PACKETS + if (!console_packet_puts(channel, outstr)) + return EC_SUCCESS; /* in packet mode, skip others */ +#endif /* CONFIG_CONSOLE_PACKETS */ rv1 = usb_puts(outstr); rv2 = uart_puts(outstr); @@ -61,6 +65,14 @@ int cprintf(enum console_channel channel, const char *format, ...) if (!(CC_MASK(channel) & channel_mask)) return EC_SUCCESS; +#ifdef CONFIG_CONSOLE_PACKETS + va_start(args, format); + if (!console_packet_vprintf(channel, format, args)) { + va_end(args); + return EC_SUCCESS; /* in packet mode, skip others */ + } + va_end(args); +#endif /* CONFIG_CONSOLE_PACKETS */ usb_va_start(args, format); rv1 = usb_vprintf(format, args); usb_va_end(args); @@ -83,6 +95,15 @@ int cprints(enum console_channel channel, const char *format, ...) rv = cprintf(channel, "[%T "); +#ifdef CONFIG_CONSOLE_PACKETS + va_start(args, format); + if (!console_packet_vprintf(channel, format, args)) { + va_end(args); + cputs(channel, "]\n"); + return EC_SUCCESS; /* in packet mode, skip others */ + } + va_end(args); +#endif /* CONFIG_CONSOLE_PACKETS */ va_start(args, format); r = uart_vprintf(format, args); if (r) diff --git a/include/config.h b/include/config.h index b8215ec976..0c39ea96c6 100644 --- a/include/config.h +++ b/include/config.h @@ -800,6 +800,9 @@ /* Max length of a single line of input */ #define CONFIG_CONSOLE_INPUT_LINE_SIZE 80 +/* Enable a 'packetized' mode for the console. */ +#undef CONFIG_CONSOLE_PACKETS + /* Enable verbose output to UART console and extra timestamp print precision. */ #define CONFIG_CONSOLE_VERBOSE diff --git a/include/console.h b/include/console.h index d8da234a24..2fffd25ba7 100644 --- a/include/console.h +++ b/include/console.h @@ -8,6 +8,7 @@ #ifndef __CROS_EC_CONSOLE_H #define __CROS_EC_CONSOLE_H +#include /* For va_list */ #include "common.h" /* Console command; used by DECLARE_CONSOLE_COMMAND macro. */ @@ -190,4 +191,14 @@ void console_has_input(void); #endif /* HAS_TASK_CONSOLE */ +/* + * Packetized console under CONFIG_CONSOLE_PACKETS flags. + */ + +int console_packet_get_command(char *buf); +void console_packet_send_response(int rv); +int console_packet_puts(enum console_channel channel, const char *outstr); +int console_packet_vprintf(enum console_channel channel, const char *format, + va_list args); + #endif /* __CROS_EC_CONSOLE_H */ -- cgit v1.2.1