MODSERIAL with support for more devices

Fork of MODSERIAL by Erik -

Revision:
5:8365c4cf8f33
Parent:
4:28de979b77cf
Child:
6:c8f77fe1cc10
diff -r 28de979b77cf -r 8365c4cf8f33 PUTC.cpp
--- a/PUTC.cpp	Sun Nov 21 14:44:02 2010 +0000
+++ b/PUTC.cpp	Sun Nov 21 16:08:36 2010 +0000
@@ -34,7 +34,21 @@
     }
     else {
         if (buffer[TxIrq] != (char *)NULL) {
-            if (block) while ( MODSERIAL_TX_BUFFER_FULL ) ; // Blocks!
+            if (block) {
+                while ( MODSERIAL_TX_BUFFER_FULL ) {  // Blocks!
+                    // If putc() is called from an ISR then we are stuffed
+                    // because in an ISR no bytes from the TX buffer will 
+                    // get transferred to teh TX FIFOs while we block here.
+                    // So, to work around this, instead of sitting in a 
+                    // loop waiting for space in the TX buffer (which will
+                    // never happen in IRQ context), check to see if the
+                    // TX FIFO has space available to move bytes from the
+                    // TX buffer to TX FIFO to make space. The easiest way
+                    // to do this is to poll the isr_tx() function while we
+                    // are blocking.
+                    isr_tx();
+                }
+            }
             else if( MODSERIAL_TX_BUFFER_FULL ) {
                 buffer_overflow[TxIrq] = c; // Oh dear, no room in buffer.
                 _isr[TxOvIrq].call();