MODSERIAL with support for more devices

Dependents:   1D-Pong BMT-K9_encoder BMT-K9-Regelaar programma_filter ... more

Check the cookbook page for more information: https://mbed.org/cookbook/MODSERIAL

Did you add a device? Please send a pull request so we can keep everything in one library instead of many copies. In that case also send a PM, since currently mbed does not inform of new pull requests. I will then also add you to the developers of this library so you can do other changes directly.

Files at this revision

API Documentation at this revision

Comitter:
AjK
Date:
Sun Nov 21 16:08:36 2010 +0000
Parent:
4:28de979b77cf
Child:
6:c8f77fe1cc10
Commit message:
1.5

Changed in this revision

ChangeLog.c Show annotated file Show diff for this revision Revisions of this file
PUTC.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/ChangeLog.c	Sun Nov 21 14:44:02 2010 +0000
+++ b/ChangeLog.c	Sun Nov 21 16:08:36 2010 +0000
@@ -1,5 +1,18 @@
 /* $Id:$
 
+1.5 - 21/11/2010
+
+    * Calling putc() (or any derived function that uses it like
+      printf()) while inside an interrupt service routine can
+      cause the system to lock up if the TX buffer is full. This
+      is because bytes are only transferred from the TX buffer to
+      the TX FIFO via the TX ISR. If we are, say in an RX ISR already,
+      then the TX ISR will never trigger. The TX buffer stays full and
+      there is never space to putc() the byte. So, while putc() blocks
+      waiting for space it calls isr_tx() to ensure if TX FIFO space
+      becomes available it will move bytes from the TX buffer to TX
+      FIFO thus removing the blocking condition within putc().
+
 1.4 - 21/11/2010
 
     * Removed all the new DMA code. I wish mbed.org had proper SVN
--- 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();