Add serial method so that lower half driver can provide RX flow control information. From Jussi Kivilinna

This commit is contained in:
Gregory Nutt
2014-05-08 09:00:33 -06:00
parent 35e94a5be4
commit 7594d8b8cf
40 changed files with 305 additions and 30 deletions
+4 -1
View File
@@ -12,7 +12,7 @@
<h1><big><font color="#3c34ec"> <h1><big><font color="#3c34ec">
<i>NuttX RTOS Porting Guide</i> <i>NuttX RTOS Porting Guide</i>
</font></big></h1> </font></big></h1>
<p>Last Updated: January 25, 2014</p> <p>Last Updated: May 8, 2014</p>
</td> </td>
</tr> </tr>
</table> </table>
@@ -3059,6 +3059,9 @@ void board_led_off(int led);
<code>int receive(FAR struct uart_dev_s *dev, unsigned int *status);</code><br> <code>int receive(FAR struct uart_dev_s *dev, unsigned int *status);</code><br>
<code>void rxint(FAR struct uart_dev_s *dev, bool enable);</code><br> <code>void rxint(FAR struct uart_dev_s *dev, bool enable);</code><br>
<code>bool rxavailable(FAR struct uart_dev_s *dev);</code><br> <code>bool rxavailable(FAR struct uart_dev_s *dev);</code><br>
<code>#ifdef CONFIG_SERIAL_IFLOWCONTROL</code><br>
<code>bool rxflowcontrol(FAR struct uart_dev_s *dev);</code><br>
<code>#endif</code><br>
<code>void send(FAR struct uart_dev_s *dev, int ch);</code><br> <code>void send(FAR struct uart_dev_s *dev, int ch);</code><br>
<code>void txint(FAR struct uart_dev_s *dev, bool enable);</code><br> <code>void txint(FAR struct uart_dev_s *dev, bool enable);</code><br>
<code>bool txready(FAR struct uart_dev_s *dev);</code><br> <code>bool txready(FAR struct uart_dev_s *dev);</code><br>
+3
View File
@@ -157,6 +157,9 @@ static const struct uart_ops_s g_uart_ops =
.receive = up_receive, .receive = up_receive,
.rxint = up_rxint, .rxint = up_rxint,
.rxavailable = up_rxavailable, .rxavailable = up_rxavailable,
#ifdef CONFIG_SERIAL_IFLOWCONTROL
.rxflowcontrol = NULL,
#endif
.send = up_send, .send = up_send,
.txint = up_txint, .txint = up_txint,
.txready = up_txready, .txready = up_txready,
+3
View File
@@ -133,6 +133,9 @@ static const struct uart_ops_s g_uart_ops =
.receive = up_receive, .receive = up_receive,
.rxint = up_rxint, .rxint = up_rxint,
.rxavailable = up_rxavailable, .rxavailable = up_rxavailable,
#ifdef CONFIG_SERIAL_IFLOWCONTROL
.rxflowcontrol = NULL,
#endif
.send = up_send, .send = up_send,
.txint = up_txint, .txint = up_txint,
.txready = up_txready, .txready = up_txready,
+3
View File
@@ -147,6 +147,9 @@ static const struct uart_ops_s g_uart_ops =
.receive = up_receive, .receive = up_receive,
.rxint = up_rxint, .rxint = up_rxint,
.rxavailable = up_rxavailable, .rxavailable = up_rxavailable,
#ifdef CONFIG_SERIAL_IFLOWCONTROL
.rxflowcontrol = NULL,
#endif
.send = up_send, .send = up_send,
.txint = up_txint, .txint = up_txint,
.txready = up_txready, .txready = up_txready,
+3
View File
@@ -114,6 +114,9 @@ static const struct uart_ops_s g_uart_ops =
.receive = up_receive, .receive = up_receive,
.rxint = up_rxint, .rxint = up_rxint,
.rxavailable = up_rxavailable, .rxavailable = up_rxavailable,
#ifdef CONFIG_SERIAL_IFLOWCONTROL
.rxflowcontrol = NULL,
#endif
.send = up_send, .send = up_send,
.txint = up_txint, .txint = up_txint,
.txready = up_txready, .txready = up_txready,
+3
View File
@@ -136,6 +136,9 @@ static const struct uart_ops_s g_uart_ops =
.receive = up_receive, .receive = up_receive,
.rxint = up_rxint, .rxint = up_rxint,
.rxavailable = up_rxavailable, .rxavailable = up_rxavailable,
#ifdef CONFIG_SERIAL_IFLOWCONTROL
.rxflowcontrol = NULL,
#endif
.send = up_send, .send = up_send,
.txint = up_txint, .txint = up_txint,
.txready = up_txready, .txready = up_txready,
+3
View File
@@ -280,6 +280,9 @@ static const struct uart_ops_s g_uart_ops =
.receive = up_receive, .receive = up_receive,
.rxint = up_rxint, .rxint = up_rxint,
.rxavailable = up_rxavailable, .rxavailable = up_rxavailable,
#ifdef CONFIG_SERIAL_IFLOWCONTROL
.rxflowcontrol = NULL,
#endif
.send = up_send, .send = up_send,
.txint = up_txint, .txint = up_txint,
.txready = up_txready, .txready = up_txready,
+3
View File
@@ -196,6 +196,9 @@ static const struct uart_ops_s g_uart_ops =
.receive = up_receive, .receive = up_receive,
.rxint = up_rxint, .rxint = up_rxint,
.rxavailable = up_rxavailable, .rxavailable = up_rxavailable,
#ifdef CONFIG_SERIAL_IFLOWCONTROL
.rxflowcontrol = NULL,
#endif
.send = up_send, .send = up_send,
.txint = up_txint, .txint = up_txint,
.txready = up_txready, .txready = up_txready,
+3
View File
@@ -129,6 +129,9 @@ static const struct uart_ops_s g_uart_ops =
.receive = up_receive, .receive = up_receive,
.rxint = up_rxint, .rxint = up_rxint,
.rxavailable = up_rxavailable, .rxavailable = up_rxavailable,
#ifdef CONFIG_SERIAL_IFLOWCONTROL
.rxflowcontrol = NULL,
#endif
.send = up_send, .send = up_send,
.txint = up_txint, .txint = up_txint,
.txready = up_txready, .txready = up_txready,
+3
View File
@@ -113,6 +113,9 @@ static const struct uart_ops_s g_uart_ops =
.receive = up_receive, .receive = up_receive,
.rxint = up_rxint, .rxint = up_rxint,
.rxavailable = up_rxavailable, .rxavailable = up_rxavailable,
#ifdef CONFIG_SERIAL_IFLOWCONTROL
.rxflowcontrol = NULL,
#endif
.send = up_send, .send = up_send,
.txint = up_txint, .txint = up_txint,
.txready = up_txready, .txready = up_txready,
+3
View File
@@ -121,6 +121,9 @@ static const struct uart_ops_s g_uart_ops =
.receive = up_receive, .receive = up_receive,
.rxint = up_rxint, .rxint = up_rxint,
.rxavailable = up_rxavailable, .rxavailable = up_rxavailable,
#ifdef CONFIG_SERIAL_IFLOWCONTROL
.rxflowcontrol = NULL,
#endif
.send = up_send, .send = up_send,
.txint = up_txint, .txint = up_txint,
.txready = up_txready, .txready = up_txready,
+3
View File
@@ -113,6 +113,9 @@ static const struct uart_ops_s g_uart_ops =
.receive = up_receive, .receive = up_receive,
.rxint = up_rxint, .rxint = up_rxint,
.rxavailable = up_rxavailable, .rxavailable = up_rxavailable,
#ifdef CONFIG_SERIAL_IFLOWCONTROL
.rxflowcontrol = NULL,
#endif
.send = up_send, .send = up_send,
.txint = up_txint, .txint = up_txint,
.txready = up_txready, .txready = up_txready,
+3
View File
@@ -126,6 +126,9 @@ static const struct uart_ops_s g_uart_ops =
.receive = up_receive, .receive = up_receive,
.rxint = up_rxint, .rxint = up_rxint,
.rxavailable = up_rxavailable, .rxavailable = up_rxavailable,
#ifdef CONFIG_SERIAL_IFLOWCONTROL
.rxflowcontrol = NULL,
#endif
.send = up_send, .send = up_send,
.txint = up_txint, .txint = up_txint,
.txready = up_txready, .txready = up_txready,
+3
View File
@@ -126,6 +126,9 @@ static const struct uart_ops_s g_uart_ops =
.receive = up_receive, .receive = up_receive,
.rxint = up_rxint, .rxint = up_rxint,
.rxavailable = up_rxavailable, .rxavailable = up_rxavailable,
#ifdef CONFIG_SERIAL_IFLOWCONTROL
.rxflowcontrol = NULL,
#endif
.send = up_send, .send = up_send,
.txint = up_txint, .txint = up_txint,
.txready = up_txready, .txready = up_txready,
+3
View File
@@ -381,6 +381,9 @@ static const struct uart_ops_s g_uart_ops =
.receive = up_receive, .receive = up_receive,
.rxint = up_rxint, .rxint = up_rxint,
.rxavailable = up_rxavailable, .rxavailable = up_rxavailable,
#ifdef CONFIG_SERIAL_IFLOWCONTROL
.rxflowcontrol = NULL,
#endif
.send = up_send, .send = up_send,
.txint = up_txint, .txint = up_txint,
.txready = up_txready, .txready = up_txready,
+3
View File
@@ -116,6 +116,9 @@ static const struct uart_ops_s g_uart_ops =
.receive = dbgu_receive, .receive = dbgu_receive,
.rxint = dbgu_rxint, .rxint = dbgu_rxint,
.rxavailable = dbgu_rxavailable, .rxavailable = dbgu_rxavailable,
#ifdef CONFIG_SERIAL_IFLOWCONTROL
.rxflowcontrol = NULL,
#endif
.send = dbgu_send, .send = dbgu_send,
.txint = dbgu_txint, .txint = dbgu_txint,
.txready = dbgu_txready, .txready = dbgu_txready,
+3
View File
@@ -376,6 +376,9 @@ static const struct uart_ops_s g_uart_ops =
.receive = up_receive, .receive = up_receive,
.rxint = up_rxint, .rxint = up_rxint,
.rxavailable = up_rxavailable, .rxavailable = up_rxavailable,
#ifdef CONFIG_SERIAL_IFLOWCONTROL
.rxflowcontrol = NULL,
#endif
.send = up_send, .send = up_send,
.txint = up_txint, .txint = up_txint,
.txready = up_txready, .txready = up_txready,
+3
View File
@@ -300,6 +300,9 @@ static const struct uart_ops_s g_uart_ops =
.receive = sam_receive, .receive = sam_receive,
.rxint = sam_rxint, .rxint = sam_rxint,
.rxavailable = sam_rxavailable, .rxavailable = sam_rxavailable,
#ifdef CONFIG_SERIAL_IFLOWCONTROL
.rxflowcontrol = NULL,
#endif
.send = sam_send, .send = sam_send,
.txint = sam_txint, .txint = sam_txint,
.txready = sam_txempty, .txready = sam_txempty,
+160 -26
View File
@@ -161,7 +161,7 @@
# if defined(CONFIG_UART4_RXDMA) # if defined(CONFIG_UART4_RXDMA)
# ifndef CONFIG_STM32_DMA2 # ifndef CONFIG_STM32_DMA2
# error STM32 USART4 receive DMA requires CONFIG_STM32_DMA2 # error STM32 UART4 receive DMA requires CONFIG_STM32_DMA2
# endif # endif
# endif # endif
@@ -170,7 +170,7 @@
# define DMAMAP_USART1_RX DMACHAN_USART1_RX # define DMAMAP_USART1_RX DMACHAN_USART1_RX
# define DMAMAP_USART2_RX DMACHAN_USART2_RX # define DMAMAP_USART2_RX DMACHAN_USART2_RX
# define DMAMAP_USART3_RX DMACHAN_USART3_RX # define DMAMAP_USART3_RX DMACHAN_USART3_RX
# define DMAMAP_UART4_RX DMACHAN_USART4_RX # define DMAMAP_UART4_RX DMACHAN_UART4_RX
# endif # endif
@@ -326,6 +326,9 @@ static int up_receive(struct uart_dev_s *dev, uint32_t *status);
static void up_rxint(struct uart_dev_s *dev, bool enable); static void up_rxint(struct uart_dev_s *dev, bool enable);
static bool up_rxavailable(struct uart_dev_s *dev); static bool up_rxavailable(struct uart_dev_s *dev);
#endif #endif
#ifdef CONFIG_SERIAL_IFLOWCONTROL
static bool up_rxflowcontrol(struct uart_dev_s *dev);
#endif
static void up_send(struct uart_dev_s *dev, int ch); static void up_send(struct uart_dev_s *dev, int ch);
static void up_txint(struct uart_dev_s *dev, bool enable); static void up_txint(struct uart_dev_s *dev, bool enable);
static bool up_txready(struct uart_dev_s *dev); static bool up_txready(struct uart_dev_s *dev);
@@ -385,6 +388,11 @@ static const struct uart_ops_s g_uart_ops =
.receive = up_receive, .receive = up_receive,
.rxint = up_rxint, .rxint = up_rxint,
.rxavailable = up_rxavailable, .rxavailable = up_rxavailable,
#ifdef CONFIG_SERIAL_IFLOWCONTROL
.rxflowcontrol = up_rxflowcontrol,
#else
.rxflowcontrol = NULL,
#endif
.send = up_send, .send = up_send,
.txint = up_txint, .txint = up_txint,
.txready = up_txready, .txready = up_txready,
@@ -508,21 +516,17 @@ static struct up_dev_s g_usart1priv =
.parity = CONFIG_USART1_PARITY, .parity = CONFIG_USART1_PARITY,
.bits = CONFIG_USART1_BITS, .bits = CONFIG_USART1_BITS,
.stopbits2 = CONFIG_USART1_2STOP, .stopbits2 = CONFIG_USART1_2STOP,
#ifdef CONFIG_SERIAL_IFLOWCONTROL
.iflow = false,
#endif
#ifdef CONFIG_SERIAL_OFLOWCONTROL
.oflow = false,
#endif
.baud = CONFIG_USART1_BAUD, .baud = CONFIG_USART1_BAUD,
.apbclock = STM32_PCLK2_FREQUENCY, .apbclock = STM32_PCLK2_FREQUENCY,
.usartbase = STM32_USART1_BASE, .usartbase = STM32_USART1_BASE,
.tx_gpio = GPIO_USART1_TX, .tx_gpio = GPIO_USART1_TX,
.rx_gpio = GPIO_USART1_RX, .rx_gpio = GPIO_USART1_RX,
#if defined(CONFIG_SERIAL_OFLOWCONTROL) && defined(CONFIG_USART1_OFLOWCONTROL) #if defined(CONFIG_SERIAL_OFLOWCONTROL) && defined(CONFIG_USART1_OFLOWCONTROL)
.oflow = true,
.cts_gpio = GPIO_USART1_CTS, .cts_gpio = GPIO_USART1_CTS,
#endif #endif
#if defined(CONFIG_SERIAL_IFLOWCONTROL) && defined(CONFIG_USART1_IFLOWCONTROL) #if defined(CONFIG_SERIAL_IFLOWCONTROL) && defined(CONFIG_USART1_IFLOWCONTROL)
.iflow = true,
.rts_gpio = GPIO_USART1_RTS, .rts_gpio = GPIO_USART1_RTS,
#endif #endif
#ifdef CONFIG_USART1_RXDMA #ifdef CONFIG_USART1_RXDMA
@@ -574,21 +578,17 @@ static struct up_dev_s g_usart2priv =
.parity = CONFIG_USART2_PARITY, .parity = CONFIG_USART2_PARITY,
.bits = CONFIG_USART2_BITS, .bits = CONFIG_USART2_BITS,
.stopbits2 = CONFIG_USART2_2STOP, .stopbits2 = CONFIG_USART2_2STOP,
#ifdef CONFIG_SERIAL_IFLOWCONTROL
.iflow = false,
#endif
#ifdef CONFIG_SERIAL_OFLOWCONTROL
.oflow = false,
#endif
.baud = CONFIG_USART2_BAUD, .baud = CONFIG_USART2_BAUD,
.apbclock = STM32_PCLK1_FREQUENCY, .apbclock = STM32_PCLK1_FREQUENCY,
.usartbase = STM32_USART2_BASE, .usartbase = STM32_USART2_BASE,
.tx_gpio = GPIO_USART2_TX, .tx_gpio = GPIO_USART2_TX,
.rx_gpio = GPIO_USART2_RX, .rx_gpio = GPIO_USART2_RX,
#if defined(CONFIG_SERIAL_OFLOWCONTROL) && defined(CONFIG_USART2_OFLOWCONTROL) #if defined(CONFIG_SERIAL_OFLOWCONTROL) && defined(CONFIG_USART2_OFLOWCONTROL)
.oflow = true,
.cts_gpio = GPIO_USART2_CTS, .cts_gpio = GPIO_USART2_CTS,
#endif #endif
#if defined(CONFIG_SERIAL_IFLOWCONTROL) && defined(CONFIG_USART2_IFLOWCONTROL) #if defined(CONFIG_SERIAL_IFLOWCONTROL) && defined(CONFIG_USART2_IFLOWCONTROL)
.iflow = true,
.rts_gpio = GPIO_USART2_RTS, .rts_gpio = GPIO_USART2_RTS,
#endif #endif
#ifdef CONFIG_USART2_RXDMA #ifdef CONFIG_USART2_RXDMA
@@ -640,21 +640,17 @@ static struct up_dev_s g_usart3priv =
.parity = CONFIG_USART3_PARITY, .parity = CONFIG_USART3_PARITY,
.bits = CONFIG_USART3_BITS, .bits = CONFIG_USART3_BITS,
.stopbits2 = CONFIG_USART3_2STOP, .stopbits2 = CONFIG_USART3_2STOP,
#ifdef CONFIG_SERIAL_IFLOWCONTROL
.iflow = false,
#endif
#ifdef CONFIG_SERIAL_OFLOWCONTROL
.oflow = false,
#endif
.baud = CONFIG_USART3_BAUD, .baud = CONFIG_USART3_BAUD,
.apbclock = STM32_PCLK1_FREQUENCY, .apbclock = STM32_PCLK1_FREQUENCY,
.usartbase = STM32_USART3_BASE, .usartbase = STM32_USART3_BASE,
.tx_gpio = GPIO_USART3_TX, .tx_gpio = GPIO_USART3_TX,
.rx_gpio = GPIO_USART3_RX, .rx_gpio = GPIO_USART3_RX,
#if defined(CONFIG_SERIAL_OFLOWCONTROL) && defined(CONFIG_USART3_OFLOWCONTROL) #if defined(CONFIG_SERIAL_OFLOWCONTROL) && defined(CONFIG_USART3_OFLOWCONTROL)
.oflow = true,
.cts_gpio = GPIO_USART3_CTS, .cts_gpio = GPIO_USART3_CTS,
#endif #endif
#if defined(CONFIG_SERIAL_IFLOWCONTROL) && defined(CONFIG_USART3_IFLOWCONTROL) #if defined(CONFIG_SERIAL_IFLOWCONTROL) && defined(CONFIG_USART3_IFLOWCONTROL)
.iflow = true,
.rts_gpio = GPIO_USART3_RTS, .rts_gpio = GPIO_USART3_RTS,
#endif #endif
#ifdef CONFIG_USART3_RXDMA #ifdef CONFIG_USART3_RXDMA
@@ -838,21 +834,17 @@ static struct up_dev_s g_usart6priv =
.parity = CONFIG_USART6_PARITY, .parity = CONFIG_USART6_PARITY,
.bits = CONFIG_USART6_BITS, .bits = CONFIG_USART6_BITS,
.stopbits2 = CONFIG_USART6_2STOP, .stopbits2 = CONFIG_USART6_2STOP,
#ifdef CONFIG_SERIAL_IFLOWCONTROL
.iflow = false,
#endif
#ifdef CONFIG_SERIAL_OFLOWCONTROL
.oflow = false,
#endif
.baud = CONFIG_USART6_BAUD, .baud = CONFIG_USART6_BAUD,
.apbclock = STM32_PCLK2_FREQUENCY, .apbclock = STM32_PCLK2_FREQUENCY,
.usartbase = STM32_USART6_BASE, .usartbase = STM32_USART6_BASE,
.tx_gpio = GPIO_USART6_TX, .tx_gpio = GPIO_USART6_TX,
.rx_gpio = GPIO_USART6_RX, .rx_gpio = GPIO_USART6_RX,
#if defined(CONFIG_SERIAL_OFLOWCONTROL) && defined(CONFIG_USART6_OFLOWCONTROL) #if defined(CONFIG_SERIAL_OFLOWCONTROL) && defined(CONFIG_USART6_OFLOWCONTROL)
.oflow = true,
.cts_gpio = GPIO_USART6_CTS, .cts_gpio = GPIO_USART6_CTS,
#endif #endif
#if defined(CONFIG_SERIAL_IFLOWCONTROL) && defined(CONFIG_USART6_IFLOWCONTROL) #if defined(CONFIG_SERIAL_IFLOWCONTROL) && defined(CONFIG_USART6_IFLOWCONTROL)
.iflow = true,
.rts_gpio = GPIO_USART6_RTS, .rts_gpio = GPIO_USART6_RTS,
#endif #endif
#ifdef CONFIG_USART6_RXDMA #ifdef CONFIG_USART6_RXDMA
@@ -910,9 +902,11 @@ static struct up_dev_s g_uart7priv =
.tx_gpio = GPIO_UART7_TX, .tx_gpio = GPIO_UART7_TX,
.rx_gpio = GPIO_UART7_RX, .rx_gpio = GPIO_UART7_RX,
#if defined(CONFIG_SERIAL_OFLOWCONTROL) && defined(CONFIG_USART7_OFLOWCONTROL) #if defined(CONFIG_SERIAL_OFLOWCONTROL) && defined(CONFIG_USART7_OFLOWCONTROL)
.oflow = true,
.cts_gpio = GPIO_UART7_CTS, .cts_gpio = GPIO_UART7_CTS,
#endif #endif
#if defined(CONFIG_SERIAL_IFLOWCONTROL) && defined(CONFIG_USART7_IFLOWCONTROL) #if defined(CONFIG_SERIAL_IFLOWCONTROL) && defined(CONFIG_USART7_IFLOWCONTROL)
.iflow = true,
.rts_gpio = GPIO_UART7_RTS, .rts_gpio = GPIO_UART7_RTS,
#endif #endif
#ifdef CONFIG_UART7_RXDMA #ifdef CONFIG_UART7_RXDMA
@@ -970,9 +964,11 @@ static struct up_dev_s g_uart8priv =
.tx_gpio = GPIO_UART8_TX, .tx_gpio = GPIO_UART8_TX,
.rx_gpio = GPIO_UART8_RX, .rx_gpio = GPIO_UART8_RX,
#if defined(CONFIG_SERIAL_OFLOWCONTROL) && defined(CONFIG_USART8_OFLOWCONTROL) #if defined(CONFIG_SERIAL_OFLOWCONTROL) && defined(CONFIG_USART8_OFLOWCONTROL)
.oflow = true,
.cts_gpio = GPIO_UART8_CTS, .cts_gpio = GPIO_UART8_CTS,
#endif #endif
#if defined(CONFIG_SERIAL_IFLOWCONTROL) && defined(CONFIG_USART8_IFLOWCONTROL) #if defined(CONFIG_SERIAL_IFLOWCONTROL) && defined(CONFIG_USART8_IFLOWCONTROL)
.iflow = true,
.rts_gpio = GPIO_UART8_RTS, .rts_gpio = GPIO_UART8_RTS,
#endif #endif
#ifdef CONFIG_UART8_RXDMA #ifdef CONFIG_UART8_RXDMA
@@ -1308,6 +1304,92 @@ static void up_set_format(struct uart_dev_s *dev)
} }
#endif /* CONFIG_SUPPRESS_UART_CONFIG */ #endif /* CONFIG_SUPPRESS_UART_CONFIG */
/****************************************************************************
* Name: up_set_apb_clock
*
* Description:
* Enable or disable APB clock for the USART peripheral
*
* Input parameters:
* dev - A reference to the UART driver state structure
* on - Enable clock if 'on' is 'true' and disable if 'false'
*
****************************************************************************/
static void up_set_apb_clock(struct uart_dev_s *dev, bool on)
{
struct up_dev_s *priv = (struct up_dev_s*)dev->priv;
uint32_t rcc_en;
uint32_t regaddr;
/* Determine which USART to configure */
switch (priv->usartbase)
{
default:
return;
#ifdef CONFIG_STM32_USART1
case STM32_USART1_BASE:
rcc_en = RCC_APB2ENR_USART1EN;
regaddr = STM32_RCC_APB2ENR;
break;
#endif
#ifdef CONFIG_STM32_USART2
case STM32_USART2_BASE:
rcc_en = RCC_APB1ENR_USART2EN;
regaddr = STM32_RCC_APB1ENR;
break;
#endif
#ifdef CONFIG_STM32_USART3
case STM32_USART3_BASE:
rcc_en = RCC_APB1ENR_USART3EN;
regaddr = STM32_RCC_APB1ENR;
break;
#endif
#ifdef CONFIG_STM32_UART4
case STM32_UART4_BASE:
rcc_en = RCC_APB1ENR_UART4EN;
regaddr = STM32_RCC_APB1ENR;
break;
#endif
#ifdef CONFIG_STM32_UART5
case STM32_UART5_BASE:
rcc_en = RCC_APB1ENR_UART5EN;
regaddr = STM32_RCC_APB1ENR;
break;
#endif
#ifdef CONFIG_STM32_USART6
case STM32_USART6_BASE:
rcc_en = RCC_APB2ENR_USART6EN;
regaddr = STM32_RCC_APB2ENR;
break;
#endif
#ifdef CONFIG_STM32_UART7
case STM32_UART7_BASE:
rcc_en = RCC_APB1ENR_USART5EN;
regaddr = STM32_RCC_APB1ENR;
break;
#endif
#ifdef CONFIG_STM32_UART8
case STM32_UART8_BASE:
rcc_en = RCC_APB1ENR_USART5EN;
regaddr = STM32_RCC_APB1ENR;
break;
#endif
}
/* Enable/disable APB 1/2 clock for USART */
if (on)
{
modifyreg32(regaddr, 0, rcc_en);
}
else
{
modifyreg32(regaddr, rcc_en, 0);
}
}
/**************************************************************************** /****************************************************************************
* Name: up_setup * Name: up_setup
* *
@@ -1328,6 +1410,10 @@ static int up_setup(struct uart_dev_s *dev)
* was enabled in stm32_lowsetup(). * was enabled in stm32_lowsetup().
*/ */
/* Enable USART APB1/2 clock */
up_set_apb_clock(dev, true);
/* Configure pins for USART use */ /* Configure pins for USART use */
stm32_configgpio(priv->tx_gpio); stm32_configgpio(priv->tx_gpio);
@@ -1404,6 +1490,8 @@ static int up_setup(struct uart_dev_s *dev)
regval |= (USART_CR1_UE|USART_CR1_TE|USART_CR1_RE); regval |= (USART_CR1_UE|USART_CR1_TE|USART_CR1_RE);
up_serialout(priv, STM32_USART_CR1_OFFSET, regval); up_serialout(priv, STM32_USART_CR1_OFFSET, regval);
#endif /* CONFIG_SUPPRESS_UART_CONFIG */
/* Set up the cached interrupt enables value */ /* Set up the cached interrupt enables value */
priv->ie = 0; priv->ie = 0;
@@ -1490,6 +1578,10 @@ static void up_shutdown(struct uart_dev_s *dev)
up_disableusartint(priv, NULL); up_disableusartint(priv, NULL);
/* Disable USART APB1/2 clock */
up_set_apb_clock(dev, false);
/* Disable Rx, Tx, and the UART */ /* Disable Rx, Tx, and the UART */
regval = up_serialin(priv, STM32_USART_CR1_OFFSET); regval = up_serialin(priv, STM32_USART_CR1_OFFSET);
@@ -2006,6 +2098,46 @@ static bool up_rxavailable(struct uart_dev_s *dev)
} }
#endif #endif
/****************************************************************************
* Name: up_rxflowcontrol
*
* Description:
* Called when Rx buffer is full. Return true if the Rx interrupt was
* disabled.
*
****************************************************************************/
#ifdef CONFIG_SERIAL_IFLOWCONTROL
static bool up_rxflowcontrol(struct uart_dev_s *dev)
{
struct up_dev_s *priv = (struct up_dev_s*)dev->priv;
uint16_t ie;
if (priv->iflow)
{
/* Disable Rx interrupt to prevent more data being from peripheral.
* When hardware RTS is enabled, this will prevent more data from
* coming in.
*
* This function is only called when UART recv buffer is full, that
* is: "dev->recv.head + 1 == dev->recv.tail".
*
* Logic in "uart_read" will automatically toggle Rx interrupts when
* buffer is read empty and thus we do not have to re-enable Rx
* interrupts in any other place.
*/
ie = priv->ie;
ie &= ~USART_CR1_RXNEIE;
up_restoreusartint(priv, ie);
return true;
}
return false;
}
#endif
/**************************************************************************** /****************************************************************************
* Name: up_dma_receive * Name: up_dma_receive
* *
@@ -2568,6 +2700,8 @@ void stm32_serial_dma_poll(void)
* *
****************************************************************************/ ****************************************************************************/
#ifdef USE_SERIALDRIVER
int up_putc(int ch) int up_putc(int ch)
{ {
#if CONSOLE_UART > 0 #if CONSOLE_UART > 0
+3
View File
@@ -279,6 +279,9 @@ static const struct uart_ops_s g_uart_ops =
.receive = up_receive, .receive = up_receive,
.rxint = up_rxint, .rxint = up_rxint,
.rxavailable = up_rxavailable, .rxavailable = up_rxavailable,
#ifdef CONFIG_SERIAL_IFLOWCONTROL
.rxflowcontrol = NULL,
#endif
.send = up_send, .send = up_send,
.txint = up_txint, .txint = up_txint,
.txready = up_txready, .txready = up_txready,
+3
View File
@@ -344,6 +344,9 @@ static const struct uart_ops_s g_uart_ops =
.receive = up_receive, .receive = up_receive,
.rxint = up_rxint, .rxint = up_rxint,
.rxavailable = up_rxavailable, .rxavailable = up_rxavailable,
#ifdef CONFIG_SERIAL_IFLOWCONTROL
.rxflowcontrol = NULL,
#endif
.send = up_send, .send = up_send,
.txint = up_txint, .txint = up_txint,
.txready = up_txready, .txready = up_txready,
+3
View File
@@ -184,6 +184,9 @@ static const struct uart_ops_s g_uart_ops =
.receive = up_receive, .receive = up_receive,
.rxint = up_rxint, .rxint = up_rxint,
.rxavailable = up_rxavailable, .rxavailable = up_rxavailable,
#ifdef CONFIG_SERIAL_IFLOWCONTROL
.rxflowcontrol = NULL,
#endif
.send = up_send, .send = up_send,
.txint = up_txint, .txint = up_txint,
.txready = up_txready, .txready = up_txready,
+4 -1
View File
@@ -107,7 +107,7 @@ static bool usart1_txempty(struct uart_dev_s *dev);
****************************************************************************/ ****************************************************************************/
struct uart_ops_s g_uart1_ops = struct uart_ops_s g_uart1_ops =
{ {O
.setup = usart1_setup, .setup = usart1_setup,
.shutdown = usart1_shutdown, .shutdown = usart1_shutdown,
.attach = usart1_attach, .attach = usart1_attach,
@@ -116,6 +116,9 @@ struct uart_ops_s g_uart1_ops =
.receive = usart1_receive, .receive = usart1_receive,
.rxint = usart1_rxint, .rxint = usart1_rxint,
.rxavailable = usart1_rxavailable, .rxavailable = usart1_rxavailable,
#ifdef CONFIG_SERIAL_IFLOWCONTROL
.rxflowcontrol = NULL,
#endif
.send = usart1_send, .send = usart1_send,
.txint = usart1_txint, .txint = usart1_txint,
.txready = usart1_txready, .txready = usart1_txready,
+3
View File
@@ -158,6 +158,9 @@ struct uart_ops_s g_usart0_ops =
.receive = usart0_receive, .receive = usart0_receive,
.rxint = usart0_rxint, .rxint = usart0_rxint,
.rxavailable = usart0_rxavailable, .rxavailable = usart0_rxavailable,
#ifdef CONFIG_SERIAL_IFLOWCONTROL
.rxflowcontrol = NULL,
#endif
.send = usart0_send, .send = usart0_send,
.txint = usart0_txint, .txint = usart0_txint,
.txready = usart0_txready, .txready = usart0_txready,
+3
View File
@@ -146,6 +146,9 @@ struct uart_ops_s g_sci_ops =
.receive = up_receive, .receive = up_receive,
.rxint = up_rxint, .rxint = up_rxint,
.rxavailable = up_rxavailable, .rxavailable = up_rxavailable,
#ifdef CONFIG_SERIAL_IFLOWCONTROL
.rxflowcontrol = NULL,
#endif
.send = up_send, .send = up_send,
.txint = up_txint, .txint = up_txint,
.txready = up_txready, .txready = up_txready,
+3
View File
@@ -198,6 +198,9 @@ static const struct uart_ops_s g_uart_ops =
.receive = up_receive, .receive = up_receive,
.rxint = up_rxint, .rxint = up_rxint,
.rxavailable = up_rxavailable, .rxavailable = up_rxavailable,
#ifdef CONFIG_SERIAL_IFLOWCONTROL
.rxflowcontrol = NULL,
#endif
.send = up_send, .send = up_send,
.txint = up_txint, .txint = up_txint,
.txready = up_txready, .txready = up_txready,
+3
View File
@@ -152,6 +152,9 @@ static struct uart_ops_s g_com_ops =
.receive = up_receive, .receive = up_receive,
.rxint = up_rxint, .rxint = up_rxint,
.rxavailable = up_rxavailable, .rxavailable = up_rxavailable,
#ifdef CONFIG_SERIAL_IFLOWCONTROL
.rxflowcontrol = NULL,
#endif
.send = up_send, .send = up_send,
.txint = up_txint, .txint = up_txint,
.txready = up_txready, .txready = up_txready,
+3
View File
@@ -292,6 +292,9 @@ static const struct uart_ops_s g_uart_ops =
.receive = up_receive, .receive = up_receive,
.rxint = up_rxint, .rxint = up_rxint,
.rxavailable = up_rxavailable, .rxavailable = up_rxavailable,
#ifdef CONFIG_SERIAL_IFLOWCONTROL
.rxflowcontrol = NULL,
#endif
.send = up_send, .send = up_send,
.txint = up_txint, .txint = up_txint,
.txready = up_txready, .txready = up_txready,
+3
View File
@@ -180,6 +180,9 @@ struct uart_ops_s g_sci_ops =
.receive = up_receive, .receive = up_receive,
.rxint = up_rxint, .rxint = up_rxint,
.rxavailable = up_rxavailable, .rxavailable = up_rxavailable,
#ifdef CONFIG_SERIAL_IFLOWCONTROL
.rxflowcontrol = NULL,
#endif
.send = up_send, .send = up_send,
.txint = up_txint, .txint = up_txint,
.txready = up_txready, .txready = up_txready,
+3
View File
@@ -121,6 +121,9 @@ static const struct uart_ops_s g_uart_ops =
z16f_receive, /* receive */ z16f_receive, /* receive */
z16f_rxint, /* rxint */ z16f_rxint, /* rxint */
z16f_rxavailable, /* rxavailable */ z16f_rxavailable, /* rxavailable */
#ifdef CONFIG_SERIAL_IFLOWCONTROL
NULL, /* rxflowcontrol */
#endif
z16f_send, /* send */ z16f_send, /* send */
z16f_txint, /* txint */ z16f_txint, /* txint */
z16f_txready, /* txready */ z16f_txready, /* txready */
+3
View File
@@ -110,6 +110,9 @@ static const struct uart_ops_s g_uart_ops =
ez80_receive, /* receive */ ez80_receive, /* receive */
ez80_rxint, /* rxint */ ez80_rxint, /* rxint */
ez80_rxavailable, /* rxavailable */ ez80_rxavailable, /* rxavailable */
#ifdef CONFIG_SERIAL_IFLOWCONTROL
NULL, /* rxflowcontrol */
#endif
ez80_send, /* send */ ez80_send, /* send */
ez80_txint, /* txint */ ez80_txint, /* txint */
ez80_txready, /* txready */ ez80_txready, /* txready */
+3
View File
@@ -114,6 +114,9 @@ static const struct uart_ops_s g_uart_ops =
z180_receive, /* receive */ z180_receive, /* receive */
z180_rxint, /* rxint */ z180_rxint, /* rxint */
z180_rxavailable, /* rxavailable */ z180_rxavailable, /* rxavailable */
#ifdef CONFIG_SERIAL_IFLOWCONTROL
NULL, /* rxflowcontrol */
#endif
z180_send, /* send */ z180_send, /* send */
z180_txint, /* txint */ z180_txint, /* txint */
z180_txready, /* txready */ z180_txready, /* txready */
+3
View File
@@ -122,6 +122,9 @@ static const struct uart_ops_s g_uart_ops =
z8_receive, /* receive */ z8_receive, /* receive */
z8_rxint, /* rxint */ z8_rxint, /* rxint */
z8_rxavailable, /* rxavailable */ z8_rxavailable, /* rxavailable */
#ifdef CONFIG_SERIAL_IFLOWCONTROL
NULL, /* rxflowcontrol */
#endif
z8_send, /* send */ z8_send, /* send */
z8_txint, /* txint */ z8_txint, /* txint */
z8_txready, /* txready */ z8_txready, /* txready */
+3
View File
@@ -132,6 +132,9 @@ static const struct uart_ops_s g_uart_ops =
up_receive, /* receive */ up_receive, /* receive */
up_rxint, /* rxint */ up_rxint, /* rxint */
up_rxavailable, /* rxavailable */ up_rxavailable, /* rxavailable */
#ifdef CONFIG_SERIAL_IFLOWCONTROL
NULL, /* rxflowcontrol */
#endif
up_send, /* send */ up_send, /* send */
up_txint, /* txint */ up_txint, /* txint */
up_txready, /* txready */ up_txready, /* txready */
+3
View File
@@ -97,6 +97,9 @@ static const struct uart_ops_s g_uart_ops =
up_receive, /* receive */ up_receive, /* receive */
up_rxint, /* rxint */ up_rxint, /* rxint */
up_rxavailable, /* rxavailable */ up_rxavailable, /* rxavailable */
#ifdef CONFIG_SERIAL_IFLOWCONTROL
NULL, /* rxflowcontrol */
#endif
up_send, /* send */ up_send, /* send */
up_txint, /* txint */ up_txint, /* txint */
up_txready, /* txready */ up_txready, /* txready */
+21 -2
View File
@@ -153,7 +153,26 @@ void uart_recvchars(FAR uart_dev_t *dev)
while (uart_rxavailable(dev)) while (uart_rxavailable(dev))
{ {
char ch = uart_receive(dev, &status); bool is_full = (nexthead == dev->recv.tail);
char ch;
#ifdef CONFIG_SERIAL_IFLOWCONTROL
/* Check if RX buffer is full and allow serial low-level driver to pause
* processing. This allows proper utilization of hardware flow control.
*/
if (is_full)
{
if (uart_rxflowcontrol(dev))
{
/* Low-level driver activated RX flow control, exit loop now. */
break;
}
}
#endif
ch = uart_receive(dev, &status);
/* If the RX buffer becomes full, then the serial data is discarded. This is /* If the RX buffer becomes full, then the serial data is discarded. This is
* necessary because on most serial hardware, you must read the data in order * necessary because on most serial hardware, you must read the data in order
@@ -163,7 +182,7 @@ void uart_recvchars(FAR uart_dev_t *dev)
* some large internal buffering). * some large internal buffering).
*/ */
if (nexthead != dev->recv.tail) if (!is_full)
{ {
/* Add the character to the buffer */ /* Add the character to the buffer */
+3
View File
@@ -119,6 +119,9 @@ static const struct uart_ops_s g_uart_ops =
.receive = u16550_receive, .receive = u16550_receive,
.rxint = u16550_rxint, .rxint = u16550_rxint,
.rxavailable = u16550_rxavailable, .rxavailable = u16550_rxavailable,
#ifdef CONFIG_SERIAL_IFLOWCONTROL
.rxflowcontrol = NULL,
#endif
.send = u16550_send, .send = u16550_send,
.txint = u16550_txint, .txint = u16550_txint,
.txready = u16550_txready, .txready = u16550_txready,
+3
View File
@@ -238,6 +238,9 @@ static const struct uart_ops_s g_uartops =
NULL, /* receive */ NULL, /* receive */
cdcuart_rxint, /* rxinit */ cdcuart_rxint, /* rxinit */
NULL, /* rxavailable */ NULL, /* rxavailable */
#ifdef CONFIG_SERIAL_IFLOWCONTROL
NULL, /* rxflowcontrol */
#endif
NULL, /* send */ NULL, /* send */
cdcuart_txint, /* txinit */ cdcuart_txint, /* txinit */
NULL, /* txready */ NULL, /* txready */
+3
View File
@@ -401,6 +401,9 @@ static const struct uart_ops_s g_uartops =
NULL, /* receive */ NULL, /* receive */
usbser_rxint, /* rxinit */ usbser_rxint, /* rxinit */
NULL, /* rxavailable */ NULL, /* rxavailable */
#ifdef CONFIG_SERIAL_IFLOWCONTROL
NULL, /* rxflowcontrol */
#endif
NULL, /* send */ NULL, /* send */
usbser_txint, /* txinit */ usbser_txint, /* txinit */
NULL, /* txready */ NULL, /* txready */
+11
View File
@@ -78,6 +78,11 @@
#define uart_send(dev,ch) dev->ops->send(dev,ch) #define uart_send(dev,ch) dev->ops->send(dev,ch)
#define uart_receive(dev,s) dev->ops->receive(dev,s) #define uart_receive(dev,s) dev->ops->receive(dev,s)
#ifdef CONFIG_SERIAL_IFLOWCONTROL
#define uart_rxflowcontrol(dev) \
(dev->ops->rxflowcontrol && dev->ops->rxflowcontrol(dev))
#endif
/************************************************************************************ /************************************************************************************
* Public Types * Public Types
************************************************************************************/ ************************************************************************************/
@@ -159,6 +164,12 @@ struct uart_ops_s
CODE bool (*rxavailable)(FAR struct uart_dev_s *dev); CODE bool (*rxavailable)(FAR struct uart_dev_s *dev);
#ifdef CONFIG_SERIAL_IFLOWCONTROL
/* Return true if UART activated RX flow control to block more incoming data. */
CODE bool (*rxflowcontrol)(FAR struct uart_dev_s *dev);
#endif
/* This method will send one byte on the UART */ /* This method will send one byte on the UART */
CODE void (*send)(FAR struct uart_dev_s *dev, int ch); CODE void (*send)(FAR struct uart_dev_s *dev, int ch);