summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincent Palatin <vpalatin@chromium.org>2017-10-04 17:20:25 +0200
committerChromeOS Commit Bot <chromeos-commit-bot@chromium.org>2017-11-06 16:48:21 +0000
commit32225b18b0a8ea30669799b3dd426fe050471acf (patch)
tree7a92dbcefe2c8ad01cf231f9620d7b6e8fe3ae7d
parentcc13a8b9ae68c91fe755a77de62e1821251ceba3 (diff)
downloadchrome-ec-32225b18b0a8ea30669799b3dd426fe050471acf.tar.gz
[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 <vpalatin@chromium.org> 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 <vpalatin@chromium.org> Trybot-Ready: Vincent Palatin <vpalatin@chromium.org> Commit-Queue: Vincent Palatin <vpalatin@chromium.org> Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
-rw-r--r--common/console.c4
-rw-r--r--common/console_output.c21
-rw-r--r--include/config.h3
-rw-r--r--include/console.h11
4 files changed, 39 insertions, 0 deletions
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 <stdarg.h> /* 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 */