[PATCH 12/30] leon, apbuart: Optimized RX processing in ISR

Daniel Hellstrom daniel at gaisler.com
Thu Apr 13 19:31:21 UTC 2017


From: Martin Aberg <maberg at gaisler.com>

Limit the number of calls to termios rtems_termios_enqueue_raw_characters() by
reading out the RX FIFO on stack and then call termios only once.
---
 c/src/lib/libbsp/sparc/shared/uart/apbuart_cons.c | 25 +++++++++++++++--------
 1 file changed, 17 insertions(+), 8 deletions(-)

diff --git a/c/src/lib/libbsp/sparc/shared/uart/apbuart_cons.c b/c/src/lib/libbsp/sparc/shared/uart/apbuart_cons.c
index 28066a3..fc1c454 100644
--- a/c/src/lib/libbsp/sparc/shared/uart/apbuart_cons.c
+++ b/c/src/lib/libbsp/sparc/shared/uart/apbuart_cons.c
@@ -806,7 +806,7 @@ static void apbuart_cons_isr(void *arg)
 	struct apbuart_priv *uart = condev_get_priv(condev);
 	struct apbuart_regs *regs = uart->regs;
 	unsigned int status;
-	char data;
+	char buf[33];
 	int cnt;
 
 	if (uart->mode == TERMIOS_TASK_DRIVEN) {
@@ -824,13 +824,22 @@ static void apbuart_cons_isr(void *arg)
 			rtems_termios_rxirq_occured(tty);
 		}
 	} else {
-		/* Get all received characters */
-		while ((status=regs->status) & APBUART_STATUS_DR) {
-			/* Data has arrived, get new data */
-			data = regs->data;
-
-			/* Tell termios layer about new character */
-			rtems_termios_enqueue_raw_characters(tty, &data, 1);
+		/*
+		 * Get all new characters from APBUART RX (FIFO) and store them
+		 * on the stack. Then tell termios about the new characters.
+		 * Maximum APBUART RX FIFO size is 32 characters.
+		 */
+		cnt = 0;
+		while (
+			((status=regs->status) & APBUART_STATUS_DR) &&
+			(cnt < sizeof(buf))
+		) {
+			buf[cnt] = regs->data;
+			cnt++;
+		}
+		if (0 < cnt) {
+			/* Tell termios layer about new characters */
+			rtems_termios_enqueue_raw_characters(tty, &buf[0], cnt);
 		}
 	}
 
-- 
2.7.4




More information about the devel mailing list