summaryrefslogtreecommitdiff
path: root/common/chargen.c
diff options
context:
space:
mode:
authorNamyoon Woo <namyoon@chromium.org>2019-08-12 13:37:40 -0700
committerCommit Bot <commit-bot@chromium.org>2020-01-15 05:56:06 +0000
commite29f365dd38c5d04e8c2bb5af37d37dc12350891 (patch)
tree7b1bbf49d15e7621afab6523ab6802609a6662cb /common/chargen.c
parent86bf6c285c456e08c012835138e9510d5fee059f (diff)
downloadchrome-ec-e29f365dd38c5d04e8c2bb5af37d37dc12350891.tar.gz
util: enable chargen for USB console
This patch allows chargen to print output to USB instead of UART, which is chosen by command parameter. If USB console is not supported, then the parameter will be ignored, and output shall go to UART port. The patch increases flash usage by 48 bytes if CONFIG_CMD_CHARGEN is defined. BUG=chromium:992607 BRANCH=None TEST=manually ran on fleex. for BOARD in {cr50, fleex} 1. Define CONFIG_CMD_CHARGEN in board/cr50/board.h, and baseboard/octopus/baseboard.h. 2. Build binaries, and program them. 3. Connect CCD to Octopus Fleex. 4. Open terminal to Cr50 and EC consoles, and run chargen (cr50) chargen 1 4 > // no output, because they went to UART. (cr50) chargen 1 4 usb 0000 > (ec) chargen 1 4 0000 > (ec) chargen 1 4 usb // usb parameter gets ignored. 0000 > Change-Id: I5810421fef56548e0bd667488e853e724f699a31 Signed-off-by: Namyoon Woo <namyoon@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1769386 Reviewed-by: Ruben Rodriguez Buchillon <coconutruben@chromium.org>
Diffstat (limited to 'common/chargen.c')
-rw-r--r--common/chargen.c37
1 files changed, 29 insertions, 8 deletions
diff --git a/common/chargen.c b/common/chargen.c
index 64cd138924..eb7e93657f 100644
--- a/common/chargen.c
+++ b/common/chargen.c
@@ -3,10 +3,12 @@
* found in the LICENSE file.
*/
+#include "common.h"
#include "config.h"
#include "console.h"
#include "timer.h"
#include "uart.h"
+#include "usb_console.h"
#include "util.h"
#include "watchdog.h"
@@ -14,9 +16,11 @@
* Microseconds time to drain entire UART_TX console buffer at 115200 b/s, 10
* bits per character.
*/
-#define BUFFER_DRAIN_TIME_US (1000000UL * 10 * CONFIG_UART_TX_BUF_SIZE / 115200)
+#define BUFFER_DRAIN_TIME_US (1000000UL * 10 * CONFIG_UART_TX_BUF_SIZE \
+ / CONFIG_UART_BAUD_RATE)
+
/*
- * Generate a stream of characters on the UART console.
+ * Generate a stream of characters on the UART (and USB) console.
*
* The stream is an ever incrementing pattern of characters from the following
* set: 0..9A..Za..z.
@@ -41,7 +45,10 @@ static int command_chargen(int argc, char **argv)
uint32_t seq_number = 0;
timestamp_t prev_watchdog_time;
- while (uart_getc() != -1)
+ int (*putc_)(int c) = uart_putc;
+ int (*tx_is_blocked_)(void) = uart_buffer_full;
+
+ while (uart_getc() != -1 || usb_getc() != -1)
; /* Drain received characters, if any. */
if (argc > 1)
@@ -50,12 +57,22 @@ static int command_chargen(int argc, char **argv)
if (argc > 2)
seq_number = atoi(argv[2]);
+#if defined(CONFIG_USB_CONSOLE) || defined(CONFIG_USB_CONSOLE_STREAM)
+ if (argc > 3) {
+ if (memcmp(argv[3], "usb", 3))
+ return EC_ERROR_PARAM3;
+
+ putc_ = usb_putc;
+ tx_is_blocked_ = usb_console_tx_blocked;
+ }
+#endif
+
c = '0';
prev_watchdog_time = get_time();
- while (uart_getc() != 'x') {
+ while (uart_getc() != 'x' && usb_getc() != 'x') {
timestamp_t current_time;
- while (uart_buffer_full()) {
+ while (tx_is_blocked_()) {
/*
* Let's sleep enough time to drain half of TX
* buffer.
@@ -72,7 +89,7 @@ static int command_chargen(int argc, char **argv)
prev_watchdog_time.val = current_time.val;
}
- uart_putc(c++);
+ putc_(c++);
if (seq_number && (++seq_counter == seq_number))
break;
@@ -91,11 +108,15 @@ static int command_chargen(int argc, char **argv)
c = 'A';
}
- uart_putc('\n');
- return 0;
+ putc_('\n');
+ return EC_SUCCESS;
}
DECLARE_SAFE_CONSOLE_COMMAND(chargen, command_chargen,
+#if defined(CONFIG_USB_CONSOLE) || defined(CONFIG_USB_CONSOLE_STREAM)
+ "[seq_length [num_chars [usb]]]",
+#else
"[seq_length [num_chars]]",
+#endif
"Generate a constant stream of characters on the "
"UART console,\nrepeating every 'seq_length' "
"characters, up to 'num_chars' total."