This is code is part of a Technion course project in advanced IoT, implementing a device to receive and present sensors data from a Formula racing car built by students at Technion - Israel Institute of Technology.

Dependencies:   mbed Buffer

Fork of DISCO-L072CZ-LRWAN1_LoRa_PingPong by ST

This is code is part of a Technion course project in advanced IoT, implementing a device to receive sensors data from another L072CZ-LRWAN1 installed on a Formula racing car (built by students at Technion - Israel Institute of Technology), and sends it to a GUI presenting the data (GUI project: github.com/ward-mattar/TechnionFormulaGUI).

How to install

  • Create an account on Mbed: https://os.mbed.com/account/signup/
  • Import project into Compiler
  • In the Program Workspace select "Formula_Nucleo_Receiver"
  • Select a Platform like so:
  1. Click button at top-left
  2. Add Board
  3. Search "NUCLEO F103RB" and then "Add to your Mbed Compiler"
  • Finally click "Compile", if the build was successful, the binary would download automatically
  • To install it on device simply plug it in to a PC, open device drive and drag then drop binary file in it
Committer:
wardm
Date:
Sat May 19 15:42:38 2018 +0000
Revision:
12:046346a16ff4
V1.0.0

Who changed what in which revision?

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