Added support for WNC M14A2A Cellular LTE Data Module.

Dependencies:   WNC14A2AInterface

Dependents:   http-example-wnc http-example-wnc-modified

Committer:
root@developer-sjc-cyan-compiler.local.mbed.org
Date:
Sun Apr 23 18:40:51 2017 +0000
Revision:
5:391eac6a0a94
Parent:
0:2563b0415d1f
Added tag att_cellular_K64_wnc_14A2A_20170423 for changeset daf182af022b

Who changed what in which revision?

UserRevisionLine numberNew contents of line
JMF 0:2563b0415d1f 1
JMF 0:2563b0415d1f 2 /**
JMF 0:2563b0415d1f 3 * @file BufferedSerial.h
JMF 0:2563b0415d1f 4 * @brief Software Buffer - Extends mbed Serial functionallity adding irq driven TX and RX
JMF 0:2563b0415d1f 5 * @author sam grove
JMF 0:2563b0415d1f 6 * @version 1.0
JMF 0:2563b0415d1f 7 * @see
JMF 0:2563b0415d1f 8 *
JMF 0:2563b0415d1f 9 * Copyright (c) 2013
JMF 0:2563b0415d1f 10 *
JMF 0:2563b0415d1f 11 * Licensed under the Apache License, Version 2.0 (the "License");
JMF 0:2563b0415d1f 12 * you may not use this file except in compliance with the License.
JMF 0:2563b0415d1f 13 * You may obtain a copy of the License at
JMF 0:2563b0415d1f 14 *
JMF 0:2563b0415d1f 15 * http://www.apache.org/licenses/LICENSE-2.0
JMF 0:2563b0415d1f 16 *
JMF 0:2563b0415d1f 17 * Unless required by applicable law or agreed to in writing, software
JMF 0:2563b0415d1f 18 * distributed under the License is distributed on an "AS IS" BASIS,
JMF 0:2563b0415d1f 19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
JMF 0:2563b0415d1f 20 * See the License for the specific language governing permissions and
JMF 0:2563b0415d1f 21 * limitations under the License.
JMF 0:2563b0415d1f 22 */
JMF 0:2563b0415d1f 23
JMF 0:2563b0415d1f 24 #ifndef BUFFEREDSERIAL_H
JMF 0:2563b0415d1f 25 #define BUFFEREDSERIAL_H
JMF 0:2563b0415d1f 26
JMF 0:2563b0415d1f 27 #include "mbed.h"
JMF 0:2563b0415d1f 28 #include "MyBuffer.h"
JMF 0:2563b0415d1f 29
JMF 0:2563b0415d1f 30 /** A serial port (UART) for communication with other serial devices
JMF 0:2563b0415d1f 31 *
JMF 0:2563b0415d1f 32 * Can be used for Full Duplex communication, or Simplex by specifying
JMF 0:2563b0415d1f 33 * one pin as NC (Not Connected)
JMF 0:2563b0415d1f 34 *
JMF 0:2563b0415d1f 35 * Example:
JMF 0:2563b0415d1f 36 * @code
JMF 0:2563b0415d1f 37 * #include "mbed.h"
JMF 0:2563b0415d1f 38 * #include "BufferedSerial.h"
JMF 0:2563b0415d1f 39 *
JMF 0:2563b0415d1f 40 * BufferedSerial pc(USBTX, USBRX);
JMF 0:2563b0415d1f 41 *
JMF 0:2563b0415d1f 42 * int main()
JMF 0:2563b0415d1f 43 * {
JMF 0:2563b0415d1f 44 * while(1)
JMF 0:2563b0415d1f 45 * {
JMF 0:2563b0415d1f 46 * Timer s;
JMF 0:2563b0415d1f 47 *
JMF 0:2563b0415d1f 48 * s.start();
JMF 0:2563b0415d1f 49 * pc.printf("Hello World - buffered\n");
JMF 0:2563b0415d1f 50 * int buffered_time = s.read_us();
JMF 0:2563b0415d1f 51 * wait(0.1f); // give time for the buffer to empty
JMF 0:2563b0415d1f 52 *
JMF 0:2563b0415d1f 53 * s.reset();
JMF 0:2563b0415d1f 54 * printf("Hello World - blocking\n");
JMF 0:2563b0415d1f 55 * int polled_time = s.read_us();
JMF 0:2563b0415d1f 56 * s.stop();
JMF 0:2563b0415d1f 57 * wait(0.1f); // give time for the buffer to empty
JMF 0:2563b0415d1f 58 *
JMF 0:2563b0415d1f 59 * pc.printf("printf buffered took %d us\n", buffered_time);
JMF 0:2563b0415d1f 60 * pc.printf("printf blocking took %d us\n", polled_time);
JMF 0:2563b0415d1f 61 * wait(0.5f);
JMF 0:2563b0415d1f 62 * }
JMF 0:2563b0415d1f 63 * }
JMF 0:2563b0415d1f 64 * @endcode
JMF 0:2563b0415d1f 65 */
JMF 0:2563b0415d1f 66
JMF 0:2563b0415d1f 67 /**
JMF 0:2563b0415d1f 68 * @class BufferedSerial
JMF 0:2563b0415d1f 69 * @brief Software buffers and interrupt driven tx and rx for Serial
JMF 0:2563b0415d1f 70 */
JMF 0:2563b0415d1f 71 class BufferedSerial : public RawSerial
JMF 0:2563b0415d1f 72 {
JMF 0:2563b0415d1f 73 private:
JMF 0:2563b0415d1f 74 MyBuffer <char> _rxbuf;
JMF 0:2563b0415d1f 75 MyBuffer <char> _txbuf;
JMF 0:2563b0415d1f 76 uint32_t _buf_size;
JMF 0:2563b0415d1f 77 uint32_t _tx_multiple;
JMF 0:2563b0415d1f 78
JMF 0:2563b0415d1f 79 void rxIrq(void);
JMF 0:2563b0415d1f 80 void txIrq(void);
JMF 0:2563b0415d1f 81 void prime(void);
JMF 0:2563b0415d1f 82
JMF 0:2563b0415d1f 83 Callback<void()> _cbs[2];
JMF 0:2563b0415d1f 84
JMF 0:2563b0415d1f 85 public:
JMF 0:2563b0415d1f 86 /** Create a BufferedSerial port, connected to the specified transmit and receive pins
JMF 0:2563b0415d1f 87 * @param tx Transmit pin
JMF 0:2563b0415d1f 88 * @param rx Receive pin
JMF 0:2563b0415d1f 89 * @param buf_size printf() buffer size
JMF 0:2563b0415d1f 90 * @param tx_multiple amount of max printf() present in the internal ring buffer at one time
JMF 0:2563b0415d1f 91 * @param name optional name
JMF 0:2563b0415d1f 92 * @note Either tx or rx may be specified as NC if unused
JMF 0:2563b0415d1f 93 */
JMF 0:2563b0415d1f 94 BufferedSerial(PinName tx, PinName rx, uint32_t buf_size = 256, uint32_t tx_multiple = 4,const char* name=NULL);
JMF 0:2563b0415d1f 95
JMF 0:2563b0415d1f 96 /** Destroy a BufferedSerial port
JMF 0:2563b0415d1f 97 */
JMF 0:2563b0415d1f 98 virtual ~BufferedSerial(void);
JMF 0:2563b0415d1f 99
JMF 0:2563b0415d1f 100 /** Check on how many bytes are in the rx buffer
JMF 0:2563b0415d1f 101 * @return 1 if something exists, 0 otherwise
JMF 0:2563b0415d1f 102 */
JMF 0:2563b0415d1f 103 virtual int readable(void);
JMF 0:2563b0415d1f 104
JMF 0:2563b0415d1f 105 /** Check to see if the tx buffer has room
JMF 0:2563b0415d1f 106 * @return 1 always has room and can overwrite previous content if too small / slow
JMF 0:2563b0415d1f 107 */
JMF 0:2563b0415d1f 108 virtual int writeable(void);
JMF 0:2563b0415d1f 109
JMF 0:2563b0415d1f 110 /** Get a single byte from the BufferedSerial Port.
JMF 0:2563b0415d1f 111 * Should check readable() before calling this.
JMF 0:2563b0415d1f 112 * @return A byte that came in on the Serial Port
JMF 0:2563b0415d1f 113 */
JMF 0:2563b0415d1f 114 virtual int getc(void);
JMF 0:2563b0415d1f 115
JMF 0:2563b0415d1f 116 /** Write a single byte to the BufferedSerial Port.
JMF 0:2563b0415d1f 117 * @param c The byte to write to the Serial Port
JMF 0:2563b0415d1f 118 * @return The byte that was written to the Serial Port Buffer
JMF 0:2563b0415d1f 119 */
JMF 0:2563b0415d1f 120 virtual int putc(int c);
JMF 0:2563b0415d1f 121
JMF 0:2563b0415d1f 122 /** Write a string to the BufferedSerial Port. Must be NULL terminated
JMF 0:2563b0415d1f 123 * @param s The string to write to the Serial Port
JMF 0:2563b0415d1f 124 * @return The number of bytes written to the Serial Port Buffer
JMF 0:2563b0415d1f 125 */
JMF 0:2563b0415d1f 126 virtual int puts(const char *s);
JMF 0:2563b0415d1f 127
JMF 0:2563b0415d1f 128 /** Write a formatted string to the BufferedSerial Port.
JMF 0:2563b0415d1f 129 * @param format The string + format specifiers to write to the Serial Port
JMF 0:2563b0415d1f 130 * @return The number of bytes written to the Serial Port Buffer
JMF 0:2563b0415d1f 131 */
JMF 0:2563b0415d1f 132 virtual int printf(const char* format, ...);
JMF 0:2563b0415d1f 133
JMF 0:2563b0415d1f 134 /** Write data to the Buffered Serial Port
JMF 0:2563b0415d1f 135 * @param s A pointer to data to send
JMF 0:2563b0415d1f 136 * @param length The amount of data being pointed to
JMF 0:2563b0415d1f 137 * @return The number of bytes written to the Serial Port Buffer
JMF 0:2563b0415d1f 138 */
JMF 0:2563b0415d1f 139 virtual ssize_t write(const void *s, std::size_t length);
JMF 0:2563b0415d1f 140
JMF 0:2563b0415d1f 141 /** Attach a function to call whenever a serial interrupt is generated
JMF 0:2563b0415d1f 142 * @param func A pointer to a void function, or 0 to set as none
JMF 0:2563b0415d1f 143 * @param type Which serial interrupt to attach the member function to (Serial::RxIrq for receive, TxIrq for transmit buffer empty)
JMF 0:2563b0415d1f 144 */
JMF 0:2563b0415d1f 145 virtual void attach(Callback<void()> func, IrqType type=RxIrq);
JMF 0:2563b0415d1f 146
JMF 0:2563b0415d1f 147 /** Attach a member function to call whenever a serial interrupt is generated
JMF 0:2563b0415d1f 148 * @param obj pointer to the object to call the member function on
JMF 0:2563b0415d1f 149 * @param method pointer to the member function to call
JMF 0:2563b0415d1f 150 * @param type Which serial interrupt to attach the member function to (Serial::RxIrq for receive, TxIrq for transmit buffer empty)
JMF 0:2563b0415d1f 151 */
JMF 0:2563b0415d1f 152 template <typename T>
JMF 0:2563b0415d1f 153 void attach(T *obj, void (T::*method)(), IrqType type=RxIrq) {
JMF 0:2563b0415d1f 154 attach(Callback<void()>(obj, method), type);
JMF 0:2563b0415d1f 155 }
JMF 0:2563b0415d1f 156
JMF 0:2563b0415d1f 157 /** Attach a member function to call whenever a serial interrupt is generated
JMF 0:2563b0415d1f 158 * @param obj pointer to the object to call the member function on
JMF 0:2563b0415d1f 159 * @param method pointer to the member function to call
JMF 0:2563b0415d1f 160 * @param type Which serial interrupt to attach the member function to (Serial::RxIrq for receive, TxIrq for transmit buffer empty)
JMF 0:2563b0415d1f 161 */
JMF 0:2563b0415d1f 162 template <typename T>
JMF 0:2563b0415d1f 163 void attach(T *obj, void (*method)(T*), IrqType type=RxIrq) {
JMF 0:2563b0415d1f 164 attach(Callback<void()>(obj, method), type);
JMF 0:2563b0415d1f 165 }
JMF 0:2563b0415d1f 166 };
JMF 0:2563b0415d1f 167
JMF 0:2563b0415d1f 168 #endif