[PATCH 9/9] libchip: Use Termios API change for NS16550

Sebastian Huber sebastian.huber at embedded-brains.de
Mon Jun 10 13:11:57 UTC 2013


This avoids a race condition on SMP configurations.
---
 c/src/libchip/serial/ns16550.c |   22 +++++++++-------------
 1 files changed, 9 insertions(+), 13 deletions(-)

diff --git a/c/src/libchip/serial/ns16550.c b/c/src/libchip/serial/ns16550.c
index 5ef0f97..bf5b1b1 100644
--- a/c/src/libchip/serial/ns16550.c
+++ b/c/src/libchip/serial/ns16550.c
@@ -550,19 +550,12 @@ NS16550_STATIC void ns16550_process( int minor)
     /* Check if we can dequeue transmitted characters */
     if (ctx->transmitFifoChars > 0
         && (get( port, NS16550_LINE_STATUS) & SP_LSR_THOLD) != 0) {
-      unsigned chars = ctx->transmitFifoChars;
-
-      /*
-       * We finished the transmission, so clear the number of characters in the
-       * transmit FIFO.
-       */
-      ctx->transmitFifoChars = 0;
 
       /* Dequeue transmitted characters */
-      if (rtems_termios_dequeue_characters( d->termios_data, chars) == 0) {
-        /* Nothing to do */
-        ns16550_enable_interrupts( c, NS16550_ENABLE_ALL_INTR_EXCEPT_TX);
-      }
+      rtems_termios_dequeue_characters(
+        d->termios_data,
+        ctx->transmitFifoChars
+      );
     }
   } while ((get( port, NS16550_INTERRUPT_ID) & SP_IID_0) == 0);
 }
@@ -595,9 +588,12 @@ ssize_t ns16550_write_support_int(
     set( port, NS16550_TRANSMIT_BUFFER, buf [i]);
   }
 
-  if (len > 0) {
-    ctx->transmitFifoChars = out;
+  ctx->transmitFifoChars = out;
+
+  if (out > 0) {
     ns16550_enable_interrupts( c, NS16550_ENABLE_ALL_INTR);
+  } else {
+    ns16550_enable_interrupts( c, NS16550_ENABLE_ALL_INTR_EXCEPT_TX);
   }
 
   return 0;
-- 
1.7.7




More information about the devel mailing list