[PATCH v2 3/3] bsps/microblaze: Fix UART transmit interrupt

Alex White alex.white at oarcorp.com
Tue Apr 4 13:33:50 UTC 2023


From: "Maldonado, Sergio E. (GSFC-580.0)" <sergio.e.maldonado at nasa.gov>

---
 bsps/microblaze/include/dev/serial/uartlite.h |  2 ++
 bsps/microblaze/shared/dev/serial/uartlite.c  | 22 ++++++++++++++-----
 2 files changed, 19 insertions(+), 5 deletions(-)

diff --git a/bsps/microblaze/include/dev/serial/uartlite.h b/bsps/microblaze/include/dev/serial/uartlite.h
index 009f416508..f58ae92ef8 100644
--- a/bsps/microblaze/include/dev/serial/uartlite.h
+++ b/bsps/microblaze/include/dev/serial/uartlite.h
@@ -51,7 +51,9 @@ typedef struct {
   uint32_t initial_baud;
   uint32_t enabled;
 #ifdef BSP_MICROBLAZE_FPGA_CONSOLE_INTERRUPTS
+  struct rtems_termios_tty *tty;
   bool transmitting;
+  size_t tx_queued;
   uint32_t irq;
 #endif
 } uart_lite_context;
diff --git a/bsps/microblaze/shared/dev/serial/uartlite.c b/bsps/microblaze/shared/dev/serial/uartlite.c
index e2007ee24a..611c339371 100644
--- a/bsps/microblaze/shared/dev/serial/uartlite.c
+++ b/bsps/microblaze/shared/dev/serial/uartlite.c
@@ -48,8 +48,11 @@ static void microblaze_uart_interrupt( void *arg )
     rtems_termios_enqueue_raw_characters( tty, &c, 1 );
   }
 
-  while ( ctx->transmitting && !XUartLite_IsTransmitEmpty( ctx->address ) ) {
-    rtems_termios_dequeue_characters( tty, 1 );
+  if ( ctx->transmitting && XUartLite_IsTransmitEmpty( ctx->address ) ) {
+    size_t sent = ctx->tx_queued;
+    ctx->transmitting = false;
+    ctx->tx_queued = 0;
+    rtems_termios_dequeue_characters( tty, sent );
   }
 }
 #endif
@@ -81,6 +84,8 @@ static bool uart_first_open(
   if ( sc != RTEMS_SUCCESSFUL ) {
     return false;
   }
+
+  ctx->tty = tty;
 #endif
 
   return true;
@@ -120,10 +125,17 @@ static void uart_write(
 
 #ifdef BSP_MICROBLAZE_FPGA_CONSOLE_INTERRUPTS
   if ( n > 0 ) {
+    size_t remaining = n;
+    const char *p = &s[0];
+
+    while (!XUartLite_IsTransmitFull( ctx->address ) && remaining > 0) {
+      XUartLite_SendByte( ctx->address, *p );
+      p++;
+      remaining--;
+    }
+
     ctx->transmitting = true;
-    XUartLite_SendByte( ctx->address, s[0] );
-  } else {
-    ctx->transmitting = false;
+    ctx->tx_queued = n - remaining;
   }
 #else
   size_t i = 0;
-- 
2.34.1



More information about the devel mailing list