Integrating the ublox LISA C200 modem

Fork of SprintUSBModemHTTPClientTest by Donatien Garnier

Committer:
sam_grove
Date:
Thu Sep 26 00:44:20 2013 -0500
Revision:
5:3f93dd1d4cb3
Exported program and replaced contents of the repo with the source
to build and debug using keil mdk. Libs NOT upto date are lwip, lwip-sys
and socket. these have newer versions under mbed_official but were starting
from a know working point

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sam_grove 5:3f93dd1d4cb3 1 /* mbed Microcontroller Library
sam_grove 5:3f93dd1d4cb3 2 * Copyright (c) 2006-2013 ARM Limited
sam_grove 5:3f93dd1d4cb3 3 *
sam_grove 5:3f93dd1d4cb3 4 * Licensed under the Apache License, Version 2.0 (the "License");
sam_grove 5:3f93dd1d4cb3 5 * you may not use this file except in compliance with the License.
sam_grove 5:3f93dd1d4cb3 6 * You may obtain a copy of the License at
sam_grove 5:3f93dd1d4cb3 7 *
sam_grove 5:3f93dd1d4cb3 8 * http://www.apache.org/licenses/LICENSE-2.0
sam_grove 5:3f93dd1d4cb3 9 *
sam_grove 5:3f93dd1d4cb3 10 * Unless required by applicable law or agreed to in writing, software
sam_grove 5:3f93dd1d4cb3 11 * distributed under the License is distributed on an "AS IS" BASIS,
sam_grove 5:3f93dd1d4cb3 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
sam_grove 5:3f93dd1d4cb3 13 * See the License for the specific language governing permissions and
sam_grove 5:3f93dd1d4cb3 14 * limitations under the License.
sam_grove 5:3f93dd1d4cb3 15 */
sam_grove 5:3f93dd1d4cb3 16 #ifndef MBED_SERIAL_H
sam_grove 5:3f93dd1d4cb3 17 #define MBED_SERIAL_H
sam_grove 5:3f93dd1d4cb3 18
sam_grove 5:3f93dd1d4cb3 19 #include "platform.h"
sam_grove 5:3f93dd1d4cb3 20
sam_grove 5:3f93dd1d4cb3 21 #if DEVICE_SERIAL
sam_grove 5:3f93dd1d4cb3 22
sam_grove 5:3f93dd1d4cb3 23 #include "Stream.h"
sam_grove 5:3f93dd1d4cb3 24 #include "FunctionPointer.h"
sam_grove 5:3f93dd1d4cb3 25 #include "serial_api.h"
sam_grove 5:3f93dd1d4cb3 26 #include "CallChain.h"
sam_grove 5:3f93dd1d4cb3 27
sam_grove 5:3f93dd1d4cb3 28 namespace mbed {
sam_grove 5:3f93dd1d4cb3 29
sam_grove 5:3f93dd1d4cb3 30 /** A serial port (UART) for communication with other serial devices
sam_grove 5:3f93dd1d4cb3 31 *
sam_grove 5:3f93dd1d4cb3 32 * Can be used for Full Duplex communication, or Simplex by specifying
sam_grove 5:3f93dd1d4cb3 33 * one pin as NC (Not Connected)
sam_grove 5:3f93dd1d4cb3 34 *
sam_grove 5:3f93dd1d4cb3 35 * Example:
sam_grove 5:3f93dd1d4cb3 36 * @code
sam_grove 5:3f93dd1d4cb3 37 * // Print "Hello World" to the PC
sam_grove 5:3f93dd1d4cb3 38 *
sam_grove 5:3f93dd1d4cb3 39 * #include "mbed.h"
sam_grove 5:3f93dd1d4cb3 40 *
sam_grove 5:3f93dd1d4cb3 41 * Serial pc(USBTX, USBRX);
sam_grove 5:3f93dd1d4cb3 42 *
sam_grove 5:3f93dd1d4cb3 43 * int main() {
sam_grove 5:3f93dd1d4cb3 44 * pc.printf("Hello World\n");
sam_grove 5:3f93dd1d4cb3 45 * }
sam_grove 5:3f93dd1d4cb3 46 * @endcode
sam_grove 5:3f93dd1d4cb3 47 */
sam_grove 5:3f93dd1d4cb3 48 class Serial : public Stream {
sam_grove 5:3f93dd1d4cb3 49
sam_grove 5:3f93dd1d4cb3 50 public:
sam_grove 5:3f93dd1d4cb3 51 /** Create a Serial port, connected to the specified transmit and receive pins
sam_grove 5:3f93dd1d4cb3 52 *
sam_grove 5:3f93dd1d4cb3 53 * @param tx Transmit pin
sam_grove 5:3f93dd1d4cb3 54 * @param rx Receive pin
sam_grove 5:3f93dd1d4cb3 55 *
sam_grove 5:3f93dd1d4cb3 56 * @note
sam_grove 5:3f93dd1d4cb3 57 * Either tx or rx may be specified as NC if unused
sam_grove 5:3f93dd1d4cb3 58 */
sam_grove 5:3f93dd1d4cb3 59 Serial(PinName tx, PinName rx, const char *name=NULL);
sam_grove 5:3f93dd1d4cb3 60
sam_grove 5:3f93dd1d4cb3 61 /** Set the baud rate of the serial port
sam_grove 5:3f93dd1d4cb3 62 *
sam_grove 5:3f93dd1d4cb3 63 * @param baudrate The baudrate of the serial port (default = 9600).
sam_grove 5:3f93dd1d4cb3 64 */
sam_grove 5:3f93dd1d4cb3 65 void baud(int baudrate);
sam_grove 5:3f93dd1d4cb3 66
sam_grove 5:3f93dd1d4cb3 67 enum Parity {
sam_grove 5:3f93dd1d4cb3 68 None = 0,
sam_grove 5:3f93dd1d4cb3 69 Odd,
sam_grove 5:3f93dd1d4cb3 70 Even,
sam_grove 5:3f93dd1d4cb3 71 Forced1,
sam_grove 5:3f93dd1d4cb3 72 Forced0
sam_grove 5:3f93dd1d4cb3 73 };
sam_grove 5:3f93dd1d4cb3 74
sam_grove 5:3f93dd1d4cb3 75 enum IrqType {
sam_grove 5:3f93dd1d4cb3 76 RxIrq = 0,
sam_grove 5:3f93dd1d4cb3 77 TxIrq
sam_grove 5:3f93dd1d4cb3 78 };
sam_grove 5:3f93dd1d4cb3 79
sam_grove 5:3f93dd1d4cb3 80 /** Set the transmission format used by the Serial port
sam_grove 5:3f93dd1d4cb3 81 *
sam_grove 5:3f93dd1d4cb3 82 * @param bits The number of bits in a word (5-8; default = 8)
sam_grove 5:3f93dd1d4cb3 83 * @param parity The parity used (Serial::None, Serial::Odd, Serial::Even, Serial::Forced1, Serial::Forced0; default = Serial::None)
sam_grove 5:3f93dd1d4cb3 84 * @param stop The number of stop bits (1 or 2; default = 1)
sam_grove 5:3f93dd1d4cb3 85 */
sam_grove 5:3f93dd1d4cb3 86 void format(int bits=8, Parity parity=Serial::None, int stop_bits=1);
sam_grove 5:3f93dd1d4cb3 87
sam_grove 5:3f93dd1d4cb3 88 /** Determine if there is a character available to read
sam_grove 5:3f93dd1d4cb3 89 *
sam_grove 5:3f93dd1d4cb3 90 * @returns
sam_grove 5:3f93dd1d4cb3 91 * 1 if there is a character available to read,
sam_grove 5:3f93dd1d4cb3 92 * 0 otherwise
sam_grove 5:3f93dd1d4cb3 93 */
sam_grove 5:3f93dd1d4cb3 94 int readable();
sam_grove 5:3f93dd1d4cb3 95
sam_grove 5:3f93dd1d4cb3 96 /** Determine if there is space available to write a character
sam_grove 5:3f93dd1d4cb3 97 *
sam_grove 5:3f93dd1d4cb3 98 * @returns
sam_grove 5:3f93dd1d4cb3 99 * 1 if there is space to write a character,
sam_grove 5:3f93dd1d4cb3 100 * 0 otherwise
sam_grove 5:3f93dd1d4cb3 101 */
sam_grove 5:3f93dd1d4cb3 102 int writeable();
sam_grove 5:3f93dd1d4cb3 103
sam_grove 5:3f93dd1d4cb3 104 /** Attach a function to call whenever a serial interrupt is generated
sam_grove 5:3f93dd1d4cb3 105 *
sam_grove 5:3f93dd1d4cb3 106 * @param fptr A pointer to a void function, or 0 to set as none
sam_grove 5:3f93dd1d4cb3 107 * @param type Which serial interrupt to attach the member function to (Seriall::RxIrq for receive, TxIrq for transmit buffer empty)
sam_grove 5:3f93dd1d4cb3 108 *
sam_grove 5:3f93dd1d4cb3 109 * @returns
sam_grove 5:3f93dd1d4cb3 110 * The function object created for 'fptr'
sam_grove 5:3f93dd1d4cb3 111 */
sam_grove 5:3f93dd1d4cb3 112 pFunctionPointer_t attach(void (*fptr)(void), IrqType type=RxIrq);
sam_grove 5:3f93dd1d4cb3 113
sam_grove 5:3f93dd1d4cb3 114 /** Add a function to be called when a serial interrupt is generated at the end of the call chain
sam_grove 5:3f93dd1d4cb3 115 *
sam_grove 5:3f93dd1d4cb3 116 * @param fptr the function to add
sam_grove 5:3f93dd1d4cb3 117 * @param type Which serial interrupt to attach the member function to (Seriall::RxIrq for receive, TxIrq for transmit buffer empty)
sam_grove 5:3f93dd1d4cb3 118 *
sam_grove 5:3f93dd1d4cb3 119 * @returns
sam_grove 5:3f93dd1d4cb3 120 * The function object created for 'fptr'
sam_grove 5:3f93dd1d4cb3 121 */
sam_grove 5:3f93dd1d4cb3 122 pFunctionPointer_t add_handler(void (*fptr)(void), IrqType type=RxIrq) {
sam_grove 5:3f93dd1d4cb3 123 return add_handler_helper(fptr, type);
sam_grove 5:3f93dd1d4cb3 124 }
sam_grove 5:3f93dd1d4cb3 125
sam_grove 5:3f93dd1d4cb3 126 /** Add a function to be called when a serial interrupt is generated at the beginning of the call chain
sam_grove 5:3f93dd1d4cb3 127 *
sam_grove 5:3f93dd1d4cb3 128 * @param fptr the function to add
sam_grove 5:3f93dd1d4cb3 129 * @param type Which serial interrupt to attach the member function to (Seriall::RxIrq for receive, TxIrq for transmit buffer empty)
sam_grove 5:3f93dd1d4cb3 130 *
sam_grove 5:3f93dd1d4cb3 131 * @returns
sam_grove 5:3f93dd1d4cb3 132 * The function object created for 'fptr'
sam_grove 5:3f93dd1d4cb3 133 */
sam_grove 5:3f93dd1d4cb3 134 pFunctionPointer_t add_handler_front(void (*fptr)(void), IrqType type=RxIrq) {
sam_grove 5:3f93dd1d4cb3 135 return add_handler_helper(fptr, type, true);
sam_grove 5:3f93dd1d4cb3 136 }
sam_grove 5:3f93dd1d4cb3 137
sam_grove 5:3f93dd1d4cb3 138 /** Attach a member function to call whenever a serial interrupt is generated
sam_grove 5:3f93dd1d4cb3 139 *
sam_grove 5:3f93dd1d4cb3 140 * @param tptr pointer to the object to call the member function on
sam_grove 5:3f93dd1d4cb3 141 * @param mptr pointer to the member function to be called
sam_grove 5:3f93dd1d4cb3 142 * @param type Which serial interrupt to attach the member function to (Seriall::RxIrq for receive, TxIrq for transmit buffer empty)
sam_grove 5:3f93dd1d4cb3 143 *
sam_grove 5:3f93dd1d4cb3 144 * @param
sam_grove 5:3f93dd1d4cb3 145 * The function object created for 'tptr' and 'mptr'
sam_grove 5:3f93dd1d4cb3 146 */
sam_grove 5:3f93dd1d4cb3 147 template<typename T>
sam_grove 5:3f93dd1d4cb3 148 pFunctionPointer_t attach(T* tptr, void (T::*mptr)(void), IrqType type=RxIrq) {
sam_grove 5:3f93dd1d4cb3 149 if((mptr != NULL) && (tptr != NULL)) {
sam_grove 5:3f93dd1d4cb3 150 _irq[type].clear();
sam_grove 5:3f93dd1d4cb3 151 pFunctionPointer_t pf = _irq[type].add(tptr, mptr);
sam_grove 5:3f93dd1d4cb3 152 serial_irq_set(&_serial, (SerialIrq)type, 1);
sam_grove 5:3f93dd1d4cb3 153 return pf;
sam_grove 5:3f93dd1d4cb3 154 }
sam_grove 5:3f93dd1d4cb3 155 else
sam_grove 5:3f93dd1d4cb3 156 return NULL;
sam_grove 5:3f93dd1d4cb3 157 }
sam_grove 5:3f93dd1d4cb3 158
sam_grove 5:3f93dd1d4cb3 159 /** Add a function to be called when a serial interrupt is generated at the end of the call chain
sam_grove 5:3f93dd1d4cb3 160 *
sam_grove 5:3f93dd1d4cb3 161 * @param tptr pointer to the object to call the member function on
sam_grove 5:3f93dd1d4cb3 162 * @param mptr pointer to the member function to be called
sam_grove 5:3f93dd1d4cb3 163 * @param type Which serial interrupt to attach the member function to (Seriall::RxIrq for receive, TxIrq for transmit buffer empty)
sam_grove 5:3f93dd1d4cb3 164 *
sam_grove 5:3f93dd1d4cb3 165 * @returns
sam_grove 5:3f93dd1d4cb3 166 * The function object created for 'fptr'
sam_grove 5:3f93dd1d4cb3 167 */
sam_grove 5:3f93dd1d4cb3 168 template<typename T>
sam_grove 5:3f93dd1d4cb3 169 pFunctionPointer_t add_handler(T* tptr, void (T::*mptr)(void), IrqType type=RxIrq) {
sam_grove 5:3f93dd1d4cb3 170 return add_handler_helper(tptr, mptr, type);
sam_grove 5:3f93dd1d4cb3 171 }
sam_grove 5:3f93dd1d4cb3 172
sam_grove 5:3f93dd1d4cb3 173 /** Add a function to be called when a serial interrupt is generated at the beginning of the call chain
sam_grove 5:3f93dd1d4cb3 174 *
sam_grove 5:3f93dd1d4cb3 175 * @param tptr pointer to the object to call the member function on
sam_grove 5:3f93dd1d4cb3 176 * @param mptr pointer to the member function to be called
sam_grove 5:3f93dd1d4cb3 177 * @param type Which serial interrupt to attach the member function to (Seriall::RxIrq for receive, TxIrq for transmit buffer empty)
sam_grove 5:3f93dd1d4cb3 178 *
sam_grove 5:3f93dd1d4cb3 179 * @returns
sam_grove 5:3f93dd1d4cb3 180 * The function object created for 'fptr'
sam_grove 5:3f93dd1d4cb3 181 */
sam_grove 5:3f93dd1d4cb3 182 template<typename T>
sam_grove 5:3f93dd1d4cb3 183 pFunctionPointer_t add_handler_front(T* tptr, void (T::*mptr)(void), IrqType type=RxIrq) {
sam_grove 5:3f93dd1d4cb3 184 return add_handler_helper(tptr, mptr, type, true);
sam_grove 5:3f93dd1d4cb3 185 }
sam_grove 5:3f93dd1d4cb3 186
sam_grove 5:3f93dd1d4cb3 187 /** Remove a function from the list of functions to be called when a serial interrupt is generated
sam_grove 5:3f93dd1d4cb3 188 *
sam_grove 5:3f93dd1d4cb3 189 * @param pf the function object to remove
sam_grove 5:3f93dd1d4cb3 190 * @param type Which serial interrupt to attach the member function to (Seriall::RxIrq for receive, TxIrq for transmit buffer empty)
sam_grove 5:3f93dd1d4cb3 191 *
sam_grove 5:3f93dd1d4cb3 192 * @returns
sam_grove 5:3f93dd1d4cb3 193 * true if the function was found and removed, false otherwise
sam_grove 5:3f93dd1d4cb3 194 */
sam_grove 5:3f93dd1d4cb3 195 bool remove_handler(pFunctionPointer_t pf, IrqType type=RxIrq);
sam_grove 5:3f93dd1d4cb3 196
sam_grove 5:3f93dd1d4cb3 197 /** Generate a break condition on the serial line
sam_grove 5:3f93dd1d4cb3 198 */
sam_grove 5:3f93dd1d4cb3 199 void send_break();
sam_grove 5:3f93dd1d4cb3 200
sam_grove 5:3f93dd1d4cb3 201 static void _irq_handler(uint32_t id, SerialIrq irq_type);
sam_grove 5:3f93dd1d4cb3 202
sam_grove 5:3f93dd1d4cb3 203 protected:
sam_grove 5:3f93dd1d4cb3 204 virtual int _getc();
sam_grove 5:3f93dd1d4cb3 205 virtual int _putc(int c);
sam_grove 5:3f93dd1d4cb3 206 pFunctionPointer_t add_handler_helper(void (*function)(void), IrqType type, bool front=false);
sam_grove 5:3f93dd1d4cb3 207
sam_grove 5:3f93dd1d4cb3 208 template<typename T>
sam_grove 5:3f93dd1d4cb3 209 pFunctionPointer_t add_handler_helper(T* tptr, void (T::*mptr)(void), IrqType type, bool front=false) {
sam_grove 5:3f93dd1d4cb3 210 if ((mptr != NULL) && (tptr != NULL)) {
sam_grove 5:3f93dd1d4cb3 211 pFunctionPointer_t pf = front ? _irq[type].add_front(tptr, mptr) : _irq[type].add(tptr, mptr);
sam_grove 5:3f93dd1d4cb3 212 serial_irq_set(&_serial, (SerialIrq)type, 1);
sam_grove 5:3f93dd1d4cb3 213 return pf;
sam_grove 5:3f93dd1d4cb3 214 }
sam_grove 5:3f93dd1d4cb3 215 else
sam_grove 5:3f93dd1d4cb3 216 return NULL;
sam_grove 5:3f93dd1d4cb3 217 }
sam_grove 5:3f93dd1d4cb3 218
sam_grove 5:3f93dd1d4cb3 219 serial_t _serial;
sam_grove 5:3f93dd1d4cb3 220 CallChain _irq[2];
sam_grove 5:3f93dd1d4cb3 221 int _baud;
sam_grove 5:3f93dd1d4cb3 222 };
sam_grove 5:3f93dd1d4cb3 223
sam_grove 5:3f93dd1d4cb3 224 } // namespace mbed
sam_grove 5:3f93dd1d4cb3 225
sam_grove 5:3f93dd1d4cb3 226 #endif
sam_grove 5:3f93dd1d4cb3 227
sam_grove 5:3f93dd1d4cb3 228 #endif