drivers/serial/serial.c: Initialize OPOST and ONLCR in uart_register

This commit is contained in:
Xiang Xiao 2019-01-27 10:40:54 -06:00 committed by Gregory Nutt
parent 5911478777
commit 63276899bf
2 changed files with 33 additions and 18 deletions

View file

@ -21,6 +21,7 @@ config SERIAL_CONSOLE
menuconfig 16550_UART
bool "16550 UART Chip support"
select ARCH_HAVE_SERIAL_TERMIOS
default n
if 16550_UART

View file

@ -378,12 +378,34 @@ static inline ssize_t uart_irqwrite(FAR uart_dev_t *dev, FAR const char *buffer,
{
int ch = *buffer++;
#ifdef CONFIG_SERIAL_TERMIOS
/* Do output post-processing */
if ((dev->tc_oflag & OPOST) != 0)
{
/* Mapping CR to NL? */
if ((ch == '\r') && (dev->tc_oflag & OCRNL) != 0)
{
ch = '\n';
}
/* Are we interested in newline processing? */
if ((ch == '\n') && (dev->tc_oflag & (ONLCR | ONLRET)) != 0)
{
uart_putc(dev, '\r');
}
}
#else /* !CONFIG_SERIAL_TERMIOS */
/* If this is the console, then we should replace LF with CR-LF */
if (dev->isconsole && ch == '\n')
{
uart_putc(dev, '\r');
}
#endif
/* Output the character, using the low-level direct UART interfaces */
@ -601,22 +623,6 @@ static int uart_open(FAR struct file *filep)
goto errout_with_sem;
}
#ifdef CONFIG_SERIAL_TERMIOS
/* Initialize termios state */
dev->tc_iflag = 0;
if (dev->isconsole)
{
/* Enable \n -> \r\n translation for the console */
dev->tc_oflag = OPOST | ONLCR;
}
else
{
dev->tc_oflag = 0;
}
#endif
#ifdef CONFIG_SERIAL_DMA
/* Notify DMA that there is free space in the RX buffer */
@ -1611,16 +1617,24 @@ errout:
int uart_register(FAR const char *path, FAR uart_dev_t *dev)
{
#if defined(CONFIG_TTY_SIGINT) || defined(CONFIG_TTY_SIGSTP)
#ifdef CONFIG_SERIAL_TERMIOS
# if defined(CONFIG_TTY_SIGINT) || defined(CONFIG_TTY_SIGSTP)
/* Initialize of the task that will receive SIGINT signals. */
dev->pid = (pid_t)-1;
# endif
/* If this UART is a serial console, then enable signals by default */
/* If this UART is a serial console */
if (dev->isconsole)
{
/* Enable signals by default */
dev->tc_lflag |= ISIG;
/* Enable \n -> \r\n translation for the console */
dev->tc_oflag = OPOST | ONLCR;
}
#endif