diff options
Diffstat (limited to 'chip/g')
-rw-r--r-- | chip/g/usb_console.c | 40 |
1 files changed, 21 insertions, 19 deletions
diff --git a/chip/g/usb_console.c b/chip/g/usb_console.c index 6dd7286dde..68cdea8a6e 100644 --- a/chip/g/usb_console.c +++ b/chip/g/usb_console.c @@ -251,6 +251,9 @@ static int usb_wait_console(void) timestamp_t deadline = get_time(); int wait_time_us = 1; + if (!is_enabled || !tx_fifo_is_ready()) + return EC_SUCCESS; + deadline.val += USB_CONSOLE_TIMEOUT_US; /* @@ -308,12 +311,10 @@ static int __tx_char(void *context, int c) while (QUEUE_ADD_UNITS(state, &c, 1) != 1) usleep(500); - - return EC_SUCCESS; #else - return QUEUE_ADD_UNITS(state, &c, 1) ? EC_SUCCESS : - EC_ERROR_OVERFLOW; + QUEUE_ADD_UNITS(state, &c, 1); #endif + return 0; } /* @@ -334,25 +335,24 @@ int usb_getc(void) int usb_puts(const char *outstr) { int ret; + struct queue state; if (!is_enabled) return EC_SUCCESS; ret = usb_wait_console(); - if (ret == EC_SUCCESS) { - struct queue state = tx_q; - - while (*outstr) { - ret = __tx_char(&state, *outstr); - if (ret != EC_SUCCESS) - break; - outstr++; - } + if (ret) + return ret; + state = tx_q; + while (*outstr) + if (__tx_char(&state, *outstr++)) + break; + + if (queue_count(&state)) handle_output(); - } - return ret; + return *outstr ? EC_ERROR_OVERFLOW : EC_SUCCESS; } int usb_putc(int c) @@ -367,18 +367,20 @@ int usb_putc(int c) int usb_vprintf(const char *format, va_list args) { int ret; + struct queue state; if (!is_enabled) return EC_SUCCESS; ret = usb_wait_console(); - if (ret == EC_SUCCESS) { - struct queue state = tx_q; + if (ret) + return ret; - ret = vfnprintf(__tx_char, &state, format, args); + state = tx_q; + ret = vfnprintf(__tx_char, &state, format, args); + if (queue_count(&state)) handle_output(); - } return ret; } |