[PATCH rtems 1/2] bsps/atsam: Improve UART / USART tx performance

Christian Mauderer christian.mauderer at embedded-brains.de
Thu Aug 12 11:41:32 UTC 2021


Put the next character into the send buffer if the buffer is empty and
not when the last character has been sent out to the line. This improves
the performance slightly.

Before that patch, the receive path was faster than the transmit path.
Therefore a simple echo could drop characters on a busy connection.
With this patch sending and receiving has about the same performance so
that no characters are lost.
---
 bsps/arm/atsam/console/console.c | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/bsps/arm/atsam/console/console.c b/bsps/arm/atsam/console/console.c
index d51d2ace7d..5e3b36b812 100644
--- a/bsps/arm/atsam/console/console.c
+++ b/bsps/arm/atsam/console/console.c
@@ -72,8 +72,9 @@ static void atsam_usart_interrupt(void *arg)
     csr = regs->US_CSR;
   }
 
-  if (ctx->transmitting && (csr & US_CSR_TXEMPTY) != 0) {
+  while (ctx->transmitting && (csr & US_CSR_TXRDY) != 0) {
     rtems_termios_dequeue_characters(tty, 1);
+    csr = regs->US_CSR;
   }
 }
 #endif
@@ -203,16 +204,16 @@ static void atsam_usart_write(
   if (len > 0) {
     ctx->transmitting = true;
     regs->US_THR = buf[0];
-    regs->US_IER = US_IDR_TXEMPTY;
+    regs->US_IER = US_IDR_TXRDY;
   } else {
     ctx->transmitting = false;
-    regs->US_IDR = US_IDR_TXEMPTY;
+    regs->US_IDR = US_IDR_TXRDY;
   }
 #else
   size_t i;
 
   for (i = 0; i < len; ++i) {
-    while ((regs->US_CSR & US_CSR_TXEMPTY) == 0) {
+    while ((regs->US_CSR & US_CSR_TXRDY) == 0) {
       /* Wait */
     }
 
@@ -311,8 +312,9 @@ static void atsam_uart_interrupt(void *arg)
     sr = regs->UART_SR;
   }
 
-  if (ctx->transmitting && (sr & UART_SR_TXEMPTY) != 0) {
+  while (ctx->transmitting && (sr & UART_SR_TXRDY) != 0) {
     rtems_termios_dequeue_characters(tty, 1);
+    sr = regs->UART_SR;
   }
 }
 #endif
@@ -429,16 +431,16 @@ static void atsam_uart_write(
   if (len > 0) {
     ctx->transmitting = true;
     regs->UART_THR = buf[0];
-    regs->UART_IER = UART_IDR_TXEMPTY;
+    regs->UART_IER = UART_IDR_TXRDY;
   } else {
     ctx->transmitting = false;
-    regs->UART_IDR = UART_IDR_TXEMPTY;
+    regs->UART_IDR = UART_IDR_TXRDY;
   }
 #else
   size_t i;
 
   for (i = 0; i < len; ++i) {
-    while ((regs->UART_SR & UART_SR_TXEMPTY) == 0) {
+    while ((regs->UART_SR & UART_SR_TXRDY) == 0) {
       /* Wait */
     }
 
-- 
2.31.1



More information about the devel mailing list