Squashed commit of the following:

drivers/serial/uart_16550.c:  Add a configuration, analogous to the STM32 configuration option, to suppress the NuttX standard re-ordering for /dev/ttySN for special case of the 16550 UART.

    config/serial: UART 16550: Add CONFIG_SERIAL_UART_ARCH_MMIO option so the a memory mapped device doesn't need to provide uart_getreg() and uart_putreg() implementations.

    u16550_txempty() should check UART_LSR_TEMT to avoid some data left in the transmit FIFO
This commit is contained in:
Xiang Xiao
2018-08-26 11:17:33 -06:00
committed by Gregory Nutt
parent ea62b13fd0
commit 46e47c8dcf
5 changed files with 203 additions and 152 deletions
-10
View File
@@ -58,16 +58,6 @@
* Public Functions * Public Functions
****************************************************************************/ ****************************************************************************/
uart_datawidth_t uart_getreg(uart_addrwidth_t base, unsigned int offset)
{
return *((volatile uart_addrwidth_t *)base + offset);
}
void uart_putreg(uart_addrwidth_t base, unsigned int offset, uart_datawidth_t value)
{
*((volatile uart_addrwidth_t *)base + offset) = value;
}
void uart_decodeirq(int irq, FAR void *context) void uart_decodeirq(int irq, FAR void *context)
{ {
int i; int i;
+1
View File
@@ -86,6 +86,7 @@ CONFIG_SCHED_CHILD_STATUS=y
CONFIG_SCHED_HAVE_PARENT=y CONFIG_SCHED_HAVE_PARENT=y
CONFIG_SCHED_HPWORK=y CONFIG_SCHED_HPWORK=y
CONFIG_SCHED_WAITPID=y CONFIG_SCHED_WAITPID=y
CONFIG_SERIAL_UART_ARCH_MMIO=y
CONFIG_STANDARD_SERIAL=y CONFIG_STANDARD_SERIAL=y
CONFIG_START_DAY=28 CONFIG_START_DAY=28
CONFIG_START_MONTH=6 CONFIG_START_MONTH=6
+14
View File
@@ -5,6 +5,16 @@
if 16550_UART if 16550_UART
config 16550_SERIAL_DISABLE_REORDERING
bool "Disable reordering of ttySx devices."
default n
---help---
NuttX per default reorders the serial ports (/dev/ttySx) so that the
console is always on /dev/ttyS0. If more than one UART is in use this
can, however, have the side-effect that all port mappings
(hardware USART1 -> /dev/ttyS0) change if the console is moved to another
UART. This option disables that re-ordering for 16550 UARTs.
config 16550_UART0 config 16550_UART0
bool "16550 UART0" bool "16550 UART0"
default n default n
@@ -307,6 +317,10 @@ config 16550_SUPRESS_CONFIG
that configures the 16550_UART. In that case, you may want to that configures the 16550_UART. In that case, you may want to
just leave the existing console configuration in place. Default: n just leave the existing console configuration in place. Default: n
config SERIAL_UART_ARCH_MMIO
bool "Platform access register through the memory mapping"
default n
config SERIAL_UART_ARCH_IOCTL config SERIAL_UART_ARCH_IOCTL
bool "Platform has own custom IOCTL" bool "Platform has own custom IOCTL"
default n default n
+49 -6
View File
@@ -2,7 +2,7 @@
* drivers/serial/uart_16550.c * drivers/serial/uart_16550.c
* Serial driver for 16550 UART * Serial driver for 16550 UART
* *
* Copyright (C) 2011, 2013, 2017 Gregory Nutt. All rights reserved. * Copyright (C) 2011, 2013, 2017-2018 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org> * Author: Gregory Nutt <gnutt@nuttx.org>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@@ -143,7 +143,7 @@ static char g_uart3rxbuffer[CONFIG_16550_UART3_RXBUFSIZE];
static char g_uart3txbuffer[CONFIG_16550_UART3_TXBUFSIZE]; static char g_uart3txbuffer[CONFIG_16550_UART3_TXBUFSIZE];
#endif #endif
/* This describes the state of the LPC17xx uart0 port. */ /* This describes the state of the 16550 uart0 port. */
#ifdef CONFIG_16550_UART0 #ifdef CONFIG_16550_UART0
static struct u16550_s g_uart0priv = static struct u16550_s g_uart0priv =
@@ -178,7 +178,7 @@ static uart_dev_t g_uart0port =
}; };
#endif #endif
/* This describes the state of the LPC17xx uart1 port. */ /* This describes the state of the 16550 uart1 port. */
#ifdef CONFIG_16550_UART1 #ifdef CONFIG_16550_UART1
static struct u16550_s g_uart1priv = static struct u16550_s g_uart1priv =
@@ -213,7 +213,7 @@ static uart_dev_t g_uart1port =
}; };
#endif #endif
/* This describes the state of the LPC17xx uart1 port. */ /* This describes the state of the 16550 uart1 port. */
#ifdef CONFIG_16550_UART2 #ifdef CONFIG_16550_UART2
static struct u16550_s g_uart2priv = static struct u16550_s g_uart2priv =
@@ -248,7 +248,7 @@ static uart_dev_t g_uart2port =
}; };
#endif #endif
/* This describes the state of the LPC17xx uart1 port. */ /* This describes the state of the 16550 uart1 port. */
#ifdef CONFIG_16550_UART3 #ifdef CONFIG_16550_UART3
static struct u16550_s g_uart3priv = static struct u16550_s g_uart3priv =
@@ -283,6 +283,39 @@ static uart_dev_t g_uart3port =
}; };
#endif #endif
/* Which UART with be tty0/console and which tty1? tty2? tty3? */
#ifdef CONFIG_16550_SERIAL_DISABLE_REORDERING
# if defined(CONFIG_16550_UART0_SERIAL_CONSOLE)
# define CONSOLE_DEV g_uart0port /* UART0=console */
# elif defined(CONFIG_16550_UART1_SERIAL_CONSOLE)
# define CONSOLE_DEV g_uart1port /* UART1=console */
# elif defined(CONFIG_16550_UART2_SERIAL_CONSOLE)
# define CONSOLE_DEV g_uart2port /* UART2=console */
# elif defined(CONFIG_16550_UART3_SERIAL_CONSOLE)
# define CONSOLE_DEV g_uart3port /* UART3=console */
# endif
# ifdef CONFIG_16550_UART0
# define TTYS0_DEV g_uart0port
# endif
# ifdef CONFIG_16550_UART1
# define TTYS1_DEV g_uart1port
# endif
# ifdef CONFIG_16550_UART2
# define TTYS2_DEV g_uart2port
# endif
# ifdef CONFIG_16550_UART3
# define TTYS3_DEV g_uart3port
# endif
#else /* CONFIG_16550_SERIAL_DISABLE_REORDERING */
/* Which UART with be tty0/console and which tty1? tty2? tty3? */ /* Which UART with be tty0/console and which tty1? tty2? tty3? */
# if defined(CONFIG_16550_UART0_SERIAL_CONSOLE) # if defined(CONFIG_16550_UART0_SERIAL_CONSOLE)
@@ -444,6 +477,8 @@ static uart_dev_t g_uart3port =
# endif # endif
# endif # endif
#endif /* CONFIG_16550_SERIAL_DISABLE_REORDERING */
/**************************************************************************** /****************************************************************************
* Private Functions * Private Functions
****************************************************************************/ ****************************************************************************/
@@ -454,7 +489,11 @@ static uart_dev_t g_uart3port =
static inline uart_datawidth_t u16550_serialin(FAR struct u16550_s *priv, int offset) static inline uart_datawidth_t u16550_serialin(FAR struct u16550_s *priv, int offset)
{ {
#ifdef CONFIG_SERIAL_UART_ARCH_MMIO
return *((FAR volatile uart_addrwidth_t *)priv->uartbase + offset);
#else
return uart_getreg(priv->uartbase, offset); return uart_getreg(priv->uartbase, offset);
#endif
} }
/**************************************************************************** /****************************************************************************
@@ -464,7 +503,11 @@ static inline uart_datawidth_t u16550_serialin(FAR struct u16550_s *priv, int of
static inline void u16550_serialout(FAR struct u16550_s *priv, int offset, static inline void u16550_serialout(FAR struct u16550_s *priv, int offset,
uart_datawidth_t value) uart_datawidth_t value)
{ {
#ifdef CONFIG_SERIAL_UART_ARCH_MMIO
*((FAR volatile uart_addrwidth_t *)priv->uartbase + offset) = value;
#else
uart_putreg(priv->uartbase, offset, value); uart_putreg(priv->uartbase, offset, value);
#endif
} }
/**************************************************************************** /****************************************************************************
@@ -1000,7 +1043,7 @@ static bool u16550_txready(struct uart_dev_s *dev)
static bool u16550_txempty(struct uart_dev_s *dev) static bool u16550_txempty(struct uart_dev_s *dev)
{ {
FAR struct u16550_s *priv = (FAR struct u16550_s *)dev->priv; FAR struct u16550_s *priv = (FAR struct u16550_s *)dev->priv;
return ((u16550_serialin(priv, UART_LSR_OFFSET) & UART_LSR_THRE) != 0); return ((u16550_serialin(priv, UART_LSR_OFFSET) & UART_LSR_TEMT) != 0);
} }
/**************************************************************************** /****************************************************************************
+3
View File
@@ -345,8 +345,11 @@ typedef uint32_t uart_addrwidth_t;
* *
************************************************************************************/ ************************************************************************************/
#ifndef CONFIG_SERIAL_UART_ARCH_MMIO
uart_datawidth_t uart_getreg(uart_addrwidth_t base, unsigned int offset); uart_datawidth_t uart_getreg(uart_addrwidth_t base, unsigned int offset);
void uart_putreg(uart_addrwidth_t base, unsigned int offset, uart_datawidth_t value); void uart_putreg(uart_addrwidth_t base, unsigned int offset, uart_datawidth_t value);
#endif
int uart_ioctl(struct file *filep, int cmd, unsigned long arg); int uart_ioctl(struct file *filep, int cmd, unsigned long arg);
#endif /* CONFIG_16550_UART */ #endif /* CONFIG_16550_UART */