diff options
-rw-r--r-- | chip/g/usb-stream.h | 18 | ||||
-rw-r--r-- | common/console.c | 5 | ||||
-rw-r--r-- | common/console_output.c | 3 | ||||
-rw-r--r-- | common/uart_buffering.c | 7 | ||||
-rw-r--r-- | common/usb_console_stream.c | 15 | ||||
-rw-r--r-- | include/uart.h | 9 | ||||
-rw-r--r-- | include/usb_console.h | 6 |
7 files changed, 54 insertions, 9 deletions
diff --git a/chip/g/usb-stream.h b/chip/g/usb-stream.h index 49048a6d9c..f051e0c093 100644 --- a/chip/g/usb-stream.h +++ b/chip/g/usb-stream.h @@ -75,6 +75,20 @@ extern struct producer_ops const usb_stream_producer_ops; #endif /* + * When in packet mode, the terminal application (Acroterm) constantly times + * out if the deferred function is used in the USB transmit path. + * + * The below allows to exclude the console channel from the set using the + * deferred function when in packet console mode. + */ +#ifdef CONFIG_EXTRACT_PRINTF_STRINGS +#define UART_CONSOLE_CHANNEL(x) (((x) == USB_EP_AP) || ((x) == USB_EP_EC)) +#else +#define UART_CONSOLE_CHANNEL(x) (((x) == USB_EP_AP) || ((x) == USB_EP_EC) || \ + ((x) == USB_EP_CONSOLE)) +#endif + +/* * Convenience macro for defining USB streams and their associated state and * buffers. * @@ -136,9 +150,7 @@ extern struct producer_ops const usb_stream_producer_ops; static size_t CONCAT2(NAME, _tx_handled); \ struct usb_stream_config const NAME = { \ .endpoint = ENDPOINT, \ - .is_uart_console = ((ENDPOINT == USB_EP_EC) || \ - (ENDPOINT == USB_EP_CONSOLE) || \ - (ENDPOINT == USB_EP_AP)), \ + .is_uart_console = UART_CONSOLE_CHANNEL(ENDPOINT), \ .tx_in_progress = &CONCAT2(NAME, _tx_in_progress_), \ .kicker_running = &CONCAT2(NAME, _kicker_running_), \ .is_reset = &CONCAT2(NAME, _is_reset_), \ diff --git a/common/console.c b/common/console.c index 8f42dffbf5..9ee3dc5b13 100644 --- a/common/console.c +++ b/common/console.c @@ -279,10 +279,7 @@ static void console_init(void) static int console_putc(int c) { - int rv1 = uart_putc(c); - int rv2 = usb_putc(c); - - return rv1 == EC_SUCCESS ? rv2 : rv1; + return ccprintf("%c", c); } #ifndef CONFIG_EXPERIMENTAL_CONSOLE diff --git a/common/console_output.c b/common/console_output.c index 2fe1ac99a9..6d883f7030 100644 --- a/common/console_output.c +++ b/common/console_output.c @@ -37,6 +37,8 @@ BUILD_ASSERT(ARRAY_SIZE(channel_names) == CC_CHANNEL_COUNT); BUILD_ASSERT(CC_CHANNEL_COUNT <= 8*sizeof(uint32_t)); #endif /* CONFIG_CONSOLE_CHANNEL */ +#ifndef CONFIG_EXTRACT_PRINTF_STRINGS + /*****************************************************************************/ /* Channel-based console output */ @@ -106,6 +108,7 @@ int cprints(enum console_channel channel, const char *format, ...) r = cputs(channel, "]\n"); return r ? r : rv; } +#endif /* ^^^^^^^^ CONFIG_EXTRACT_PRINTF_STRINGS NOT defined. */ void cflush(void) { diff --git a/common/uart_buffering.c b/common/uart_buffering.c index e3b7e73fbd..c54cbf98dd 100644 --- a/common/uart_buffering.c +++ b/common/uart_buffering.c @@ -84,9 +84,11 @@ static int __tx_char(void *context, int c) { int tx_buf_next, tx_buf_new_tail; +#ifndef CONFIG_EXTRACT_PRINTF_STRINGS /* Do newline to CRLF translation */ if (c == '\n' && __tx_char(NULL, '\r')) return 1; +#endif #if defined CONFIG_POLLING_UART (void) tx_buf_next; @@ -122,6 +124,11 @@ static int __tx_char(void *context, int c) return 0; } +size_t uart_buffer_room(void) +{ + return (tx_buf_tail - tx_buf_head - 1) & (CONFIG_UART_TX_BUF_SIZE - 1); +} + #ifdef CONFIG_UART_TX_DMA /** diff --git a/common/usb_console_stream.c b/common/usb_console_stream.c index 40bbc07e3c..6ba1f484a4 100644 --- a/common/usb_console_stream.c +++ b/common/usb_console_stream.c @@ -162,6 +162,21 @@ static int __tx_char(void *context, int c) #endif } +size_t usb_buffer_room(void) +{ + if (!is_enabled) + return 0; + + return queue_space(&tx_q); +} + +int usb_put(const char *s, int len) +{ + QUEUE_ADD_UNITS(&tx_q, s, len); + handle_output(); + return EC_SUCCESS; +} + /* * Public USB console implementation below. */ diff --git a/include/uart.h b/include/uart.h index e333196d4a..3b798140ae 100644 --- a/include/uart.h +++ b/include/uart.h @@ -9,8 +9,10 @@ #define __CROS_EC_UART_H #include <stdarg.h> /* For va_list */ + #include "common.h" #include "gpio.h" +#include "stddef.h" /** * Initialize the UART module. @@ -352,9 +354,12 @@ int uart_console_read_buffer(uint8_t type, uint16_t dest_size, uint16_t *write_count); -#endif /* __CROS_EC_UART_H */ - /** * Initialize tx buffer head and tail */ void uart_init_buffer(void); + +/* Return the size of the free room in the UART TX circular buffer. */ +size_t uart_buffer_room(void); + +#endif /* __CROS_EC_UART_H */ diff --git a/include/usb_console.h b/include/usb_console.h index 296829ff9c..cac8fde093 100644 --- a/include/usb_console.h +++ b/include/usb_console.h @@ -62,6 +62,12 @@ uint32_t usb_console_crc(void); */ void usb_console_enable(int enabled, int readonly); +/* Return the size of the free room in the USB TX circular buffer. */ +size_t usb_buffer_room(void); + +/* Send characters to the USB channel. */ +int usb_put(const char *str, int count); + #define usb_va_start va_start #define usb_va_end va_end #else |