Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of football_project by
Diff: io/MTSSerial.cpp
- 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 );
+}
+
