Tyler Weaver / Mbed 2 deprecated Serial_interrupts_buffered

Dependencies:   buffered-serial1 mbed-rtos mbed

Fork of Serial_interrupts by jim hamblen

Revision:
7:180678808740
Parent:
6:ddab1e541812
--- a/buffered_serial.cpp	Mon Dec 10 23:07:39 2012 +0000
+++ b/buffered_serial.cpp	Mon Dec 10 23:27:28 2012 +0000
@@ -43,8 +43,8 @@
         if (IS_TX_FULL) {
             // End Critical Section - need to let interrupt routine empty buffer by sending
             NVIC_EnableIRQ(device_irqn);
-            while (IS_TX_FULL) ; // buffer is full
-
+            //while (IS_TX_FULL) ; // buffer is full
+            tx_sem.wait();
             // Start Critical Section - don't interrupt while changing global buffer variables
             NVIC_DisableIRQ(device_irqn);
         }
@@ -72,22 +72,20 @@
     // Loop reading rx buffer characters until end of line character
     while ((i==0) || (rx_line[i-1] != '\r')) {
         // Wait if buffer empty
-        if (rx_in == rx_out) { // buffer empty
+        if (IS_RX_EMPTY) { // buffer empty
             // End Critical Section - need to allow rx interrupt to get new characters for buffer
             NVIC_EnableIRQ(device_irqn);
             //while (rx_in == rx_out) ; // buffer empty
             rx_sem.wait();
             // Start Critical Section - don't interrupt while changing global buffer variables
             NVIC_DisableIRQ(device_irqn);
-            rx_line[i] = rx_buffer[rx_out];
-            i++;
-            rx_out = NEXT(rx_out);
         } else {
             rx_sem.wait();
-            rx_line[i] = rx_buffer[rx_out];
-            i++;
-            rx_out = NEXT(rx_out);
         }
+        rx_line[i] = rx_buffer[rx_out];
+        i++;
+        rx_out = NEXT(rx_out);
+
     }
     rx_line[i-1] = 0;
     // End Critical Section
@@ -117,5 +115,7 @@
         LPC_UART1->THR = tx_buffer[tx_out]; // send the character
         tx_out = NEXT(tx_out);
     }
+    if(!IS_TX_FULL) // if not full
+        tx_sem.release();
     led2=0;
 }
\ No newline at end of file