diff options
Diffstat (limited to 'chip/g/usart.c')
-rw-r--r-- | chip/g/usart.c | 33 |
1 files changed, 26 insertions, 7 deletions
diff --git a/chip/g/usart.c b/chip/g/usart.c index 5236acf202..6580ca9eb0 100644 --- a/chip/g/usart.c +++ b/chip/g/usart.c @@ -15,6 +15,11 @@ #define USE_UART_INTERRUPTS (!(defined(CONFIG_CUSTOMIZED_RO) && \ defined(SECTION_IS_RO))) #define QUEUE_SIZE 64 +/* + * Want to be able to accumulate larger amounts of data while USB is + * momentarily stalled for whatever reason. + */ +#define QUEUE_SIZE_UART_RX 512 #ifdef CONFIG_STREAM_SIGNATURE /* @@ -57,7 +62,8 @@ SIGNER_CONFIG(sig, stream_uart, sig_to_usb, ap_uart_output); #else /* Not CONFIG_STREAM_SIGNATURE */ static struct queue const ap_uart_output = - QUEUE_DIRECT(QUEUE_SIZE, uint8_t, ap_uart.producer, ap_usb.consumer); + QUEUE_DIRECT(QUEUE_SIZE_UART_RX, uint8_t, + ap_uart.producer, ap_usb.consumer); #endif static struct queue const ap_usb_to_uart = @@ -100,7 +106,8 @@ struct usb_stream_config const ec_usb; struct usart_config const ec_uart; static struct queue const ec_uart_to_usb = - QUEUE_DIRECT(QUEUE_SIZE, uint8_t, ec_uart.producer, ec_usb.consumer); + QUEUE_DIRECT(QUEUE_SIZE_UART_RX, uint8_t, + ec_uart.producer, ec_usb.consumer); static struct queue const ec_usb_to_uart = QUEUE_DIRECT(QUEUE_SIZE, uint8_t, ec_usb.producer, ec_uart.consumer); @@ -135,14 +142,26 @@ void get_data_from_usb(struct usart_config const *config) void send_data_to_usb(struct usart_config const *config) { + /* + * UART RX FIFO is 32 bytes in size, let's have little extra room so + * that we could catch up if we are draining the FIFO while the chip + * keeps receiving. + */ + uint8_t buffer[50]; + uint32_t i; + uint32_t room; struct queue const *uart_in = config->producer.queue; + int uart = config->uart; + + + i = 0; + room = MIN(sizeof(buffer), queue_space(uart_in)); - /* Copy input from buffer until RX fifo empty or the queue is full */ - while (uartn_rx_available(config->uart) && queue_space(uart_in)) { - int c = uartn_read_char(config->uart); + while ((i < room) && uartn_rx_available(uart)) + buffer[i++] = uartn_read_char(uart); - QUEUE_ADD_UNITS(uart_in, &c, 1); - } + if (i) + QUEUE_ADD_UNITS(uart_in, buffer, i); } static void uart_read(struct producer const *producer, size_t count) |