RTOS safe buffered serial driver

Fork of SerialDriver by BlazeX .

Revision:
3:ea9719695b6a
Parent:
0:cd0d79be0c1a
Child:
4:3c0d0c37ad75
--- a/SerialDriver.cpp	Thu Jan 15 09:53:09 2015 +0000
+++ b/SerialDriver.cpp	Mon Jan 26 19:21:56 2015 +0000
@@ -35,10 +35,13 @@
     rxIn= rxOut= 0;
     txCount= rxCount= 0;
     
+    // reset drop counters
+    numTxDrops= 0;
+    numRxDrops= 0;
+    
     // attach interrupt routines
     attach(this, &SerialDriver::onTxIrq, TxIrq);
     attach(this, &SerialDriver::onRxIrq, RxIrq);
-    
 }
 
 int SerialDriver::putc(int c, unsigned int timeoutMs)
@@ -58,6 +61,7 @@
         disableTxInterrupt();
         if(isTxBufferFull()) // still full? drop byte!
         {
+            numTxDrops++;
             enableTxInterrupt();
             return 0;
         }
@@ -152,7 +156,9 @@
             rxBuffer[rxIn]= (unsigned char)c;
             rxIn= (rxIn+1) % rxBufferLength;
             rxCount++;
-        }   // else drop byte :(
+        }
+        else    // drop byte :(
+            numRxDrops++;
     }
     
     if(wasEmpty && !isRxBufferEmpty())   // more bytes can go
@@ -212,4 +218,4 @@
     return length;
 } 
 
-// for XTN
+// still thinking of XTN