SMS Scheduler that will automatically send and receive text messages using the Enfora 1308 GSM Modem. Please note that it uses a modified NetServices library and to set the baud rate for the GSM Modem to 19.2K.

Dependencies:   mbed

Committer:
mafischl
Date:
Thu Oct 13 18:01:31 2011 +0000
Revision:
1:5a7cce9994a3
Parent:
0:d9266031f832

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mafischl 0:d9266031f832 1 /*
mafischl 0:d9266031f832 2 Copyright (c) 2010 Andy Kirkham
mafischl 0:d9266031f832 3
mafischl 0:d9266031f832 4 Permission is hereby granted, free of charge, to any person obtaining a copy
mafischl 0:d9266031f832 5 of this software and associated documentation files (the "Software"), to deal
mafischl 0:d9266031f832 6 in the Software without restriction, including without limitation the rights
mafischl 0:d9266031f832 7 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
mafischl 0:d9266031f832 8 copies of the Software, and to permit persons to whom the Software is
mafischl 0:d9266031f832 9 furnished to do so, subject to the following conditions:
mafischl 0:d9266031f832 10
mafischl 0:d9266031f832 11 The above copyright notice and this permission notice shall be included in
mafischl 0:d9266031f832 12 all copies or substantial portions of the Software.
mafischl 0:d9266031f832 13
mafischl 0:d9266031f832 14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
mafischl 0:d9266031f832 15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
mafischl 0:d9266031f832 16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
mafischl 0:d9266031f832 17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
mafischl 0:d9266031f832 18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
mafischl 0:d9266031f832 19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
mafischl 0:d9266031f832 20 THE SOFTWARE.
mafischl 0:d9266031f832 21 */
mafischl 0:d9266031f832 22
mafischl 0:d9266031f832 23 #include "MODSERIAL.h"
mafischl 0:d9266031f832 24 #include "MACROS.h"
mafischl 0:d9266031f832 25
mafischl 0:d9266031f832 26 namespace AjK {
mafischl 0:d9266031f832 27
mafischl 0:d9266031f832 28 int
mafischl 0:d9266031f832 29 MODSERIAL::__putc(int c, bool block) {
mafischl 0:d9266031f832 30
mafischl 0:d9266031f832 31 // If no buffer is in use fall back to standard TX FIFO usage.
mafischl 0:d9266031f832 32 // Note, we must block in this case and ignore bool "block"
mafischl 0:d9266031f832 33 // so as to maintain compat with Mbed Serial.
mafischl 0:d9266031f832 34 if (buffer[TxIrq] == (char *)NULL || buffer_size[TxIrq] == 0) {
mafischl 0:d9266031f832 35 while (! MODSERIAL_THR_HAS_SPACE) ; // Wait for space in the TX FIFO.
mafischl 0:d9266031f832 36 _THR = (uint32_t)c;
mafischl 0:d9266031f832 37 return 0;
mafischl 0:d9266031f832 38 }
mafischl 0:d9266031f832 39
mafischl 0:d9266031f832 40 if ( MODSERIAL_THR_HAS_SPACE && MODSERIAL_TX_BUFFER_EMPTY && dmaSendChannel == -1 ) {
mafischl 0:d9266031f832 41 _THR = (uint32_t)c;
mafischl 0:d9266031f832 42 }
mafischl 0:d9266031f832 43 else {
mafischl 0:d9266031f832 44 if (block) {
mafischl 0:d9266031f832 45 uint32_t ier = _IER; _IER = 1;
mafischl 0:d9266031f832 46 while ( MODSERIAL_TX_BUFFER_FULL ) { // Blocks!
mafischl 0:d9266031f832 47 // If putc() is called from an ISR then we are stuffed
mafischl 0:d9266031f832 48 // because in an ISR no bytes from the TX buffer will
mafischl 0:d9266031f832 49 // get transferred to teh TX FIFOs while we block here.
mafischl 0:d9266031f832 50 // So, to work around this, instead of sitting in a
mafischl 0:d9266031f832 51 // loop waiting for space in the TX buffer (which will
mafischl 0:d9266031f832 52 // never happen in IRQ context), check to see if the
mafischl 0:d9266031f832 53 // TX FIFO has space available to move bytes from the
mafischl 0:d9266031f832 54 // TX buffer to TX FIFO to make space. The easiest way
mafischl 0:d9266031f832 55 // to do this is to poll the isr_tx() function while we
mafischl 0:d9266031f832 56 // are blocking.
mafischl 0:d9266031f832 57 isr_tx(false);
mafischl 0:d9266031f832 58 }
mafischl 0:d9266031f832 59 _IER = ier;
mafischl 0:d9266031f832 60 }
mafischl 0:d9266031f832 61 else if( MODSERIAL_TX_BUFFER_FULL ) {
mafischl 0:d9266031f832 62 buffer_overflow[TxIrq] = c; // Oh dear, no room in buffer.
mafischl 0:d9266031f832 63 _isr[TxOvIrq].call(&this->callbackInfo);
mafischl 0:d9266031f832 64 return -1;
mafischl 0:d9266031f832 65 }
mafischl 0:d9266031f832 66 _IER &= ~2;
mafischl 0:d9266031f832 67 buffer[TxIrq][buffer_in[TxIrq]] = c;
mafischl 0:d9266031f832 68 buffer_count[TxIrq]++;
mafischl 0:d9266031f832 69 buffer_in[TxIrq]++;
mafischl 0:d9266031f832 70 if (buffer_in[TxIrq] >= buffer_size[TxIrq]) {
mafischl 0:d9266031f832 71 buffer_in[TxIrq] = 0;
mafischl 0:d9266031f832 72 }
mafischl 0:d9266031f832 73 _IER |= 2;
mafischl 0:d9266031f832 74 }
mafischl 0:d9266031f832 75
mafischl 0:d9266031f832 76 return 0;
mafischl 0:d9266031f832 77 }
mafischl 0:d9266031f832 78
mafischl 0:d9266031f832 79 }; // namespace AjK ends