Skip to content

Commit 21f9fc2

Browse files
jpaaliacassis
authored andcommitted
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.
1 parent 0d46c68 commit 21f9fc2

File tree

1 file changed

+46
-1
lines changed

1 file changed

+46
-1
lines changed

arch/risc-v/src/mpfs/mpfs_serial.c

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,10 @@ static int up_ioctl(struct file *filep, int cmd, unsigned long arg);
142142
static int up_receive(struct uart_dev_s *dev, unsigned int *status);
143143
static void up_rxint(struct uart_dev_s *dev, bool enable);
144144
static bool up_rxavailable(struct uart_dev_s *dev);
145+
#ifdef CONFIG_SERIAL_IFLOWCONTROL
146+
static bool up_rxflowcontrol(struct uart_dev_s *dev,
147+
unsigned int nbuffered, bool upper);
148+
#endif
145149
static void up_send(struct uart_dev_s *dev, int ch);
146150
static void up_txint(struct uart_dev_s *dev, bool enable);
147151
static bool up_txready(struct uart_dev_s *dev);
@@ -162,7 +166,7 @@ static const struct uart_ops_s g_uart_ops =
162166
.rxint = up_rxint,
163167
.rxavailable = up_rxavailable,
164168
#ifdef CONFIG_SERIAL_IFLOWCONTROL
165-
.rxflowcontrol = NULL,
169+
.rxflowcontrol = up_rxflowcontrol,
166170
#endif
167171
.send = up_send,
168172
.txint = up_txint,
@@ -1015,6 +1019,47 @@ static bool up_rxavailable(struct uart_dev_s *dev)
10151019
return ((up_serialin(priv, MPFS_UART_LSR_OFFSET) & UART_LSR_DR) != 0);
10161020
}
10171021

1022+
#ifdef CONFIG_SERIAL_IFLOWCONTROL
1023+
/****************************************************************************
1024+
* Name: up_rxflowcontrol
1025+
*
1026+
* Description:
1027+
* Basic flowcontrol functionality.
1028+
* Disable RX interrupts and clear the fifo in case of full RX buffer.
1029+
* Enable RX interrupts in case of empty buffer.
1030+
* Return true if RX FIFO was cleared.
1031+
*
1032+
****************************************************************************/
1033+
1034+
static bool up_rxflowcontrol(struct uart_dev_s *dev,
1035+
unsigned int nbuffered, bool upper)
1036+
{
1037+
struct up_dev_s *priv = (struct up_dev_s *)dev->priv;
1038+
bool ret = false;
1039+
1040+
if (nbuffered == 0 || upper == false)
1041+
{
1042+
/* Empty buffer. Enable RX ints */
1043+
1044+
up_rxint(dev, true);
1045+
1046+
ret = false;
1047+
}
1048+
else
1049+
{
1050+
/* Full buffer. Disable RX ints and clear the RX FIFO */
1051+
1052+
up_rxint(dev, false);
1053+
1054+
up_serialout(priv, MPFS_UART_FCR_OFFSET, UART_FCR_RFIFOR);
1055+
1056+
ret = true;
1057+
}
1058+
1059+
return ret;
1060+
}
1061+
#endif
1062+
10181063
/****************************************************************************
10191064
* Name: up_send
10201065
*

0 commit comments

Comments
 (0)