Level measurement using range finder and lora technology
Dependencies: Cayenne-LPP SDBlockDevice
mbed-lora-radio-drv/SX1276/SX1276_LoRaRadio.h@0:f930f0440fd5, 2019-06-26 (annotated)
- Committer:
- wamae
- Date:
- Wed Jun 26 10:35:50 2019 +0000
- Revision:
- 0:f930f0440fd5
better copy
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
wamae | 0:f930f0440fd5 | 1 | /** |
wamae | 0:f930f0440fd5 | 2 | / _____) _ | | |
wamae | 0:f930f0440fd5 | 3 | ( (____ _____ ____ _| |_ _____ ____| |__ |
wamae | 0:f930f0440fd5 | 4 | \____ \| ___ | (_ _) ___ |/ ___) _ \ |
wamae | 0:f930f0440fd5 | 5 | _____) ) ____| | | || |_| ____( (___| | | | |
wamae | 0:f930f0440fd5 | 6 | (______/|_____)_|_|_| \__)_____)\____)_| |_| |
wamae | 0:f930f0440fd5 | 7 | (C)2013 Semtech |
wamae | 0:f930f0440fd5 | 8 | ___ _____ _ ___ _ _____ ___ ___ ___ ___ |
wamae | 0:f930f0440fd5 | 9 | / __|_ _/_\ / __| |/ / __/ _ \| _ \/ __| __| |
wamae | 0:f930f0440fd5 | 10 | \__ \ | |/ _ \ (__| ' <| _| (_) | / (__| _| |
wamae | 0:f930f0440fd5 | 11 | |___/ |_/_/ \_\___|_|\_\_| \___/|_|_\\___|___| |
wamae | 0:f930f0440fd5 | 12 | embedded.connectivity.solutions=============== |
wamae | 0:f930f0440fd5 | 13 | |
wamae | 0:f930f0440fd5 | 14 | Description: LoRaWAN stack layer that controls both MAC and PHY underneath |
wamae | 0:f930f0440fd5 | 15 | |
wamae | 0:f930f0440fd5 | 16 | License: Revised BSD License, see LICENSE.TXT file include in the project |
wamae | 0:f930f0440fd5 | 17 | |
wamae | 0:f930f0440fd5 | 18 | Maintainer: Miguel Luis ( Semtech ), Gregory Cristian ( Semtech ) and Daniel Jaeckle ( STACKFORCE ) |
wamae | 0:f930f0440fd5 | 19 | |
wamae | 0:f930f0440fd5 | 20 | |
wamae | 0:f930f0440fd5 | 21 | Copyright (c) 2017, Arm Limited and affiliates. |
wamae | 0:f930f0440fd5 | 22 | |
wamae | 0:f930f0440fd5 | 23 | SPDX-License-Identifier: BSD-3-Clause |
wamae | 0:f930f0440fd5 | 24 | */ |
wamae | 0:f930f0440fd5 | 25 | |
wamae | 0:f930f0440fd5 | 26 | #ifndef SX1276_LORARADIO_H_ |
wamae | 0:f930f0440fd5 | 27 | #define SX1276_LORARADIO_H_ |
wamae | 0:f930f0440fd5 | 28 | |
wamae | 0:f930f0440fd5 | 29 | #include "PinNames.h" |
wamae | 0:f930f0440fd5 | 30 | #include "InterruptIn.h" |
wamae | 0:f930f0440fd5 | 31 | #include "DigitalOut.h" |
wamae | 0:f930f0440fd5 | 32 | #include "DigitalInOut.h" |
wamae | 0:f930f0440fd5 | 33 | #include "SPI.h" |
wamae | 0:f930f0440fd5 | 34 | #include "Timeout.h" |
wamae | 0:f930f0440fd5 | 35 | #include "platform/PlatformMutex.h" |
wamae | 0:f930f0440fd5 | 36 | #ifdef MBED_CONF_RTOS_PRESENT |
wamae | 0:f930f0440fd5 | 37 | #include "rtos/Thread.h" |
wamae | 0:f930f0440fd5 | 38 | #endif |
wamae | 0:f930f0440fd5 | 39 | |
wamae | 0:f930f0440fd5 | 40 | #include "lorawan/LoRaRadio.h" |
wamae | 0:f930f0440fd5 | 41 | |
wamae | 0:f930f0440fd5 | 42 | #ifdef MBED_CONF_SX1276_LORA_DRIVER_BUFFER_SIZE |
wamae | 0:f930f0440fd5 | 43 | #define MAX_DATA_BUFFER_SIZE_SX1276 MBED_CONF_SX1276_LORA_DRIVER_BUFFER_SIZE |
wamae | 0:f930f0440fd5 | 44 | #else |
wamae | 0:f930f0440fd5 | 45 | #define MAX_DATA_BUFFER_SIZE_SX1276 256 |
wamae | 0:f930f0440fd5 | 46 | #endif |
wamae | 0:f930f0440fd5 | 47 | |
wamae | 0:f930f0440fd5 | 48 | #ifdef DEVICE_SPI |
wamae | 0:f930f0440fd5 | 49 | |
wamae | 0:f930f0440fd5 | 50 | /** |
wamae | 0:f930f0440fd5 | 51 | * Radio driver implementation for Semtech SX1272 plus variants. |
wamae | 0:f930f0440fd5 | 52 | * Supports only SPI at the moment. Implements pure virtual LoRaRadio class. |
wamae | 0:f930f0440fd5 | 53 | */ |
wamae | 0:f930f0440fd5 | 54 | class SX1276_LoRaRadio: public LoRaRadio { |
wamae | 0:f930f0440fd5 | 55 | public: |
wamae | 0:f930f0440fd5 | 56 | /** |
wamae | 0:f930f0440fd5 | 57 | * Use this constructor if pin definitions are provided manually. |
wamae | 0:f930f0440fd5 | 58 | * The pins that are marked NC are optional. It is assumed that these |
wamae | 0:f930f0440fd5 | 59 | * pins are not connected until/unless configured otherwise. |
wamae | 0:f930f0440fd5 | 60 | * |
wamae | 0:f930f0440fd5 | 61 | * Note: Pin ant_switch is equivalent to RxTx pin at |
wamae | 0:f930f0440fd5 | 62 | * https://developer.mbed.org/components/SX1276MB1xAS/. |
wamae | 0:f930f0440fd5 | 63 | * Reading the state of this pin indicates if the radio module type is |
wamae | 0:f930f0440fd5 | 64 | * SX1276MB1LAS(North American frequency band supported) or SX1276MAS |
wamae | 0:f930f0440fd5 | 65 | * (European frequency band supported). |
wamae | 0:f930f0440fd5 | 66 | * Pin dio4 can be mapped to multiple pins on the board, please refer to |
wamae | 0:f930f0440fd5 | 67 | * schematic of your board. For reference look at |
wamae | 0:f930f0440fd5 | 68 | * https://developer.mbed.org/components/SX1276MB1xAS/ |
wamae | 0:f930f0440fd5 | 69 | * |
wamae | 0:f930f0440fd5 | 70 | * Most of the radio module control pins are not being used at the moment as |
wamae | 0:f930f0440fd5 | 71 | * the SX1276MB1xAS shield has not connected them. For consistency and future |
wamae | 0:f930f0440fd5 | 72 | * use we are leaving the pins in the constructor. For example, if in some |
wamae | 0:f930f0440fd5 | 73 | * setting SX1276 radio module gets connected to an external power amplifier |
wamae | 0:f930f0440fd5 | 74 | * or radio latch controls are connected. |
wamae | 0:f930f0440fd5 | 75 | */ |
wamae | 0:f930f0440fd5 | 76 | SX1276_LoRaRadio(PinName mosi, |
wamae | 0:f930f0440fd5 | 77 | PinName miso, |
wamae | 0:f930f0440fd5 | 78 | PinName sclk, |
wamae | 0:f930f0440fd5 | 79 | PinName nss, |
wamae | 0:f930f0440fd5 | 80 | PinName reset, |
wamae | 0:f930f0440fd5 | 81 | PinName dio0, |
wamae | 0:f930f0440fd5 | 82 | PinName dio1, |
wamae | 0:f930f0440fd5 | 83 | PinName dio2, |
wamae | 0:f930f0440fd5 | 84 | PinName dio3, |
wamae | 0:f930f0440fd5 | 85 | PinName dio4, |
wamae | 0:f930f0440fd5 | 86 | PinName dio5, |
wamae | 0:f930f0440fd5 | 87 | PinName rf_switch_ctl1 = NC, |
wamae | 0:f930f0440fd5 | 88 | PinName rf_switch_ctl2 = NC, |
wamae | 0:f930f0440fd5 | 89 | PinName txctl = NC, |
wamae | 0:f930f0440fd5 | 90 | PinName rxctl = NC, |
wamae | 0:f930f0440fd5 | 91 | PinName ant_switch = NC, |
wamae | 0:f930f0440fd5 | 92 | PinName pwr_amp_ctl = NC, |
wamae | 0:f930f0440fd5 | 93 | PinName tcxo = NC); |
wamae | 0:f930f0440fd5 | 94 | |
wamae | 0:f930f0440fd5 | 95 | /** |
wamae | 0:f930f0440fd5 | 96 | * Destructor |
wamae | 0:f930f0440fd5 | 97 | */ |
wamae | 0:f930f0440fd5 | 98 | virtual ~SX1276_LoRaRadio(); |
wamae | 0:f930f0440fd5 | 99 | |
wamae | 0:f930f0440fd5 | 100 | /** |
wamae | 0:f930f0440fd5 | 101 | * Registers radio events with the Mbed LoRaWAN stack and |
wamae | 0:f930f0440fd5 | 102 | * undergoes initialization steps if any |
wamae | 0:f930f0440fd5 | 103 | * |
wamae | 0:f930f0440fd5 | 104 | * @param events Structure containing the driver callback functions |
wamae | 0:f930f0440fd5 | 105 | */ |
wamae | 0:f930f0440fd5 | 106 | virtual void init_radio(radio_events_t *events); |
wamae | 0:f930f0440fd5 | 107 | |
wamae | 0:f930f0440fd5 | 108 | /** |
wamae | 0:f930f0440fd5 | 109 | * Resets the radio module |
wamae | 0:f930f0440fd5 | 110 | */ |
wamae | 0:f930f0440fd5 | 111 | virtual void radio_reset(); |
wamae | 0:f930f0440fd5 | 112 | |
wamae | 0:f930f0440fd5 | 113 | /** |
wamae | 0:f930f0440fd5 | 114 | * Put the RF module in sleep mode |
wamae | 0:f930f0440fd5 | 115 | */ |
wamae | 0:f930f0440fd5 | 116 | virtual void sleep(void); |
wamae | 0:f930f0440fd5 | 117 | |
wamae | 0:f930f0440fd5 | 118 | /** |
wamae | 0:f930f0440fd5 | 119 | * Sets the radio in standby mode |
wamae | 0:f930f0440fd5 | 120 | */ |
wamae | 0:f930f0440fd5 | 121 | virtual void standby(void); |
wamae | 0:f930f0440fd5 | 122 | |
wamae | 0:f930f0440fd5 | 123 | /** |
wamae | 0:f930f0440fd5 | 124 | * Sets the reception parameters |
wamae | 0:f930f0440fd5 | 125 | * |
wamae | 0:f930f0440fd5 | 126 | * @param modem Radio modem to be used [0: FSK, 1: LoRa] |
wamae | 0:f930f0440fd5 | 127 | * @param bandwidth Sets the bandwidth |
wamae | 0:f930f0440fd5 | 128 | * FSK : >= 2600 and <= 250000 Hz |
wamae | 0:f930f0440fd5 | 129 | * LoRa: [0: 125 kHz, 1: 250 kHz, |
wamae | 0:f930f0440fd5 | 130 | * 2: 500 kHz, 3: Reserved] |
wamae | 0:f930f0440fd5 | 131 | * @param datarate Sets the Datarate |
wamae | 0:f930f0440fd5 | 132 | * FSK : 600..300000 bits/s |
wamae | 0:f930f0440fd5 | 133 | * LoRa: [6: 64, 7: 128, 8: 256, 9: 512, |
wamae | 0:f930f0440fd5 | 134 | * 10: 1024, 11: 2048, 12: 4096 chips] |
wamae | 0:f930f0440fd5 | 135 | * @param coderate Sets the coding rate ( LoRa only ) |
wamae | 0:f930f0440fd5 | 136 | * FSK : N/A ( set to 0 ) |
wamae | 0:f930f0440fd5 | 137 | * LoRa: [1: 4/5, 2: 4/6, 3: 4/7, 4: 4/8] |
wamae | 0:f930f0440fd5 | 138 | * @param bandwidth_afc Sets the AFC Bandwidth ( FSK only ) |
wamae | 0:f930f0440fd5 | 139 | * FSK : >= 2600 and <= 250000 Hz |
wamae | 0:f930f0440fd5 | 140 | * LoRa: N/A ( set to 0 ) |
wamae | 0:f930f0440fd5 | 141 | * @param preamble_len Sets the Preamble length ( LoRa only ) |
wamae | 0:f930f0440fd5 | 142 | * FSK : N/A ( set to 0 ) |
wamae | 0:f930f0440fd5 | 143 | * LoRa: Length in symbols ( the hardware adds 4 more symbols ) |
wamae | 0:f930f0440fd5 | 144 | * @param symb_timeout Sets the RxSingle timeout value |
wamae | 0:f930f0440fd5 | 145 | * FSK : timeout number of bytes |
wamae | 0:f930f0440fd5 | 146 | * LoRa: timeout in symbols |
wamae | 0:f930f0440fd5 | 147 | * @param fixLen Fixed length packets [0: variable, 1: fixed] |
wamae | 0:f930f0440fd5 | 148 | * @param payload_len Sets payload length when fixed lenght is used |
wamae | 0:f930f0440fd5 | 149 | * @param crc_on Enables/Disables the CRC [0: OFF, 1: ON] |
wamae | 0:f930f0440fd5 | 150 | * @param freq_hop_on Enables disables the intra-packet frequency hopping [0: OFF, 1: ON] (LoRa only) |
wamae | 0:f930f0440fd5 | 151 | * @param hop_period Number of symbols bewteen each hop (LoRa only) |
wamae | 0:f930f0440fd5 | 152 | * @param iq_inverted Inverts IQ signals ( LoRa only ) |
wamae | 0:f930f0440fd5 | 153 | * FSK : N/A ( set to 0 ) |
wamae | 0:f930f0440fd5 | 154 | * LoRa: [0: not inverted, 1: inverted] |
wamae | 0:f930f0440fd5 | 155 | * @param rx_continuous Sets the reception in continuous mode |
wamae | 0:f930f0440fd5 | 156 | * [false: single mode, true: continuous mode] |
wamae | 0:f930f0440fd5 | 157 | */ |
wamae | 0:f930f0440fd5 | 158 | virtual void set_rx_config (radio_modems_t modem, uint32_t bandwidth, |
wamae | 0:f930f0440fd5 | 159 | uint32_t datarate, uint8_t coderate, |
wamae | 0:f930f0440fd5 | 160 | uint32_t bandwidth_afc, uint16_t preamble_len, |
wamae | 0:f930f0440fd5 | 161 | uint16_t symb_timeout, bool fix_len, |
wamae | 0:f930f0440fd5 | 162 | uint8_t payload_len, |
wamae | 0:f930f0440fd5 | 163 | bool crc_on, bool freq_hop_on, uint8_t hop_period, |
wamae | 0:f930f0440fd5 | 164 | bool iq_inverted, bool rx_continuous); |
wamae | 0:f930f0440fd5 | 165 | |
wamae | 0:f930f0440fd5 | 166 | /** |
wamae | 0:f930f0440fd5 | 167 | * Sets the transmission parameters |
wamae | 0:f930f0440fd5 | 168 | * |
wamae | 0:f930f0440fd5 | 169 | * @param modem Radio modem to be used [0: FSK, 1: LoRa] |
wamae | 0:f930f0440fd5 | 170 | * @param power Sets the output power [dBm] |
wamae | 0:f930f0440fd5 | 171 | * @param fdev Sets the frequency deviation ( FSK only ) |
wamae | 0:f930f0440fd5 | 172 | * FSK : [Hz] |
wamae | 0:f930f0440fd5 | 173 | * LoRa: 0 |
wamae | 0:f930f0440fd5 | 174 | * @param bandwidth Sets the bandwidth ( LoRa only ) |
wamae | 0:f930f0440fd5 | 175 | * FSK : 0 |
wamae | 0:f930f0440fd5 | 176 | * LoRa: [0: 125 kHz, 1: 250 kHz, |
wamae | 0:f930f0440fd5 | 177 | * 2: 500 kHz, 3: Reserved] |
wamae | 0:f930f0440fd5 | 178 | * @param datarate Sets the Datarate |
wamae | 0:f930f0440fd5 | 179 | * FSK : 600..300000 bits/s |
wamae | 0:f930f0440fd5 | 180 | * LoRa: [6: 64, 7: 128, 8: 256, 9: 512, |
wamae | 0:f930f0440fd5 | 181 | * 10: 1024, 11: 2048, 12: 4096 chips] |
wamae | 0:f930f0440fd5 | 182 | * @param coderate Sets the coding rate ( LoRa only ) |
wamae | 0:f930f0440fd5 | 183 | * FSK : N/A ( set to 0 ) |
wamae | 0:f930f0440fd5 | 184 | * LoRa: [1: 4/5, 2: 4/6, 3: 4/7, 4: 4/8] |
wamae | 0:f930f0440fd5 | 185 | * @param preamble_len Sets the preamble length |
wamae | 0:f930f0440fd5 | 186 | * @param fix_len Fixed length packets [0: variable, 1: fixed] |
wamae | 0:f930f0440fd5 | 187 | * @param crc_on Enables disables the CRC [0: OFF, 1: ON] |
wamae | 0:f930f0440fd5 | 188 | * @param freq_hop_on Enables disables the intra-packet frequency hopping [0: OFF, 1: ON] (LoRa only) |
wamae | 0:f930f0440fd5 | 189 | * @param hop_period Number of symbols bewteen each hop (LoRa only) |
wamae | 0:f930f0440fd5 | 190 | * @param iq_inverted Inverts IQ signals ( LoRa only ) |
wamae | 0:f930f0440fd5 | 191 | * FSK : N/A ( set to 0 ) |
wamae | 0:f930f0440fd5 | 192 | * LoRa: [0: not inverted, 1: inverted] |
wamae | 0:f930f0440fd5 | 193 | * @param timeout Transmission timeout [us] |
wamae | 0:f930f0440fd5 | 194 | */ |
wamae | 0:f930f0440fd5 | 195 | virtual void set_tx_config(radio_modems_t modem, int8_t power, uint32_t fdev, |
wamae | 0:f930f0440fd5 | 196 | uint32_t bandwidth, uint32_t datarate, |
wamae | 0:f930f0440fd5 | 197 | uint8_t coderate, uint16_t preamble_len, |
wamae | 0:f930f0440fd5 | 198 | bool fix_len, bool crc_on, bool freq_hop_on, |
wamae | 0:f930f0440fd5 | 199 | uint8_t hop_period, bool iq_inverted, uint32_t timeout); |
wamae | 0:f930f0440fd5 | 200 | |
wamae | 0:f930f0440fd5 | 201 | /** |
wamae | 0:f930f0440fd5 | 202 | * Sends the buffer of size |
wamae | 0:f930f0440fd5 | 203 | * |
wamae | 0:f930f0440fd5 | 204 | * Prepares the packet to be sent and sets the radio in transmission |
wamae | 0:f930f0440fd5 | 205 | * |
wamae | 0:f930f0440fd5 | 206 | * @param buffer Buffer pointer |
wamae | 0:f930f0440fd5 | 207 | * @param size Buffer size |
wamae | 0:f930f0440fd5 | 208 | */ |
wamae | 0:f930f0440fd5 | 209 | virtual void send(uint8_t *buffer, uint8_t size); |
wamae | 0:f930f0440fd5 | 210 | |
wamae | 0:f930f0440fd5 | 211 | /** |
wamae | 0:f930f0440fd5 | 212 | * Sets the radio in reception mode for the given time |
wamae | 0:f930f0440fd5 | 213 | * |
wamae | 0:f930f0440fd5 | 214 | * It should be noted that if the timeout is set to 0, it essentially |
wamae | 0:f930f0440fd5 | 215 | * puts the receiver in continuous mode and hence from thereon it should |
wamae | 0:f930f0440fd5 | 216 | * be treated as if in continuous mode. However, an appropriate way of |
wamae | 0:f930f0440fd5 | 217 | * setting the receiver in continuous mode is by using set_rx_config() |
wamae | 0:f930f0440fd5 | 218 | * API. |
wamae | 0:f930f0440fd5 | 219 | * |
wamae | 0:f930f0440fd5 | 220 | * @param timeout Reception timeout [ms] |
wamae | 0:f930f0440fd5 | 221 | * |
wamae | 0:f930f0440fd5 | 222 | */ |
wamae | 0:f930f0440fd5 | 223 | virtual void receive(uint32_t timeout); |
wamae | 0:f930f0440fd5 | 224 | |
wamae | 0:f930f0440fd5 | 225 | /** |
wamae | 0:f930f0440fd5 | 226 | * Sets the carrier frequency |
wamae | 0:f930f0440fd5 | 227 | * |
wamae | 0:f930f0440fd5 | 228 | * @param freq Channel RF frequency |
wamae | 0:f930f0440fd5 | 229 | */ |
wamae | 0:f930f0440fd5 | 230 | virtual void set_channel(uint32_t freq); |
wamae | 0:f930f0440fd5 | 231 | |
wamae | 0:f930f0440fd5 | 232 | /** |
wamae | 0:f930f0440fd5 | 233 | * Generates a 32 bits random value based on the RSSI readings |
wamae | 0:f930f0440fd5 | 234 | * |
wamae | 0:f930f0440fd5 | 235 | * Remark this function sets the radio in LoRa modem mode and disables |
wamae | 0:f930f0440fd5 | 236 | * all interrupts. |
wamae | 0:f930f0440fd5 | 237 | * After calling this function either Radio.SetRxConfig or |
wamae | 0:f930f0440fd5 | 238 | * Radio.SetTxConfig functions must be called. |
wamae | 0:f930f0440fd5 | 239 | * |
wamae | 0:f930f0440fd5 | 240 | * @return 32 bits random value |
wamae | 0:f930f0440fd5 | 241 | */ |
wamae | 0:f930f0440fd5 | 242 | virtual uint32_t random(void); |
wamae | 0:f930f0440fd5 | 243 | |
wamae | 0:f930f0440fd5 | 244 | /** |
wamae | 0:f930f0440fd5 | 245 | * Get radio status |
wamae | 0:f930f0440fd5 | 246 | * |
wamae | 0:f930f0440fd5 | 247 | * @param status Radio status [RF_IDLE, RF_RX_RUNNING, RF_TX_RUNNING] |
wamae | 0:f930f0440fd5 | 248 | * @return Return current radio status |
wamae | 0:f930f0440fd5 | 249 | */ |
wamae | 0:f930f0440fd5 | 250 | virtual uint8_t get_status(void); |
wamae | 0:f930f0440fd5 | 251 | |
wamae | 0:f930f0440fd5 | 252 | /** |
wamae | 0:f930f0440fd5 | 253 | * Sets the maximum payload length |
wamae | 0:f930f0440fd5 | 254 | * |
wamae | 0:f930f0440fd5 | 255 | * @param modem Radio modem to be used [0: FSK, 1: LoRa] |
wamae | 0:f930f0440fd5 | 256 | * @param max Maximum payload length in bytes |
wamae | 0:f930f0440fd5 | 257 | */ |
wamae | 0:f930f0440fd5 | 258 | virtual void set_max_payload_length(radio_modems_t modem, uint8_t max); |
wamae | 0:f930f0440fd5 | 259 | |
wamae | 0:f930f0440fd5 | 260 | /** |
wamae | 0:f930f0440fd5 | 261 | * Sets the network to public or private |
wamae | 0:f930f0440fd5 | 262 | * |
wamae | 0:f930f0440fd5 | 263 | * Updates the sync byte. Applies to LoRa modem only |
wamae | 0:f930f0440fd5 | 264 | * |
wamae | 0:f930f0440fd5 | 265 | * @param enable if true, it enables a public network |
wamae | 0:f930f0440fd5 | 266 | */ |
wamae | 0:f930f0440fd5 | 267 | virtual void set_public_network(bool enable); |
wamae | 0:f930f0440fd5 | 268 | |
wamae | 0:f930f0440fd5 | 269 | /** |
wamae | 0:f930f0440fd5 | 270 | * Computes the packet time on air for the given payload |
wamae | 0:f930f0440fd5 | 271 | * |
wamae | 0:f930f0440fd5 | 272 | * Remark can only be called once SetRxConfig or SetTxConfig have been called |
wamae | 0:f930f0440fd5 | 273 | * |
wamae | 0:f930f0440fd5 | 274 | * @param modem Radio modem to be used [0: FSK, 1: LoRa] |
wamae | 0:f930f0440fd5 | 275 | * @param pkt_len Packet payload length |
wamae | 0:f930f0440fd5 | 276 | * @return Computed airTime for the given packet payload length |
wamae | 0:f930f0440fd5 | 277 | */ |
wamae | 0:f930f0440fd5 | 278 | virtual uint32_t time_on_air(radio_modems_t modem, uint8_t pkt_len); |
wamae | 0:f930f0440fd5 | 279 | |
wamae | 0:f930f0440fd5 | 280 | /** |
wamae | 0:f930f0440fd5 | 281 | * Perform carrier sensing |
wamae | 0:f930f0440fd5 | 282 | * |
wamae | 0:f930f0440fd5 | 283 | * Checks for a certain time if the RSSI is above a given threshold. |
wamae | 0:f930f0440fd5 | 284 | * This threshold determines if there is already a transmission going on |
wamae | 0:f930f0440fd5 | 285 | * in the channel or not. |
wamae | 0:f930f0440fd5 | 286 | * |
wamae | 0:f930f0440fd5 | 287 | * @param modem Type of the radio modem |
wamae | 0:f930f0440fd5 | 288 | * @param freq Carrier frequency |
wamae | 0:f930f0440fd5 | 289 | * @param rssi_threshold Threshold value of RSSI |
wamae | 0:f930f0440fd5 | 290 | * @param max_carrier_sense_time time to sense the channel |
wamae | 0:f930f0440fd5 | 291 | * |
wamae | 0:f930f0440fd5 | 292 | * @return true if there is no active transmission |
wamae | 0:f930f0440fd5 | 293 | * in the channel, false otherwise |
wamae | 0:f930f0440fd5 | 294 | */ |
wamae | 0:f930f0440fd5 | 295 | virtual bool perform_carrier_sense(radio_modems_t modem, |
wamae | 0:f930f0440fd5 | 296 | uint32_t freq, |
wamae | 0:f930f0440fd5 | 297 | int16_t rssi_threshold, |
wamae | 0:f930f0440fd5 | 298 | uint32_t max_carrier_sense_time); |
wamae | 0:f930f0440fd5 | 299 | |
wamae | 0:f930f0440fd5 | 300 | /** |
wamae | 0:f930f0440fd5 | 301 | * Sets the radio in CAD mode |
wamae | 0:f930f0440fd5 | 302 | * |
wamae | 0:f930f0440fd5 | 303 | */ |
wamae | 0:f930f0440fd5 | 304 | virtual void start_cad(void); |
wamae | 0:f930f0440fd5 | 305 | |
wamae | 0:f930f0440fd5 | 306 | /** |
wamae | 0:f930f0440fd5 | 307 | * Check if the given RF is in range |
wamae | 0:f930f0440fd5 | 308 | * |
wamae | 0:f930f0440fd5 | 309 | * @param frequency frequency needed to be checked |
wamae | 0:f930f0440fd5 | 310 | */ |
wamae | 0:f930f0440fd5 | 311 | virtual bool check_rf_frequency(uint32_t frequency); |
wamae | 0:f930f0440fd5 | 312 | |
wamae | 0:f930f0440fd5 | 313 | /** Sets the radio in continuous wave transmission mode |
wamae | 0:f930f0440fd5 | 314 | * |
wamae | 0:f930f0440fd5 | 315 | * @param freq Channel RF frequency |
wamae | 0:f930f0440fd5 | 316 | * @param power Sets the output power [dBm] |
wamae | 0:f930f0440fd5 | 317 | * @param time Transmission mode timeout [s] |
wamae | 0:f930f0440fd5 | 318 | */ |
wamae | 0:f930f0440fd5 | 319 | virtual void set_tx_continuous_wave(uint32_t freq, int8_t power, uint16_t time); |
wamae | 0:f930f0440fd5 | 320 | |
wamae | 0:f930f0440fd5 | 321 | /** |
wamae | 0:f930f0440fd5 | 322 | * Acquire exclusive access |
wamae | 0:f930f0440fd5 | 323 | */ |
wamae | 0:f930f0440fd5 | 324 | virtual void lock(void); |
wamae | 0:f930f0440fd5 | 325 | |
wamae | 0:f930f0440fd5 | 326 | /** |
wamae | 0:f930f0440fd5 | 327 | * Release exclusive access |
wamae | 0:f930f0440fd5 | 328 | */ |
wamae | 0:f930f0440fd5 | 329 | virtual void unlock(void); |
wamae | 0:f930f0440fd5 | 330 | |
wamae | 0:f930f0440fd5 | 331 | private: |
wamae | 0:f930f0440fd5 | 332 | |
wamae | 0:f930f0440fd5 | 333 | // SPI and chip select control |
wamae | 0:f930f0440fd5 | 334 | mbed::SPI _spi; |
wamae | 0:f930f0440fd5 | 335 | mbed::DigitalOut _chip_select; |
wamae | 0:f930f0440fd5 | 336 | |
wamae | 0:f930f0440fd5 | 337 | // module rest control |
wamae | 0:f930f0440fd5 | 338 | mbed::DigitalInOut _reset_ctl; |
wamae | 0:f930f0440fd5 | 339 | |
wamae | 0:f930f0440fd5 | 340 | // Interrupt controls |
wamae | 0:f930f0440fd5 | 341 | mbed::InterruptIn _dio0_ctl; |
wamae | 0:f930f0440fd5 | 342 | mbed::InterruptIn _dio1_ctl; |
wamae | 0:f930f0440fd5 | 343 | mbed::InterruptIn _dio2_ctl; |
wamae | 0:f930f0440fd5 | 344 | mbed::InterruptIn _dio3_ctl; |
wamae | 0:f930f0440fd5 | 345 | mbed::InterruptIn _dio4_ctl; |
wamae | 0:f930f0440fd5 | 346 | mbed::InterruptIn _dio5_ctl; |
wamae | 0:f930f0440fd5 | 347 | |
wamae | 0:f930f0440fd5 | 348 | // Radio specific controls |
wamae | 0:f930f0440fd5 | 349 | mbed::DigitalOut _rf_switch_ctl1; |
wamae | 0:f930f0440fd5 | 350 | mbed::DigitalOut _rf_switch_ctl2; |
wamae | 0:f930f0440fd5 | 351 | mbed::DigitalOut _txctl; |
wamae | 0:f930f0440fd5 | 352 | mbed::DigitalOut _rxctl; |
wamae | 0:f930f0440fd5 | 353 | mbed::DigitalInOut _ant_switch; |
wamae | 0:f930f0440fd5 | 354 | mbed::DigitalOut _pwr_amp_ctl; |
wamae | 0:f930f0440fd5 | 355 | mbed::DigitalOut _tcxo; |
wamae | 0:f930f0440fd5 | 356 | |
wamae | 0:f930f0440fd5 | 357 | // Contains all RF control pin names |
wamae | 0:f930f0440fd5 | 358 | // This storage is needed even after assigning the |
wamae | 0:f930f0440fd5 | 359 | // pins to corresponding object, as the driver needs to know |
wamae | 0:f930f0440fd5 | 360 | // which control pins are connected and which are not. This |
wamae | 0:f930f0440fd5 | 361 | // variation is inherent to driver because of target configuration. |
wamae | 0:f930f0440fd5 | 362 | rf_ctrls _rf_ctrls; |
wamae | 0:f930f0440fd5 | 363 | |
wamae | 0:f930f0440fd5 | 364 | // We need these PinNames as not all modules have those connected |
wamae | 0:f930f0440fd5 | 365 | PinName _dio4_pin; |
wamae | 0:f930f0440fd5 | 366 | PinName _dio5_pin; |
wamae | 0:f930f0440fd5 | 367 | |
wamae | 0:f930f0440fd5 | 368 | // Structure containing all user and network specified settings |
wamae | 0:f930f0440fd5 | 369 | // for radio module |
wamae | 0:f930f0440fd5 | 370 | radio_settings_t _rf_settings; |
wamae | 0:f930f0440fd5 | 371 | |
wamae | 0:f930f0440fd5 | 372 | // Structure containing function pointers to the stack callbacks |
wamae | 0:f930f0440fd5 | 373 | radio_events_t *_radio_events; |
wamae | 0:f930f0440fd5 | 374 | |
wamae | 0:f930f0440fd5 | 375 | // Data buffer used for both TX and RX |
wamae | 0:f930f0440fd5 | 376 | // Size of this buffer is configurable via Mbed config system |
wamae | 0:f930f0440fd5 | 377 | // Default is 256 bytes |
wamae | 0:f930f0440fd5 | 378 | uint8_t _data_buffer[MAX_DATA_BUFFER_SIZE_SX1276]; |
wamae | 0:f930f0440fd5 | 379 | |
wamae | 0:f930f0440fd5 | 380 | // TX/RX Timers - all use milisecond units |
wamae | 0:f930f0440fd5 | 381 | mbed::Timeout tx_timeout_timer; |
wamae | 0:f930f0440fd5 | 382 | mbed::Timeout rx_timeout_timer; |
wamae | 0:f930f0440fd5 | 383 | mbed::Timeout rx_timeout_sync_word; |
wamae | 0:f930f0440fd5 | 384 | |
wamae | 0:f930f0440fd5 | 385 | #ifdef MBED_CONF_RTOS_PRESENT |
wamae | 0:f930f0440fd5 | 386 | // Thread to handle interrupts |
wamae | 0:f930f0440fd5 | 387 | rtos::Thread irq_thread; |
wamae | 0:f930f0440fd5 | 388 | #endif |
wamae | 0:f930f0440fd5 | 389 | |
wamae | 0:f930f0440fd5 | 390 | // Access protection |
wamae | 0:f930f0440fd5 | 391 | PlatformMutex mutex; |
wamae | 0:f930f0440fd5 | 392 | |
wamae | 0:f930f0440fd5 | 393 | uint8_t radio_variant; |
wamae | 0:f930f0440fd5 | 394 | |
wamae | 0:f930f0440fd5 | 395 | // helper functions |
wamae | 0:f930f0440fd5 | 396 | void setup_registers(); |
wamae | 0:f930f0440fd5 | 397 | void default_antenna_switch_ctrls(); |
wamae | 0:f930f0440fd5 | 398 | void set_antenna_switch(uint8_t operation_mode); |
wamae | 0:f930f0440fd5 | 399 | void setup_spi(); |
wamae | 0:f930f0440fd5 | 400 | void gpio_init(); |
wamae | 0:f930f0440fd5 | 401 | void gpio_deinit(); |
wamae | 0:f930f0440fd5 | 402 | void setup_interrupts(); |
wamae | 0:f930f0440fd5 | 403 | void set_operation_mode(uint8_t operation_mode); |
wamae | 0:f930f0440fd5 | 404 | void set_low_power_mode(); |
wamae | 0:f930f0440fd5 | 405 | void set_sx1276_variant_type(); |
wamae | 0:f930f0440fd5 | 406 | uint8_t get_pa_conf_reg(uint32_t channel); |
wamae | 0:f930f0440fd5 | 407 | void set_rf_tx_power(int8_t power); |
wamae | 0:f930f0440fd5 | 408 | int16_t get_rssi(radio_modems_t modem); |
wamae | 0:f930f0440fd5 | 409 | uint8_t get_fsk_bw_reg_val(uint32_t bandwidth); |
wamae | 0:f930f0440fd5 | 410 | void write_to_register(uint8_t addr, uint8_t data); |
wamae | 0:f930f0440fd5 | 411 | void write_to_register(uint8_t addr, uint8_t *data, uint8_t size); |
wamae | 0:f930f0440fd5 | 412 | uint8_t read_register(uint8_t addr); |
wamae | 0:f930f0440fd5 | 413 | void read_register(uint8_t addr, uint8_t *buffer, uint8_t size); |
wamae | 0:f930f0440fd5 | 414 | void write_fifo(uint8_t *buffer, uint8_t size); |
wamae | 0:f930f0440fd5 | 415 | void read_fifo(uint8_t *buffer, uint8_t size); |
wamae | 0:f930f0440fd5 | 416 | void transmit(uint32_t timeout); |
wamae | 0:f930f0440fd5 | 417 | void rf_irq_task(void); |
wamae | 0:f930f0440fd5 | 418 | void set_modem(uint8_t modem); |
wamae | 0:f930f0440fd5 | 419 | void rx_chain_calibration(void); |
wamae | 0:f930f0440fd5 | 420 | |
wamae | 0:f930f0440fd5 | 421 | // ISRs |
wamae | 0:f930f0440fd5 | 422 | void dio0_irq_isr(); |
wamae | 0:f930f0440fd5 | 423 | void dio1_irq_isr(); |
wamae | 0:f930f0440fd5 | 424 | void dio2_irq_isr(); |
wamae | 0:f930f0440fd5 | 425 | void dio3_irq_isr(); |
wamae | 0:f930f0440fd5 | 426 | void dio4_irq_isr(); |
wamae | 0:f930f0440fd5 | 427 | void dio5_irq_isr(); |
wamae | 0:f930f0440fd5 | 428 | void timeout_irq_isr(); |
wamae | 0:f930f0440fd5 | 429 | |
wamae | 0:f930f0440fd5 | 430 | // Handlers called by thread in response to signal |
wamae | 0:f930f0440fd5 | 431 | void handle_dio0_irq(); |
wamae | 0:f930f0440fd5 | 432 | void handle_dio1_irq(); |
wamae | 0:f930f0440fd5 | 433 | void handle_dio2_irq(); |
wamae | 0:f930f0440fd5 | 434 | void handle_dio3_irq(); |
wamae | 0:f930f0440fd5 | 435 | void handle_dio4_irq(); |
wamae | 0:f930f0440fd5 | 436 | void handle_dio5_irq(); |
wamae | 0:f930f0440fd5 | 437 | void handle_timeout_irq(); |
wamae | 0:f930f0440fd5 | 438 | }; |
wamae | 0:f930f0440fd5 | 439 | |
wamae | 0:f930f0440fd5 | 440 | #endif //DEVICE_SPI |
wamae | 0:f930f0440fd5 | 441 | |
wamae | 0:f930f0440fd5 | 442 | #endif // SX1276_LORARADIO_H_ |