This is code is part of a Technion course project in advanced IoT, implementing a device to read and transmit 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 read and transmit sensors data from a Formula racing car built by students at Technion - Israel Institute of Technology.

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_Reader"
  • Select a Platform like so:
  1. Click button at top-left
  2. Add Board
  3. Search "B-L072Z-LRWAN1" 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 11:41:10 2018 +0000
Revision:
12:02d779e8c4f6
Code for Technion Formula car sensors reader transmit

Who changed what in which revision?

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