testing hex for lorawan communication

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