summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaisuke Nojiri <dnojiri@chromium.org>2019-08-15 16:20:56 -0700
committerCommit Bot <commit-bot@chromium.org>2020-01-24 08:35:00 +0000
commitdf00f2c6857b73db36fe9082128422bb788bf1cb (patch)
tree33c18690cdb0ab716800d3116949e469b0816dcf
parent20652520d6004778a447d01c6dac2bc5d4a76d68 (diff)
downloadchrome-ec-df00f2c6857b73db36fe9082128422bb788bf1cb.tar.gz
uart: Add uart_put_raw
uart_put_raw sends byte stream without translating '\n' to '\r\n'. Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> BUG=b/119329144,chromium:998135 BRANCH=none TEST=Boot Nami Change-Id: Iaac4244d45231bf5904d917f2f446f87e8e10c50 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1757273 Commit-Queue: Daisuke Nojiri <dnojiri@chromium.org> Tested-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-by: Jett Rink <jettrink@chromium.org> Reviewed-by: Aseda Aboagye <aaboagye@chromium.org> Auto-Submit: Daisuke Nojiri <dnojiri@chromium.org>
-rw-r--r--common/uart_buffering.c28
-rw-r--r--include/uart.h11
2 files changed, 33 insertions, 6 deletions
diff --git a/common/uart_buffering.c b/common/uart_buffering.c
index e3b7e73fbd..1c0db3b151 100644
--- a/common/uart_buffering.c
+++ b/common/uart_buffering.c
@@ -80,14 +80,10 @@ void uart_init_buffer(void)
* @param c Character to write.
* @return 0 if the character was transmitted, 1 if it was dropped.
*/
-static int __tx_char(void *context, int c)
+static int __tx_char_raw(void *context, int c)
{
int tx_buf_next, tx_buf_new_tail;
- /* Do newline to CRLF translation */
- if (c == '\n' && __tx_char(NULL, '\r'))
- return 1;
-
#if defined CONFIG_POLLING_UART
(void) tx_buf_next;
(void) tx_buf_new_tail;
@@ -122,6 +118,14 @@ static int __tx_char(void *context, int c)
return 0;
}
+static int __tx_char(void *context, int c)
+{
+ /* Translate '\n' to '\r\n' */
+ if (c == '\n' && __tx_char_raw(NULL, '\r'))
+ return 1;
+ return __tx_char_raw(context, c);
+}
+
#ifdef CONFIG_UART_TX_DMA
/**
@@ -298,6 +302,20 @@ int uart_put(const char *out, int len)
return len ? EC_ERROR_OVERFLOW : EC_SUCCESS;
}
+int uart_put_raw(const char *out, int len)
+{
+ /* Put all characters in the output buffer */
+ while (len--) {
+ if (__tx_char_raw(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 e333196d4a..502757cdf2 100644
--- a/include/uart.h
+++ b/include/uart.h
@@ -48,7 +48,7 @@ int uart_putc(int c);
int uart_puts(const char *outstr);
/**
- * Put byte stream to the UART
+ * Put byte stream to the UART while translating '\n' to '\r\n'
*
* @param out Pointer to data to send
* @param len Length of transfer in bytes
@@ -57,6 +57,15 @@ int uart_puts(const char *outstr);
int uart_put(const char *out, int len);
/**
+ * Put raw 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_raw(const char *out, int len);
+
+/**
* Print formatted output to the UART, like printf().
*
* See printf.h for valid formatting codes.