How to measure water in a reservoir

Dependencies:   Cayenne-MQTT-mbed Cayenne-LPP

Committer:
wamae
Date:
Fri Mar 08 11:34:56 2019 +0000
Revision:
0:7bfeb237e600
working code

Who changed what in which revision?

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