From a975c98fb2f378e4fc94cf73c38fe8afa8cb6eeb Mon Sep 17 00:00:00 2001 From: Vincent Palatin Date: Mon, 16 Jun 2014 13:46:59 -0700 Subject: usb: add USB console driver Provide access to the EC console through 2 USB bulk endpoints. (which can be used through the usbserial driver) Signed-off-by: Vincent Palatin BRANCH=none BUG=none TEST=run on Fruitpie and use the console over USB Change-Id: Ia897764f3a030972ee2ed323f293c5fca899765a Reviewed-on: https://chromium-review.googlesource.com/204167 Reviewed-by: Anton Staaf Commit-Queue: Vic Yang Tested-by: Vic Yang --- common/console.c | 39 ++++++++++++++++++++++++++++++--------- common/console_output.c | 31 +++++++++++++++++++++++++------ 2 files changed, 55 insertions(+), 15 deletions(-) (limited to 'common') diff --git a/common/console.c b/common/console.c index 2920db60fc..20ec4ce50f 100644 --- a/common/console.c +++ b/common/console.c @@ -4,12 +4,14 @@ */ /* Console module for Chrome EC */ + #include "clock.h" #include "console.h" #include "link_defs.h" #include "system.h" #include "task.h" #include "uart.h" +#include "usb_console.h" #include "util.h" #define MAX_ARGS_PER_COMMAND 10 @@ -205,6 +207,14 @@ static void console_init(void) ccputs(PROMPT); } +static int console_putc(int c) +{ + int rv1 = uart_putc(c); + int rv2 = usb_putc(c); + + return rv1 == EC_SUCCESS ? rv2 : rv1; +} + static void move_cursor_right(void) { if (input_pos == input_len) @@ -244,7 +254,7 @@ static void move_cursor_begin(void) static void repeat_char(char c, int cnt) { while (cnt--) - uart_putc(c); + console_putc(c); } #ifdef CONFIG_CONSOLE_HISTORY @@ -289,7 +299,7 @@ static void handle_backspace(void) return; /* Already at beginning of line */ /* Move cursor back */ - uart_putc('\b'); + console_putc('\b'); /* Print and move anything following the cursor position */ if (input_pos != input_len) { @@ -302,7 +312,7 @@ static void handle_backspace(void) } /* Space over last character and move cursor to correct position */ - uart_putc(' '); + console_putc(' '); repeat_char('\b', input_len - input_pos + 1); input_len--; @@ -413,7 +423,7 @@ static void console_handle_char(int c) case '\n': /* Terminate this line */ - uart_puts("\r\n"); + console_putc('\n'); #ifdef CONFIG_CONSOLE_HISTORY /* Save command in history buffer */ @@ -512,7 +522,7 @@ static void console_handle_char(int c) break; /* Print character */ - uart_putc(c); + console_putc(c); /* If not at end of line, print rest of line and move it down */ if (input_pos != input_len) { @@ -554,12 +564,23 @@ void console_task(void) console_init(); while (1) { - int c = uart_getc(); + int c; + + while (1) { + c = uart_getc(); + if (c == -1) + break; + console_handle_char(c); + } - if (c == -1) - task_wait_event(-1); /* Wait for more input */ - else + while (1) { + c = usb_getc(); + if (c == -1) + break; console_handle_char(c); + } + + task_wait_event(-1); /* Wait for more input */ } } diff --git a/common/console_output.c b/common/console_output.c index 3bbad84ad4..bc28a8a3b1 100644 --- a/common/console_output.c +++ b/common/console_output.c @@ -7,6 +7,7 @@ #include "console.h" #include "uart.h" +#include "usb_console.h" #include "util.h" /* Default to all channels active */ @@ -68,26 +69,36 @@ BUILD_ASSERT(ARRAY_SIZE(channel_names) == CC_CHANNEL_COUNT); int cputs(enum console_channel channel, const char *outstr) { + int rv1, rv2; + /* Filter out inactive channels */ if (!(CC_MASK(channel) & channel_mask)) return EC_SUCCESS; - return uart_puts(outstr); + rv1 = usb_puts(outstr); + rv2 = uart_puts(outstr); + + return rv1 == EC_SUCCESS ? rv2 : rv1; } int cprintf(enum console_channel channel, const char *format, ...) { - int rv; + int rv1, rv2; va_list args; /* Filter out inactive channels */ if (!(CC_MASK(channel) & channel_mask)) return EC_SUCCESS; + usb_va_start(args, format); + rv1 = usb_vprintf(format, args); + usb_va_end(args); + va_start(args, format); - rv = uart_vprintf(format, args); + rv2 = uart_vprintf(format, args); va_end(args); - return rv; + + return rv1 == EC_SUCCESS ? rv2 : rv1; } int cprints(enum console_channel channel, const char *format, ...) @@ -99,13 +110,21 @@ int cprints(enum console_channel channel, const char *format, ...) if (!(CC_MASK(channel) & channel_mask)) return EC_SUCCESS; + rv = cprintf(channel, "[%T "); + va_start(args, format); - rv = uart_printf("[%T "); r = uart_vprintf(format, args); if (r) rv = r; - r = uart_puts("]\n"); va_end(args); + + usb_va_start(args, format); + r = usb_vprintf(format, args); + if (r) + rv = r; + usb_va_end(args); + + r = cputs(channel, "]\n"); return r ? r : rv; } -- cgit v1.2.1