testing hex for lorawan communication

Committer:
brunnobbco
Date:
Thu Nov 12 22:09:59 2020 +0000
Revision:
2:6c5853c2fd72
Parent:
1:3bdd6f917bf5
Removed debug related code.

Who changed what in which revision?

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