UART1 buffered serial driver, requires RTOS

Dependents:   Serial_interrupts_buffered HARP2 HARP3

Buffered serial UART1 - Setup to work with UART1 (p13,p14)

Uses RTOS to block current thread.

Reference: http://mbed.org/users/tylerjw/notebook/buffered-serial-with-rtos/

Revision:
1:eabb26ce183b
Parent:
0:707b9f3904dd
Child:
2:8ccf9bb8dc65
--- a/buffered_serial.cpp	Mon Dec 10 23:42:38 2012 +0000
+++ b/buffered_serial.cpp	Tue Dec 11 00:08:24 2012 +0000
@@ -56,8 +56,9 @@
     i = 0;
     // Start Critical Section - don't interrupt while changing global buffer variables
     NVIC_DisableIRQ(device_irqn);
+    memset(rx_line,LINE_SIZE,0);
     // Loop reading rx buffer characters until end of line character
-    while ((i==0) || (rx_line[i-1] != '\r')) {
+    while ((i==0) || (rx_line[i-1] != '\n')) {
         // Wait if buffer empty
         if (IS_RX_EMPTY) { // buffer empty
             // End Critical Section - need to allow rx interrupt to get new characters for buffer
@@ -72,12 +73,18 @@
         rx_line[i] = rx_buffer[rx_out];
         i++;
         rx_out = NEXT(rx_out);
-
+        
+        // prevent overflow on rx_line
+        /*if(i >= (LINE_SIZE - 1)) // not working!!!
+        {
+            i--;
+            break;
+        }*/
     }
-    rx_line[i-1] = 0;
+    rx_line[i++] = 0;
     // End Critical Section
     NVIC_EnableIRQ(device_irqn);
-    strncpy(c,rx_line,LINE_SIZE);
+    strncpy(c,rx_line,i);
 }
 
 // Interupt Routine to read in data from serial port