summaryrefslogtreecommitdiff
path: root/common/console.c
diff options
context:
space:
mode:
authorJes B. Klinke <jbk@chromium.org>2021-10-06 12:07:30 -0700
committerCommit Bot <commit-bot@chromium.org>2021-10-08 00:16:57 +0000
commit0b21ad072215053b2d1a872d800fe5ad9caadac7 (patch)
tree4835fd19dbe7dc8fbfe47d708221f1dad3bd5528 /common/console.c
parent048193fdb82e04f4af067083bc2621619223fdb2 (diff)
downloadchrome-ec-0b21ad072215053b2d1a872d800fe5ad9caadac7.tar.gz
common/console: Add support for ^C
When making USB connection to the console, theoretically, one does not know if a previous session has typed a partial command into the buffer. One could send a newline before typing the desired command, but it would be even safer to have a keypress that would discard any partial command. In particular, the HyperDebug device to be used with OpenTitan is similar to Servo micro, but there will not be a daemon like servod maintaining a single USB connection. Instead each invocation of the "OpenTitan tool" (somewhat equivalent to dut-control) will establish its own connection with the USB console endpoint, and issue commands. This design increases the risk of e.g. a testing script being interrupted on the development workstation resulting in a partial command being left on the console. This change adds support for the Ctrl-C character in the EC console, having the effect of discarding any input, and printing a new command prompt. This is similar behavior to most Linux shells. BUG=b:192262089 BRANCH=none TEST=Upload to Nucleo board, manually connect to ttyUSBn Signed-off-by: Jes B. Klinke <jbk@chromium.org> Change-Id: I082b76a7db4961cd4ce2feb91745c465003d416f Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3208915 Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
Diffstat (limited to 'common/console.c')
-rw-r--r--common/console.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/common/console.c b/common/console.c
index e7adc084b3..51f7a0bf38 100644
--- a/common/console.c
+++ b/common/console.c
@@ -518,6 +518,18 @@ static void console_handle_char(int c)
case 0x7f:
handle_backspace();
break;
+
+ case CTRL('C'):
+ /* Terminate this line */
+ ccputs("^C\n");
+
+ /* Start new line, discarding any existing partial input. */
+ input_pos = input_len = 0;
+ input_buf[0] = '\0';
+
+ /* Reprint prompt */
+ ccputs(PROMPT);
+ break;
#endif /* !defined(CONFIG_EXPERIMENTAL_CONSOLE) */
case '\n':