Radio library for the MAX20361 Demo

Fork of SX1276GenericLib by Walter Luu

Committer:
Helmut Tschemernjak
Date:
Sun May 07 18:09:10 2017 +0200
Revision:
38:d9189d958db8
Parent:
34:07e89f23c734
Child:
39:706c32eda7e7
Migrated typedefs.h into the sx1276 source.
Migrated radio init register values and settings into sx1276.cpp
where it belongs to.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
GregCr 0:e6ceb13d2d05 1 /*
GregCr 0:e6ceb13d2d05 2 / _____) _ | |
GregCr 0:e6ceb13d2d05 3 ( (____ _____ ____ _| |_ _____ ____| |__
GregCr 0:e6ceb13d2d05 4 \____ \| ___ | (_ _) ___ |/ ___) _ \
GregCr 0:e6ceb13d2d05 5 _____) ) ____| | | || |_| ____( (___| | | |
GregCr 0:e6ceb13d2d05 6 (______/|_____)_|_|_| \__)_____)\____)_| |_|
mluis 22:7f3aab69cca9 7 (C) 2014 Semtech
GregCr 0:e6ceb13d2d05 8
GregCr 0:e6ceb13d2d05 9 Description: Actual implementation of a SX1276 radio, inherits Radio
GregCr 0:e6ceb13d2d05 10
GregCr 0:e6ceb13d2d05 11 License: Revised BSD License, see LICENSE.TXT file include in the project
GregCr 0:e6ceb13d2d05 12
GregCr 0:e6ceb13d2d05 13 Maintainers: Miguel Luis, Gregory Cristian and Nicolas Huguenin
GregCr 0:e6ceb13d2d05 14 */
Helmut Tschemernjak 34:07e89f23c734 15
Helmut Tschemernjak 34:07e89f23c734 16 /*
Helmut Tschemernjak 38:d9189d958db8 17 * additional development to make it more generic across multiple OS versions
Helmut Tschemernjak 34:07e89f23c734 18 * (c) 2017 Helmut Tschemernjak
Helmut Tschemernjak 34:07e89f23c734 19 * 30826 Garbsen (Hannover) Germany
Helmut Tschemernjak 34:07e89f23c734 20 */
Helmut Tschemernjak 34:07e89f23c734 21
GregCr 0:e6ceb13d2d05 22 #ifndef __SX1276_H__
GregCr 0:e6ceb13d2d05 23 #define __SX1276_H__
GregCr 0:e6ceb13d2d05 24
GregCr 0:e6ceb13d2d05 25 #include "radio.h"
GregCr 0:e6ceb13d2d05 26 #include "./registers/sx1276Regs-Fsk.h"
GregCr 0:e6ceb13d2d05 27 #include "./registers/sx1276Regs-LoRa.h"
Helmut Tschemernjak 38:d9189d958db8 28
Helmut Tschemernjak 38:d9189d958db8 29 class SX1276;
Helmut Tschemernjak 38:d9189d958db8 30 class SX1276Generic;
Helmut Tschemernjak 38:d9189d958db8 31
Helmut Tschemernjak 38:d9189d958db8 32
GregCr 0:e6ceb13d2d05 33
mluis 16:d447f8d2d2d6 34 /*!
Helmut Tschemernjak 31:e50929bd3f32 35 * Radio wake-up time from sleep
Helmut Tschemernjak 31:e50929bd3f32 36 */
Helmut Tschemernjak 32:f6f0bff38543 37 #define RADIO_WAKEUP_TIME 1 // [ms]
Helmut Tschemernjak 31:e50929bd3f32 38
Helmut Tschemernjak 31:e50929bd3f32 39 /*!
Helmut Tschemernjak 31:e50929bd3f32 40 * Sync word for Private LoRa networks
mluis 16:d447f8d2d2d6 41 */
Helmut Tschemernjak 31:e50929bd3f32 42 #define LORA_MAC_PRIVATE_SYNCWORD 0x12
Helmut Tschemernjak 31:e50929bd3f32 43
Helmut Tschemernjak 31:e50929bd3f32 44 /*!
Helmut Tschemernjak 31:e50929bd3f32 45 * Sync word for Public LoRa networks
Helmut Tschemernjak 31:e50929bd3f32 46 */
Helmut Tschemernjak 31:e50929bd3f32 47 #define LORA_MAC_PUBLIC_SYNCWORD 0x34
Helmut Tschemernjak 31:e50929bd3f32 48
mluis 25:3778e6204cc1 49
mluis 25:3778e6204cc1 50 /*!
mluis 16:d447f8d2d2d6 51 * SX1276 definitions
mluis 16:d447f8d2d2d6 52 */
GregCr 0:e6ceb13d2d05 53 #define XTAL_FREQ 32000000
GregCr 0:e6ceb13d2d05 54 #define FREQ_STEP 61.03515625
GregCr 0:e6ceb13d2d05 55
GregCr 0:e6ceb13d2d05 56 #define RX_BUFFER_SIZE 256
GregCr 0:e6ceb13d2d05 57
GregCr 0:e6ceb13d2d05 58 /*!
GregCr 0:e6ceb13d2d05 59 * Constant values need to compute the RSSI value
GregCr 0:e6ceb13d2d05 60 */
GregCr 0:e6ceb13d2d05 61 #define RSSI_OFFSET_LF -164.0
GregCr 0:e6ceb13d2d05 62 #define RSSI_OFFSET_HF -157.0
GregCr 0:e6ceb13d2d05 63
GregCr 0:e6ceb13d2d05 64 #define RF_MID_BAND_THRESH 525000000
GregCr 0:e6ceb13d2d05 65
Helmut Tschemernjak 34:07e89f23c734 66 #if 0
Helmut64 27:1a9d7dadb593 67 #ifdef TARGET_STM32L0
Helmut Tschemernjak 28:6d83af9f8563 68 #define MURATA_ANT_SWITCH 1 // STM B-L072Z-LRWAN1 device
Helmut Tschemernjak 28:6d83af9f8563 69 #elif TARGET_STM32L4
Helmut Tschemernjak 28:6d83af9f8563 70 #define RFM95_MODULE 1 // RFM95 modules are SX1276MB1LAS compatible
Helmut64 27:1a9d7dadb593 71 #endif
Helmut Tschemernjak 34:07e89f23c734 72 #endif
Helmut Tschemernjak 34:07e89f23c734 73
Helmut64 26:87796ee62589 74
Helmut Tschemernjak 38:d9189d958db8 75 /*!
Helmut Tschemernjak 38:d9189d958db8 76 * FSK bandwidth definition
Helmut Tschemernjak 38:d9189d958db8 77 */
Helmut Tschemernjak 38:d9189d958db8 78 typedef struct
Helmut Tschemernjak 38:d9189d958db8 79 {
Helmut Tschemernjak 38:d9189d958db8 80 uint32_t bandwidth;
Helmut Tschemernjak 38:d9189d958db8 81 uint8_t RegValue;
Helmut Tschemernjak 38:d9189d958db8 82 }FskBandwidth_t;
Helmut Tschemernjak 38:d9189d958db8 83
Helmut Tschemernjak 38:d9189d958db8 84
Helmut Tschemernjak 38:d9189d958db8 85
Helmut Tschemernjak 38:d9189d958db8 86 /*!
Helmut Tschemernjak 38:d9189d958db8 87 * Radio registers definition
Helmut Tschemernjak 38:d9189d958db8 88 */
Helmut Tschemernjak 38:d9189d958db8 89 typedef struct
Helmut Tschemernjak 38:d9189d958db8 90 {
Helmut Tschemernjak 38:d9189d958db8 91 ModemType Modem;
Helmut Tschemernjak 38:d9189d958db8 92 uint8_t Addr;
Helmut Tschemernjak 38:d9189d958db8 93 uint8_t Value;
Helmut Tschemernjak 38:d9189d958db8 94 }RadioRegisters_t;
Helmut Tschemernjak 38:d9189d958db8 95
Helmut Tschemernjak 38:d9189d958db8 96 /*!
Helmut Tschemernjak 38:d9189d958db8 97 * Hardware IO IRQ callback function definition
Helmut Tschemernjak 38:d9189d958db8 98 */
Helmut Tschemernjak 38:d9189d958db8 99 typedef void ( SX1276::*DioIrqHandler )( void );
Helmut Tschemernjak 38:d9189d958db8 100
Helmut Tschemernjak 38:d9189d958db8 101
Helmut Tschemernjak 33:5db0d1e716b1 102 typedef enum {
Helmut Tschemernjak 33:5db0d1e716b1 103 LORA_BANKWIDTH_7kHz = 0, // 7.8 kHz requires TCXO
Helmut Tschemernjak 33:5db0d1e716b1 104 LORA_BANKWIDTH_10kHz = 1, // 10.4 kHz requires TCXO
Helmut Tschemernjak 33:5db0d1e716b1 105 LORA_BANKWIDTH_15kHz = 2, // 15.6 kHz requires TCXO
Helmut Tschemernjak 33:5db0d1e716b1 106 LORA_BANKWIDTH_20kHz = 3, // 20.8 kHz requires TCXO
Helmut Tschemernjak 33:5db0d1e716b1 107 LORA_BANKWIDTH_31kHz = 4, // 31.2 kHz requires TCXO
Helmut Tschemernjak 33:5db0d1e716b1 108 LORA_BANKWIDTH_41kHz = 5, // 41.4 kHz requires TCXO
Helmut Tschemernjak 33:5db0d1e716b1 109 LORA_BANKWIDTH_62kHz = 6, // 62.5 kHz requires TCXO
Helmut Tschemernjak 33:5db0d1e716b1 110
Helmut Tschemernjak 33:5db0d1e716b1 111 LORA_BANKWIDTH_125kHz = 7,
Helmut Tschemernjak 33:5db0d1e716b1 112 LORA_BANKWIDTH_250kHz = 8,
Helmut Tschemernjak 33:5db0d1e716b1 113 LORA_BANKWIDTH_500kHz = 9,
Helmut Tschemernjak 33:5db0d1e716b1 114 LORA_BANKWIDTH_RESERVED = 10,
Helmut Tschemernjak 33:5db0d1e716b1 115 } Lora_bandwidth_t;
Helmut Tschemernjak 33:5db0d1e716b1 116
Helmut Tschemernjak 33:5db0d1e716b1 117
Helmut Tschemernjak 33:5db0d1e716b1 118
Helmut Tschemernjak 33:5db0d1e716b1 119 typedef enum {
Helmut Tschemernjak 33:5db0d1e716b1 120 LORA_SF6 = 6, // 64 chips/symbol, SF6 requires an TCXO!
Helmut Tschemernjak 33:5db0d1e716b1 121 LORA_SF7 = 7, // 128 chips/symbol
Helmut Tschemernjak 33:5db0d1e716b1 122 LORA_SF8 = 8, // 256 chips/symbol
Helmut Tschemernjak 33:5db0d1e716b1 123 LORA_SF9 = 9, // 512 chips/symbol
Helmut Tschemernjak 33:5db0d1e716b1 124 LORA_SF10 = 10, // 1024 chips/symbol
Helmut Tschemernjak 33:5db0d1e716b1 125 LORA_SF11 = 11, // 2048 chips/symbol
Helmut Tschemernjak 33:5db0d1e716b1 126 LORA_SF12 = 12, // 4096 chips/symbol
Helmut Tschemernjak 33:5db0d1e716b1 127 } lora_spreading_factor_t;
Helmut Tschemernjak 33:5db0d1e716b1 128
Helmut Tschemernjak 33:5db0d1e716b1 129
Helmut Tschemernjak 33:5db0d1e716b1 130 typedef enum { // cyclic error coding to perform forward error detection and correction
Helmut Tschemernjak 33:5db0d1e716b1 131 LORA_ERROR_CODING_RATE_4_5 = 1, // 1.25x overhead
Helmut Tschemernjak 33:5db0d1e716b1 132 LORA_ERROR_CODING_RATE_4_6 = 2, // 1.50x overhead
Helmut Tschemernjak 33:5db0d1e716b1 133 LORA_ERROR_CODING_RATE_4_7 = 3, // 1.75x overhead
Helmut Tschemernjak 33:5db0d1e716b1 134 LORA_ERROR_CODING_RATE_4_8 = 4, // 2.00x overhead
Helmut Tschemernjak 33:5db0d1e716b1 135 } lora_coding_rate_t;
Helmut Tschemernjak 33:5db0d1e716b1 136
Helmut Tschemernjak 33:5db0d1e716b1 137
Helmut Tschemernjak 33:5db0d1e716b1 138 typedef enum {
Helmut Tschemernjak 33:5db0d1e716b1 139 RF_FREQUENCY_868_0 = 868000000, // Hz
Helmut Tschemernjak 33:5db0d1e716b1 140 RF_FREQUENCY_868_1 = 868100000, // Hz
Helmut Tschemernjak 33:5db0d1e716b1 141 RF_FREQUENCY_868_3 = 868300000, // Hz
Helmut Tschemernjak 33:5db0d1e716b1 142 RF_FREQUENCY_868_5 = 868500000, // Hz
Helmut Tschemernjak 33:5db0d1e716b1 143 } rf_frequency_t;
Helmut Tschemernjak 33:5db0d1e716b1 144
Helmut Tschemernjak 33:5db0d1e716b1 145
Helmut Tschemernjak 33:5db0d1e716b1 146
Helmut Tschemernjak 33:5db0d1e716b1 147 /*!
GregCr 0:e6ceb13d2d05 148 * Actual implementation of a SX1276 radio, inherits Radio
GregCr 0:e6ceb13d2d05 149 */
GregCr 0:e6ceb13d2d05 150 class SX1276 : public Radio
GregCr 0:e6ceb13d2d05 151 {
GregCr 0:e6ceb13d2d05 152 protected:
mluis 25:3778e6204cc1 153
mluis 13:618826a997e2 154 bool isRadioActive;
mluis 25:3778e6204cc1 155
Helmut Tschemernjak 34:07e89f23c734 156 BoardType_t boardConnected; //1 = SX1276MB1LAS; 0 = SX1276MB1MAS
mluis 25:3778e6204cc1 157
GregCr 23:1e143575df0f 158 uint8_t *rxtxBuffer;
mluis 13:618826a997e2 159
mluis 13:618826a997e2 160 /*!
mluis 13:618826a997e2 161 * Hardware DIO IRQ functions
mluis 13:618826a997e2 162 */
mluis 13:618826a997e2 163 DioIrqHandler *dioIrq;
mluis 25:3778e6204cc1 164
mluis 13:618826a997e2 165 /*!
mluis 13:618826a997e2 166 * Tx and Rx timers
mluis 13:618826a997e2 167 */
mluis 13:618826a997e2 168 Timeout txTimeoutTimer;
mluis 13:618826a997e2 169 Timeout rxTimeoutTimer;
mluis 13:618826a997e2 170 Timeout rxTimeoutSyncWord;
mluis 25:3778e6204cc1 171
mluis 13:618826a997e2 172 RadioSettings_t settings;
mluis 25:3778e6204cc1 173
Helmut Tschemernjak 31:e50929bd3f32 174 static const FskBandwidth_t FskBandwidths[];
Helmut Tschemernjak 38:d9189d958db8 175
GregCr 0:e6ceb13d2d05 176 protected:
GregCr 0:e6ceb13d2d05 177
mluis 13:618826a997e2 178 /*!
mluis 13:618826a997e2 179 * Performs the Rx chain calibration for LF and HF bands
mluis 13:618826a997e2 180 * \remark Must be called just after the reset so all registers are at their
mluis 13:618826a997e2 181 * default values
mluis 13:618826a997e2 182 */
mluis 13:618826a997e2 183 void RxChainCalibration( void );
GregCr 0:e6ceb13d2d05 184
GregCr 0:e6ceb13d2d05 185 public:
Helmut Tschemernjak 34:07e89f23c734 186 SX1276( RadioEvents_t *events);
mluis 13:618826a997e2 187 virtual ~SX1276( );
mluis 13:618826a997e2 188
mluis 13:618826a997e2 189 //-------------------------------------------------------------------------
mluis 13:618826a997e2 190 // Redefined Radio functions
mluis 13:618826a997e2 191 //-------------------------------------------------------------------------
mluis 13:618826a997e2 192 /*!
mluis 21:2e496deb7858 193 * @brief Initializes the radio
mluis 21:2e496deb7858 194 *
mluis 21:2e496deb7858 195 * @param [IN] events Structure containing the driver callback functions
mluis 21:2e496deb7858 196 */
mluis 21:2e496deb7858 197 virtual void Init( RadioEvents_t *events );
Helmut Tschemernjak 38:d9189d958db8 198
Helmut Tschemernjak 38:d9189d958db8 199 /*!
Helmut Tschemernjak 38:d9189d958db8 200 * @brief Initializes the radio registers
Helmut Tschemernjak 38:d9189d958db8 201 */
Helmut Tschemernjak 38:d9189d958db8 202 virtual void RadioRegistersInit(void);
Helmut Tschemernjak 38:d9189d958db8 203
mluis 21:2e496deb7858 204 /*!
GregCr 0:e6ceb13d2d05 205 * Return current radio status
GregCr 0:e6ceb13d2d05 206 *
mluis 21:2e496deb7858 207 * @param status Radio status. [RF_IDLE, RX_RUNNING, TX_RUNNING]
GregCr 0:e6ceb13d2d05 208 */
GregCr 19:71a47bb03fbb 209 virtual RadioState GetStatus( void );
mluis 25:3778e6204cc1 210
mluis 13:618826a997e2 211 /*!
mluis 13:618826a997e2 212 * @brief Configures the SX1276 with the given modem
mluis 13:618826a997e2 213 *
mluis 13:618826a997e2 214 * @param [IN] modem Modem to be used [0: FSK, 1: LoRa]
mluis 13:618826a997e2 215 */
mluis 22:7f3aab69cca9 216 virtual void SetModem( RadioModems_t modem );
mluis 13:618826a997e2 217
mluis 13:618826a997e2 218 /*!
GregCr 0:e6ceb13d2d05 219 * @brief Sets the channel frequency
GregCr 0:e6ceb13d2d05 220 *
GregCr 0:e6ceb13d2d05 221 * @param [IN] freq Channel RF frequency
GregCr 0:e6ceb13d2d05 222 */
GregCr 0:e6ceb13d2d05 223 virtual void SetChannel( uint32_t freq );
mluis 25:3778e6204cc1 224
mluis 13:618826a997e2 225 /*!
GregCr 0:e6ceb13d2d05 226 * @brief Sets the channels configuration
GregCr 0:e6ceb13d2d05 227 *
GregCr 0:e6ceb13d2d05 228 * @param [IN] modem Radio modem to be used [0: FSK, 1: LoRa]
GregCr 0:e6ceb13d2d05 229 * @param [IN] freq Channel RF frequency
GregCr 0:e6ceb13d2d05 230 * @param [IN] rssiThresh RSSI threshold
GregCr 0:e6ceb13d2d05 231 *
GregCr 0:e6ceb13d2d05 232 * @retval isFree [true: Channel is free, false: Channel is not free]
GregCr 0:e6ceb13d2d05 233 */
mluis 22:7f3aab69cca9 234 virtual bool IsChannelFree( RadioModems_t modem, uint32_t freq, int16_t rssiThresh );
mluis 25:3778e6204cc1 235
mluis 13:618826a997e2 236 /*!
GregCr 0:e6ceb13d2d05 237 * @brief Generates a 32 bits random value based on the RSSI readings
GregCr 0:e6ceb13d2d05 238 *
GregCr 0:e6ceb13d2d05 239 * \remark This function sets the radio in LoRa modem mode and disables
GregCr 0:e6ceb13d2d05 240 * all interrupts.
GregCr 0:e6ceb13d2d05 241 * After calling this function either Radio.SetRxConfig or
GregCr 0:e6ceb13d2d05 242 * Radio.SetTxConfig functions must be called.
GregCr 0:e6ceb13d2d05 243 *
GregCr 0:e6ceb13d2d05 244 * @retval randomValue 32 bits random value
GregCr 0:e6ceb13d2d05 245 */
GregCr 0:e6ceb13d2d05 246 virtual uint32_t Random( void );
mluis 25:3778e6204cc1 247
mluis 13:618826a997e2 248 /*!
GregCr 0:e6ceb13d2d05 249 * @brief Sets the reception parameters
GregCr 0:e6ceb13d2d05 250 *
GregCr 0:e6ceb13d2d05 251 * @param [IN] modem Radio modem to be used [0: FSK, 1: LoRa]
GregCr 0:e6ceb13d2d05 252 * @param [IN] bandwidth Sets the bandwidth
GregCr 0:e6ceb13d2d05 253 * FSK : >= 2600 and <= 250000 Hz
GregCr 0:e6ceb13d2d05 254 * LoRa: [0: 125 kHz, 1: 250 kHz,
GregCr 0:e6ceb13d2d05 255 * 2: 500 kHz, 3: Reserved]
GregCr 0:e6ceb13d2d05 256 * @param [IN] datarate Sets the Datarate
GregCr 0:e6ceb13d2d05 257 * FSK : 600..300000 bits/s
GregCr 0:e6ceb13d2d05 258 * LoRa: [6: 64, 7: 128, 8: 256, 9: 512,
GregCr 0:e6ceb13d2d05 259 * 10: 1024, 11: 2048, 12: 4096 chips]
GregCr 0:e6ceb13d2d05 260 * @param [IN] coderate Sets the coding rate ( LoRa only )
GregCr 0:e6ceb13d2d05 261 * FSK : N/A ( set to 0 )
GregCr 0:e6ceb13d2d05 262 * LoRa: [1: 4/5, 2: 4/6, 3: 4/7, 4: 4/8]
GregCr 0:e6ceb13d2d05 263 * @param [IN] bandwidthAfc Sets the AFC Bandwidth ( FSK only )
GregCr 0:e6ceb13d2d05 264 * FSK : >= 2600 and <= 250000 Hz
GregCr 0:e6ceb13d2d05 265 * LoRa: N/A ( set to 0 )
GregCr 0:e6ceb13d2d05 266 * @param [IN] preambleLen Sets the Preamble length ( LoRa only )
GregCr 0:e6ceb13d2d05 267 * FSK : N/A ( set to 0 )
GregCr 0:e6ceb13d2d05 268 * LoRa: Length in symbols ( the hardware adds 4 more symbols )
Helmut Tschemernjak 31:e50929bd3f32 269 * @param [IN] symbTimeout Sets the RxSingle timeout value
Helmut Tschemernjak 31:e50929bd3f32 270 * FSK : timeout number of bytes
GregCr 0:e6ceb13d2d05 271 * LoRa: timeout in symbols
GregCr 0:e6ceb13d2d05 272 * @param [IN] fixLen Fixed length packets [0: variable, 1: fixed]
mluis 13:618826a997e2 273 * @param [IN] payloadLen Sets payload length when fixed lenght is used
GregCr 0:e6ceb13d2d05 274 * @param [IN] crcOn Enables/Disables the CRC [0: OFF, 1: ON]
mluis 13:618826a997e2 275 * @param [IN] freqHopOn Enables disables the intra-packet frequency hopping [0: OFF, 1: ON] (LoRa only)
mluis 13:618826a997e2 276 * @param [IN] hopPeriod Number of symbols bewteen each hop (LoRa only)
GregCr 0:e6ceb13d2d05 277 * @param [IN] iqInverted Inverts IQ signals ( LoRa only )
GregCr 0:e6ceb13d2d05 278 * FSK : N/A ( set to 0 )
GregCr 0:e6ceb13d2d05 279 * LoRa: [0: not inverted, 1: inverted]
GregCr 0:e6ceb13d2d05 280 * @param [IN] rxContinuous Sets the reception in continuous mode
GregCr 0:e6ceb13d2d05 281 * [false: single mode, true: continuous mode]
GregCr 0:e6ceb13d2d05 282 */
mluis 22:7f3aab69cca9 283 virtual void SetRxConfig ( RadioModems_t modem, uint32_t bandwidth,
GregCr 0:e6ceb13d2d05 284 uint32_t datarate, uint8_t coderate,
GregCr 0:e6ceb13d2d05 285 uint32_t bandwidthAfc, uint16_t preambleLen,
GregCr 0:e6ceb13d2d05 286 uint16_t symbTimeout, bool fixLen,
mluis 13:618826a997e2 287 uint8_t payloadLen,
mluis 13:618826a997e2 288 bool crcOn, bool freqHopOn, uint8_t hopPeriod,
GregCr 6:e7f02929cd3d 289 bool iqInverted, bool rxContinuous );
mluis 25:3778e6204cc1 290
mluis 13:618826a997e2 291 /*!
GregCr 0:e6ceb13d2d05 292 * @brief Sets the transmission parameters
GregCr 0:e6ceb13d2d05 293 *
GregCr 0:e6ceb13d2d05 294 * @param [IN] modem Radio modem to be used [0: FSK, 1: LoRa]
GregCr 0:e6ceb13d2d05 295 * @param [IN] power Sets the output power [dBm]
GregCr 0:e6ceb13d2d05 296 * @param [IN] fdev Sets the frequency deviation ( FSK only )
GregCr 0:e6ceb13d2d05 297 * FSK : [Hz]
GregCr 0:e6ceb13d2d05 298 * LoRa: 0
GregCr 0:e6ceb13d2d05 299 * @param [IN] bandwidth Sets the bandwidth ( LoRa only )
GregCr 0:e6ceb13d2d05 300 * FSK : 0
GregCr 0:e6ceb13d2d05 301 * LoRa: [0: 125 kHz, 1: 250 kHz,
GregCr 0:e6ceb13d2d05 302 * 2: 500 kHz, 3: Reserved]
GregCr 0:e6ceb13d2d05 303 * @param [IN] datarate Sets the Datarate
GregCr 0:e6ceb13d2d05 304 * FSK : 600..300000 bits/s
GregCr 0:e6ceb13d2d05 305 * LoRa: [6: 64, 7: 128, 8: 256, 9: 512,
GregCr 0:e6ceb13d2d05 306 * 10: 1024, 11: 2048, 12: 4096 chips]
GregCr 0:e6ceb13d2d05 307 * @param [IN] coderate Sets the coding rate ( LoRa only )
GregCr 0:e6ceb13d2d05 308 * FSK : N/A ( set to 0 )
GregCr 0:e6ceb13d2d05 309 * LoRa: [1: 4/5, 2: 4/6, 3: 4/7, 4: 4/8]
GregCr 0:e6ceb13d2d05 310 * @param [IN] preambleLen Sets the preamble length
GregCr 0:e6ceb13d2d05 311 * @param [IN] fixLen Fixed length packets [0: variable, 1: fixed]
GregCr 0:e6ceb13d2d05 312 * @param [IN] crcOn Enables disables the CRC [0: OFF, 1: ON]
mluis 13:618826a997e2 313 * @param [IN] freqHopOn Enables disables the intra-packet frequency hopping [0: OFF, 1: ON] (LoRa only)
mluis 13:618826a997e2 314 * @param [IN] hopPeriod Number of symbols bewteen each hop (LoRa only)
GregCr 0:e6ceb13d2d05 315 * @param [IN] iqInverted Inverts IQ signals ( LoRa only )
GregCr 0:e6ceb13d2d05 316 * FSK : N/A ( set to 0 )
GregCr 0:e6ceb13d2d05 317 * LoRa: [0: not inverted, 1: inverted]
Helmut Tschemernjak 31:e50929bd3f32 318 * @param [IN] timeout Transmission timeout [ms]
GregCr 0:e6ceb13d2d05 319 */
mluis 22:7f3aab69cca9 320 virtual void SetTxConfig( RadioModems_t modem, int8_t power, uint32_t fdev,
GregCr 0:e6ceb13d2d05 321 uint32_t bandwidth, uint32_t datarate,
GregCr 0:e6ceb13d2d05 322 uint8_t coderate, uint16_t preambleLen,
mluis 13:618826a997e2 323 bool fixLen, bool crcOn, bool freqHopOn,
mluis 13:618826a997e2 324 uint8_t hopPeriod, bool iqInverted, uint32_t timeout );
mluis 25:3778e6204cc1 325
Helmut Tschemernjak 38:d9189d958db8 326
mluis 13:618826a997e2 327 /*!
Helmut Tschemernjak 31:e50929bd3f32 328 * @brief Checks if the given RF frequency is supported by the hardware
Helmut Tschemernjak 31:e50929bd3f32 329 *
Helmut Tschemernjak 31:e50929bd3f32 330 * @param [IN] frequency RF frequency to be checked
Helmut Tschemernjak 31:e50929bd3f32 331 * @retval isSupported [true: supported, false: unsupported]
Helmut Tschemernjak 31:e50929bd3f32 332 */
Helmut Tschemernjak 31:e50929bd3f32 333 virtual bool CheckRfFrequency( uint32_t frequency ) = 0;
Helmut Tschemernjak 31:e50929bd3f32 334
Helmut Tschemernjak 31:e50929bd3f32 335 /*!
GregCr 0:e6ceb13d2d05 336 * @brief Computes the packet time on air for the given payload
GregCr 0:e6ceb13d2d05 337 *
GregCr 0:e6ceb13d2d05 338 * \Remark Can only be called once SetRxConfig or SetTxConfig have been called
GregCr 0:e6ceb13d2d05 339 *
GregCr 0:e6ceb13d2d05 340 * @param [IN] modem Radio modem to be used [0: FSK, 1: LoRa]
GregCr 0:e6ceb13d2d05 341 * @param [IN] pktLen Packet payload length
GregCr 0:e6ceb13d2d05 342 *
GregCr 0:e6ceb13d2d05 343 * @retval airTime Computed airTime for the given packet payload length
GregCr 0:e6ceb13d2d05 344 */
Helmut Tschemernjak 31:e50929bd3f32 345 virtual uint32_t TimeOnAir ( RadioModems_t modem, uint8_t pktLen );
mluis 25:3778e6204cc1 346
mluis 13:618826a997e2 347 /*!
GregCr 0:e6ceb13d2d05 348 * @brief Sends the buffer of size. Prepares the packet to be sent and sets
GregCr 0:e6ceb13d2d05 349 * the radio in transmission
GregCr 0:e6ceb13d2d05 350 *
GregCr 0:e6ceb13d2d05 351 * @param [IN]: buffer Buffer pointer
GregCr 0:e6ceb13d2d05 352 * @param [IN]: size Buffer size
GregCr 0:e6ceb13d2d05 353 */
GregCr 0:e6ceb13d2d05 354 virtual void Send( uint8_t *buffer, uint8_t size );
mluis 25:3778e6204cc1 355
mluis 13:618826a997e2 356 /*!
GregCr 0:e6ceb13d2d05 357 * @brief Sets the radio in sleep mode
GregCr 0:e6ceb13d2d05 358 */
GregCr 0:e6ceb13d2d05 359 virtual void Sleep( void );
GregCr 0:e6ceb13d2d05 360
mluis 13:618826a997e2 361 /*!
GregCr 0:e6ceb13d2d05 362 * @brief Sets the radio in standby mode
GregCr 0:e6ceb13d2d05 363 */
GregCr 0:e6ceb13d2d05 364 virtual void Standby( void );
Helmut Tschemernjak 31:e50929bd3f32 365
Helmut Tschemernjak 31:e50929bd3f32 366 /*!
Helmut Tschemernjak 31:e50929bd3f32 367 * @brief Sets the radio in CAD mode
Helmut Tschemernjak 31:e50929bd3f32 368 */
Helmut Tschemernjak 31:e50929bd3f32 369 virtual void StartCad( void );
mluis 25:3778e6204cc1 370
mluis 13:618826a997e2 371 /*!
GregCr 0:e6ceb13d2d05 372 * @brief Sets the radio in reception mode for the given time
Helmut Tschemernjak 31:e50929bd3f32 373 * @param [IN] timeout Reception timeout [ms]
GregCr 0:e6ceb13d2d05 374 * [0: continuous, others timeout]
GregCr 0:e6ceb13d2d05 375 */
GregCr 0:e6ceb13d2d05 376 virtual void Rx( uint32_t timeout );
mluis 25:3778e6204cc1 377
mluis 13:618826a997e2 378 /*!
GregCr 0:e6ceb13d2d05 379 * @brief Sets the radio in transmission mode for the given time
Helmut Tschemernjak 31:e50929bd3f32 380 * @param [IN] timeout Transmission timeout [ms]
GregCr 0:e6ceb13d2d05 381 * [0: continuous, others timeout]
GregCr 0:e6ceb13d2d05 382 */
GregCr 0:e6ceb13d2d05 383 virtual void Tx( uint32_t timeout );
mluis 25:3778e6204cc1 384
mluis 13:618826a997e2 385 /*!
Helmut Tschemernjak 31:e50929bd3f32 386 * @brief Sets the radio in continuous wave transmission mode
Helmut Tschemernjak 31:e50929bd3f32 387 *
Helmut Tschemernjak 31:e50929bd3f32 388 * @param [IN]: freq Channel RF frequency
Helmut Tschemernjak 31:e50929bd3f32 389 * @param [IN]: power Sets the output power [dBm]
Helmut Tschemernjak 31:e50929bd3f32 390 * @param [IN]: time Transmission mode timeout [s]
GregCr 7:2b555111463f 391 */
Helmut Tschemernjak 31:e50929bd3f32 392
Helmut Tschemernjak 31:e50929bd3f32 393 virtual void SetTxContinuousWave( uint32_t freq, int8_t power, uint16_t time );
mluis 25:3778e6204cc1 394
mluis 13:618826a997e2 395 /*!
GregCr 0:e6ceb13d2d05 396 * @brief Reads the current RSSI value
GregCr 0:e6ceb13d2d05 397 *
GregCr 0:e6ceb13d2d05 398 * @retval rssiValue Current RSSI value in [dBm]
GregCr 0:e6ceb13d2d05 399 */
mluis 22:7f3aab69cca9 400 virtual int16_t GetRssi ( RadioModems_t modem );
mluis 25:3778e6204cc1 401
mluis 13:618826a997e2 402 /*!
GregCr 0:e6ceb13d2d05 403 * @brief Writes the radio register at the specified address
GregCr 0:e6ceb13d2d05 404 *
GregCr 0:e6ceb13d2d05 405 * @param [IN]: addr Register address
GregCr 0:e6ceb13d2d05 406 * @param [IN]: data New register value
GregCr 0:e6ceb13d2d05 407 */
GregCr 0:e6ceb13d2d05 408 virtual void Write ( uint8_t addr, uint8_t data ) = 0;
mluis 25:3778e6204cc1 409
mluis 13:618826a997e2 410 /*!
GregCr 0:e6ceb13d2d05 411 * @brief Reads the radio register at the specified address
GregCr 0:e6ceb13d2d05 412 *
GregCr 0:e6ceb13d2d05 413 * @param [IN]: addr Register address
GregCr 0:e6ceb13d2d05 414 * @retval data Register value
GregCr 0:e6ceb13d2d05 415 */
GregCr 0:e6ceb13d2d05 416 virtual uint8_t Read ( uint8_t addr ) = 0;
mluis 25:3778e6204cc1 417
mluis 13:618826a997e2 418 /*!
GregCr 0:e6ceb13d2d05 419 * @brief Writes multiple radio registers starting at address
GregCr 0:e6ceb13d2d05 420 *
GregCr 0:e6ceb13d2d05 421 * @param [IN] addr First Radio register address
GregCr 0:e6ceb13d2d05 422 * @param [IN] buffer Buffer containing the new register's values
GregCr 0:e6ceb13d2d05 423 * @param [IN] size Number of registers to be written
GregCr 0:e6ceb13d2d05 424 */
GregCr 0:e6ceb13d2d05 425 virtual void Write( uint8_t addr, uint8_t *buffer, uint8_t size ) = 0;
mluis 25:3778e6204cc1 426
mluis 13:618826a997e2 427 /*!
GregCr 0:e6ceb13d2d05 428 * @brief Reads multiple radio registers starting at address
GregCr 0:e6ceb13d2d05 429 *
GregCr 0:e6ceb13d2d05 430 * @param [IN] addr First Radio register address
GregCr 0:e6ceb13d2d05 431 * @param [OUT] buffer Buffer where to copy the registers data
GregCr 0:e6ceb13d2d05 432 * @param [IN] size Number of registers to be read
GregCr 0:e6ceb13d2d05 433 */
GregCr 0:e6ceb13d2d05 434 virtual void Read ( uint8_t addr, uint8_t *buffer, uint8_t size ) = 0;
mluis 25:3778e6204cc1 435
mluis 13:618826a997e2 436 /*!
mluis 13:618826a997e2 437 * @brief Writes the buffer contents to the SX1276 FIFO
mluis 13:618826a997e2 438 *
mluis 13:618826a997e2 439 * @param [IN] buffer Buffer containing data to be put on the FIFO.
mluis 13:618826a997e2 440 * @param [IN] size Number of bytes to be written to the FIFO
mluis 13:618826a997e2 441 */
mluis 13:618826a997e2 442 virtual void WriteFifo( uint8_t *buffer, uint8_t size ) = 0;
GregCr 0:e6ceb13d2d05 443
mluis 13:618826a997e2 444 /*!
mluis 13:618826a997e2 445 * @brief Reads the contents of the SX1276 FIFO
mluis 13:618826a997e2 446 *
mluis 13:618826a997e2 447 * @param [OUT] buffer Buffer where to copy the FIFO read data.
mluis 13:618826a997e2 448 * @param [IN] size Number of bytes to be read from the FIFO
mluis 13:618826a997e2 449 */
mluis 13:618826a997e2 450 virtual void ReadFifo( uint8_t *buffer, uint8_t size ) = 0;
mluis 13:618826a997e2 451 /*!
mluis 13:618826a997e2 452 * @brief Resets the SX1276
mluis 13:618826a997e2 453 */
mluis 13:618826a997e2 454 virtual void Reset( void ) = 0;
mluis 25:3778e6204cc1 455
mluis 20:e05596ba4166 456 /*!
mluis 20:e05596ba4166 457 * @brief Sets the maximum payload length.
mluis 20:e05596ba4166 458 *
mluis 20:e05596ba4166 459 * @param [IN] modem Radio modem to be used [0: FSK, 1: LoRa]
mluis 20:e05596ba4166 460 * @param [IN] max Maximum payload length in bytes
mluis 20:e05596ba4166 461 */
mluis 22:7f3aab69cca9 462 virtual void SetMaxPayloadLength( RadioModems_t modem, uint8_t max );
mluis 25:3778e6204cc1 463
Helmut Tschemernjak 31:e50929bd3f32 464 /*!
Helmut Tschemernjak 31:e50929bd3f32 465 * \brief Sets the network to public or private. Updates the sync byte.
Helmut Tschemernjak 31:e50929bd3f32 466 *
Helmut Tschemernjak 31:e50929bd3f32 467 * \remark Applies to LoRa modem only
Helmut Tschemernjak 31:e50929bd3f32 468 *
Helmut Tschemernjak 31:e50929bd3f32 469 * \param [IN] enable if true, it enables a public network
Helmut Tschemernjak 31:e50929bd3f32 470 */
Helmut Tschemernjak 31:e50929bd3f32 471 virtual void SetPublicNetwork( bool enable );
Helmut Tschemernjak 31:e50929bd3f32 472
Helmut Tschemernjak 31:e50929bd3f32 473
mluis 13:618826a997e2 474 //-------------------------------------------------------------------------
mluis 13:618826a997e2 475 // Board relative functions
mluis 13:618826a997e2 476 //-------------------------------------------------------------------------
Helmut Tschemernjak 38:d9189d958db8 477 static const RadioRegisters_t RadioRegsInit[];
Helmut Tschemernjak 38:d9189d958db8 478 private:
Helmut Tschemernjak 38:d9189d958db8 479
GregCr 0:e6ceb13d2d05 480 protected:
mluis 13:618826a997e2 481 /*!
mluis 13:618826a997e2 482 * @brief Initializes the radio I/Os pins interface
mluis 13:618826a997e2 483 */
mluis 13:618826a997e2 484 virtual void IoInit( void ) = 0;
mluis 13:618826a997e2 485
mluis 13:618826a997e2 486 /*!
mluis 13:618826a997e2 487 * @brief Initializes the radio SPI
mluis 13:618826a997e2 488 */
mluis 13:618826a997e2 489 virtual void SpiInit( void ) = 0;
mluis 25:3778e6204cc1 490
mluis 13:618826a997e2 491 /*!
mluis 13:618826a997e2 492 * @brief Initializes DIO IRQ handlers
mluis 13:618826a997e2 493 *
mluis 13:618826a997e2 494 * @param [IN] irqHandlers Array containing the IRQ callback functions
mluis 13:618826a997e2 495 */
mluis 13:618826a997e2 496 virtual void IoIrqInit( DioIrqHandler *irqHandlers ) = 0;
GregCr 0:e6ceb13d2d05 497
mluis 13:618826a997e2 498 /*!
mluis 13:618826a997e2 499 * @brief De-initializes the radio I/Os pins interface.
mluis 13:618826a997e2 500 *
mluis 13:618826a997e2 501 * \remark Useful when going in MCU lowpower modes
mluis 13:618826a997e2 502 */
mluis 13:618826a997e2 503 virtual void IoDeInit( void ) = 0;
GregCr 0:e6ceb13d2d05 504
mluis 13:618826a997e2 505 /*!
Helmut Tschemernjak 31:e50929bd3f32 506 * @brief Sets the radio output power.
Helmut Tschemernjak 31:e50929bd3f32 507 *
Helmut Tschemernjak 31:e50929bd3f32 508 * @param [IN] power Sets the RF output power
Helmut Tschemernjak 31:e50929bd3f32 509 */
Helmut Tschemernjak 31:e50929bd3f32 510 virtual void SetRfTxPower( int8_t power ) = 0;
Helmut Tschemernjak 31:e50929bd3f32 511
Helmut Tschemernjak 31:e50929bd3f32 512 /*!
mluis 13:618826a997e2 513 * @brief Gets the board PA selection configuration
mluis 13:618826a997e2 514 *
mluis 13:618826a997e2 515 * @param [IN] channel Channel frequency in Hz
mluis 13:618826a997e2 516 * @retval PaSelect RegPaConfig PaSelect value
mluis 13:618826a997e2 517 */
mluis 13:618826a997e2 518 virtual uint8_t GetPaSelect( uint32_t channel ) = 0;
GregCr 0:e6ceb13d2d05 519
mluis 13:618826a997e2 520 /*!
mluis 13:618826a997e2 521 * @brief Set the RF Switch I/Os pins in Low Power mode
mluis 13:618826a997e2 522 *
mluis 13:618826a997e2 523 * @param [IN] status enable or disable
mluis 13:618826a997e2 524 */
mluis 13:618826a997e2 525 virtual void SetAntSwLowPower( bool status ) = 0;
GregCr 0:e6ceb13d2d05 526
mluis 13:618826a997e2 527 /*!
mluis 13:618826a997e2 528 * @brief Initializes the RF Switch I/Os pins interface
mluis 13:618826a997e2 529 */
mluis 13:618826a997e2 530 virtual void AntSwInit( void ) = 0;
GregCr 0:e6ceb13d2d05 531
mluis 13:618826a997e2 532 /*!
mluis 13:618826a997e2 533 * @brief De-initializes the RF Switch I/Os pins interface
mluis 13:618826a997e2 534 *
mluis 13:618826a997e2 535 * \remark Needed to decrease the power consumption in MCU lowpower modes
mluis 13:618826a997e2 536 */
mluis 13:618826a997e2 537 virtual void AntSwDeInit( void ) = 0;
GregCr 0:e6ceb13d2d05 538
mluis 13:618826a997e2 539 /*!
Helmut Tschemernjak 31:e50929bd3f32 540 * @brief Controls the antenna switch if necessary.
mluis 13:618826a997e2 541 *
mluis 13:618826a997e2 542 * \remark see errata note
mluis 13:618826a997e2 543 *
Helmut Tschemernjak 31:e50929bd3f32 544 * @param [IN] opMode Current radio operating mode
mluis 13:618826a997e2 545 */
Helmut Tschemernjak 31:e50929bd3f32 546 virtual void SetAntSw( uint8_t opMode ) = 0;
Helmut Tschemernjak 31:e50929bd3f32 547
Helmut Tschemernjak 38:d9189d958db8 548 /*
Helmut Tschemernjak 38:d9189d958db8 549 * The the Timeout for a given Timer.
Helmut Tschemernjak 38:d9189d958db8 550 */
Helmut Tschemernjak 38:d9189d958db8 551 virtual void SetTimeout(Timeout_t timer, int timeout_ms) = 0;
Helmut Tschemernjak 38:d9189d958db8 552
Helmut Tschemernjak 38:d9189d958db8 553
GregCr 0:e6ceb13d2d05 554 protected:
GregCr 0:e6ceb13d2d05 555
mluis 13:618826a997e2 556 /*!
mluis 13:618826a997e2 557 * @brief Sets the SX1276 operating mode
mluis 13:618826a997e2 558 *
mluis 13:618826a997e2 559 * @param [IN] opMode New operating mode
mluis 13:618826a997e2 560 */
mluis 13:618826a997e2 561 virtual void SetOpMode( uint8_t opMode );
GregCr 0:e6ceb13d2d05 562
mluis 13:618826a997e2 563 /*
mluis 13:618826a997e2 564 * SX1276 DIO IRQ callback functions prototype
mluis 13:618826a997e2 565 */
GregCr 0:e6ceb13d2d05 566
mluis 13:618826a997e2 567 /*!
mluis 13:618826a997e2 568 * @brief DIO 0 IRQ callback
mluis 13:618826a997e2 569 */
mluis 13:618826a997e2 570 virtual void OnDio0Irq( void );
GregCr 0:e6ceb13d2d05 571
mluis 13:618826a997e2 572 /*!
mluis 13:618826a997e2 573 * @brief DIO 1 IRQ callback
mluis 13:618826a997e2 574 */
mluis 13:618826a997e2 575 virtual void OnDio1Irq( void );
GregCr 0:e6ceb13d2d05 576
mluis 13:618826a997e2 577 /*!
mluis 13:618826a997e2 578 * @brief DIO 2 IRQ callback
mluis 13:618826a997e2 579 */
mluis 13:618826a997e2 580 virtual void OnDio2Irq( void );
GregCr 0:e6ceb13d2d05 581
mluis 13:618826a997e2 582 /*!
mluis 13:618826a997e2 583 * @brief DIO 3 IRQ callback
mluis 13:618826a997e2 584 */
mluis 13:618826a997e2 585 virtual void OnDio3Irq( void );
GregCr 0:e6ceb13d2d05 586
mluis 13:618826a997e2 587 /*!
mluis 13:618826a997e2 588 * @brief DIO 4 IRQ callback
mluis 13:618826a997e2 589 */
mluis 13:618826a997e2 590 virtual void OnDio4Irq( void );
GregCr 0:e6ceb13d2d05 591
mluis 13:618826a997e2 592 /*!
mluis 13:618826a997e2 593 * @brief DIO 5 IRQ callback
mluis 13:618826a997e2 594 */
mluis 13:618826a997e2 595 virtual void OnDio5Irq( void );
GregCr 0:e6ceb13d2d05 596
mluis 13:618826a997e2 597 /*!
mluis 13:618826a997e2 598 * @brief Tx & Rx timeout timer callback
mluis 13:618826a997e2 599 */
mluis 13:618826a997e2 600 virtual void OnTimeoutIrq( void );
mluis 25:3778e6204cc1 601
mluis 13:618826a997e2 602 /*!
mluis 13:618826a997e2 603 * Returns the known FSK bandwidth registers value
mluis 13:618826a997e2 604 *
mluis 13:618826a997e2 605 * \param [IN] bandwidth Bandwidth value in Hz
mluis 13:618826a997e2 606 * \retval regValue Bandwidth register value.
mluis 13:618826a997e2 607 */
mluis 13:618826a997e2 608 static uint8_t GetFskBandwidthRegValue( uint32_t bandwidth );
GregCr 0:e6ceb13d2d05 609 };
GregCr 0:e6ceb13d2d05 610
mluis 22:7f3aab69cca9 611 #endif // __SX1276_H__