A talking braille-input text message device!!

Dependencies:   Braille_In PinDetect mbed

Files at this revision

API Documentation at this revision

Comitter:
aganger3
Date:
Fri Oct 12 18:02:43 2012 +0000
Child:
1:4e1b66d0799f
Commit message:
It works :);

Changed in this revision

Braille_In.lib Show annotated file Show diff for this revision Revisions of this file
MODSERIAL/FLUSH.cpp Show annotated file Show diff for this revision Revisions of this file
MODSERIAL/GETC.cpp Show annotated file Show diff for this revision Revisions of this file
MODSERIAL/INIT.cpp Show annotated file Show diff for this revision Revisions of this file
MODSERIAL/ISR_RX.cpp Show annotated file Show diff for this revision Revisions of this file
MODSERIAL/ISR_TX.cpp Show annotated file Show diff for this revision Revisions of this file
MODSERIAL/MACROS.h Show annotated file Show diff for this revision Revisions of this file
MODSERIAL/MODSERIAL.cpp Show annotated file Show diff for this revision Revisions of this file
MODSERIAL/MODSERIAL.h Show annotated file Show diff for this revision Revisions of this file
MODSERIAL/MODSERIAL_IRQ_INFO.cpp Show annotated file Show diff for this revision Revisions of this file
MODSERIAL/PUTC.cpp Show annotated file Show diff for this revision Revisions of this file
MODSERIAL/RESIZE.cpp Show annotated file Show diff for this revision Revisions of this file
PinDetect.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Braille_In.lib	Fri Oct 12 18:02:43 2012 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/aganger3/code/Braille_In/#cc189ce99a98
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MODSERIAL/FLUSH.cpp	Fri Oct 12 18:02:43 2012 +0000
@@ -0,0 +1,47 @@
+/*
+    Copyright (c) 2010 Andy Kirkham
+ 
+    Permission is hereby granted, free of charge, to any person obtaining a copy
+    of this software and associated documentation files (the "Software"), to deal
+    in the Software without restriction, including without limitation the rights
+    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+    copies of the Software, and to permit persons to whom the Software is
+    furnished to do so, subject to the following conditions:
+ 
+    The above copyright notice and this permission notice shall be included in
+    all copies or substantial portions of the Software.
+ 
+    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+    THE SOFTWARE.
+*/
+
+#include "MODSERIAL.h"
+#include "MACROS.h"
+
+namespace AjK {
+
+void
+MODSERIAL::flushBuffer(IrqType type)
+{
+    uint32_t ier = _IER;
+    switch(type) {
+        case TxIrq: _IER &= ~(1UL << 1); break;
+        case RxIrq: _IER &= ~(1UL << 0); break;
+    }
+    buffer_in[type]       = 0;
+    buffer_out[type]      = 0;
+    buffer_count[type]    = 0;
+    buffer_overflow[type] = 0;  
+    switch(type) {
+        case TxIrq: _FCR = MODSERIAL_FIFO_TX_RESET; break;
+        case RxIrq: _FCR = MODSERIAL_FIFO_RX_RESET; break;
+    }
+    _IER = ier;
+}
+
+}; // namespace AjK ends
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MODSERIAL/GETC.cpp	Fri Oct 12 18:02:43 2012 +0000
@@ -0,0 +1,63 @@
+/*
+    Copyright (c) 2010 Andy Kirkham
+ 
+    Permission is hereby granted, free of charge, to any person obtaining a copy
+    of this software and associated documentation files (the "Software"), to deal
+    in the Software without restriction, including without limitation the rights
+    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+    copies of the Software, and to permit persons to whom the Software is
+    furnished to do so, subject to the following conditions:
+ 
+    The above copyright notice and this permission notice shall be included in
+    all copies or substantial portions of the Software.
+ 
+    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+    THE SOFTWARE.
+*/
+
+#include "MODSERIAL.h"
+#include "MACROS.h"
+
+namespace AjK {
+
+int 
+MODSERIAL::__getc(bool block)
+{
+    // If no buffer is in use fall back to standard RX FIFO usage.
+    // Note, we must block in this case and ignore bool "block" 
+    // so as to maintain compat with Mbed Serial.
+    if (buffer_size[RxIrq] == 0 || buffer[RxIrq] == (char *)NULL) {
+        while(! MODSERIAL_RBR_HAS_DATA ) ;
+        return (int)(_RBR & 0xFF);
+    }
+
+    if (block) { while ( MODSERIAL_RX_BUFFER_EMPTY ) ; } // Blocks.
+    else if ( MODSERIAL_RX_BUFFER_EMPTY ) return -1;
+    
+    int c = buffer[RxIrq][buffer_out[RxIrq]];
+    buffer_out[RxIrq]++;
+    if (buffer_out[RxIrq] >= buffer_size[RxIrq]) {
+        buffer_out[RxIrq] = 0;
+    }
+    
+    // If we have made space in the RX Buffer then copy over
+    // any characters in the RX FIFO that my reside there.
+    // Temporarily disable the RX IRQ so that we do not re-enter 
+    // it under interrupts.
+    if ( ! MODSERIAL_RX_BUFFER_FULL ) {
+        uint32_t ier = _IER;
+        _IER &= ~(1UL << 0);
+        isr_rx();    
+        _IER = ier;
+    }
+    
+    buffer_count[RxIrq]--;   
+    return c;
+}
+
+}; // namespace AjK ends
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MODSERIAL/INIT.cpp	Fri Oct 12 18:02:43 2012 +0000
@@ -0,0 +1,74 @@
+/*
+    Copyright (c) 2010 Andy Kirkham
+ 
+    Permission is hereby granted, free of charge, to any person obtaining a copy
+    of this software and associated documentation files (the "Software"), to deal
+    in the Software without restriction, including without limitation the rights
+    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+    copies of the Software, and to permit persons to whom the Software is
+    furnished to do so, subject to the following conditions:
+ 
+    The above copyright notice and this permission notice shall be included in
+    all copies or substantial portions of the Software.
+ 
+    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+    THE SOFTWARE.
+*/
+
+#include "MODSERIAL.h"
+#include "MACROS.h"
+
+namespace AjK {
+
+void
+MODSERIAL::init(int txSize, int rxSize)
+{
+    disableIrq();
+    
+    callbackInfo.setSerial(this);
+    
+    switch(_uidx) {
+        case 0:   _base = LPC_UART0; break;
+        case 1:   _base = LPC_UART1; break;
+        case 2:   _base = LPC_UART2; break;
+        case 3:   _base = LPC_UART3; break;
+        default : _base = NULL;      break;
+    }
+    
+    dmaSendChannel  = -1;
+    moddma_p        = (void *)NULL;
+    
+    if (_base != NULL) {
+        buffer_size[RxIrq]     = rxSize;
+        buffer[RxIrq]          = rxSize > 0 ? (char *)malloc(buffer_size[RxIrq]) : (char *)NULL;
+        buffer_in[RxIrq]       = 0;
+        buffer_out[RxIrq]      = 0;
+        buffer_count[RxIrq]    = 0;
+        buffer_overflow[RxIrq] = 0;
+        Serial::attach(this, &MODSERIAL::isr_rx, Serial::RxIrq);        
+        
+        buffer_size[TxIrq]     = txSize;
+        buffer[TxIrq]          = txSize > 0 ? (char *)malloc(buffer_size[TxIrq]) : (char *)NULL;
+        buffer_in[TxIrq]       = 0;
+        buffer_out[TxIrq]      = 0;
+        buffer_count[TxIrq]    = 0;
+        buffer_overflow[TxIrq] = 0;
+        Serial::attach(this, &MODSERIAL::isr_tx, Serial::TxIrq);
+    }
+    else {
+        error("MODSERIAL must have a defined UART to function.");
+    }
+    
+    _FCR = MODSERIAL_FIFO_ENABLE | MODSERIAL_FIFO_RX_RESET | MODSERIAL_FIFO_TX_RESET;
+    
+    auto_detect_char = 0;
+    
+    enableIrq();
+}
+
+}; // namespace AjK ends
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MODSERIAL/ISR_RX.cpp	Fri Oct 12 18:02:43 2012 +0000
@@ -0,0 +1,60 @@
+/*
+    Copyright (c) 2010 Andy Kirkham
+ 
+    Permission is hereby granted, free of charge, to any person obtaining a copy
+    of this software and associated documentation files (the "Software"), to deal
+    in the Software without restriction, including without limitation the rights
+    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+    copies of the Software, and to permit persons to whom the Software is
+    furnished to do so, subject to the following conditions:
+ 
+    The above copyright notice and this permission notice shall be included in
+    all copies or substantial portions of the Software.
+ 
+    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+    THE SOFTWARE.
+*/
+
+#include "MODSERIAL.h"
+#include "MACROS.h"
+
+namespace AjK {
+        
+void 
+MODSERIAL::isr_rx(void)
+{
+    if (! _base || buffer_size[RxIrq] == 0 || buffer[RxIrq] == (char *)NULL) {
+        _isr[RxIrq].call(&this->callbackInfo); 
+        return;
+    } 
+    
+    while( MODSERIAL_RBR_HAS_DATA ) {
+        rxc = (char)(_RBR & 0xFF); 
+        if ( MODSERIAL_RX_BUFFER_FULL ) {
+            buffer_overflow[RxIrq] = rxc; // Oh dear, no room in buffer.
+            _isr[RxOvIrq].call(&this->callbackInfo);
+        }
+        else {
+            if (buffer[RxIrq] != (char *)NULL) {
+                buffer[RxIrq][buffer_in[RxIrq]] = rxc;
+                buffer_count[RxIrq]++; 
+                buffer_in[RxIrq]++;
+                if (buffer_in[RxIrq] >= buffer_size[RxIrq]) {
+                    buffer_in[RxIrq] = 0;
+                }
+            }  
+            _isr[RxIrq].call(&this->callbackInfo); 
+        }
+        if (auto_detect_char == rxc) {
+            _isr[RxAutoDetect].call(&this->callbackInfo);
+        }
+    }    
+}
+
+}; // namespace AjK ends
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MODSERIAL/ISR_TX.cpp	Fri Oct 12 18:02:43 2012 +0000
@@ -0,0 +1,54 @@
+/*
+    Copyright (c) 2010 Andy Kirkham
+ 
+    Permission is hereby granted, free of charge, to any person obtaining a copy
+    of this software and associated documentation files (the "Software"), to deal
+    in the Software without restriction, including without limitation the rights
+    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+    copies of the Software, and to permit persons to whom the Software is
+    furnished to do so, subject to the following conditions:
+ 
+    The above copyright notice and this permission notice shall be included in
+    all copies or substantial portions of the Software.
+ 
+    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+    THE SOFTWARE.
+*/
+
+#include "MODSERIAL.h"
+#include "MACROS.h"
+
+namespace AjK {
+
+void 
+MODSERIAL::isr_tx(bool doCallback)
+{
+    if (! _base || buffer_size[TxIrq] == 0 || buffer[TxIrq] == (char *)NULL) {
+        _isr[TxIrq].call(&this->callbackInfo); 
+        return;
+    }
+    
+    while (! MODSERIAL_TX_BUFFER_EMPTY && MODSERIAL_THR_HAS_SPACE ) {
+        _THR = txc = (uint8_t)(buffer[TxIrq][buffer_out[TxIrq]]);
+        buffer_count[TxIrq]--;   
+        buffer_out[TxIrq]++;
+        if (buffer_out[TxIrq] >= buffer_size[TxIrq]) {
+            buffer_out[TxIrq] = 0;
+        }
+        if (doCallback) _isr[TxIrq].call(&this->callbackInfo);
+    }
+        
+    if ( MODSERIAL_TX_BUFFER_EMPTY ) { 
+        _IER = 1;
+        _isr[TxEmpty].call(&this->callbackInfo);
+    }        
+}
+
+}; // namespace AjK ends
+
+        
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MODSERIAL/MACROS.h	Fri Oct 12 18:02:43 2012 +0000
@@ -0,0 +1,70 @@
+/*
+    Copyright (c) 2010 Andy Kirkham
+ 
+    Permission is hereby granted, free of charge, to any person obtaining a copy
+    of this software and associated documentation files (the "Software"), to deal
+    in the Software without restriction, including without limitation the rights
+    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+    copies of the Software, and to permit persons to whom the Software is
+    furnished to do so, subject to the following conditions:
+ 
+    The above copyright notice and this permission notice shall be included in
+    all copies or substantial portions of the Software.
+ 
+    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+    THE SOFTWARE.
+*/
+
+#ifndef MODSERIAL_MACROS_H
+#define MODSERIAL_MACROS_H
+
+#define MODSERIAL_RBR  0x00
+#define MODSERIAL_THR  0x00
+#define MODSERIAL_DLL  0x00
+#define MODSERIAL_IER  0x04
+#define MODSERIAL_DML  0x04
+#define MODSERIAL_IIR  0x08
+#define MODSERIAL_FCR  0x08
+#define MODSERIAL_LCR  0x0C
+#define MODSERIAL_LSR  0x14
+#define MODSERIAL_SCR  0x1C
+#define MODSERIAL_ACR  0x20
+#define MODSERIAL_ICR  0x24
+#define MODSERIAL_FDR  0x28
+#define MODSERIAL_TER  0x30
+
+#define MODSERIAL_LSR_RDR  (1UL << 0)
+#define MODSERIAL_LSR_OE   (1UL << 1)
+#define MODSERIAL_LSR_PE   (1UL << 2)
+#define MODSERIAL_LSR_FE   (1UL << 3)
+#define MODSERIAL_LSR_BR   (1UL << 4)
+#define MODSERIAL_LSR_THRE (1UL << 5)
+#define MODSERIAL_LSR_TEMT (1UL << 6)
+#define MODSERIAL_LSR_RXFE (1UL << 7)
+
+#define MODSERIAL_FIFO_ENABLE   1
+#define MODSERIAL_FIFO_RX_RESET 2
+#define MODSERIAL_FIFO_TX_RESET 4
+
+#define _RBR    *((char *)_base+MODSERIAL_RBR)
+#define _THR    *((char *)_base+MODSERIAL_THR)
+#define _IIR    *((char *)_base+MODSERIAL_IIR)
+#define _IER    *((char *)_base+MODSERIAL_IER)
+#define _LSR    *((char *)_base+MODSERIAL_LSR)
+#define _FCR    *((char *)_base+MODSERIAL_FCR)
+
+#define MODSERIAL_TX_BUFFER_EMPTY (buffer_count[TxIrq]==0)
+#define MODSERIAL_RX_BUFFER_EMPTY (buffer_count[RxIrq]==0)
+#define MODSERIAL_TX_BUFFER_FULL  (buffer_count[TxIrq]==buffer_size[TxIrq])
+#define MODSERIAL_RX_BUFFER_FULL  (buffer_count[RxIrq]==buffer_size[RxIrq])
+
+#define MODSERIAL_THR_HAS_SPACE ((int)_LSR&MODSERIAL_LSR_THRE)
+#define MODSERIAL_TEMT_IS_EMPTY ((int)_LSR&MODSERIAL_LSR_TEMT)
+#define MODSERIAL_RBR_HAS_DATA  ((int)_LSR&MODSERIAL_LSR_RDR)
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MODSERIAL/MODSERIAL.cpp	Fri Oct 12 18:02:43 2012 +0000
@@ -0,0 +1,128 @@
+/*
+    Copyright (c) 2010 Andy Kirkham
+ 
+    Permission is hereby granted, free of charge, to any person obtaining a copy
+    of this software and associated documentation files (the "Software"), to deal
+    in the Software without restriction, including without limitation the rights
+    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+    copies of the Software, and to permit persons to whom the Software is
+    furnished to do so, subject to the following conditions:
+ 
+    The above copyright notice and this permission notice shall be included in
+    all copies or substantial portions of the Software.
+ 
+    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+    THE SOFTWARE.
+    
+    @file          MODSERIAL.h 
+    @purpose       Extends Serial to provide fully buffered IO
+    @version       1.6
+    @date          Nov 2010
+    @author        Andy Kirkham    
+*/
+
+#include "MODSERIAL.h"
+#include "MACROS.h"
+
+namespace AjK {
+
+MODSERIAL::MODSERIAL(PinName tx, PinName rx, const char *name) : Serial(tx, rx, name)
+{
+    init(MODSERIAL_DEFAULT_TX_BUFFER_SIZE, MODSERIAL_DEFAULT_RX_BUFFER_SIZE);
+}
+
+MODSERIAL::MODSERIAL(PinName tx, PinName rx, int bufferSize, const char *name) : Serial(tx, rx, name)
+{
+    init(bufferSize, bufferSize);
+}
+
+MODSERIAL::MODSERIAL(PinName tx, PinName rx, int txSize, int rxSize, const char *name) : Serial(tx, rx, name)
+{
+    init(txSize, rxSize);
+}
+
+MODSERIAL::~MODSERIAL()
+{
+    disableIrq();
+    if (buffer[0] != NULL) free((char *)buffer[0]);
+    if (buffer[1] != NULL) free((char *)buffer[1]);    
+}
+
+bool 
+MODSERIAL::txBufferFull(void) 
+{ 
+    return MODSERIAL_TX_BUFFER_FULL; 
+}
+
+bool 
+MODSERIAL::rxBufferFull(void) 
+{ 
+    return MODSERIAL_RX_BUFFER_FULL; 
+}
+
+bool 
+MODSERIAL::txBufferEmpty(void) 
+{ 
+    return MODSERIAL_TX_BUFFER_EMPTY; 
+}
+
+bool 
+MODSERIAL::rxBufferEmpty(void) 
+{ 
+    return MODSERIAL_RX_BUFFER_EMPTY; 
+}
+
+bool 
+MODSERIAL::txIsBusy(void) 
+{ 
+    return (_LSR & (3UL << 5) == 0) ? true : false; 
+} 
+
+void
+MODSERIAL::disableIrq(void)
+{
+    switch(_uidx) {
+        case 0:   NVIC_DisableIRQ(UART0_IRQn); break;
+        case 1:   NVIC_DisableIRQ(UART1_IRQn); break;
+        case 2:   NVIC_DisableIRQ(UART2_IRQn); break;
+        case 3:   NVIC_DisableIRQ(UART3_IRQn); break;
+    }
+}
+
+void
+MODSERIAL::enableIrq(void)
+{
+    switch(_uidx) {
+        case 0:   NVIC_EnableIRQ(UART0_IRQn); break;
+        case 1:   NVIC_EnableIRQ(UART1_IRQn); break;
+        case 2:   NVIC_EnableIRQ(UART2_IRQn); break;
+        case 3:   NVIC_EnableIRQ(UART3_IRQn); break;
+    }
+}
+
+int 
+MODSERIAL::rxDiscardLastChar(void)
+{
+    // This function can only be called indirectly from
+    // an rxCallback function. Therefore, we know we 
+    // just placed a char into the buffer.
+    char c = buffer[RxIrq][buffer_in[RxIrq]];
+    
+    if (buffer_count[RxIrq]) {        
+        buffer_count[RxIrq]--;
+        buffer_in[RxIrq]--;
+        if (buffer_in[RxIrq] < 0) {
+            buffer_in[RxIrq] = buffer_size[RxIrq] - 1;
+        }
+    }
+    
+    return (int)c;
+}
+
+
+}; // namespace AjK ends
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MODSERIAL/MODSERIAL.h	Fri Oct 12 18:02:43 2012 +0000
@@ -0,0 +1,1091 @@
+/*
+    Copyright (c) 2010 Andy Kirkham
+ 
+    Permission is hereby granted, free of charge, to any person obtaining a copy
+    of this software and associated documentation files (the "Software"), to deal
+    in the Software without restriction, including without limitation the rights
+    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+    copies of the Software, and to permit persons to whom the Software is
+    furnished to do so, subject to the following conditions:
+ 
+    The above copyright notice and this permission notice shall be included in
+    all copies or substantial portions of the Software.
+ 
+    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+    THE SOFTWARE.
+    
+    @file          MODSERIAL.h 
+    @purpose       Extends Serial to provide fully buffered IO
+    @version       see ChangeLog.c
+    @date          Nov 2010
+    @author        Andy Kirkham
+*/
+
+#ifndef MODSERIAL_H
+#define MODSERIAL_H
+
+/** @defgroup API The MODSERIAL API */
+/** @defgroup MISC Misc MODSERIAL functions */
+/** @defgroup INTERNALS MODSERIAL Internals */
+
+#ifndef MODSERIAL_DEFAULT_RX_BUFFER_SIZE
+#define MODSERIAL_DEFAULT_RX_BUFFER_SIZE    256
+#endif
+
+#ifndef MODSERIAL_DEFAULT_TX_BUFFER_SIZE
+#define MODSERIAL_DEFAULT_TX_BUFFER_SIZE    256
+#endif
+
+#include "mbed.h"
+
+namespace AjK {
+
+// Forward reference.
+class MODSERIAL;
+
+/**
+ * @author Andy Kirkham
+ * @see http://mbed.org/cookbook/MODSERIAL
+ * @see example3a.cpp
+ * @see example3b.cpp
+ * @see API 
+ *
+ * <b>MODSERIAL_IRQ_INFO</b> is a class used to pass information (and access to protected
+ * MODSERIAL functions) to IRQ callbacks. 
+ */
+class MODSERIAL_IRQ_INFO
+{
+public:
+    friend class MODSERIAL;
+    
+    MODSERIAL *serial;
+    
+    MODSERIAL_IRQ_INFO() { serial = 0; }
+    
+    /** rxDiscardLastChar()
+     *
+     * Remove the last char placed into the rx buffer.
+     * This is an operation that can only be performed
+     * by an rxCallback function. 
+     * @ingroup API
+     * @return The byte removed from the buffer.
+     */
+    int rxDiscardLastChar(void);
+
+protected:
+
+    /** setSerial()
+     *
+     * Used internally by MODSERIAL to set the "this" pointer
+     * of the MODSERIAL that created this object.
+     * @ingroup INTERNAL
+     * @param A pointer to a MODSERIAL object instance.
+     */
+    void setSerial(MODSERIAL *s) { serial = s; }    
+};
+
+// Forward reference dummy class.
+class MODSERIAL_callback_dummy;
+
+/**
+ * @author Andy Kirkham
+ * @see http://mbed.org/cookbook/MODSERIAL
+ * @see example3a.cpp
+ * @see example3b.cpp
+ * @see API 
+ *
+ * <b>MODSERIAL_callback</b> is a class used to hold application callbacks that
+ * MODSERIAL can invoke on certain events.
+ */
+class MODSERIAL_callback 
+{
+protected:
+
+    //! C callback function pointer.
+    void (*c_callback)(MODSERIAL_IRQ_INFO *); 
+    
+    //! C++ callback object/method pointer (the object part).
+    MODSERIAL_callback_dummy *obj_callback;
+    
+    //! C++ callback object/method pointer (the method part).
+    void (MODSERIAL_callback_dummy::*method_callback)(MODSERIAL_IRQ_INFO *);
+
+public:
+    
+    /** Constructor
+     */
+    MODSERIAL_callback() {
+        c_callback      = 0;
+        obj_callback    = 0;
+        method_callback = 0;
+    }
+    
+    /** attach - Overloaded attachment function.
+     *
+     * Attach a C type function pointer as the callback.
+     *
+     * Note, the callback function prototype must be:-
+     * @code
+     * void myCallbackFunction(MODSERIAL_IRQ_INFO *);
+     * @endcode
+     * @param A C function pointer to call.
+     */
+    void attach(void (*function)(MODSERIAL_IRQ_INFO *) = 0) { c_callback = function; }
+    
+    /** attach - Overloaded attachment function.
+     *
+     * Attach a C++ type object/method pointer as the callback.
+     *
+     * Note, the callback method prototype must be:-
+     * @code
+     *     public:
+     *         void myCallbackFunction(MODSERIAL_IRQ_INFO *);
+     * @endcode
+     * @param A C++ object pointer.
+     * @param A C++ method within the object to call.
+     */
+    template<class T> 
+    void attach(T* item, void (T::*method)(MODSERIAL_IRQ_INFO *)) { 
+        obj_callback    = (MODSERIAL_callback_dummy *)item; 
+        method_callback = (void (MODSERIAL_callback_dummy::*)(MODSERIAL_IRQ_INFO *))method; 
+    }
+
+    /** call - Overloaded callback initiator.
+     *
+     * call the callback function.
+     *
+     * @param A pointer to a MODSERIAL_IRQ_INFO object.
+     */
+    void call(MODSERIAL_IRQ_INFO *arg) {
+        if (c_callback != 0) {
+            (*c_callback)(arg);
+        }
+        else {
+            if (obj_callback  != 0 && method_callback != 0) {
+                (obj_callback->*method_callback)(arg);
+            }
+        }       
+    }    
+};
+
+/**
+ * @author Andy Kirkham
+ * @see http://mbed.org/cookbook/MODSERIAL
+ * @see http://mbed.org/handbook/Serial
+ * @see example1.cpp
+ * @see example2.cpp
+ * @see example3a.cpp
+ * @see example3b.cpp
+ * @see example_dma.cpp
+ * @see API 
+ *
+ * <b>MODSERIAL</b> extends the Mbed library <a href="/handbook/Serial">Serial</a> to provide fully buffered
+ * TX and RX streams. Buffer length is fully customisable. 
+ *
+ * Before using MODSERIAL users should be familar with Mbed's standard <a href="/handbook/Serial">Serial</a>
+ * library object. MODSERIAL is a direct "drop in" replacement for <a href="/handbook/Serial">Serial</a>. Where
+ * previously Serial was used, MODSERIAL can be used as adirect replacement instantly offering standard
+ * TX and RX buffering. By default, both TX and RX buffers are 256 bytes in length.
+ *
+ * @image html /media/uploads/mbedofficial/serial_interfaces.png
+ *
+ * Standard example:
+ * @code
+ * #include "mbed.h"
+ * #include "MODSERIAL.h"
+ *
+ * MODSERIAL pc(USBTX, USBRX); // tx, rx
+ *
+ * int main() {
+ *     pc.printf("Hello World!");
+ *     while(1) {
+ *         pc.putc(pc.getc() + 1);
+ *     }
+ * }
+ * @endcode
+ *
+ * Example with alternate buffer length:
+ * @code
+ * #include "mbed.h"
+ * #include "MODSERIAL.h"
+ *
+ * // Make TX and RX buffers 512byes in length
+ * MODSERIAL pc(USBTX, USBRX, 512); // tx, rx
+ *
+ * int main() {
+ *     pc.printf("Hello World!");
+ *     while(1) {
+ *         pc.putc(pc.getc() + 1);
+ *     }
+ * }
+ * @endcode
+ *
+ * Example with alternate buffer length:
+ * @code
+ * #include "mbed.h"
+ * #include "MODSERIAL.h"
+ *
+ * // Make TX 1024bytes and RX 512byes in length
+ * MODSERIAL pc(USBTX, USBRX, 1024, 512); // tx, rx
+ *
+ * int main() {
+ *     pc.printf("Hello World!");
+ *     while(1) {
+ *         pc.putc(pc.getc() + 1);
+ *     }
+ * }
+ * @endcode
+ */
+class MODSERIAL : public Serial 
+{
+public:
+
+    // Allow instances of MODSERIAL_IRQ_INFO to use protected properties and methods.
+    friend class MODSERIAL_IRQ_INFO;
+
+    //! A copy of the Serial parity enum
+    /** @see http://mbed.org/projects/libraries/api/mbed/trunk/Serial#Serial.format */
+    enum Parity {
+          None = 0
+        , Odd
+        , Even
+        , Forced1   
+        , Forced0
+    };
+    
+    //! A copy of the Serial IrqType enum
+    enum IrqType {
+          RxIrq = 0
+        , TxIrq
+        , RxOvIrq
+        , TxOvIrq
+        , TxEmpty
+        , RxAutoDetect
+        , NumOfIrqTypes
+    };
+    
+    //! Non-blocking functions return code.
+    enum Result {
+          Ok = 0                /*!< Ok. */
+        , NoMemory       = -1   /*!< Memory allocation failed. */
+        , NoChar         = -1   /*!< No character in buffer. */
+        , BufferOversize = -2   /*!< Oversized buffer. */
+    };
+    
+    /**
+     * The MODSERIAL constructor is used to initialise the serial object.
+     *
+     * @param tx PinName of the TX pin.
+     * @param rx PinName of the TX pin.
+     * @param name An option name for RPC usage.
+     */    
+    MODSERIAL(PinName tx, PinName rx, const char *name = NULL);
+    
+    /**
+     * The MODSERIAL constructor is used to initialise the serial object.
+     *
+     * @param tx PinName of the TX pin.
+     * @param rx PinName of the TX pin.
+     * @param bufferSize Integer of the TX and RX buffer sizes.
+     * @param name An option name for RPC usage.
+     */    
+    MODSERIAL(PinName tx, PinName rx, int bufferSize, const char *name = NULL);
+    
+    /**
+     * The MODSERIAL constructor is used to initialise the serial object.
+     *
+     * @param tx PinName of the TX pin.
+     * @param rx PinName of the TX pin.
+     * @param txBufferSize Integer of the TX buffer sizes.
+     * @param rxBufferSize Integer of the RX buffer sizes.
+     * @param name An option name for RPC usage.
+     */    
+    MODSERIAL(PinName tx, PinName rx, int txBufferSize, int rxBufferSize, const char *name = NULL);
+    
+    virtual ~MODSERIAL();
+
+    /**
+     * Function: attach
+     *  
+     * The Mbed standard <a href="/handbook/Serial">Serial</a> library object allows an interrupt callback
+     * to be made when a byte is received by the TX or RX UART hardware. MODSERIAL traps these interrupts
+     * to enable it's buffering system. However, after the byte has been received/sent under interrupt control, 
+     * MODSERIAL can callback a user function as a notification of the interrupt. Note, user code should not
+     * directly interact with the Uart hardware, MODSERIAL does that, instead, MODSERIAL API functions should
+     * be used.
+     *
+     * <b>Note</b>, a character is written out then, if there is room in the TX FIFO and the TX buffer is empty,
+     * putc() will put the character directly into THR (the output holding register). If the TX FIFO is full and 
+     * cannot accept the character, it is placed into the TX output buffer. The TX interrupts are then enabled
+     * so that when the TX FIFO empties, the TX buffer is then transferred to the THR FIFO. The TxIrq will ONLY 
+     * be activated when this transfer of a character from BUFFER to THR FIFO takes place. If your character 
+     * throughput is not high bandwidth, then the 16 byte TX FIFO may be enough and the TX output buffer may 
+     * never come into play.
+     *
+     * @code
+     * #include "mbed.h"
+     * #include "MODSERIAL.h"
+     *
+     * DigitalOut led1(LED1);
+     * DigitalOut led2(LED2);
+     * DigitalOut led3(LED3);
+     *
+     * // To test, connect p9 to p10 as a loopback.
+     * MODSERIAL pc(p9, p10);
+     *
+     * // This function is called when a character goes into the TX buffer.
+     * void txCallback(void) {
+     *     led2 = !led2;
+     * }
+     *
+     * // This function is called when a character goes into the RX buffer.
+     * void rxCallback(void) {
+     *     led3 = !led3;
+     * }
+     *
+     * int main() {
+     *     pc.baud(115200);
+     *     pc.attach(&txCallback, MODSERIAL::TxIrq);
+     *     pc.attach(&rxCallback, MODSERIAL::RxIrq);
+     *
+     *     while(1) {
+     *         led1 = !led1;
+     *         wait(0.5);
+     *         pc.putc('A');
+     *         wait(0.5);
+     *     }
+     * ]
+     * @endcode
+     *
+     * @ingroup API
+     * @param fptr A pointer to a void function, or 0 to set as none
+     * @param type Which serial interrupt to attach the member function to (Seriall::RxIrq for receive, TxIrq for transmit buffer empty)
+     */  
+    void attach(void (*fptr)(MODSERIAL_IRQ_INFO *), IrqType type = RxIrq) { _isr[type].attach(fptr); }
+    
+    /**
+     * Function: attach
+     *  
+     * The Mbed standard <a href="/handbook/Serial">Serial</a> library object allows an interrupt callback
+     * to be made when a byte is received by the TX or RX UART hardware. MODSERIAL traps these interrupts
+     * to enable it's buffering system. However, after the byte has been received/sent under interrupt control, 
+     * MODSERIAL can callback a user function as a notification of the interrupt. Note, user code should not
+     * directly interact with the Uart hardware, MODSERIAL does that, instead, MODSERIAL API functions should
+     * be used.
+     *
+     * <b>Note</b>, a character is written out then, if there is room in the TX FIFO and the TX buffer is empty,
+     * putc() will put the character directly into THR (the output holding register). If the TX FIFO is full and 
+     * cannot accept the character, it is placed into the TX output buffer. The TX interrupts are then enabled
+     * so that when the TX FIFO empties, the TX buffer is then transferred to the THR FIFO. The TxIrq will ONLY 
+     * be activated when this transfer of a character from BUFFER to THR FIFO takes place. If your character 
+     * throughput is not high bandwidth, then the 16 byte TX FIFO may be enough and the TX output buffer may 
+     * never come into play.
+     *
+     * @code
+     * #include "mbed.h"
+     * #include "MODSERIAL.h"
+     *
+     * DigitalOut led1(LED1);
+     * DigitalOut led2(LED2);
+     * DigitalOut led3(LED3);
+     *
+     * // To test, connect p9 to p10 as a loopback.
+     * MODSERIAL pc(p9, p10);
+     *
+     * class Foo {
+     * public:
+     *     // This method is called when a character goes into the TX buffer.
+     *     void txCallback(void) { led2 = !led2; }
+     *
+     *     // This method is called when a character goes into the RX buffer.
+     *     void rxCallback(void) { led3 = !led3; }
+     * };
+     *
+     * Foo foo;
+     *
+     * int main() {
+     *     pc.baud(115200);
+     *     pc.attach(&foo, &Foo::txCallback, MODSERIAL::TxIrq);
+     *     pc.attach(&foo, &Foo::rxCallback, MODSERIAL::RxIrq);
+     *
+     *     while(1) {
+     *         led1 = !led1;
+     *         wait(0.5);
+     *         pc.putc('A');
+     *         wait(0.5);
+     *     }
+     * ]
+     * @endcode
+     *     
+     * @ingroup API
+     * @param  tptr A pointer to the object to call the member function on
+     * @param  mptr A pointer to the member function to be called
+     * @param  type Which serial interrupt to attach the member function to (Seriall::RxIrq for receive, TxIrq for transmit buffer empty)
+     */
+    template<typename T>
+    void attach(T* tptr, void (T::*mptr)(MODSERIAL_IRQ_INFO *), IrqType type = RxIrq) {
+        if((mptr != 0) && (tptr != 0)) {
+            _isr[type].attach(tptr, mptr);            
+        }
+    }
+
+    /**
+     * @see attach
+     * @ingroup API
+     */
+    void connect(void (*fptr)(MODSERIAL_IRQ_INFO *), IrqType type = RxIrq) { _isr[RxIrq].attach(fptr); }
+    
+    /**
+     * @see attach
+     * @ingroup API
+     */
+    template<typename T>
+    void connect(T* tptr, void (T::*mptr)(MODSERIAL_IRQ_INFO *), IrqType type = RxIrq) {
+        if((mptr != 0) && (tptr != 0)) {
+            _isr[type].attach(tptr, mptr);            
+        }
+    }
+    
+    /**
+     * Function: writeable
+     *  
+     * Determine if there is space available to write a byte
+     *
+     * @ingroup API
+     * @return 1 if there is space to write a character, else 0
+     */
+    int writeable() { return txBufferFull() ? 0 : 1; }
+    
+    /**
+     * Function: readable
+     *  
+     * Determine if there is a byte available to read
+     *
+     * @ingroup API
+     * @return 1 if there is a character available to read, else 0
+     */
+    int readable() { return rxBufferEmpty() ? 0 : 1; } 
+    
+    /**
+     * Function: txBufferSane
+     *  
+     * Determine if the TX buffer has been initialized.
+     *
+     * @ingroup API
+     * @return true if the buffer is initialized, else false
+     */
+    bool txBufferSane(void) { return buffer[TxIrq] != (char *)NULL ? true : false; }
+    
+    /**
+     * Function: rxBufferSane
+     *  
+     * Determine if the RX buffer has been initialized.
+     *
+     * @ingroup API
+     * @return true if the buffer is initialized, else false
+     */
+    bool rxBufferSane(void) { return buffer[TxIrq] != (char *)NULL ? true : false; }
+    
+    /**
+     * Function: txBufferGetCount
+     *  
+     * Returns how many bytes are in the TX buffer
+     *
+     * @ingroup API
+     * @return The number of bytes in the TX buffer
+     */
+    int txBufferGetCount(void)    { return buffer_count[TxIrq]; }
+    
+    /**
+     * Function: rxBufferGetCount
+     *  
+     * Returns how many bytes are in the RX buffer
+     *
+     * @ingroup API
+     * @return The number of bytes in the RX buffer
+     */
+    int rxBufferGetCount(void)    { return buffer_count[RxIrq]; }
+    
+    /**
+     * Function: txBufferGetSize
+     *  
+     * Returns the current size of the TX buffer
+     *
+     * @ingroup API
+     * @return The length iof the TX buffer in bytes
+     */
+    int txBufferGetSize(int size) { return buffer_size[TxIrq]; } 
+    
+    /**
+     * Function: rxBufferGetSize
+     *  
+     * Returns the current size of the RX buffer
+     *
+     * @ingroup API
+     * @return The length iof the RX buffer in bytes
+     */
+    int rxBufferGetSize(int size) { return buffer_size[RxIrq]; } 
+    
+    /**
+     * Function: txBufferFull
+     *  
+     * Is the TX buffer full?
+     *
+     * @ingroup API
+     * @return true if the TX buffer is full, otherwise false
+     */
+    bool txBufferFull(void);
+    
+    /**
+     * Function: rxBufferFull
+     *  
+     * Is the RX buffer full?
+     *
+     * @ingroup API
+     * @return true if the RX buffer is full, otherwise false
+     */
+    bool rxBufferFull(void);
+    
+    /**
+     * Function: txBufferEmpty
+     *  
+     * Is the TX buffer empty?
+     *
+     * @ingroup API
+     * @return true if the TX buffer is empty, otherwise false
+     */
+    bool txBufferEmpty(void);
+    
+    /**
+     * Function: rxBufferEmpty
+     *  
+     * Is the RX buffer empty?
+     *
+     * @ingroup API
+     * @return true if the RX buffer is empty, otherwise false
+     */
+    bool rxBufferEmpty(void);
+    
+    /**
+     * Function: txBufferSetSize
+     *  
+     * Change the TX buffer size.
+     *
+     * @see Result
+     * @ingroup API
+     * @param size The new TX buffer size in bytes.
+     * @param m Perform a memory sanity check. Errs the Mbed if memory alloc fails.
+     * @return Result Ok on success.
+     */
+    int txBufferSetSize(int size, bool m) { return resizeBuffer(size, TxIrq, m); } 
+    
+    /**
+     * Function: rxBufferSetSize
+     *  
+     * Change the RX buffer size.
+     *
+     * @see Result
+     * @ingroup API
+     * @param size The new RX buffer size in bytes.
+     * @param m Perform a memory sanity check. Errs the Mbed if memory alloc fails.
+     * @return Result Ok on success.
+     */
+    int rxBufferSetSize(int size, bool m) { return resizeBuffer(size, RxIrq, m); } 
+    
+    /**
+     * Function: txBufferSetSize
+     *  
+     * Change the TX buffer size.
+     * Always performs a memory sanity check, halting the Mbed on failure.
+     *
+     * @see Result
+     * @ingroup API
+     * @param size The new TX buffer size in bytes.
+     * @return Result Ok on success.
+     */
+    int txBufferSetSize(int size) { return resizeBuffer(size, TxIrq, true); } 
+    
+    /**
+     * Function: rxBufferSetSize
+     *  
+     * Change the RX buffer size.
+     * Always performs a memory sanity check, halting the Mbed on failure.
+     *
+     * @see Result
+     * @ingroup API
+     * @param size The new RX buffer size in bytes.
+     * @return Result Ok on success.
+     */
+    int rxBufferSetSize(int size) { return resizeBuffer(size, RxIrq, true); } 
+    
+    /**
+     * Function: txBufferFlush
+     *  
+     * Remove all bytes from the TX buffer.
+     * @ingroup API
+     */
+    void txBufferFlush(void) { flushBuffer(TxIrq); }
+    
+    /**
+     * Function: rxBufferFlush
+     *  
+     * Remove all bytes from the RX buffer.
+     * @ingroup API
+     */
+    void rxBufferFlush(void) { flushBuffer(RxIrq); }
+        
+    /**
+     * Function: getcNb
+     *
+     * Like getc() but is non-blocking. If no bytes are in the RX buffer this
+     * function returns Result::NoChar (-1)
+     *
+     * @ingroup API
+     * @return A byte from the RX buffer or Result::NoChar (-1) if bufer empty.
+     */
+    int getcNb() { return __getc(false); }
+    
+    /**
+     * Function: getc
+     *
+     * Overloaded version of Serial::getc()
+     * 
+     * This function blocks (if the RX buffer is empty the function will wait for a
+     * character to arrive and then return that character).
+     *
+     * @ingroup API
+     * @return A byte from the RX buffer
+     */
+    int getc()   { return __getc(true);  }
+    
+    /**
+     * Function: txGetLastChar
+     *
+     * Rteurn the last byte to pass through the TX interrupt handler.
+     *
+     * @ingroup MISC
+     * @return The byte
+     */
+    char txGetLastChar(void) { return txc; }
+    
+    /**
+     * Function: rxGetLastChar
+     *
+     * Return the last byte to pass through the RX interrupt handler.
+     *
+     * @ingroup MISC
+     * @return The byte
+     */
+    char rxGetLastChar(void) { return rxc; }
+    
+    /**
+     * Function: txIsBusy
+     *
+     * If the Uart is still actively sending characters this
+     * function will return true.
+     *
+     * @ingroup API
+     * @return bool
+     */
+    bool txIsBusy(void);
+    
+    /**
+     * Function: autoDetectChar
+     *
+     * Set the char that, if seen incoming, invokes the AutoDetectChar callback.
+     *
+     * @ingroup API
+     * @param int c The character to detect.
+     */
+    void autoDetectChar(char c) { auto_detect_char = c; }
+    
+    /**
+     * Function: move
+     *
+     * Move contents of RX buffer to external buffer. Stops if "end" detected.
+     *
+     * @ingroup API
+     * @param char *s The destination buffer address
+     * @param int max The maximum number of chars to move.
+     * @param char end If this char is detected stop moving.
+     */
+    int move(char *s, int max, char end) {
+        int counter = 0;
+        char c;
+        while(readable()) {
+            c = getc();
+            if (c == end) break;
+            *(s++) = c;
+            counter++;
+            if (counter == max) break;
+        }
+        return counter;
+    }
+    
+    /**
+     * Function: move (overloaded)
+     *
+     * Move contents of RX buffer to external buffer. Stops if auto_detect_char detected.
+     *
+     * @ingroup API
+     * @param int max The maximum number of chars to move.
+     * @param char *s The destination buffer address
+     */
+    int move(char *s, int max) {
+        return move(s, max, auto_detect_char);
+    }
+    
+    #if 0 // Inhereted from Serial/Stream, for documentation only
+    /**
+     * Function: putc
+     * 
+     * Write a character
+     * Inhereted from Serial/Stream
+     *
+     * @see http://mbed.org/projects/libraries/api/mbed/trunk/Serial#Serial.putc
+     * @ingroup API
+     * @param c The character to write to the serial port
+     */
+    int putc(int c);
+    #endif
+    
+    #if 0 // Inhereted from Serial/Stream, for documentation only
+    /**
+     * Function: printf
+     *  
+     * Write a formated string
+     * Inhereted from Serial/Stream
+     *
+     * @see http://mbed.org/projects/libraries/api/mbed/trunk/Serial#Serial.printf
+     * @ingroup API
+     * @param format A printf-style format string, followed by the variables to use in formating the string.
+     */
+    int printf(const char* format, ...);
+    #endif
+    
+    #if 0 // Inhereted from Serial/Stream, for documentation only
+    /**
+     * Function: scanf
+     *  
+     * Read a formated string
+     * Inhereted from Serial/Stream
+     *
+     * @see http://mbed.org/projects/libraries/api/mbed/trunk/Serial#Serial.scanf
+     * @ingroup API
+     * @param format - A scanf-style format string, followed by the pointers to variables to store the results.
+     */
+    int scanf(const char* format, ...);
+    #endif
+
+protected:    
+    /**
+     * Used to pass information to callbacks.
+     * @ingroup INTERNALS
+     */
+    MODSERIAL_IRQ_INFO callbackInfo;
+
+    /**
+     * Remove the last char placed into the rx buffer.
+     * This is an operation that can only be performed
+     * by an rxCallback function. To protect the buffers
+     * this function is defined protected so that a 
+     * regular application cannot call it directly. It 
+     * can only be called by the public version within a
+     * MODSERIAL_IRQ_INFO class.
+     * @ingroup INTERNALS
+     * @return The byte removed from the buffer.
+     */
+    int rxDiscardLastChar(void);    
+            
+private:
+
+    /**
+     * A pointer to the UART peripheral base address being used.
+     * @ingroup INTERNALS
+     */
+    void *_base;
+    
+    /**
+     * The last byte to pass through the TX IRQ handler.
+     * @ingroup INTERNALS
+     */
+    volatile char txc;
+    
+    /**
+     * The last byte to pass through the RX IRQ handler.
+     * @ingroup INTERNALS
+     */
+    volatile char rxc;
+    
+    /**
+     * Pointers to the TX and RX buffers.
+     * @ingroup INTERNALS
+     */
+    volatile char *buffer[2];
+    
+    /**
+     * Buffer in pointers.
+     * @ingroup INTERNALS
+     */
+    volatile int   buffer_in[2];
+    
+    /**
+     * Buffer out pointers.
+     * @ingroup INTERNALS
+     */
+    volatile int   buffer_out[2];
+    
+    /**
+     * Buffer lengths.
+     * @ingroup INTERNALS
+     */
+    volatile int   buffer_size[2];
+    
+    /**
+     * Buffer content counters.
+     * @ingroup INTERNALS
+     */
+    volatile int   buffer_count[2];
+    
+    /**
+     * Buffer overflow.
+     * @ingroup INTERNALS
+     */
+    volatile int   buffer_overflow[2];
+    
+    /**
+     * Auto-detect character.
+     * @ingroup INTERNALS
+     */
+    volatile char auto_detect_char;
+    
+    /**
+     * Callback system.
+     * @ingroup INTERNALS
+     */
+    MODSERIAL_callback _isr[NumOfIrqTypes];
+    
+    /**
+     * TX Interrupt Service Routine.
+     * @ingroup INTERNALS
+     */
+    void isr_tx(bool doCallback);
+    
+    /**
+     * TX Interrupt Service Routine stub version.
+     * @ingroup INTERNALS
+     */ 
+    void isr_tx(void) { isr_tx(true); }
+    
+    
+    /**
+     * RX Interrupt Service Routine.
+     * @ingroup INTERNALS
+     */
+    void isr_rx(void);
+    
+    /**
+     * Disable the interrupts for this Uart.
+     * @ingroup INTERNALS
+     */
+    void disableIrq(void);
+    
+    /**
+     * Enable the interrupts for this Uart.
+     * @ingroup INTERNALS
+     */
+    void enableIrq(void);
+    
+    /**
+     * Get a character from the RX buffer
+     * @ingroup INTERNALS
+     * @param bool True to block (wait for input)
+     * @return A byte from the buffer.
+     */
+    int __getc(bool);
+    
+    /**
+     * Put a character from the TX buffer
+     * @ingroup INTERNALS
+     * @param bool True to block (wait for space in the TX buffer if full)
+     * @return 0 on success
+     */
+    int __putc(int c, bool);
+    
+    /**
+     * Function: _putc 
+     * Overloaded virtual function.
+     */
+    virtual int _putc(int c) { return __putc(c, true); }
+    
+    /**
+     * Function: _getc 
+     * Overloaded virtual function.
+     */
+    virtual int _getc()      { return __getc(true); }
+        
+    /** 
+     * Function: init
+     * Initialize the MODSERIAL object
+     * @ingroup INTERNALS
+     */
+    void init(int txSize, int rxSize);
+    
+    /** 
+     * Function: flushBuffer
+     * @ingroup INTERNALS
+     */
+    void flushBuffer(IrqType type);
+
+    /** 
+     * Function: resizeBuffer
+     * @ingroup INTERNALS
+     */
+    int resizeBuffer(int size, IrqType type = RxIrq, bool memory_check = true);   
+    
+    /** 
+     * Function: downSizeBuffer
+     * @ingroup INTERNALS
+     */
+    int downSizeBuffer(int size, IrqType type, bool memory_check); 
+    
+    /** 
+     * Function: upSizeBuffer
+     * @ingroup INTERNALS
+     */
+    int upSizeBuffer(int size, IrqType type, bool memory_check); 
+
+    /*
+     * If MODDMA is available the compile in code to handle sending
+     * an arbitary char buffer. Note, the parts before teh #ifdef
+     * are declared so that MODSERIAL can access then even if MODDMA
+     * isn't avaiable. Since MODDMA.h is only available at this point
+     * all DMA functionality must be declared inline in the class
+     * definition.
+     */
+public:
+
+    int dmaSendChannel;
+    void *moddma_p;
+    
+#ifdef MODDMA_H
+
+    MODDMA_Config *config;
+    
+    /**
+     * Set the "void pointer" moddma_p to be a pointer to a
+     * MODDMA controller class instance. Used to manage the
+     * data transfer of DMA configurations.
+     *
+     * @ingroup API
+     * @param p A pointer to "the" instance of MODDMA.
+     */
+    void MODDMA(MODDMA *p) { moddma_p = p; }
+    
+    /**
+     * Send a char buffer to the Uarts TX system
+     * using DMA. This blocks regular library
+     * sending.
+     *
+     * @param buffer A char buffer of bytes to send.
+     * @param len The length of the buffer to send.
+     * @param dmaChannel The DMA channel to use, defaults to 7
+     * @return MODDMA::Status MODDMA::ok if all went ok
+     */   
+    int dmaSend(char *buffer, int len, int dmaChannel = 7) 
+    {
+        if (moddma_p == (void *)NULL) return -2;
+        class MODDMA *dma = (class MODDMA *)moddma_p;
+        
+        dmaSendChannel = dmaChannel & 0x7;
+        
+        uint32_t conn = MODDMA::UART0_Tx;
+        switch(_uidx) {
+            case 0: conn = MODDMA::UART0_Tx; break;
+            case 1: conn = MODDMA::UART1_Tx; break;
+            case 2: conn = MODDMA::UART2_Tx; break;
+            case 3: conn = MODDMA::UART3_Tx; break;
+        }
+        
+        config = new MODDMA_Config;
+        config
+         ->channelNum    ( (MODDMA::CHANNELS)(dmaSendChannel & 0x7) )
+         ->srcMemAddr    ( (uint32_t) buffer )
+         ->transferSize  ( len )
+         ->transferType  ( MODDMA::m2p )
+         ->dstConn       ( conn )
+         ->attach_tc     ( this, &MODSERIAL::dmaSendCallback )
+         ->attach_err    ( this, &MODSERIAL::dmaSendCallback )
+        ; // config end
+        
+        // Setup the configuration.
+        if (dma->Setup(config) == 0) { 
+            return -1;
+        }
+        
+        //dma.Enable( MODDMA::Channel_0 );
+        dma->Enable( config->channelNum() );
+        return MODDMA::Ok;
+    }
+    
+    /**
+     * Attach a callback to the DMA completion.
+     *
+     * @ingroup API
+     * @param fptr A function pointer to call
+     * @return this
+     */
+    void attach_dmaSendComplete(void (*fptr)(MODSERIAL_IRQ_INFO *)) {  
+        _isrDmaSendComplete.attach(fptr);         
+    }
+    
+    /**
+     * Attach a callback to the DMA completion.
+     *
+     * @ingroup API
+     * @param tptr A template pointer to the calling object
+     * @param mptr A method pointer within the object to call.
+     * @return this
+     */
+    template<typename T>
+    void attach_dmaSendComplete(T* tptr, void (T::*mptr)(MODSERIAL_IRQ_INFO *)) {  
+        if((mptr != NULL) && (tptr != NULL)) {
+            _isrDmaSendComplete.attach(tptr, mptr);         
+        }
+    }
+    
+    MODSERIAL_callback _isrDmaSendComplete;
+    
+protected:    
+    /**
+     * Callback for dmaSend(). 
+     */
+    void dmaSendCallback(void) 
+    {
+        if (moddma_p == (void *)NULL) return;
+        class MODDMA *dma = (class MODDMA *)moddma_p;
+        
+        MODDMA_Config *config = dma->getConfig();
+        dma->haltAndWaitChannelComplete( (MODDMA::CHANNELS)config->channelNum());
+        dma->Disable( (MODDMA::CHANNELS)config->channelNum() );
+        if (dma->irqType() == MODDMA::TcIrq)  dma->clearTcIrq();
+        if (dma->irqType() == MODDMA::ErrIrq) dma->clearErrIrq();
+        dmaSendChannel = -1;
+        _isrDmaSendComplete.call(&this->callbackInfo);
+        delete(config);
+    }
+    
+#endif // MODDMA_H
+
+};
+
+}; // namespace AjK ends
+
+using namespace AjK;
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MODSERIAL/MODSERIAL_IRQ_INFO.cpp	Fri Oct 12 18:02:43 2012 +0000
@@ -0,0 +1,38 @@
+/*
+    Copyright (c) 2010 Andy Kirkham
+ 
+    Permission is hereby granted, free of charge, to any person obtaining a copy
+    of this software and associated documentation files (the "Software"), to deal
+    in the Software without restriction, including without limitation the rights
+    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+    copies of the Software, and to permit persons to whom the Software is
+    furnished to do so, subject to the following conditions:
+ 
+    The above copyright notice and this permission notice shall be included in
+    all copies or substantial portions of the Software.
+ 
+    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+    THE SOFTWARE.
+    
+    @file          MODSERIAL_IRQ_INFO.cpp 
+    @author        Andy Kirkham    
+*/
+
+#include "MODSERIAL.h"
+
+namespace AjK {
+
+int 
+MODSERIAL_IRQ_INFO::rxDiscardLastChar(void) 
+{ 
+    if (!serial) return -1;
+    
+    return serial->rxDiscardLastChar(); 
+}
+
+}; // namespace AjK ends
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MODSERIAL/PUTC.cpp	Fri Oct 12 18:02:43 2012 +0000
@@ -0,0 +1,79 @@
+/*
+    Copyright (c) 2010 Andy Kirkham
+ 
+    Permission is hereby granted, free of charge, to any person obtaining a copy
+    of this software and associated documentation files (the "Software"), to deal
+    in the Software without restriction, including without limitation the rights
+    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+    copies of the Software, and to permit persons to whom the Software is
+    furnished to do so, subject to the following conditions:
+ 
+    The above copyright notice and this permission notice shall be included in
+    all copies or substantial portions of the Software.
+ 
+    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+    THE SOFTWARE.
+*/
+
+#include "MODSERIAL.h"
+#include "MACROS.h"
+
+namespace AjK {
+
+int
+MODSERIAL::__putc(int c, bool block) {
+    
+    // If no buffer is in use fall back to standard TX FIFO usage.
+    // Note, we must block in this case and ignore bool "block" 
+    // so as to maintain compat with Mbed Serial.
+    if (buffer[TxIrq] == (char *)NULL || buffer_size[TxIrq] == 0) {
+        while (! MODSERIAL_THR_HAS_SPACE) ; // Wait for space in the TX FIFO.
+        _THR = (uint32_t)c;
+        return 0;
+    }
+    
+    if ( MODSERIAL_THR_HAS_SPACE && MODSERIAL_TX_BUFFER_EMPTY && dmaSendChannel == -1 ) {
+        _THR = (uint32_t)c;
+    }
+    else {
+        if (block) {
+            uint32_t ier = _IER; _IER = 1;
+            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(false);
+            }
+            _IER = ier;
+        }
+        else if( MODSERIAL_TX_BUFFER_FULL ) {
+            buffer_overflow[TxIrq] = c; // Oh dear, no room in buffer.
+            _isr[TxOvIrq].call(&this->callbackInfo);
+            return -1;
+        }
+        _IER &= ~2;
+        buffer[TxIrq][buffer_in[TxIrq]] = c;
+        buffer_count[TxIrq]++;
+        buffer_in[TxIrq]++;
+        if (buffer_in[TxIrq] >= buffer_size[TxIrq]) {
+            buffer_in[TxIrq] = 0;
+        }            
+        _IER |= 2;        
+    }
+      
+    return 0;
+}
+
+}; // namespace AjK ends
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MODSERIAL/RESIZE.cpp	Fri Oct 12 18:02:43 2012 +0000
@@ -0,0 +1,123 @@
+/*
+    Copyright (c) 2010 Andy Kirkham
+ 
+    Permission is hereby granted, free of charge, to any person obtaining a copy
+    of this software and associated documentation files (the "Software"), to deal
+    in the Software without restriction, including without limitation the rights
+    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+    copies of the Software, and to permit persons to whom the Software is
+    furnished to do so, subject to the following conditions:
+ 
+    The above copyright notice and this permission notice shall be included in
+    all copies or substantial portions of the Software.
+ 
+    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+    THE SOFTWARE.
+*/
+
+#include "MODSERIAL.h"
+#include "MACROS.h"
+
+namespace AjK {
+
+int
+MODSERIAL::resizeBuffer(int size, IrqType type, bool memory_check)
+{
+    int rval = Ok;
+    
+    // If the requested size is the same as the current size there's nothing to do,
+    // just continue to use the same buffer as it's fine as it is.
+    if (buffer_size[type] == size) return rval;
+    
+    // Make sure the ISR cannot use the buffers while we are manipulating them.
+    disableIrq();
+    
+    // If the requested buffer size is larger than the current size, 
+    // attempt to create a new buffer and use it.
+    if (buffer_size[type] < size) {
+        rval = upSizeBuffer(size, type, memory_check);
+    }
+    else if (buffer_size[type] > size) {
+        rval = downSizeBuffer(size, type, memory_check);
+    }
+    
+    // Start the ISR system again with the new buffers.
+    enableIrq();
+    
+    return rval;
+}
+
+int 
+MODSERIAL::downSizeBuffer(int size, IrqType type, bool memory_check)
+{
+    if (size >= buffer_count[type]) {
+        return BufferOversize;
+    }
+    
+    char *s = (char *)malloc(size);
+    
+    if (s == (char *)NULL) {
+        if (memory_check) {
+            error("Failed to allocate memory for %s buffer", type == TxIrq ? "TX" : "RX");
+        }
+        return NoMemory;
+    }
+    
+    int c, new_in = 0;
+    
+    do {
+        c = __getc(false);
+        if (c != -1) s[new_in++] = (char)c;
+        if (new_in >= size) new_in = 0;
+    }
+    while (c != -1);
+    
+    free((char *)buffer[type]);
+    buffer[type]      = s;
+    buffer_in[type]   = new_in;
+    buffer_out[type]  = 0;
+    return Ok;        
+}
+
+int 
+MODSERIAL::upSizeBuffer(int size, IrqType type, bool memory_check)
+{
+    char *s = (char *)malloc(size);
+    
+    if (s == (char *)NULL) {
+        if (memory_check) {
+            error("Failed to allocate memory for %s buffer", type == TxIrq ? "TX" : "RX");
+        }
+        return NoMemory;
+    }
+    
+    if (buffer_count[type] == 0) { // Current buffer empty?
+        free((char *)buffer[type]);
+        buffer[type]      = s;
+        buffer_in[type]   = 0;
+        buffer_out[type]  = 0;
+    }        
+    else { // Copy the current contents into the new buffer.
+        int c, new_in = 0;
+        do {
+            c = __getc(false);
+            if (c != -1) s[new_in++] = (char)c;
+            if (new_in >= size) new_in = 0; // Shouldn't happen, but be sure.
+        }
+        while (c != -1);
+        free((char *)buffer[type]);
+        buffer[type]      = s;
+        buffer_in[type]   = new_in;
+        buffer_out[type]  = 0;
+    }
+    
+    buffer_size[type] = size;
+    return Ok;
+}
+
+}; // namespace AjK ends
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/PinDetect.lib	Fri Oct 12 18:02:43 2012 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/AjK/code/PinDetect/#cb3afc45028b
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri Oct 12 18:02:43 2012 +0000
@@ -0,0 +1,463 @@
+//Contest Winner using GSM Modem
+
+#include "mbed.h"
+#include "MODSERIAL.h"
+#include <math.h>
+#include <iostream>
+#include <string>
+#include <stdlib.h>
+#include <ctype.h>
+#include "Braille_In.h"
+#include "PinDetect.h"
+#define MESSAGE_BUFFER_SIZE 1024
+using namespace std;
+
+// OPTIONAL SETTINGS
+
+int SMSinterval = 15;       //Send a SMS Vote once every n seconds
+string phoneNumber = "16783503079";    //Phone Number to send SMS Votes
+string bodyText = "Buzz";    //Message to send in vote
+
+//END OF OPTIONAL SETTINGS
+
+
+//MODSERIAL gsm(p28,p27);
+//Serial pc(USBTX, USBRX); // PC Virtual Serial Port over USB
+
+MODSERIAL gsm(USBTX,USBRX);
+MODSERIAL pc(p28, p27);
+Serial speakjet(p13,p14);
+DigitalOut led1(LED1);
+DigitalOut led2(LED2);
+DigitalOut led3(LED3);
+DigitalOut led4(LED4);
+
+DigitalOut dot1LED(p5);
+DigitalOut dot2LED(p26);
+DigitalOut dot3LED(p25);
+DigitalOut dot4LED(p30);
+DigitalOut dot5LED(p29);
+DigitalOut dot6LED(p6);
+
+BrailleInput bparse;
+InterruptIn dot1(p15);
+InterruptIn dot2(p16);
+InterruptIn dot3(p17);
+InterruptIn dot4(p18);
+InterruptIn dot5(p23);
+InterruptIn dot6(p24);
+PinDetect dotSp(p21);
+char ExampleSentance[] = { 0x20, 0x3,  0x17, 0x1, 0xA, 0x7, 0x7, 0x11, 127, 0x1E, 0x11, 0x2D,0x1E, 127, 0xA, 0xE, 127, 0x1, 0x3A, 0x11, 0x0E, 0x15, 0xD, 0x11, 0x16, '\0' };
+PinDetect SendSMS(p22);
+
+int SMScount = 0;
+int timeCount;
+int statusMessage = 0;
+int compareResult = 0;
+int messageResponse = 0;
+int mpResult = 0;
+bool timeOrDate = 0;
+bool statusMessageAlert = 0;
+bool statusMessageInterrupt = 0;
+char messageBufferIncoming[MESSAGE_BUFFER_SIZE];
+char messageBufferOutgoing[MESSAGE_BUFFER_SIZE];
+bool messageReceived;
+
+char braillein[256];
+char buf[40];
+char buf1[40];
+char buf2= 0x1A;    //CTRL+Z, Substitute character
+
+bool sendMsgDesired=false;
+bool InputDone=false;
+bool SMS_Rcv=false;
+bool SMS_Header_Rcv=false;
+int SMS_Rcv_loc=0;
+char paranoidWasteBuf[25];
+char messageHeader[400];
+
+char currentBrailleChar=0;
+string BrailleIn=" ";
+
+void ledCellRefresh()
+{
+    dot1LED=currentBrailleChar & 0x1;
+    dot2LED=currentBrailleChar & 0x2;
+    dot3LED=currentBrailleChar & 0x4;
+    dot4LED=currentBrailleChar & 0x8;
+    dot5LED=currentBrailleChar & 0x10;
+    dot6LED=currentBrailleChar & 0x20;
+   }
+
+void setLEDs(int in)
+{
+    switch (in){
+        case 1:
+            led1=0;  led2=0;  led3=0;  led4=1;
+            break;
+        case 2:
+            led1=0;  led2=0;  led3=1;  led4=0;
+            break;
+        case 3:
+            led1=0;  led2=0;  led3=1;  led4=1;
+            break;
+        case 4:
+            led1=0;  led2=1;  led3=0;  led4=0;
+            break;
+        case 5:
+            led1=0;  led2=1;  led3=0;  led4=1;
+            break;
+        case 6:
+            led1=0;  led2=1;  led3=1;  led4=0;
+            break;
+        case 7:
+            led1=0;  led2=1;  led3=1;  led4=1;
+            break;
+        case 8:
+            led1=1;  led2=0;  led3=0;  led4=0;
+            break;
+        case 9:
+            led1=1;  led2=0;  led3=0;  led4=1;
+            break;
+         default:
+            led1=0; led2=0; led3=0; led4=0;
+         }
+         ledCellRefresh();
+         }
+            
+
+    
+
+void d1(){ currentBrailleChar = currentBrailleChar | 0x01; setLEDs(1);}
+void d2(){ currentBrailleChar = currentBrailleChar | 0x02; setLEDs(2);}
+void d3(){ currentBrailleChar = currentBrailleChar | 0x04; setLEDs(3);}
+void d4(){ currentBrailleChar = currentBrailleChar | 0x08; setLEDs(4);}
+void d5(){ currentBrailleChar = currentBrailleChar | 0x10; setLEDs(5);}
+void d6(){ currentBrailleChar = currentBrailleChar | 0x20; setLEDs(6);}
+void dSp(){ 
+if (currentBrailleChar==0) currentBrailleChar=127;
+BrailleIn+=currentBrailleChar;
+currentBrailleChar=0;
+setLEDs(7);
+}
+void select_SMS_Send() { sendMsgDesired=true;  setLEDs(8); }
+void select_SMS_Held() { InputDone=true; BrailleIn+=currentBrailleChar; currentBrailleChar=0;setLEDs(9);}
+
+
+string extract_first_num(string in)
+{
+    int firstnum = in.find_first_of("123456789");
+    string out="";
+    while ( isdigit(  in[firstnum] ) )
+    {
+        out+=in[firstnum];
+        firstnum++;
+     }
+     return out;
+}
+
+string getBrailleInput()
+{
+  string BrailleOut = bparse.translateBraille(BrailleIn.c_str(),BrailleIn.length());
+  pc.printf("getBrailleInput\t %s\n",BrailleOut.c_str());
+  return BrailleOut;
+}   
+
+string Braille_Letters_Numbers(string in)
+{
+    string out = in;
+    char c,d;
+    pc.printf("Braille_Letters_Numbers %s\n",in.c_str());
+    for (int i=0; i<in.length()-1; i++)
+    {
+        c = in[i];
+        switch (c){
+            case 'a':
+                d='1';
+                break;
+            case 'b':
+                d='2';
+                break;
+            case 'c':
+                d='3';
+                break;
+            case 'd':
+                d='4';
+                break;
+            case 'e':
+                d='5';
+                break;
+            case 'f':
+                d='6';
+                break;
+            case 'g':
+                d='7';
+                break;
+            case 'h':
+                d='8';
+                break;
+            case 'i':
+                d='9';
+                break;
+            case 'j':
+                d='0';
+                break;
+            }
+           
+            out[i]=d;
+            
+           }     
+       out[in.length()-1]='\0';    
+    pc.printf(out.c_str());
+    return out;
+ }
+
+
+void speak(string input)
+{
+    //stub to be replaced w/ speakjet code
+    speakjet.printf("\t%s\n",input);
+    //ctrl.printf("%s\n",input);
+    
+}
+
+
+void messageReceive(MODSERIAL_IRQ_INFO *q) {
+    MODSERIAL *sys = q->serial;
+    
+   sys->move(messageBufferIncoming, MESSAGE_BUFFER_SIZE);
+    
+    messageReceived = true;
+    return;
+}
+
+int messageProcess(void) {
+    string msgbufstr(messageBufferIncoming); 
+    string temp;
+    
+  if (!strncmp(messageBufferIncoming, "+CMTI:",sizeof("+CMTI:")-1)) 
+    {
+        SMS_Rcv=true;
+        temp = extract_first_num(msgbufstr);
+        SMS_Rcv_loc = atoi(temp.c_str());
+       
+     }
+     
+     
+     
+        
+    
+    if (!strncmp(messageBufferIncoming, "OK", sizeof("OK")-1)) mpResult = 1;
+    else if (!strncmp(messageBufferIncoming, "ERROR", sizeof("ERROR")-1)) mpResult = 2;
+    else mpResult = 1;
+    
+    pc.printf("%s\r\n", messageBufferIncoming);
+     gsm.rxBufferFlush();                            //Flush the Buffer
+    messageReceived = false;
+    return mpResult;
+}
+
+void send_SMS() {
+    //Send SMS
+    
+    gsm.printf("AT+CMGS=\"%s\"\r\n", phoneNumber);
+    wait(.5);
+    gsm.printf("%s%c\r\n", bodyText, buf2);
+    wait(.5);
+    
+    if (messageProcess()==1) {
+        statusMessageAlert = 1;
+        statusMessage = 5;
+        SMScount = SMScount + 1;
+        pc.printf("SMS sent: %d\r\n", SMScount);
+    } else {
+        statusMessageAlert = 1;
+        statusMessage = 7; //This value will also force a auto re-send
+        pc.printf("SMS send failed\r\n");
+    }
+}
+
+
+
+void RetreiveSMS(int smsLoc)
+{
+    char * messageHeader2;
+    char command[20];
+    gsm.autoDetectChar('\a');
+    wait(.5);
+    sprintf(command,"AT+CMGR=%d\r\n",smsLoc);
+    gsm.printf(command);
+    wait(2);
+    int i=0;
+    while(gsm.readable())
+    {
+        messageHeader[i]=gsm.getc();
+        i++;
+    
+    
+    
+    }
+    messageHeader[i]='\0';
+    
+    
+    wait(.5);
+    sprintf(command,"AT+CMGD=%d\r\n",smsLoc);
+    gsm.printf(command);
+    wait(.5);
+    gsm.rxBufferFlush();
+    wait(0.2); 
+    
+    SMS_Rcv=false;
+    SMS_Header_Rcv=false;
+  
+    gsm.autoDetectChar('\n');
+    wait(1);
+    
+    messageHeader2=strtok(messageHeader,"\n");
+   //under here getting SMS header
+    messageHeader2=strtok(NULL,"\n");
+    string SMS_Hdr(messageHeader2);
+    //Under here getting SMS body?
+    messageHeader2=strtok(NULL,"\n");
+    string Rcv_PhoneNum=extract_first_num(SMS_Hdr);
+    string SMS_Body(messageHeader2);
+    SMS_Body.erase(SMS_Body.find_last_not_of(" \n\r\t")+1); 
+    Rcv_PhoneNum.erase(Rcv_PhoneNum.find_last_not_of(" \n\r\t")+1); 
+
+    
+   
+    //gsm.printf(Rcv_PhoneNum.c_str());
+    gsm.printf("AT\r\n");
+    
+    wait(.2);
+    
+    speak("Incoming SMS from ");
+    speak(Rcv_PhoneNum);
+    wait(.5);
+    speak(SMS_Body);
+    wait(1);
+     
+        
+    phoneNumber=Rcv_PhoneNum;
+    bodyText=SMS_Body;
+    
+  
+    messageProcess();
+
+    
+}
+
+
+
+
+
+int main() {
+    messageReceived = false;
+    gsm.baud(19200);
+    gsm.format(8, Serial::None, 1);
+    gsm.attach(&messageReceive, MODSERIAL::RxAutoDetect);     //Attaches Interrupts
+    gsm.autoDetectChar('\n');                                 //Set Detection to Line Feed
+    pc.baud(19200);
+    speakjet.baud(9600);
+    wait(2);
+    
+    
+    dot1.mode(PullUp);
+    dot2.mode(PullUp);
+    dot3.mode(PullUp);
+    dot4.mode(PullUp);
+    dot5.mode(PullUp);
+    dot6.mode(PullUp);
+    dotSp.mode(PullUp);
+    SendSMS.mode(PullUp);
+    wait(0.01);
+    dot1.fall(d1);
+    dot2.fall(d2);
+    dot3.fall(d3);
+    dot4.fall(d4);
+    dot5.fall(d5);
+    dot6.fall(d6);
+    dotSp.setAssertValue( 0 );
+    dotSp.attach_asserted( dSp );
+    SendSMS.setAssertValue(0);
+    SendSMS.attach_asserted(select_SMS_Send);
+    SendSMS.attach_asserted_held( select_SMS_Held );
+
+    dotSp.setSampleFrequency();
+    SendSMS.setSampleFrequency();
+    
+    
+    
+    // Set-UP GSM Modem
+
+    speak("Welcome to S M S Braille O Tron!");
+    wait(1);
+    pc.printf("Setting up GSM Modem\r\n");
+    pc.printf("GSM Modem Setup");
+    wait(1);
+    gsm.printf("AT\r\n");
+    wait(0.5);
+    messageProcess();
+    
+    wait(1);
+    string ExStr = ExampleSentance;
+    bodyText = bparse.translateBraille(ExStr.c_str(),ExStr.length());
+    //send_SMS();
+    wait(4);
+    gsm.printf("AT\r\n");
+    wait(0.5);
+    messageProcess();
+    while (1) {
+   
+    
+    if (SMS_Rcv) 
+    {
+       // pc.printf("SMS RCV\n");
+       messageProcess();
+        RetreiveSMS(SMS_Rcv_loc);
+        wait(2);
+        send_SMS();
+    }
+    
+     
+    
+      
+    if (sendMsgDesired)
+    {
+    speak("Enter Phone Number: ");
+    BrailleIn="a";
+    BrailleIn[0]=0x1;
+    while (!InputDone){ wait(.5);}
+    InputDone=false;
+    phoneNumber = getBrailleInput();
+    phoneNumber = extract_first_num(Braille_Letters_Numbers(phoneNumber));
+    BrailleIn=" ";
+    BrailleIn[0]=127;
+    speak("Enter Message Text: ");
+    while (!InputDone){wait(.5);}
+    
+    InputDone=false;
+    bodyText= getBrailleInput();
+    wait(.5);
+    send_SMS();
+    wait(1);
+    sendMsgDesired=false;
+    }
+    
+          
+  //  gsm.printf("AT\r\n");                     //Check Connection
+    wait(0.5);
+    wait(1);
+    messageProcess();    
+    wait(.5);
+    
+    wait(5);     
+    
+                     //Process incoming message
+    }
+    
+    
+    
+ 
+    return 0;
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Fri Oct 12 18:02:43 2012 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/cd19af002ccc
\ No newline at end of file