Mbed SDK for XRange SX1272 LoRa module
Dependents: XRangePingPong XRange-LoRaWAN-lmic-app lora-transceiver
SX1272 LoRa RF module
https://www.netblocks.eu/xrange-sx1272-lora-datasheet/
api/SerialBase.h@339:ac6f3fd999f3, 2016-01-07 (annotated)
- Committer:
- netblocks
- Date:
- Thu Jan 07 13:01:25 2016 +0000
- Revision:
- 339:ac6f3fd999f3
- Parent:
- 336:1e18a06a987b
HSE_VALUE set for XTAL 16Mhz
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dudmuck | 336:1e18a06a987b | 1 | /* mbed Microcontroller Library |
dudmuck | 336:1e18a06a987b | 2 | * Copyright (c) 2006-2013 ARM Limited |
dudmuck | 336:1e18a06a987b | 3 | * |
dudmuck | 336:1e18a06a987b | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
dudmuck | 336:1e18a06a987b | 5 | * you may not use this file except in compliance with the License. |
dudmuck | 336:1e18a06a987b | 6 | * You may obtain a copy of the License at |
dudmuck | 336:1e18a06a987b | 7 | * |
dudmuck | 336:1e18a06a987b | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
dudmuck | 336:1e18a06a987b | 9 | * |
dudmuck | 336:1e18a06a987b | 10 | * Unless required by applicable law or agreed to in writing, software |
dudmuck | 336:1e18a06a987b | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
dudmuck | 336:1e18a06a987b | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
dudmuck | 336:1e18a06a987b | 13 | * See the License for the specific language governing permissions and |
dudmuck | 336:1e18a06a987b | 14 | * limitations under the License. |
dudmuck | 336:1e18a06a987b | 15 | */ |
dudmuck | 336:1e18a06a987b | 16 | #ifndef MBED_SERIALBASE_H |
dudmuck | 336:1e18a06a987b | 17 | #define MBED_SERIALBASE_H |
dudmuck | 336:1e18a06a987b | 18 | |
dudmuck | 336:1e18a06a987b | 19 | #include "platform.h" |
dudmuck | 336:1e18a06a987b | 20 | |
dudmuck | 336:1e18a06a987b | 21 | #if DEVICE_SERIAL |
dudmuck | 336:1e18a06a987b | 22 | |
dudmuck | 336:1e18a06a987b | 23 | #include "Stream.h" |
dudmuck | 336:1e18a06a987b | 24 | #include "FunctionPointer.h" |
dudmuck | 336:1e18a06a987b | 25 | #include "serial_api.h" |
dudmuck | 336:1e18a06a987b | 26 | |
dudmuck | 336:1e18a06a987b | 27 | namespace mbed { |
dudmuck | 336:1e18a06a987b | 28 | |
dudmuck | 336:1e18a06a987b | 29 | /** A base class for serial port implementations |
dudmuck | 336:1e18a06a987b | 30 | * Can't be instantiated directly (use Serial or RawSerial) |
dudmuck | 336:1e18a06a987b | 31 | */ |
dudmuck | 336:1e18a06a987b | 32 | class SerialBase { |
dudmuck | 336:1e18a06a987b | 33 | |
dudmuck | 336:1e18a06a987b | 34 | public: |
dudmuck | 336:1e18a06a987b | 35 | /** Set the baud rate of the serial port |
dudmuck | 336:1e18a06a987b | 36 | * |
dudmuck | 336:1e18a06a987b | 37 | * @param baudrate The baudrate of the serial port (default = 9600). |
dudmuck | 336:1e18a06a987b | 38 | */ |
dudmuck | 336:1e18a06a987b | 39 | void baud(int baudrate); |
dudmuck | 336:1e18a06a987b | 40 | |
dudmuck | 336:1e18a06a987b | 41 | enum Parity { |
dudmuck | 336:1e18a06a987b | 42 | None = 0, |
dudmuck | 336:1e18a06a987b | 43 | Odd, |
dudmuck | 336:1e18a06a987b | 44 | Even, |
dudmuck | 336:1e18a06a987b | 45 | Forced1, |
dudmuck | 336:1e18a06a987b | 46 | Forced0 |
dudmuck | 336:1e18a06a987b | 47 | }; |
dudmuck | 336:1e18a06a987b | 48 | |
dudmuck | 336:1e18a06a987b | 49 | enum IrqType { |
dudmuck | 336:1e18a06a987b | 50 | RxIrq = 0, |
dudmuck | 336:1e18a06a987b | 51 | TxIrq |
dudmuck | 336:1e18a06a987b | 52 | }; |
dudmuck | 336:1e18a06a987b | 53 | |
dudmuck | 336:1e18a06a987b | 54 | enum Flow { |
dudmuck | 336:1e18a06a987b | 55 | Disabled = 0, |
dudmuck | 336:1e18a06a987b | 56 | RTS, |
dudmuck | 336:1e18a06a987b | 57 | CTS, |
dudmuck | 336:1e18a06a987b | 58 | RTSCTS |
dudmuck | 336:1e18a06a987b | 59 | }; |
dudmuck | 336:1e18a06a987b | 60 | |
dudmuck | 336:1e18a06a987b | 61 | /** Set the transmission format used by the serial port |
dudmuck | 336:1e18a06a987b | 62 | * |
dudmuck | 336:1e18a06a987b | 63 | * @param bits The number of bits in a word (5-8; default = 8) |
dudmuck | 336:1e18a06a987b | 64 | * @param parity The parity used (SerialBase::None, SerialBase::Odd, SerialBase::Even, SerialBase::Forced1, SerialBase::Forced0; default = SerialBase::None) |
dudmuck | 336:1e18a06a987b | 65 | * @param stop The number of stop bits (1 or 2; default = 1) |
dudmuck | 336:1e18a06a987b | 66 | */ |
dudmuck | 336:1e18a06a987b | 67 | void format(int bits=8, Parity parity=SerialBase::None, int stop_bits=1); |
dudmuck | 336:1e18a06a987b | 68 | |
dudmuck | 336:1e18a06a987b | 69 | /** Determine if there is a character available to read |
dudmuck | 336:1e18a06a987b | 70 | * |
dudmuck | 336:1e18a06a987b | 71 | * @returns |
dudmuck | 336:1e18a06a987b | 72 | * 1 if there is a character available to read, |
dudmuck | 336:1e18a06a987b | 73 | * 0 otherwise |
dudmuck | 336:1e18a06a987b | 74 | */ |
dudmuck | 336:1e18a06a987b | 75 | int readable(); |
dudmuck | 336:1e18a06a987b | 76 | |
dudmuck | 336:1e18a06a987b | 77 | /** Determine if there is space available to write a character |
dudmuck | 336:1e18a06a987b | 78 | * |
dudmuck | 336:1e18a06a987b | 79 | * @returns |
dudmuck | 336:1e18a06a987b | 80 | * 1 if there is space to write a character, |
dudmuck | 336:1e18a06a987b | 81 | * 0 otherwise |
dudmuck | 336:1e18a06a987b | 82 | */ |
dudmuck | 336:1e18a06a987b | 83 | int writeable(); |
dudmuck | 336:1e18a06a987b | 84 | |
dudmuck | 336:1e18a06a987b | 85 | /** Attach a function to call whenever a serial interrupt is generated |
dudmuck | 336:1e18a06a987b | 86 | * |
dudmuck | 336:1e18a06a987b | 87 | * @param fptr A pointer to a void function, or 0 to set as none |
dudmuck | 336:1e18a06a987b | 88 | * @param type Which serial interrupt to attach the member function to (Seriall::RxIrq for receive, TxIrq for transmit buffer empty) |
dudmuck | 336:1e18a06a987b | 89 | */ |
dudmuck | 336:1e18a06a987b | 90 | void attach(void (*fptr)(void), IrqType type=RxIrq); |
dudmuck | 336:1e18a06a987b | 91 | |
dudmuck | 336:1e18a06a987b | 92 | /** Attach a member function to call whenever a serial interrupt is generated |
dudmuck | 336:1e18a06a987b | 93 | * |
dudmuck | 336:1e18a06a987b | 94 | * @param tptr pointer to the object to call the member function on |
dudmuck | 336:1e18a06a987b | 95 | * @param mptr pointer to the member function to be called |
dudmuck | 336:1e18a06a987b | 96 | * @param type Which serial interrupt to attach the member function to (Seriall::RxIrq for receive, TxIrq for transmit buffer empty) |
dudmuck | 336:1e18a06a987b | 97 | */ |
dudmuck | 336:1e18a06a987b | 98 | template<typename T> |
dudmuck | 336:1e18a06a987b | 99 | void attach(T* tptr, void (T::*mptr)(void), IrqType type=RxIrq) { |
dudmuck | 336:1e18a06a987b | 100 | if((mptr != NULL) && (tptr != NULL)) { |
dudmuck | 336:1e18a06a987b | 101 | _irq[type].attach(tptr, mptr); |
dudmuck | 336:1e18a06a987b | 102 | serial_irq_set(&_serial, (SerialIrq)type, 1); |
dudmuck | 336:1e18a06a987b | 103 | } |
dudmuck | 336:1e18a06a987b | 104 | } |
dudmuck | 336:1e18a06a987b | 105 | |
dudmuck | 336:1e18a06a987b | 106 | /** Generate a break condition on the serial line |
dudmuck | 336:1e18a06a987b | 107 | */ |
dudmuck | 336:1e18a06a987b | 108 | void send_break(); |
dudmuck | 336:1e18a06a987b | 109 | |
dudmuck | 336:1e18a06a987b | 110 | #if DEVICE_SERIAL_FC |
dudmuck | 336:1e18a06a987b | 111 | /** Set the flow control type on the serial port |
dudmuck | 336:1e18a06a987b | 112 | * |
dudmuck | 336:1e18a06a987b | 113 | * @param type the flow control type (Disabled, RTS, CTS, RTSCTS) |
dudmuck | 336:1e18a06a987b | 114 | * @param flow1 the first flow control pin (RTS for RTS or RTSCTS, CTS for CTS) |
dudmuck | 336:1e18a06a987b | 115 | * @param flow2 the second flow control pin (CTS for RTSCTS) |
dudmuck | 336:1e18a06a987b | 116 | */ |
dudmuck | 336:1e18a06a987b | 117 | void set_flow_control(Flow type, PinName flow1=NC, PinName flow2=NC); |
dudmuck | 336:1e18a06a987b | 118 | #endif |
dudmuck | 336:1e18a06a987b | 119 | |
dudmuck | 336:1e18a06a987b | 120 | static void _irq_handler(uint32_t id, SerialIrq irq_type); |
dudmuck | 336:1e18a06a987b | 121 | |
dudmuck | 336:1e18a06a987b | 122 | protected: |
dudmuck | 336:1e18a06a987b | 123 | SerialBase(PinName tx, PinName rx); |
dudmuck | 336:1e18a06a987b | 124 | virtual ~SerialBase() { |
dudmuck | 336:1e18a06a987b | 125 | } |
dudmuck | 336:1e18a06a987b | 126 | |
dudmuck | 336:1e18a06a987b | 127 | int _base_getc(); |
dudmuck | 336:1e18a06a987b | 128 | int _base_putc(int c); |
dudmuck | 336:1e18a06a987b | 129 | |
dudmuck | 336:1e18a06a987b | 130 | serial_t _serial; |
dudmuck | 336:1e18a06a987b | 131 | FunctionPointer _irq[2]; |
dudmuck | 336:1e18a06a987b | 132 | int _baud; |
dudmuck | 336:1e18a06a987b | 133 | }; |
dudmuck | 336:1e18a06a987b | 134 | |
dudmuck | 336:1e18a06a987b | 135 | } // namespace mbed |
dudmuck | 336:1e18a06a987b | 136 | |
dudmuck | 336:1e18a06a987b | 137 | #endif |
dudmuck | 336:1e18a06a987b | 138 | |
dudmuck | 336:1e18a06a987b | 139 | #endif |