summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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 */