From ecffe722573a88b155dfc4c7b3058b1039370e90 Mon Sep 17 00:00:00 2001 From: Kelvin Lawson Date: Tue, 17 Sep 2013 22:13:27 +0100 Subject: [PATCH] dm36x: UART convert \n to \r\n --- ports/arm/platforms/dm36x/uart.c | 40 +++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/ports/arm/platforms/dm36x/uart.c b/ports/arm/platforms/dm36x/uart.c index 1369376..95ff3d1 100644 --- a/ports/arm/platforms/dm36x/uart.c +++ b/ports/arm/platforms/dm36x/uart.c @@ -47,7 +47,7 @@ /* Constants */ /** Select relevant UART for this platform */ -#define UART_BASE DM36X_UART1_BASE +#define UART_BASE DM36X_UART0_BASE /** FR Register bits */ #define UART_FR_RXFE 0x10 @@ -73,6 +73,7 @@ static int initialised = FALSE; /* Forward declarations */ static int uart_init (void); +static void uart_write_char (const char c); /** @@ -208,12 +209,12 @@ int uart_write (const char *ptr, int len) /* Loop through all bytes to write */ for (todo = 0; todo < len; todo++) { - /* Wait for empty */ - while(UART_LSR(UART_BASE) & UART_LSR_TEMT) - ; + /* Convert \n to \r\n */ + if (*ptr == '\n') + uart_write_char('\r'); /* Write byte to UART */ - UART_DR(UART_BASE) = *ptr++; + uart_write_char(*ptr++); } /* Return mutex access */ @@ -248,12 +249,12 @@ void uart_write_halt (const char *ptr) /* Loop through all bytes until NULL terminator encountered */ while (*ptr != '\0') { - /* Wait for empty */ - while(UART_LSR(UART_BASE) & UART_LSR_TEMT) - ; + /* Convert \n to \r\n */ + if (*ptr == '\n') + uart_write_char('\r'); /* Write byte to UART */ - UART_DR(UART_BASE) = *ptr++; + uart_write_char(*ptr++); } } @@ -262,3 +263,24 @@ void uart_write_halt (const char *ptr) ; } + + +/** + * \b uart_putchar + * + * Simple polled UART write char. + * + * Assumes that the mutex has already been taken, or + * is not expected to be taken (e.g. on interrupt). + * + * @param[in] c Char to write + */ +static void uart_write_char (const char c) +{ + /* Wait for empty */ + while(UART_LSR(UART_BASE) & UART_LSR_TEMT) + ; + + /* Write byte to UART */ + UART_DR(UART_BASE) = c; +}