Andriy Makukha / Mbed 2 deprecated football_project_wo_output

Dependencies:   mbed

Fork of football_project by MZJ

Revision:
10:72ceef287b0f
Parent:
5:1b9734e68327
Child:
11:d3aa5fca2330
--- a/io/MTSSerial.cpp	Sun Apr 19 19:59:46 2015 +0000
+++ b/io/MTSSerial.cpp	Tue Apr 21 07:00:55 2015 +0000
@@ -25,7 +25,9 @@
     : MTSBufferedIO(txBufferSize, rxBufferSize)
     , serial( TXD, RXD, NULL, RTS, CTS )
 {
-    serial.attach(this, &MTSSerial::handleRead, Serial::RxIrq);
+    enableRxIrq();
+//  serial.attach(this, &MTSSerial::handleRead, Serial::RxIrq);
+    enableTxIrq();
     //serial.attach(this, &MTSSerial::handleWrite, Serial::TxIrq);
 }
 
@@ -44,6 +46,8 @@
     serial.format(bits, parity, stop_bits);
 }
 
+extern DigitalOut _led1;  //  ALS
+
 void MTSSerial::handleRead()
 {
     char byte = serial.getc();
@@ -51,12 +55,13 @@
     //  printf("[ERROR] Serial Rx Byte Dropped [%c][0x%02X]\r\n", byte, byte);
         printf( "\r\n!  " );
     }
+    _led1 = !_led1;  // Toggle LED on char in.  ALS
 }
 
-// Currently uses Non-Irq based blocking write calls
+// Currently uses Non-Irq based blocking write calls   -- Now uses TXDRDY IRQ  ALS  20150419
 void MTSSerial::handleWrite()
 {
-    while(txBuffer.size() != 0) {
+    /* while */ if(txBuffer.size() != 0) {
         if (serial.writeable()) {
             char byte;
             if(txBuffer.read(byte) == 1) {
@@ -67,7 +72,30 @@
         } else {
             return;
         }
-    }
+    } else if( serial.writeable() )  disableTxIrq();  // Prevent needless IRQs, but keep TXDRDY set.  ALS
+}
+
+// TXDRDY IRQ enable/disable   ALS  20150419
+void MTSSerial::disableTxIrq()
+{
+    serial.attach( NULL, Serial::TxIrq );
 }
 
+void MTSSerial::enableTxIrq()
+{
+    serial.attach( this, &MTSSerial::handleWrite, Serial::TxIrq );
 
+    handleWrite();  // Start the ball rolling if necessary.
+}
+
+// RXDRDY IRQ enable/disable   ALS  20150420
+void MTSSerial::disableRxIrq()
+{
+    serial.attach( NULL, Serial::RxIrq );
+}
+
+void MTSSerial::enableRxIrq()
+{
+    serial.attach( this, &MTSSerial::handleRead, Serial::RxIrq );
+}
+