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