diff options
author | Daisuke Nojiri <dnojiri@chromium.org> | 2019-02-06 12:49:44 -0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2019-02-08 06:03:47 -0800 |
commit | b937f5c5b2bd54323b91f38be9650c975b00618c (patch) | |
tree | e1edd2b24f7f3da8e478d89a6ea9c16d0ca8e99d | |
parent | b2ec2a5eb56f9f6bb769ed0200fe11bcc075167d (diff) | |
download | chrome-ec-b937f5c5b2bd54323b91f38be9650c975b00618c.tar.gz |
UART: Add uart_put API
The uart_puts API takes a null-terminated string. This patch adds
the uart_put API, which works like uart_puts but allows the caller
to specify the data size.
Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org>
BUG=b/119329144
BRANCH=none
TEST=buildall
Change-Id: I18b2625f9a2339b68ca586b6f1b3c36511cb725c
Reviewed-on: https://chromium-review.googlesource.com/1457576
Commit-Ready: Daisuke Nojiri <dnojiri@chromium.org>
Tested-by: Daisuke Nojiri <dnojiri@chromium.org>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
-rw-r--r-- | common/uart_buffering.c | 14 | ||||
-rw-r--r-- | include/uart.h | 9 |
2 files changed, 23 insertions, 0 deletions
diff --git a/common/uart_buffering.c b/common/uart_buffering.c index 7b4b864c09..2b83cb7cfc 100644 --- a/common/uart_buffering.c +++ b/common/uart_buffering.c @@ -244,6 +244,20 @@ int uart_puts(const char *outstr) return *outstr ? EC_ERROR_OVERFLOW : EC_SUCCESS; } +int uart_put(const char *out, int len) +{ + /* Put all characters in the output buffer */ + while (len--) { + if (__tx_char(NULL, *out++) != 0) + break; + } + + uart_tx_start(); + + /* Successful if we consumed all output */ + return len ? EC_ERROR_OVERFLOW : EC_SUCCESS; +} + int uart_vprintf(const char *format, va_list args) { int rv = vfnprintf(__tx_char, NULL, format, args); diff --git a/include/uart.h b/include/uart.h index e40b0e866f..9fdc3e8dec 100644 --- a/include/uart.h +++ b/include/uart.h @@ -48,6 +48,15 @@ int uart_putc(int c); int uart_puts(const char *outstr); /** + * Put byte stream to the UART + * + * @param out Pointer to data to send + * @param len Length of transfer in bytes + * @return EC_SUCCESS, or non-zero if output was truncated. + */ +int uart_put(const char *out, int len); + +/** * Print formatted output to the UART, like printf(). * * See printf.h for valid formatting codes. |