summaryrefslogtreecommitdiff
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
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>
-rw-r--r--chip/g/usb_console.c5
-rw-r--r--chip/stm32/usb_console.c5
-rw-r--r--common/chargen.c37
-rw-r--r--common/usb_console_stream.c5
-rw-r--r--include/usb_console.h10
5 files changed, 54 insertions, 8 deletions
diff --git a/chip/g/usb_console.c b/chip/g/usb_console.c
index 68cdea8a6e..ae36bcd89e 100644
--- a/chip/g/usb_console.c
+++ b/chip/g/usb_console.c
@@ -390,3 +390,8 @@ void usb_console_enable(int enabled, int readonly)
is_enabled = enabled;
is_readonly = readonly;
}
+
+int usb_console_tx_blocked(void)
+{
+ return is_enabled && (queue_space(&tx_q) < USB_MAX_PACKET_SIZE);
+}
diff --git a/chip/stm32/usb_console.c b/chip/stm32/usb_console.c
index 587609ba5d..0a792fe012 100644
--- a/chip/stm32/usb_console.c
+++ b/chip/stm32/usb_console.c
@@ -271,3 +271,8 @@ void usb_console_enable(int enabled, int readonly)
is_enabled = enabled;
is_readonly = readonly;
}
+
+int usb_console_tx_blocked(void)
+{
+ return is_enabled && usb_console_tx_valid();
+}
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."
diff --git a/common/usb_console_stream.c b/common/usb_console_stream.c
index 40bbc07e3c..13dd7f8264 100644
--- a/common/usb_console_stream.c
+++ b/common/usb_console_stream.c
@@ -231,3 +231,8 @@ void usb_console_enable(int enabled, int readonly)
is_enabled = enabled;
is_readonly = readonly;
}
+
+int usb_console_tx_blocked(void)
+{
+ return is_enabled && (queue_space(&tx_q) < USB_MAX_PACKET_SIZE);
+}
diff --git a/include/usb_console.h b/include/usb_console.h
index 296829ff9c..2e0aa7dfa6 100644
--- a/include/usb_console.h
+++ b/include/usb_console.h
@@ -62,6 +62,15 @@ uint32_t usb_console_crc(void);
*/
void usb_console_enable(int enabled, int readonly);
+/**
+ * Is USB TX queue blocked?
+ *
+ * Return 1, if USB console is enabled and USB TX Queue does not have enough
+ * space for the next packet.
+ * 0, otherwise.
+ */
+int usb_console_tx_blocked(void);
+
#define usb_va_start va_start
#define usb_va_end va_end
#else
@@ -71,6 +80,7 @@ void usb_console_enable(int enabled, int readonly);
#define usb_getc(x) (-1)
#define usb_va_start(x, y)
#define usb_va_end(x)
+#define usb_console_tx_blocked() (0)
#endif
#endif /* __CROS_EC_USB_CONSOLE_H */