testing hex for lorawan communication

Committer:
brunnobbco
Date:
Thu Nov 12 19:26:24 2020 +0000
Revision:
0:561d07a737bc
SX1272 driver using only DIO0 and polling.

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