Level measurement using range finder and lora technology

Dependencies:   Cayenne-LPP SDBlockDevice

Committer:
wamae
Date:
Wed Jun 26 10:35:50 2019 +0000
Revision:
0:f930f0440fd5
better copy

Who changed what in which revision?

UserRevisionLine numberNew 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: Radio driver for Semtech SX1272 radio. Implements LoRaRadio class.
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 SX1272_LORARADIO_H_
wamae 0:f930f0440fd5 27 #define SX1272_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 DEVICE_SPI
wamae 0:f930f0440fd5 43
wamae 0:f930f0440fd5 44 #ifdef MBED_CONF_SX1272_LORA_DRIVER_BUFFER_SIZE
wamae 0:f930f0440fd5 45 #define MAX_DATA_BUFFER_SIZE_SX172 MBED_CONF_SX1272_LORA_DRIVER_BUFFER_SIZE
wamae 0:f930f0440fd5 46 #else
wamae 0:f930f0440fd5 47 #define MAX_DATA_BUFFER_SIZE_SX172 256
wamae 0:f930f0440fd5 48 #endif
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 SX1272_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 SX1272_LoRaRadio(PinName mosi,
wamae 0:f930f0440fd5 62 PinName miso,
wamae 0:f930f0440fd5 63 PinName sclk,
wamae 0:f930f0440fd5 64 PinName nss,
wamae 0:f930f0440fd5 65 PinName reset,
wamae 0:f930f0440fd5 66 PinName dio0,
wamae 0:f930f0440fd5 67 PinName dio1,
wamae 0:f930f0440fd5 68 PinName dio2,
wamae 0:f930f0440fd5 69 PinName dio3,
wamae 0:f930f0440fd5 70 PinName dio4,
wamae 0:f930f0440fd5 71 PinName dio5,
wamae 0:f930f0440fd5 72 PinName rf_switch_ctl1 = NC,
wamae 0:f930f0440fd5 73 PinName rf_switch_ctl2 = NC,
wamae 0:f930f0440fd5 74 PinName txctl = NC,
wamae 0:f930f0440fd5 75 PinName rxctl = NC,
wamae 0:f930f0440fd5 76 PinName ant_switch = NC,
wamae 0:f930f0440fd5 77 PinName pwr_amp_ctl = NC,
wamae 0:f930f0440fd5 78 PinName tcxo = NC);
wamae 0:f930f0440fd5 79
wamae 0:f930f0440fd5 80 /**
wamae 0:f930f0440fd5 81 * Destructor
wamae 0:f930f0440fd5 82 */
wamae 0:f930f0440fd5 83 virtual ~SX1272_LoRaRadio();
wamae 0:f930f0440fd5 84
wamae 0:f930f0440fd5 85 /**
wamae 0:f930f0440fd5 86 * Registers radio events with the Mbed LoRaWAN stack and
wamae 0:f930f0440fd5 87 * undergoes initialization steps if any
wamae 0:f930f0440fd5 88 *
wamae 0:f930f0440fd5 89 * @param events Structure containing the driver callback functions
wamae 0:f930f0440fd5 90 */
wamae 0:f930f0440fd5 91 virtual void init_radio(radio_events_t *events);
wamae 0:f930f0440fd5 92
wamae 0:f930f0440fd5 93 /**
wamae 0:f930f0440fd5 94 * Resets the radio module
wamae 0:f930f0440fd5 95 */
wamae 0:f930f0440fd5 96 virtual void radio_reset();
wamae 0:f930f0440fd5 97
wamae 0:f930f0440fd5 98 /**
wamae 0:f930f0440fd5 99 * Put the RF module in sleep mode
wamae 0:f930f0440fd5 100 */
wamae 0:f930f0440fd5 101 virtual void sleep(void);
wamae 0:f930f0440fd5 102
wamae 0:f930f0440fd5 103 /**
wamae 0:f930f0440fd5 104 * Sets the radio in standby mode
wamae 0:f930f0440fd5 105 */
wamae 0:f930f0440fd5 106 virtual void standby(void);
wamae 0:f930f0440fd5 107
wamae 0:f930f0440fd5 108 /**
wamae 0:f930f0440fd5 109 * Sets the reception parameters
wamae 0:f930f0440fd5 110 *
wamae 0:f930f0440fd5 111 * @param modem Radio modem to be used [0: FSK, 1: LoRa]
wamae 0:f930f0440fd5 112 * @param bandwidth Sets the bandwidth
wamae 0:f930f0440fd5 113 * FSK : >= 2600 and <= 250000 Hz
wamae 0:f930f0440fd5 114 * LoRa: [0: 125 kHz, 1: 250 kHz,
wamae 0:f930f0440fd5 115 * 2: 500 kHz, 3: Reserved]
wamae 0:f930f0440fd5 116 * @param datarate Sets the Datarate
wamae 0:f930f0440fd5 117 * FSK : 600..300000 bits/s
wamae 0:f930f0440fd5 118 * LoRa: [6: 64, 7: 128, 8: 256, 9: 512,
wamae 0:f930f0440fd5 119 * 10: 1024, 11: 2048, 12: 4096 chips]
wamae 0:f930f0440fd5 120 * @param coderate Sets the coding rate ( LoRa only )
wamae 0:f930f0440fd5 121 * FSK : N/A ( set to 0 )
wamae 0:f930f0440fd5 122 * LoRa: [1: 4/5, 2: 4/6, 3: 4/7, 4: 4/8]
wamae 0:f930f0440fd5 123 * @param bandwidth_afc Sets the AFC Bandwidth ( FSK only )
wamae 0:f930f0440fd5 124 * FSK : >= 2600 and <= 250000 Hz
wamae 0:f930f0440fd5 125 * LoRa: N/A ( set to 0 )
wamae 0:f930f0440fd5 126 * @param preamble_len Sets the Preamble length ( LoRa only )
wamae 0:f930f0440fd5 127 * FSK : N/A ( set to 0 )
wamae 0:f930f0440fd5 128 * LoRa: Length in symbols ( the hardware adds 4 more symbols )
wamae 0:f930f0440fd5 129 * @param symb_timeout Sets the RxSingle timeout value
wamae 0:f930f0440fd5 130 * FSK : timeout number of bytes
wamae 0:f930f0440fd5 131 * LoRa: timeout in symbols
wamae 0:f930f0440fd5 132 * @param fixLen Fixed length packets [0: variable, 1: fixed]
wamae 0:f930f0440fd5 133 * @param payload_len Sets payload length when fixed lenght is used
wamae 0:f930f0440fd5 134 * @param crc_on Enables/Disables the CRC [0: OFF, 1: ON]
wamae 0:f930f0440fd5 135 * @param freq_hop_on Enables disables the intra-packet frequency hopping [0: OFF, 1: ON] (LoRa only)
wamae 0:f930f0440fd5 136 * @param hop_period Number of symbols bewteen each hop (LoRa only)
wamae 0:f930f0440fd5 137 * @param iq_inverted Inverts IQ signals ( LoRa only )
wamae 0:f930f0440fd5 138 * FSK : N/A ( set to 0 )
wamae 0:f930f0440fd5 139 * LoRa: [0: not inverted, 1: inverted]
wamae 0:f930f0440fd5 140 * @param rx_continuous Sets the reception in continuous mode
wamae 0:f930f0440fd5 141 * [false: single mode, true: continuous mode]
wamae 0:f930f0440fd5 142 */
wamae 0:f930f0440fd5 143 virtual void set_rx_config (radio_modems_t modem, uint32_t bandwidth,
wamae 0:f930f0440fd5 144 uint32_t datarate, uint8_t coderate,
wamae 0:f930f0440fd5 145 uint32_t bandwidth_afc, uint16_t preamble_len,
wamae 0:f930f0440fd5 146 uint16_t symb_timeout, bool fix_len,
wamae 0:f930f0440fd5 147 uint8_t payload_len,
wamae 0:f930f0440fd5 148 bool crc_on, bool freq_hop_on, uint8_t hop_period,
wamae 0:f930f0440fd5 149 bool iq_inverted, bool rx_continuous);
wamae 0:f930f0440fd5 150
wamae 0:f930f0440fd5 151 /**
wamae 0:f930f0440fd5 152 * Sets the transmission parameters
wamae 0:f930f0440fd5 153 *
wamae 0:f930f0440fd5 154 * @param modem Radio modem to be used [0: FSK, 1: LoRa]
wamae 0:f930f0440fd5 155 * @param power Sets the output power [dBm]
wamae 0:f930f0440fd5 156 * @param fdev Sets the frequency deviation ( FSK only )
wamae 0:f930f0440fd5 157 * FSK : [Hz]
wamae 0:f930f0440fd5 158 * LoRa: 0
wamae 0:f930f0440fd5 159 * @param bandwidth Sets the bandwidth ( LoRa only )
wamae 0:f930f0440fd5 160 * FSK : 0
wamae 0:f930f0440fd5 161 * LoRa: [0: 125 kHz, 1: 250 kHz,
wamae 0:f930f0440fd5 162 * 2: 500 kHz, 3: Reserved]
wamae 0:f930f0440fd5 163 * @param datarate Sets the Datarate
wamae 0:f930f0440fd5 164 * FSK : 600..300000 bits/s
wamae 0:f930f0440fd5 165 * LoRa: [6: 64, 7: 128, 8: 256, 9: 512,
wamae 0:f930f0440fd5 166 * 10: 1024, 11: 2048, 12: 4096 chips]
wamae 0:f930f0440fd5 167 * @param coderate Sets the coding rate ( LoRa only )
wamae 0:f930f0440fd5 168 * FSK : N/A ( set to 0 )
wamae 0:f930f0440fd5 169 * LoRa: [1: 4/5, 2: 4/6, 3: 4/7, 4: 4/8]
wamae 0:f930f0440fd5 170 * @param preamble_len Sets the preamble length
wamae 0:f930f0440fd5 171 * @param fix_len Fixed length packets [0: variable, 1: fixed]
wamae 0:f930f0440fd5 172 * @param crc_on Enables disables the CRC [0: OFF, 1: ON]
wamae 0:f930f0440fd5 173 * @param freq_hop_on Enables disables the intra-packet frequency hopping [0: OFF, 1: ON] (LoRa only)
wamae 0:f930f0440fd5 174 * @param hop_period Number of symbols bewteen each hop (LoRa only)
wamae 0:f930f0440fd5 175 * @param iq_inverted Inverts IQ signals ( LoRa only )
wamae 0:f930f0440fd5 176 * FSK : N/A ( set to 0 )
wamae 0:f930f0440fd5 177 * LoRa: [0: not inverted, 1: inverted]
wamae 0:f930f0440fd5 178 * @param timeout Transmission timeout [us]
wamae 0:f930f0440fd5 179 */
wamae 0:f930f0440fd5 180 virtual void set_tx_config(radio_modems_t modem, int8_t power, uint32_t fdev,
wamae 0:f930f0440fd5 181 uint32_t bandwidth, uint32_t datarate,
wamae 0:f930f0440fd5 182 uint8_t coderate, uint16_t preamble_len,
wamae 0:f930f0440fd5 183 bool fix_len, bool crc_on, bool freq_hop_on,
wamae 0:f930f0440fd5 184 uint8_t hop_period, bool iq_inverted, uint32_t timeout);
wamae 0:f930f0440fd5 185
wamae 0:f930f0440fd5 186 /**
wamae 0:f930f0440fd5 187 * Sends the buffer of size
wamae 0:f930f0440fd5 188 *
wamae 0:f930f0440fd5 189 * Prepares the packet to be sent and sets the radio in transmission
wamae 0:f930f0440fd5 190 *
wamae 0:f930f0440fd5 191 * @param buffer Buffer pointer
wamae 0:f930f0440fd5 192 * @param size Buffer size
wamae 0:f930f0440fd5 193 */
wamae 0:f930f0440fd5 194 virtual void send(uint8_t *buffer, uint8_t size);
wamae 0:f930f0440fd5 195
wamae 0:f930f0440fd5 196 /**
wamae 0:f930f0440fd5 197 * Sets the radio in reception mode for the given time
wamae 0:f930f0440fd5 198 *
wamae 0:f930f0440fd5 199 * It should be noted that if the timeout is set to 0, it essentially
wamae 0:f930f0440fd5 200 * puts the receiver in continuous mode and hence from thereon it should
wamae 0:f930f0440fd5 201 * be treated as if in continuous mode. However, an appropriate way of
wamae 0:f930f0440fd5 202 * setting the receiver in continuous mode is by using set_rx_config()
wamae 0:f930f0440fd5 203 * API.
wamae 0:f930f0440fd5 204 *
wamae 0:f930f0440fd5 205 * @param timeout Reception timeout [ms]
wamae 0:f930f0440fd5 206 *
wamae 0:f930f0440fd5 207 */
wamae 0:f930f0440fd5 208 virtual void receive(uint32_t timeout);
wamae 0:f930f0440fd5 209
wamae 0:f930f0440fd5 210 /**
wamae 0:f930f0440fd5 211 * Sets the carrier frequency
wamae 0:f930f0440fd5 212 *
wamae 0:f930f0440fd5 213 * @param freq Channel RF frequency
wamae 0:f930f0440fd5 214 */
wamae 0:f930f0440fd5 215 virtual void set_channel(uint32_t freq);
wamae 0:f930f0440fd5 216
wamae 0:f930f0440fd5 217 /**
wamae 0:f930f0440fd5 218 * Generates a 32 bits random value based on the RSSI readings
wamae 0:f930f0440fd5 219 *
wamae 0:f930f0440fd5 220 * Remark this function sets the radio in LoRa modem mode and disables
wamae 0:f930f0440fd5 221 * all interrupts.
wamae 0:f930f0440fd5 222 * After calling this function either Radio.SetRxConfig or
wamae 0:f930f0440fd5 223 * Radio.SetTxConfig functions must be called.
wamae 0:f930f0440fd5 224 *
wamae 0:f930f0440fd5 225 * @return 32 bits random value
wamae 0:f930f0440fd5 226 */
wamae 0:f930f0440fd5 227 virtual uint32_t random(void);
wamae 0:f930f0440fd5 228
wamae 0:f930f0440fd5 229 /**
wamae 0:f930f0440fd5 230 * Get radio status
wamae 0:f930f0440fd5 231 *
wamae 0:f930f0440fd5 232 * @param status Radio status [RF_IDLE, RF_RX_RUNNING, RF_TX_RUNNING]
wamae 0:f930f0440fd5 233 * @return Return current radio status
wamae 0:f930f0440fd5 234 */
wamae 0:f930f0440fd5 235 virtual uint8_t get_status(void);
wamae 0:f930f0440fd5 236
wamae 0:f930f0440fd5 237 /**
wamae 0:f930f0440fd5 238 * Sets the maximum payload length
wamae 0:f930f0440fd5 239 *
wamae 0:f930f0440fd5 240 * @param modem Radio modem to be used [0: FSK, 1: LoRa]
wamae 0:f930f0440fd5 241 * @param max Maximum payload length in bytes
wamae 0:f930f0440fd5 242 */
wamae 0:f930f0440fd5 243 virtual void set_max_payload_length(radio_modems_t modem, uint8_t max);
wamae 0:f930f0440fd5 244
wamae 0:f930f0440fd5 245 /**
wamae 0:f930f0440fd5 246 * Sets the network to public or private
wamae 0:f930f0440fd5 247 *
wamae 0:f930f0440fd5 248 * Updates the sync byte. Applies to LoRa modem only
wamae 0:f930f0440fd5 249 *
wamae 0:f930f0440fd5 250 * @param enable if true, it enables a public network
wamae 0:f930f0440fd5 251 */
wamae 0:f930f0440fd5 252 virtual void set_public_network(bool enable);
wamae 0:f930f0440fd5 253
wamae 0:f930f0440fd5 254 /**
wamae 0:f930f0440fd5 255 * Computes the packet time on air for the given payload
wamae 0:f930f0440fd5 256 *
wamae 0:f930f0440fd5 257 * Remark can only be called once SetRxConfig or SetTxConfig have been called
wamae 0:f930f0440fd5 258 *
wamae 0:f930f0440fd5 259 * @param modem Radio modem to be used [0: FSK, 1: LoRa]
wamae 0:f930f0440fd5 260 * @param pkt_len Packet payload length
wamae 0:f930f0440fd5 261 * @return Computed airTime for the given packet payload length
wamae 0:f930f0440fd5 262 */
wamae 0:f930f0440fd5 263 virtual uint32_t time_on_air(radio_modems_t modem, uint8_t pkt_len);
wamae 0:f930f0440fd5 264
wamae 0:f930f0440fd5 265 /**
wamae 0:f930f0440fd5 266 * Perform carrier sensing
wamae 0:f930f0440fd5 267 *
wamae 0:f930f0440fd5 268 * Checks for a certain time if the RSSI is above a given threshold.
wamae 0:f930f0440fd5 269 * This threshold determines if there is already a transmission going on
wamae 0:f930f0440fd5 270 * in the channel or not.
wamae 0:f930f0440fd5 271 *
wamae 0:f930f0440fd5 272 * @param modem Type of the radio modem
wamae 0:f930f0440fd5 273 * @param freq Carrier frequency
wamae 0:f930f0440fd5 274 * @param rssi_threshold Threshold value of RSSI
wamae 0:f930f0440fd5 275 * @param max_carrier_sense_time time to sense the channel
wamae 0:f930f0440fd5 276 *
wamae 0:f930f0440fd5 277 * @return true if there is no active transmission
wamae 0:f930f0440fd5 278 * in the channel, false otherwise
wamae 0:f930f0440fd5 279 */
wamae 0:f930f0440fd5 280 virtual bool perform_carrier_sense(radio_modems_t modem,
wamae 0:f930f0440fd5 281 uint32_t freq,
wamae 0:f930f0440fd5 282 int16_t rssi_threshold,
wamae 0:f930f0440fd5 283 uint32_t max_carrier_sense_time);
wamae 0:f930f0440fd5 284
wamae 0:f930f0440fd5 285 /**
wamae 0:f930f0440fd5 286 * Sets the radio in CAD mode
wamae 0:f930f0440fd5 287 *
wamae 0:f930f0440fd5 288 */
wamae 0:f930f0440fd5 289 virtual void start_cad(void);
wamae 0:f930f0440fd5 290
wamae 0:f930f0440fd5 291 /**
wamae 0:f930f0440fd5 292 * Check if the given RF is in range
wamae 0:f930f0440fd5 293 *
wamae 0:f930f0440fd5 294 * @param frequency frequency needed to be checked
wamae 0:f930f0440fd5 295 */
wamae 0:f930f0440fd5 296 virtual bool check_rf_frequency(uint32_t frequency);
wamae 0:f930f0440fd5 297
wamae 0:f930f0440fd5 298 /** Sets the radio in continuous wave transmission mode
wamae 0:f930f0440fd5 299 *
wamae 0:f930f0440fd5 300 * @param freq Channel RF frequency
wamae 0:f930f0440fd5 301 * @param power Sets the output power [dBm]
wamae 0:f930f0440fd5 302 * @param time Transmission mode timeout [s]
wamae 0:f930f0440fd5 303 */
wamae 0:f930f0440fd5 304 virtual void set_tx_continuous_wave(uint32_t freq, int8_t power, uint16_t time);
wamae 0:f930f0440fd5 305
wamae 0:f930f0440fd5 306 /**
wamae 0:f930f0440fd5 307 * Acquire exclusive access
wamae 0:f930f0440fd5 308 */
wamae 0:f930f0440fd5 309 virtual void lock(void);
wamae 0:f930f0440fd5 310
wamae 0:f930f0440fd5 311 /**
wamae 0:f930f0440fd5 312 * Release exclusive access
wamae 0:f930f0440fd5 313 */
wamae 0:f930f0440fd5 314 virtual void unlock(void);
wamae 0:f930f0440fd5 315
wamae 0:f930f0440fd5 316 private:
wamae 0:f930f0440fd5 317
wamae 0:f930f0440fd5 318 // SPI and chip select control
wamae 0:f930f0440fd5 319 mbed::SPI _spi;
wamae 0:f930f0440fd5 320 mbed::DigitalOut _chip_select;
wamae 0:f930f0440fd5 321
wamae 0:f930f0440fd5 322 // module rest control
wamae 0:f930f0440fd5 323 mbed::DigitalInOut _reset_ctl;
wamae 0:f930f0440fd5 324
wamae 0:f930f0440fd5 325 // Interrupt controls
wamae 0:f930f0440fd5 326 mbed::InterruptIn _dio0_ctl;
wamae 0:f930f0440fd5 327 mbed::InterruptIn _dio1_ctl;
wamae 0:f930f0440fd5 328 mbed::InterruptIn _dio2_ctl;
wamae 0:f930f0440fd5 329 mbed::InterruptIn _dio3_ctl;
wamae 0:f930f0440fd5 330 mbed::InterruptIn _dio4_ctl;
wamae 0:f930f0440fd5 331 mbed::InterruptIn _dio5_ctl;
wamae 0:f930f0440fd5 332
wamae 0:f930f0440fd5 333 // Radio specific controls
wamae 0:f930f0440fd5 334 mbed::DigitalOut _rf_switch_ctl1;
wamae 0:f930f0440fd5 335 mbed::DigitalOut _rf_switch_ctl2;
wamae 0:f930f0440fd5 336 mbed::DigitalOut _txctl;
wamae 0:f930f0440fd5 337 mbed::DigitalOut _rxctl;
wamae 0:f930f0440fd5 338 mbed::DigitalInOut _ant_switch;
wamae 0:f930f0440fd5 339 mbed::DigitalOut _pwr_amp_ctl;
wamae 0:f930f0440fd5 340 mbed::DigitalOut _tcxo;
wamae 0:f930f0440fd5 341
wamae 0:f930f0440fd5 342 // Contains all RF control pin names
wamae 0:f930f0440fd5 343 // This storage is needed even after assigning the
wamae 0:f930f0440fd5 344 // pins to corresponding object, as the driver needs to know
wamae 0:f930f0440fd5 345 // which control pins are connected and which are not. This
wamae 0:f930f0440fd5 346 // variation is inherent to driver because of target configuration.
wamae 0:f930f0440fd5 347 rf_ctrls _rf_ctrls;
wamae 0:f930f0440fd5 348
wamae 0:f930f0440fd5 349 // We need these PinNames as not all modules have those connected
wamae 0:f930f0440fd5 350 PinName _dio4_pin;
wamae 0:f930f0440fd5 351 PinName _dio5_pin;
wamae 0:f930f0440fd5 352
wamae 0:f930f0440fd5 353 // Structure containing all user and network specified settings
wamae 0:f930f0440fd5 354 // for radio module
wamae 0:f930f0440fd5 355 radio_settings_t _rf_settings;
wamae 0:f930f0440fd5 356
wamae 0:f930f0440fd5 357 // Structure containing function pointers to the stack callbacks
wamae 0:f930f0440fd5 358 radio_events_t *_radio_events;
wamae 0:f930f0440fd5 359
wamae 0:f930f0440fd5 360 // Data buffer used for both TX and RX
wamae 0:f930f0440fd5 361 // Size of this buffer is configurable via Mbed config system
wamae 0:f930f0440fd5 362 // Default is 256 bytes
wamae 0:f930f0440fd5 363 uint8_t _data_buffer[MAX_DATA_BUFFER_SIZE_SX172];
wamae 0:f930f0440fd5 364
wamae 0:f930f0440fd5 365 // TX/RX Timers - all use milisecond units
wamae 0:f930f0440fd5 366 mbed::Timeout tx_timeout_timer;
wamae 0:f930f0440fd5 367 mbed::Timeout rx_timeout_timer;
wamae 0:f930f0440fd5 368 mbed::Timeout rx_timeout_sync_word;
wamae 0:f930f0440fd5 369
wamae 0:f930f0440fd5 370 #ifdef MBED_CONF_RTOS_PRESENT
wamae 0:f930f0440fd5 371 // Thread to handle interrupts
wamae 0:f930f0440fd5 372 rtos::Thread irq_thread;
wamae 0:f930f0440fd5 373 #endif
wamae 0:f930f0440fd5 374
wamae 0:f930f0440fd5 375 // Access protection
wamae 0:f930f0440fd5 376 PlatformMutex mutex;
wamae 0:f930f0440fd5 377
wamae 0:f930f0440fd5 378 uint8_t radio_variant;
wamae 0:f930f0440fd5 379
wamae 0:f930f0440fd5 380 /**
wamae 0:f930f0440fd5 381 * Flag used to set the RF switch control pins in low power mode when the radio is not active.
wamae 0:f930f0440fd5 382 */
wamae 0:f930f0440fd5 383 bool radio_is_active;
wamae 0:f930f0440fd5 384
wamae 0:f930f0440fd5 385 // helper functions
wamae 0:f930f0440fd5 386 void setup_registers();
wamae 0:f930f0440fd5 387 void default_antenna_switch_ctrls();
wamae 0:f930f0440fd5 388 void set_antenna_switch(uint8_t operation_mode);
wamae 0:f930f0440fd5 389 void setup_spi();
wamae 0:f930f0440fd5 390 void gpio_init();
wamae 0:f930f0440fd5 391 void gpio_deinit();
wamae 0:f930f0440fd5 392 void setup_interrupts();
wamae 0:f930f0440fd5 393 void set_modem(uint8_t modem);
wamae 0:f930f0440fd5 394 void set_operation_mode(uint8_t mode);
wamae 0:f930f0440fd5 395 void set_low_power_mode(bool status);
wamae 0:f930f0440fd5 396 void set_sx1272_variant_type();
wamae 0:f930f0440fd5 397 uint8_t get_pa_conf_reg();
wamae 0:f930f0440fd5 398 void set_rf_tx_power(int8_t power);
wamae 0:f930f0440fd5 399 int16_t get_rssi(radio_modems_t modem);
wamae 0:f930f0440fd5 400 uint8_t get_fsk_bw_reg_val(uint32_t bandwidth);
wamae 0:f930f0440fd5 401 void write_to_register(uint8_t addr, uint8_t data);
wamae 0:f930f0440fd5 402 void write_to_register(uint8_t addr, uint8_t *data, uint8_t size);
wamae 0:f930f0440fd5 403 uint8_t read_register(uint8_t addr);
wamae 0:f930f0440fd5 404 void read_register(uint8_t addr, uint8_t *buffer, uint8_t size);
wamae 0:f930f0440fd5 405 void write_fifo(uint8_t *buffer, uint8_t size);
wamae 0:f930f0440fd5 406 void read_fifo(uint8_t *buffer, uint8_t size);
wamae 0:f930f0440fd5 407 void transmit(uint32_t timeout);
wamae 0:f930f0440fd5 408 void rf_irq_task(void);
wamae 0:f930f0440fd5 409
wamae 0:f930f0440fd5 410 // ISRs
wamae 0:f930f0440fd5 411 void dio0_irq_isr();
wamae 0:f930f0440fd5 412 void dio1_irq_isr();
wamae 0:f930f0440fd5 413 void dio2_irq_isr();
wamae 0:f930f0440fd5 414 void dio3_irq_isr();
wamae 0:f930f0440fd5 415 void dio4_irq_isr();
wamae 0:f930f0440fd5 416 void dio5_irq_isr();
wamae 0:f930f0440fd5 417 void timeout_irq_isr();
wamae 0:f930f0440fd5 418
wamae 0:f930f0440fd5 419 // Handlers called by thread in response to signal
wamae 0:f930f0440fd5 420 void handle_dio0_irq();
wamae 0:f930f0440fd5 421 void handle_dio1_irq();
wamae 0:f930f0440fd5 422 void handle_dio2_irq();
wamae 0:f930f0440fd5 423 void handle_dio3_irq();
wamae 0:f930f0440fd5 424 void handle_dio4_irq();
wamae 0:f930f0440fd5 425 void handle_dio5_irq();
wamae 0:f930f0440fd5 426 void handle_timeout_irq();
wamae 0:f930f0440fd5 427 };
wamae 0:f930f0440fd5 428
wamae 0:f930f0440fd5 429 #endif //DEVICE_SPI
wamae 0:f930f0440fd5 430
wamae 0:f930f0440fd5 431 #endif /* SX1272_LORARADIO_H_ */