You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by ac...@apache.org on 2024/09/27 13:53:18 UTC

(nuttx) branch master updated: mpfs_serial.c: Add RX flowcontrol

This is an automated email from the ASF dual-hosted git repository.

acassis pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new 21f9fc2b28 mpfs_serial.c: Add RX flowcontrol
21f9fc2b28 is described below

commit 21f9fc2b285d981f196b5977cb95999f7c938378
Author: Jani Paalijarvi <ja...@unikie.com>
AuthorDate: Fri Sep 20 08:32:05 2024 +0300

    mpfs_serial.c: Add RX flowcontrol
    
    Disable RX interrupts and clear the fifo in case of full RX buffer.
    Enable RX interrupts in case of empty buffer.
---
 arch/risc-v/src/mpfs/mpfs_serial.c | 47 +++++++++++++++++++++++++++++++++++++-
 1 file changed, 46 insertions(+), 1 deletion(-)

diff --git a/arch/risc-v/src/mpfs/mpfs_serial.c b/arch/risc-v/src/mpfs/mpfs_serial.c
index ab262dc2a5..7a49eb8ad6 100644
--- a/arch/risc-v/src/mpfs/mpfs_serial.c
+++ b/arch/risc-v/src/mpfs/mpfs_serial.c
@@ -142,6 +142,10 @@ static int  up_ioctl(struct file *filep, int cmd, unsigned long arg);
 static int  up_receive(struct uart_dev_s *dev, unsigned int *status);
 static void up_rxint(struct uart_dev_s *dev, bool enable);
 static bool up_rxavailable(struct uart_dev_s *dev);
+#ifdef CONFIG_SERIAL_IFLOWCONTROL
+static bool up_rxflowcontrol(struct uart_dev_s *dev,
+                             unsigned int nbuffered, bool upper);
+#endif
 static void up_send(struct uart_dev_s *dev, int ch);
 static void up_txint(struct uart_dev_s *dev, bool enable);
 static bool up_txready(struct uart_dev_s *dev);
@@ -162,7 +166,7 @@ static const struct uart_ops_s g_uart_ops =
   .rxint          = up_rxint,
   .rxavailable    = up_rxavailable,
 #ifdef CONFIG_SERIAL_IFLOWCONTROL
-  .rxflowcontrol  = NULL,
+  .rxflowcontrol  = up_rxflowcontrol,
 #endif
   .send           = up_send,
   .txint          = up_txint,
@@ -1015,6 +1019,47 @@ static bool up_rxavailable(struct uart_dev_s *dev)
   return ((up_serialin(priv, MPFS_UART_LSR_OFFSET) & UART_LSR_DR) != 0);
 }
 
+#ifdef CONFIG_SERIAL_IFLOWCONTROL
+/****************************************************************************
+ * Name: up_rxflowcontrol
+ *
+ * Description:
+ *   Basic flowcontrol functionality.
+ *   Disable RX interrupts and clear the fifo in case of full RX buffer.
+ *   Enable RX interrupts in case of empty buffer.
+ *   Return true if RX FIFO was cleared.
+ *
+ ****************************************************************************/
+
+static bool up_rxflowcontrol(struct uart_dev_s *dev,
+                             unsigned int nbuffered, bool upper)
+{
+  struct up_dev_s *priv = (struct up_dev_s *)dev->priv;
+  bool ret = false;
+
+  if (nbuffered == 0 || upper == false)
+    {
+      /* Empty buffer. Enable RX ints */
+
+      up_rxint(dev, true);
+
+      ret = false;
+    }
+  else
+    {
+      /* Full buffer. Disable RX ints and clear the RX FIFO */
+
+      up_rxint(dev, false);
+
+      up_serialout(priv, MPFS_UART_FCR_OFFSET, UART_FCR_RFIFOR);
+
+      ret = true;
+    }
+
+  return ret;
+}
+#endif
+
 /****************************************************************************
  * Name: up_send
  *