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.
MODSERIAL/MODSERIAL.cpp@0:d9266031f832, 2011-10-13 (annotated)
- Committer:
- mafischl
- Date:
- Thu Oct 13 17:02:29 2011 +0000
- Revision:
- 0:d9266031f832
Who changed what in which revision?
User | Revision | Line number | New 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 | @file MODSERIAL.h |
mafischl | 0:d9266031f832 | 23 | @purpose Extends Serial to provide fully buffered IO |
mafischl | 0:d9266031f832 | 24 | @version 1.6 |
mafischl | 0:d9266031f832 | 25 | @date Nov 2010 |
mafischl | 0:d9266031f832 | 26 | @author Andy Kirkham |
mafischl | 0:d9266031f832 | 27 | */ |
mafischl | 0:d9266031f832 | 28 | |
mafischl | 0:d9266031f832 | 29 | #include "MODSERIAL.h" |
mafischl | 0:d9266031f832 | 30 | #include "MACROS.h" |
mafischl | 0:d9266031f832 | 31 | |
mafischl | 0:d9266031f832 | 32 | namespace AjK { |
mafischl | 0:d9266031f832 | 33 | |
mafischl | 0:d9266031f832 | 34 | MODSERIAL::MODSERIAL(PinName tx, PinName rx, const char *name) : Serial(tx, rx, name) |
mafischl | 0:d9266031f832 | 35 | { |
mafischl | 0:d9266031f832 | 36 | init(MODSERIAL_DEFAULT_TX_BUFFER_SIZE, MODSERIAL_DEFAULT_RX_BUFFER_SIZE); |
mafischl | 0:d9266031f832 | 37 | } |
mafischl | 0:d9266031f832 | 38 | |
mafischl | 0:d9266031f832 | 39 | MODSERIAL::MODSERIAL(PinName tx, PinName rx, int bufferSize, const char *name) : Serial(tx, rx, name) |
mafischl | 0:d9266031f832 | 40 | { |
mafischl | 0:d9266031f832 | 41 | init(bufferSize, bufferSize); |
mafischl | 0:d9266031f832 | 42 | } |
mafischl | 0:d9266031f832 | 43 | |
mafischl | 0:d9266031f832 | 44 | MODSERIAL::MODSERIAL(PinName tx, PinName rx, int txSize, int rxSize, const char *name) : Serial(tx, rx, name) |
mafischl | 0:d9266031f832 | 45 | { |
mafischl | 0:d9266031f832 | 46 | init(txSize, rxSize); |
mafischl | 0:d9266031f832 | 47 | } |
mafischl | 0:d9266031f832 | 48 | |
mafischl | 0:d9266031f832 | 49 | MODSERIAL::~MODSERIAL() |
mafischl | 0:d9266031f832 | 50 | { |
mafischl | 0:d9266031f832 | 51 | disableIrq(); |
mafischl | 0:d9266031f832 | 52 | if (buffer[0] != NULL) free((char *)buffer[0]); |
mafischl | 0:d9266031f832 | 53 | if (buffer[1] != NULL) free((char *)buffer[1]); |
mafischl | 0:d9266031f832 | 54 | } |
mafischl | 0:d9266031f832 | 55 | |
mafischl | 0:d9266031f832 | 56 | bool |
mafischl | 0:d9266031f832 | 57 | MODSERIAL::txBufferFull(void) |
mafischl | 0:d9266031f832 | 58 | { |
mafischl | 0:d9266031f832 | 59 | return MODSERIAL_TX_BUFFER_FULL; |
mafischl | 0:d9266031f832 | 60 | } |
mafischl | 0:d9266031f832 | 61 | |
mafischl | 0:d9266031f832 | 62 | bool |
mafischl | 0:d9266031f832 | 63 | MODSERIAL::rxBufferFull(void) |
mafischl | 0:d9266031f832 | 64 | { |
mafischl | 0:d9266031f832 | 65 | return MODSERIAL_RX_BUFFER_FULL; |
mafischl | 0:d9266031f832 | 66 | } |
mafischl | 0:d9266031f832 | 67 | |
mafischl | 0:d9266031f832 | 68 | bool |
mafischl | 0:d9266031f832 | 69 | MODSERIAL::txBufferEmpty(void) |
mafischl | 0:d9266031f832 | 70 | { |
mafischl | 0:d9266031f832 | 71 | return MODSERIAL_TX_BUFFER_EMPTY; |
mafischl | 0:d9266031f832 | 72 | } |
mafischl | 0:d9266031f832 | 73 | |
mafischl | 0:d9266031f832 | 74 | bool |
mafischl | 0:d9266031f832 | 75 | MODSERIAL::rxBufferEmpty(void) |
mafischl | 0:d9266031f832 | 76 | { |
mafischl | 0:d9266031f832 | 77 | return MODSERIAL_RX_BUFFER_EMPTY; |
mafischl | 0:d9266031f832 | 78 | } |
mafischl | 0:d9266031f832 | 79 | |
mafischl | 0:d9266031f832 | 80 | bool |
mafischl | 0:d9266031f832 | 81 | MODSERIAL::txIsBusy(void) |
mafischl | 0:d9266031f832 | 82 | { |
mafischl | 0:d9266031f832 | 83 | return (_LSR & (3UL << 5) == 0) ? true : false; |
mafischl | 0:d9266031f832 | 84 | } |
mafischl | 0:d9266031f832 | 85 | |
mafischl | 0:d9266031f832 | 86 | void |
mafischl | 0:d9266031f832 | 87 | MODSERIAL::disableIrq(void) |
mafischl | 0:d9266031f832 | 88 | { |
mafischl | 0:d9266031f832 | 89 | switch(_uidx) { |
mafischl | 0:d9266031f832 | 90 | case 0: NVIC_DisableIRQ(UART0_IRQn); break; |
mafischl | 0:d9266031f832 | 91 | case 1: NVIC_DisableIRQ(UART1_IRQn); break; |
mafischl | 0:d9266031f832 | 92 | case 2: NVIC_DisableIRQ(UART2_IRQn); break; |
mafischl | 0:d9266031f832 | 93 | case 3: NVIC_DisableIRQ(UART3_IRQn); break; |
mafischl | 0:d9266031f832 | 94 | } |
mafischl | 0:d9266031f832 | 95 | } |
mafischl | 0:d9266031f832 | 96 | |
mafischl | 0:d9266031f832 | 97 | void |
mafischl | 0:d9266031f832 | 98 | MODSERIAL::enableIrq(void) |
mafischl | 0:d9266031f832 | 99 | { |
mafischl | 0:d9266031f832 | 100 | switch(_uidx) { |
mafischl | 0:d9266031f832 | 101 | case 0: NVIC_EnableIRQ(UART0_IRQn); break; |
mafischl | 0:d9266031f832 | 102 | case 1: NVIC_EnableIRQ(UART1_IRQn); break; |
mafischl | 0:d9266031f832 | 103 | case 2: NVIC_EnableIRQ(UART2_IRQn); break; |
mafischl | 0:d9266031f832 | 104 | case 3: NVIC_EnableIRQ(UART3_IRQn); break; |
mafischl | 0:d9266031f832 | 105 | } |
mafischl | 0:d9266031f832 | 106 | } |
mafischl | 0:d9266031f832 | 107 | |
mafischl | 0:d9266031f832 | 108 | int |
mafischl | 0:d9266031f832 | 109 | MODSERIAL::rxDiscardLastChar(void) |
mafischl | 0:d9266031f832 | 110 | { |
mafischl | 0:d9266031f832 | 111 | // This function can only be called indirectly from |
mafischl | 0:d9266031f832 | 112 | // an rxCallback function. Therefore, we know we |
mafischl | 0:d9266031f832 | 113 | // just placed a char into the buffer. |
mafischl | 0:d9266031f832 | 114 | char c = buffer[RxIrq][buffer_in[RxIrq]]; |
mafischl | 0:d9266031f832 | 115 | |
mafischl | 0:d9266031f832 | 116 | if (buffer_count[RxIrq]) { |
mafischl | 0:d9266031f832 | 117 | buffer_count[RxIrq]--; |
mafischl | 0:d9266031f832 | 118 | buffer_in[RxIrq]--; |
mafischl | 0:d9266031f832 | 119 | if (buffer_in[RxIrq] < 0) { |
mafischl | 0:d9266031f832 | 120 | buffer_in[RxIrq] = buffer_size[RxIrq] - 1; |
mafischl | 0:d9266031f832 | 121 | } |
mafischl | 0:d9266031f832 | 122 | } |
mafischl | 0:d9266031f832 | 123 | |
mafischl | 0:d9266031f832 | 124 | return (int)c; |
mafischl | 0:d9266031f832 | 125 | } |
mafischl | 0:d9266031f832 | 126 | |
mafischl | 0:d9266031f832 | 127 | |
mafischl | 0:d9266031f832 | 128 | }; // namespace AjK ends |