SX1276Lib updated in order to be RTOS aware

Fork of SX1276Lib by Semtech

Committer:
mluis
Date:
Mon Apr 24 09:26:23 2017 +0000
Revision:
26:d09a8ef807e2
Parent:
22:7f3aab69cca9
Child:
27:8a37a9362714
WARNING: Radio API timings changed from micro-seconds to milliseconds; ; Synchronized with https://github.com/Lora-net/LoRaMac-node git revision e506c246652fa44c3f24cecb89d0707b49ece739

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 */
GregCr 0:e6ceb13d2d05 15 #ifndef __SX1276_H__
GregCr 0:e6ceb13d2d05 16 #define __SX1276_H__
GregCr 0:e6ceb13d2d05 17
GregCr 0:e6ceb13d2d05 18 #include "radio.h"
GregCr 0:e6ceb13d2d05 19 #include "./registers/sx1276Regs-Fsk.h"
GregCr 0:e6ceb13d2d05 20 #include "./registers/sx1276Regs-LoRa.h"
GregCr 0:e6ceb13d2d05 21 #include "./typedefs/typedefs.h"
GregCr 0:e6ceb13d2d05 22
mluis 16:d447f8d2d2d6 23 /*!
mluis 26:d09a8ef807e2 24 * Radio wake-up time from sleep
mluis 26:d09a8ef807e2 25 */
mluis 26:d09a8ef807e2 26 #define RADIO_WAKEUP_TIME 1 // [ms]
mluis 26:d09a8ef807e2 27
mluis 26:d09a8ef807e2 28 /*!
mluis 26:d09a8ef807e2 29 * Sync word for Private LoRa networks
mluis 16:d447f8d2d2d6 30 */
mluis 26:d09a8ef807e2 31 #define LORA_MAC_PRIVATE_SYNCWORD 0x12
mluis 26:d09a8ef807e2 32
mluis 26:d09a8ef807e2 33 /*!
mluis 26:d09a8ef807e2 34 * Sync word for Public LoRa networks
mluis 26:d09a8ef807e2 35 */
mluis 26:d09a8ef807e2 36 #define LORA_MAC_PUBLIC_SYNCWORD 0x34
mluis 26:d09a8ef807e2 37
mluis 16:d447f8d2d2d6 38
mluis 16:d447f8d2d2d6 39 /*!
mluis 16:d447f8d2d2d6 40 * SX1276 definitions
mluis 16:d447f8d2d2d6 41 */
GregCr 0:e6ceb13d2d05 42 #define XTAL_FREQ 32000000
GregCr 0:e6ceb13d2d05 43 #define FREQ_STEP 61.03515625
GregCr 0:e6ceb13d2d05 44
GregCr 0:e6ceb13d2d05 45 #define RX_BUFFER_SIZE 256
GregCr 0:e6ceb13d2d05 46
GregCr 0:e6ceb13d2d05 47 /*!
GregCr 0:e6ceb13d2d05 48 * Constant values need to compute the RSSI value
GregCr 0:e6ceb13d2d05 49 */
GregCr 0:e6ceb13d2d05 50 #define RSSI_OFFSET_LF -164.0
GregCr 0:e6ceb13d2d05 51 #define RSSI_OFFSET_HF -157.0
GregCr 0:e6ceb13d2d05 52
GregCr 0:e6ceb13d2d05 53 #define RF_MID_BAND_THRESH 525000000
GregCr 0:e6ceb13d2d05 54
GregCr 0:e6ceb13d2d05 55 /*!
GregCr 0:e6ceb13d2d05 56 * Actual implementation of a SX1276 radio, inherits Radio
GregCr 0:e6ceb13d2d05 57 */
GregCr 0:e6ceb13d2d05 58 class SX1276 : public Radio
GregCr 0:e6ceb13d2d05 59 {
GregCr 0:e6ceb13d2d05 60 protected:
GregCr 0:e6ceb13d2d05 61 /*!
GregCr 0:e6ceb13d2d05 62 * SPI Interface
GregCr 0:e6ceb13d2d05 63 */
GregCr 0:e6ceb13d2d05 64 SPI spi; // mosi, miso, sclk
GregCr 0:e6ceb13d2d05 65 DigitalOut nss;
GregCr 0:e6ceb13d2d05 66
GregCr 0:e6ceb13d2d05 67 /*!
GregCr 0:e6ceb13d2d05 68 * SX1276 Reset pin
GregCr 0:e6ceb13d2d05 69 */
GregCr 4:f0ce52e94d3f 70 DigitalInOut reset;
GregCr 0:e6ceb13d2d05 71
GregCr 0:e6ceb13d2d05 72 /*!
GregCr 0:e6ceb13d2d05 73 * SX1276 DIO pins
GregCr 0:e6ceb13d2d05 74 */
mluis 13:618826a997e2 75 InterruptIn dio0;
mluis 13:618826a997e2 76 InterruptIn dio1;
mluis 13:618826a997e2 77 InterruptIn dio2;
mluis 13:618826a997e2 78 InterruptIn dio3;
mluis 13:618826a997e2 79 InterruptIn dio4;
mluis 13:618826a997e2 80 DigitalIn dio5;
mluis 26:d09a8ef807e2 81
mluis 13:618826a997e2 82 bool isRadioActive;
mluis 26:d09a8ef807e2 83
mluis 13:618826a997e2 84 uint8_t boardConnected; //1 = SX1276MB1LAS; 0 = SX1276MB1MAS
mluis 26:d09a8ef807e2 85
mluis 26:d09a8ef807e2 86 uint8_t *rxtxBuffer;
mluis 26:d09a8ef807e2 87
mluis 13:618826a997e2 88 /*!
mluis 13:618826a997e2 89 * Hardware DIO IRQ functions
mluis 13:618826a997e2 90 */
mluis 13:618826a997e2 91 DioIrqHandler *dioIrq;
mluis 26:d09a8ef807e2 92
mluis 13:618826a997e2 93 /*!
mluis 13:618826a997e2 94 * Tx and Rx timers
mluis 13:618826a997e2 95 */
mluis 13:618826a997e2 96 Timeout txTimeoutTimer;
mluis 13:618826a997e2 97 Timeout rxTimeoutTimer;
mluis 13:618826a997e2 98 Timeout rxTimeoutSyncWord;
mluis 26:d09a8ef807e2 99
mluis 13:618826a997e2 100 RadioSettings_t settings;
mluis 26:d09a8ef807e2 101
mluis 26:d09a8ef807e2 102 static const FskBandwidth_t FskBandwidths[];
GregCr 0:e6ceb13d2d05 103 protected:
GregCr 0:e6ceb13d2d05 104
mluis 13:618826a997e2 105 /*!
mluis 13:618826a997e2 106 * Performs the Rx chain calibration for LF and HF bands
mluis 13:618826a997e2 107 * \remark Must be called just after the reset so all registers are at their
mluis 13:618826a997e2 108 * default values
mluis 13:618826a997e2 109 */
mluis 13:618826a997e2 110 void RxChainCalibration( void );
GregCr 0:e6ceb13d2d05 111
GregCr 0:e6ceb13d2d05 112 public:
mluis 21:2e496deb7858 113 SX1276( RadioEvents_t *events,
mluis 13:618826a997e2 114 PinName mosi, PinName miso, PinName sclk, PinName nss, PinName reset,
mluis 26:d09a8ef807e2 115 PinName dio0, PinName dio1, PinName dio2, PinName dio3, PinName dio4, PinName dio5 );
mluis 21:2e496deb7858 116 SX1276( RadioEvents_t *events );
mluis 13:618826a997e2 117 virtual ~SX1276( );
mluis 13:618826a997e2 118
mluis 13:618826a997e2 119 //-------------------------------------------------------------------------
mluis 13:618826a997e2 120 // Redefined Radio functions
mluis 13:618826a997e2 121 //-------------------------------------------------------------------------
mluis 13:618826a997e2 122 /*!
mluis 21:2e496deb7858 123 * @brief Initializes the radio
mluis 21:2e496deb7858 124 *
mluis 21:2e496deb7858 125 * @param [IN] events Structure containing the driver callback functions
mluis 21:2e496deb7858 126 */
mluis 21:2e496deb7858 127 virtual void Init( RadioEvents_t *events );
mluis 21:2e496deb7858 128 /*!
GregCr 0:e6ceb13d2d05 129 * Return current radio status
GregCr 0:e6ceb13d2d05 130 *
mluis 21:2e496deb7858 131 * @param status Radio status. [RF_IDLE, RX_RUNNING, TX_RUNNING]
GregCr 0:e6ceb13d2d05 132 */
GregCr 19:71a47bb03fbb 133 virtual RadioState GetStatus( void );
mluis 13:618826a997e2 134 /*!
mluis 13:618826a997e2 135 * @brief Configures the SX1276 with the given modem
mluis 13:618826a997e2 136 *
mluis 13:618826a997e2 137 * @param [IN] modem Modem to be used [0: FSK, 1: LoRa]
mluis 13:618826a997e2 138 */
mluis 22:7f3aab69cca9 139 virtual void SetModem( RadioModems_t modem );
mluis 13:618826a997e2 140 /*!
GregCr 0:e6ceb13d2d05 141 * @brief Sets the channel frequency
GregCr 0:e6ceb13d2d05 142 *
GregCr 0:e6ceb13d2d05 143 * @param [IN] freq Channel RF frequency
GregCr 0:e6ceb13d2d05 144 */
GregCr 0:e6ceb13d2d05 145 virtual void SetChannel( uint32_t freq );
mluis 13:618826a997e2 146 /*!
GregCr 0:e6ceb13d2d05 147 * @brief Sets the channels configuration
GregCr 0:e6ceb13d2d05 148 *
GregCr 0:e6ceb13d2d05 149 * @param [IN] modem Radio modem to be used [0: FSK, 1: LoRa]
GregCr 0:e6ceb13d2d05 150 * @param [IN] freq Channel RF frequency
GregCr 0:e6ceb13d2d05 151 * @param [IN] rssiThresh RSSI threshold
GregCr 0:e6ceb13d2d05 152 *
GregCr 0:e6ceb13d2d05 153 * @retval isFree [true: Channel is free, false: Channel is not free]
GregCr 0:e6ceb13d2d05 154 */
mluis 22:7f3aab69cca9 155 virtual bool IsChannelFree( RadioModems_t modem, uint32_t freq, int16_t rssiThresh );
mluis 13:618826a997e2 156 /*!
GregCr 0:e6ceb13d2d05 157 * @brief Generates a 32 bits random value based on the RSSI readings
GregCr 0:e6ceb13d2d05 158 *
GregCr 0:e6ceb13d2d05 159 * \remark This function sets the radio in LoRa modem mode and disables
GregCr 0:e6ceb13d2d05 160 * all interrupts.
GregCr 0:e6ceb13d2d05 161 * After calling this function either Radio.SetRxConfig or
GregCr 0:e6ceb13d2d05 162 * Radio.SetTxConfig functions must be called.
GregCr 0:e6ceb13d2d05 163 *
GregCr 0:e6ceb13d2d05 164 * @retval randomValue 32 bits random value
GregCr 0:e6ceb13d2d05 165 */
GregCr 0:e6ceb13d2d05 166 virtual uint32_t Random( void );
mluis 13:618826a997e2 167 /*!
GregCr 0:e6ceb13d2d05 168 * @brief Sets the reception parameters
GregCr 0:e6ceb13d2d05 169 *
GregCr 0:e6ceb13d2d05 170 * @param [IN] modem Radio modem to be used [0: FSK, 1: LoRa]
GregCr 0:e6ceb13d2d05 171 * @param [IN] bandwidth Sets the bandwidth
GregCr 0:e6ceb13d2d05 172 * FSK : >= 2600 and <= 250000 Hz
GregCr 0:e6ceb13d2d05 173 * LoRa: [0: 125 kHz, 1: 250 kHz,
GregCr 0:e6ceb13d2d05 174 * 2: 500 kHz, 3: Reserved]
GregCr 0:e6ceb13d2d05 175 * @param [IN] datarate Sets the Datarate
GregCr 0:e6ceb13d2d05 176 * FSK : 600..300000 bits/s
GregCr 0:e6ceb13d2d05 177 * LoRa: [6: 64, 7: 128, 8: 256, 9: 512,
GregCr 0:e6ceb13d2d05 178 * 10: 1024, 11: 2048, 12: 4096 chips]
GregCr 0:e6ceb13d2d05 179 * @param [IN] coderate Sets the coding rate ( LoRa only )
GregCr 0:e6ceb13d2d05 180 * FSK : N/A ( set to 0 )
GregCr 0:e6ceb13d2d05 181 * LoRa: [1: 4/5, 2: 4/6, 3: 4/7, 4: 4/8]
GregCr 0:e6ceb13d2d05 182 * @param [IN] bandwidthAfc Sets the AFC Bandwidth ( FSK only )
GregCr 0:e6ceb13d2d05 183 * FSK : >= 2600 and <= 250000 Hz
GregCr 0:e6ceb13d2d05 184 * LoRa: N/A ( set to 0 )
GregCr 0:e6ceb13d2d05 185 * @param [IN] preambleLen Sets the Preamble length ( LoRa only )
GregCr 0:e6ceb13d2d05 186 * FSK : N/A ( set to 0 )
GregCr 0:e6ceb13d2d05 187 * LoRa: Length in symbols ( the hardware adds 4 more symbols )
mluis 26:d09a8ef807e2 188 * @param [IN] symbTimeout Sets the RxSingle timeout value
mluis 26:d09a8ef807e2 189 * FSK : timeout number of bytes
GregCr 0:e6ceb13d2d05 190 * LoRa: timeout in symbols
GregCr 0:e6ceb13d2d05 191 * @param [IN] fixLen Fixed length packets [0: variable, 1: fixed]
mluis 13:618826a997e2 192 * @param [IN] payloadLen Sets payload length when fixed lenght is used
GregCr 0:e6ceb13d2d05 193 * @param [IN] crcOn Enables/Disables the CRC [0: OFF, 1: ON]
mluis 13:618826a997e2 194 * @param [IN] freqHopOn Enables disables the intra-packet frequency hopping [0: OFF, 1: ON] (LoRa only)
mluis 13:618826a997e2 195 * @param [IN] hopPeriod Number of symbols bewteen each hop (LoRa only)
GregCr 0:e6ceb13d2d05 196 * @param [IN] iqInverted Inverts IQ signals ( LoRa only )
GregCr 0:e6ceb13d2d05 197 * FSK : N/A ( set to 0 )
GregCr 0:e6ceb13d2d05 198 * LoRa: [0: not inverted, 1: inverted]
GregCr 0:e6ceb13d2d05 199 * @param [IN] rxContinuous Sets the reception in continuous mode
GregCr 0:e6ceb13d2d05 200 * [false: single mode, true: continuous mode]
GregCr 0:e6ceb13d2d05 201 */
mluis 22:7f3aab69cca9 202 virtual void SetRxConfig ( RadioModems_t modem, uint32_t bandwidth,
GregCr 0:e6ceb13d2d05 203 uint32_t datarate, uint8_t coderate,
GregCr 0:e6ceb13d2d05 204 uint32_t bandwidthAfc, uint16_t preambleLen,
GregCr 0:e6ceb13d2d05 205 uint16_t symbTimeout, bool fixLen,
mluis 13:618826a997e2 206 uint8_t payloadLen,
mluis 13:618826a997e2 207 bool crcOn, bool freqHopOn, uint8_t hopPeriod,
GregCr 6:e7f02929cd3d 208 bool iqInverted, bool rxContinuous );
mluis 13:618826a997e2 209 /*!
GregCr 0:e6ceb13d2d05 210 * @brief Sets the transmission parameters
GregCr 0:e6ceb13d2d05 211 *
GregCr 0:e6ceb13d2d05 212 * @param [IN] modem Radio modem to be used [0: FSK, 1: LoRa]
GregCr 0:e6ceb13d2d05 213 * @param [IN] power Sets the output power [dBm]
GregCr 0:e6ceb13d2d05 214 * @param [IN] fdev Sets the frequency deviation ( FSK only )
GregCr 0:e6ceb13d2d05 215 * FSK : [Hz]
GregCr 0:e6ceb13d2d05 216 * LoRa: 0
GregCr 0:e6ceb13d2d05 217 * @param [IN] bandwidth Sets the bandwidth ( LoRa only )
GregCr 0:e6ceb13d2d05 218 * FSK : 0
GregCr 0:e6ceb13d2d05 219 * LoRa: [0: 125 kHz, 1: 250 kHz,
GregCr 0:e6ceb13d2d05 220 * 2: 500 kHz, 3: Reserved]
GregCr 0:e6ceb13d2d05 221 * @param [IN] datarate Sets the Datarate
GregCr 0:e6ceb13d2d05 222 * FSK : 600..300000 bits/s
GregCr 0:e6ceb13d2d05 223 * LoRa: [6: 64, 7: 128, 8: 256, 9: 512,
GregCr 0:e6ceb13d2d05 224 * 10: 1024, 11: 2048, 12: 4096 chips]
GregCr 0:e6ceb13d2d05 225 * @param [IN] coderate Sets the coding rate ( LoRa only )
GregCr 0:e6ceb13d2d05 226 * FSK : N/A ( set to 0 )
GregCr 0:e6ceb13d2d05 227 * LoRa: [1: 4/5, 2: 4/6, 3: 4/7, 4: 4/8]
GregCr 0:e6ceb13d2d05 228 * @param [IN] preambleLen Sets the preamble length
GregCr 0:e6ceb13d2d05 229 * @param [IN] fixLen Fixed length packets [0: variable, 1: fixed]
GregCr 0:e6ceb13d2d05 230 * @param [IN] crcOn Enables disables the CRC [0: OFF, 1: ON]
mluis 13:618826a997e2 231 * @param [IN] freqHopOn Enables disables the intra-packet frequency hopping [0: OFF, 1: ON] (LoRa only)
mluis 13:618826a997e2 232 * @param [IN] hopPeriod Number of symbols bewteen each hop (LoRa only)
GregCr 0:e6ceb13d2d05 233 * @param [IN] iqInverted Inverts IQ signals ( LoRa only )
GregCr 0:e6ceb13d2d05 234 * FSK : N/A ( set to 0 )
GregCr 0:e6ceb13d2d05 235 * LoRa: [0: not inverted, 1: inverted]
mluis 26:d09a8ef807e2 236 * @param [IN] timeout Transmission timeout [ms]
GregCr 0:e6ceb13d2d05 237 */
mluis 22:7f3aab69cca9 238 virtual void SetTxConfig( RadioModems_t modem, int8_t power, uint32_t fdev,
GregCr 0:e6ceb13d2d05 239 uint32_t bandwidth, uint32_t datarate,
GregCr 0:e6ceb13d2d05 240 uint8_t coderate, uint16_t preambleLen,
mluis 13:618826a997e2 241 bool fixLen, bool crcOn, bool freqHopOn,
mluis 13:618826a997e2 242 uint8_t hopPeriod, bool iqInverted, uint32_t timeout );
mluis 26:d09a8ef807e2 243 /*!
mluis 26:d09a8ef807e2 244 * @brief Checks if the given RF frequency is supported by the hardware
mluis 26:d09a8ef807e2 245 *
mluis 26:d09a8ef807e2 246 * @param [IN] frequency RF frequency to be checked
mluis 26:d09a8ef807e2 247 * @retval isSupported [true: supported, false: unsupported]
mluis 26:d09a8ef807e2 248 */
mluis 26:d09a8ef807e2 249 virtual bool CheckRfFrequency( uint32_t frequency ) = 0;
mluis 13:618826a997e2 250 /*!
GregCr 0:e6ceb13d2d05 251 * @brief Computes the packet time on air for the given payload
GregCr 0:e6ceb13d2d05 252 *
GregCr 0:e6ceb13d2d05 253 * \Remark Can only be called once SetRxConfig or SetTxConfig have been called
GregCr 0:e6ceb13d2d05 254 *
GregCr 0:e6ceb13d2d05 255 * @param [IN] modem Radio modem to be used [0: FSK, 1: LoRa]
GregCr 0:e6ceb13d2d05 256 * @param [IN] pktLen Packet payload length
GregCr 0:e6ceb13d2d05 257 *
GregCr 0:e6ceb13d2d05 258 * @retval airTime Computed airTime for the given packet payload length
GregCr 0:e6ceb13d2d05 259 */
mluis 26:d09a8ef807e2 260 virtual uint32_t TimeOnAir ( RadioModems_t modem, uint8_t pktLen );
mluis 13:618826a997e2 261 /*!
GregCr 0:e6ceb13d2d05 262 * @brief Sends the buffer of size. Prepares the packet to be sent and sets
GregCr 0:e6ceb13d2d05 263 * the radio in transmission
GregCr 0:e6ceb13d2d05 264 *
GregCr 0:e6ceb13d2d05 265 * @param [IN]: buffer Buffer pointer
GregCr 0:e6ceb13d2d05 266 * @param [IN]: size Buffer size
GregCr 0:e6ceb13d2d05 267 */
GregCr 0:e6ceb13d2d05 268 virtual void Send( uint8_t *buffer, uint8_t size );
mluis 13:618826a997e2 269 /*!
GregCr 0:e6ceb13d2d05 270 * @brief Sets the radio in sleep mode
GregCr 0:e6ceb13d2d05 271 */
GregCr 0:e6ceb13d2d05 272 virtual void Sleep( void );
mluis 13:618826a997e2 273 /*!
GregCr 0:e6ceb13d2d05 274 * @brief Sets the radio in standby mode
GregCr 0:e6ceb13d2d05 275 */
GregCr 0:e6ceb13d2d05 276 virtual void Standby( void );
mluis 26:d09a8ef807e2 277 /*!
mluis 26:d09a8ef807e2 278 * @brief Sets the radio in CAD mode
mluis 26:d09a8ef807e2 279 */
mluis 26:d09a8ef807e2 280 virtual void StartCad( void );
mluis 13:618826a997e2 281 /*!
GregCr 0:e6ceb13d2d05 282 * @brief Sets the radio in reception mode for the given time
mluis 26:d09a8ef807e2 283 * @param [IN] timeout Reception timeout [ms]
GregCr 0:e6ceb13d2d05 284 * [0: continuous, others timeout]
GregCr 0:e6ceb13d2d05 285 */
GregCr 0:e6ceb13d2d05 286 virtual void Rx( uint32_t timeout );
mluis 13:618826a997e2 287 /*!
GregCr 0:e6ceb13d2d05 288 * @brief Sets the radio in transmission mode for the given time
mluis 26:d09a8ef807e2 289 * @param [IN] timeout Transmission timeout [ms]
GregCr 0:e6ceb13d2d05 290 * [0: continuous, others timeout]
GregCr 0:e6ceb13d2d05 291 */
GregCr 0:e6ceb13d2d05 292 virtual void Tx( uint32_t timeout );
mluis 13:618826a997e2 293 /*!
mluis 26:d09a8ef807e2 294 * @brief Sets the radio in continuous wave transmission mode
mluis 26:d09a8ef807e2 295 *
mluis 26:d09a8ef807e2 296 * @param [IN]: freq Channel RF frequency
mluis 26:d09a8ef807e2 297 * @param [IN]: power Sets the output power [dBm]
mluis 26:d09a8ef807e2 298 * @param [IN]: time Transmission mode timeout [s]
GregCr 7:2b555111463f 299 */
mluis 26:d09a8ef807e2 300 virtual void SetTxContinuousWave( uint32_t freq, int8_t power, uint16_t time );
mluis 13:618826a997e2 301 /*!
GregCr 0:e6ceb13d2d05 302 * @brief Reads the current RSSI value
GregCr 0:e6ceb13d2d05 303 *
GregCr 0:e6ceb13d2d05 304 * @retval rssiValue Current RSSI value in [dBm]
GregCr 0:e6ceb13d2d05 305 */
mluis 22:7f3aab69cca9 306 virtual int16_t GetRssi ( RadioModems_t modem );
mluis 13:618826a997e2 307 /*!
GregCr 0:e6ceb13d2d05 308 * @brief Writes the radio register at the specified address
GregCr 0:e6ceb13d2d05 309 *
GregCr 0:e6ceb13d2d05 310 * @param [IN]: addr Register address
GregCr 0:e6ceb13d2d05 311 * @param [IN]: data New register value
GregCr 0:e6ceb13d2d05 312 */
GregCr 0:e6ceb13d2d05 313 virtual void Write ( uint8_t addr, uint8_t data ) = 0;
mluis 13:618826a997e2 314 /*!
GregCr 0:e6ceb13d2d05 315 * @brief Reads the radio register at the specified address
GregCr 0:e6ceb13d2d05 316 *
GregCr 0:e6ceb13d2d05 317 * @param [IN]: addr Register address
GregCr 0:e6ceb13d2d05 318 * @retval data Register value
GregCr 0:e6ceb13d2d05 319 */
GregCr 0:e6ceb13d2d05 320 virtual uint8_t Read ( uint8_t addr ) = 0;
mluis 13:618826a997e2 321 /*!
GregCr 0:e6ceb13d2d05 322 * @brief Writes multiple radio registers starting at address
GregCr 0:e6ceb13d2d05 323 *
GregCr 0:e6ceb13d2d05 324 * @param [IN] addr First Radio register address
GregCr 0:e6ceb13d2d05 325 * @param [IN] buffer Buffer containing the new register's values
GregCr 0:e6ceb13d2d05 326 * @param [IN] size Number of registers to be written
GregCr 0:e6ceb13d2d05 327 */
GregCr 0:e6ceb13d2d05 328 virtual void Write( uint8_t addr, uint8_t *buffer, uint8_t size ) = 0;
mluis 13:618826a997e2 329 /*!
GregCr 0:e6ceb13d2d05 330 * @brief Reads multiple radio registers starting at address
GregCr 0:e6ceb13d2d05 331 *
GregCr 0:e6ceb13d2d05 332 * @param [IN] addr First Radio register address
GregCr 0:e6ceb13d2d05 333 * @param [OUT] buffer Buffer where to copy the registers data
GregCr 0:e6ceb13d2d05 334 * @param [IN] size Number of registers to be read
GregCr 0:e6ceb13d2d05 335 */
GregCr 0:e6ceb13d2d05 336 virtual void Read ( uint8_t addr, uint8_t *buffer, uint8_t size ) = 0;
mluis 13:618826a997e2 337 /*!
mluis 13:618826a997e2 338 * @brief Writes the buffer contents to the SX1276 FIFO
mluis 13:618826a997e2 339 *
mluis 13:618826a997e2 340 * @param [IN] buffer Buffer containing data to be put on the FIFO.
mluis 13:618826a997e2 341 * @param [IN] size Number of bytes to be written to the FIFO
mluis 13:618826a997e2 342 */
mluis 13:618826a997e2 343 virtual void WriteFifo( uint8_t *buffer, uint8_t size ) = 0;
mluis 13:618826a997e2 344 /*!
mluis 13:618826a997e2 345 * @brief Reads the contents of the SX1276 FIFO
mluis 13:618826a997e2 346 *
mluis 13:618826a997e2 347 * @param [OUT] buffer Buffer where to copy the FIFO read data.
mluis 13:618826a997e2 348 * @param [IN] size Number of bytes to be read from the FIFO
mluis 13:618826a997e2 349 */
mluis 13:618826a997e2 350 virtual void ReadFifo( uint8_t *buffer, uint8_t size ) = 0;
mluis 13:618826a997e2 351 /*!
mluis 13:618826a997e2 352 * @brief Resets the SX1276
mluis 13:618826a997e2 353 */
mluis 13:618826a997e2 354 virtual void Reset( void ) = 0;
mluis 26:d09a8ef807e2 355
mluis 20:e05596ba4166 356 /*!
mluis 20:e05596ba4166 357 * @brief Sets the maximum payload length.
mluis 20:e05596ba4166 358 *
mluis 20:e05596ba4166 359 * @param [IN] modem Radio modem to be used [0: FSK, 1: LoRa]
mluis 20:e05596ba4166 360 * @param [IN] max Maximum payload length in bytes
mluis 20:e05596ba4166 361 */
mluis 22:7f3aab69cca9 362 virtual void SetMaxPayloadLength( RadioModems_t modem, uint8_t max );
mluis 26:d09a8ef807e2 363
mluis 26:d09a8ef807e2 364 /*!
mluis 26:d09a8ef807e2 365 * \brief Sets the network to public or private. Updates the sync byte.
mluis 26:d09a8ef807e2 366 *
mluis 26:d09a8ef807e2 367 * \remark Applies to LoRa modem only
mluis 26:d09a8ef807e2 368 *
mluis 26:d09a8ef807e2 369 * \param [IN] enable if true, it enables a public network
mluis 26:d09a8ef807e2 370 */
mluis 26:d09a8ef807e2 371 virtual void SetPublicNetwork( bool enable );
mluis 26:d09a8ef807e2 372
mluis 13:618826a997e2 373 //-------------------------------------------------------------------------
mluis 13:618826a997e2 374 // Board relative functions
mluis 13:618826a997e2 375 //-------------------------------------------------------------------------
mluis 26:d09a8ef807e2 376
GregCr 0:e6ceb13d2d05 377 protected:
mluis 13:618826a997e2 378 /*!
mluis 13:618826a997e2 379 * @brief Initializes the radio I/Os pins interface
mluis 13:618826a997e2 380 */
mluis 13:618826a997e2 381 virtual void IoInit( void ) = 0;
mluis 13:618826a997e2 382
mluis 13:618826a997e2 383 /*!
mluis 13:618826a997e2 384 * @brief Initializes the radio registers
mluis 13:618826a997e2 385 */
mluis 13:618826a997e2 386 virtual void RadioRegistersInit( ) = 0;
mluis 13:618826a997e2 387
mluis 13:618826a997e2 388 /*!
mluis 13:618826a997e2 389 * @brief Initializes the radio SPI
mluis 13:618826a997e2 390 */
mluis 13:618826a997e2 391 virtual void SpiInit( void ) = 0;
mluis 26:d09a8ef807e2 392
mluis 13:618826a997e2 393 /*!
mluis 13:618826a997e2 394 * @brief Initializes DIO IRQ handlers
mluis 13:618826a997e2 395 *
mluis 13:618826a997e2 396 * @param [IN] irqHandlers Array containing the IRQ callback functions
mluis 13:618826a997e2 397 */
mluis 13:618826a997e2 398 virtual void IoIrqInit( DioIrqHandler *irqHandlers ) = 0;
GregCr 0:e6ceb13d2d05 399
mluis 13:618826a997e2 400 /*!
mluis 13:618826a997e2 401 * @brief De-initializes the radio I/Os pins interface.
mluis 13:618826a997e2 402 *
mluis 13:618826a997e2 403 * \remark Useful when going in MCU lowpower modes
mluis 13:618826a997e2 404 */
mluis 13:618826a997e2 405 virtual void IoDeInit( void ) = 0;
GregCr 0:e6ceb13d2d05 406
mluis 13:618826a997e2 407 /*!
mluis 26:d09a8ef807e2 408 * @brief Sets the radio output power.
mluis 26:d09a8ef807e2 409 *
mluis 26:d09a8ef807e2 410 * @param [IN] power Sets the RF output power
mluis 26:d09a8ef807e2 411 */
mluis 26:d09a8ef807e2 412 virtual void SetRfTxPower( int8_t power ) = 0;
mluis 26:d09a8ef807e2 413
mluis 26:d09a8ef807e2 414 /*!
mluis 13:618826a997e2 415 * @brief Gets the board PA selection configuration
mluis 13:618826a997e2 416 *
mluis 13:618826a997e2 417 * @param [IN] channel Channel frequency in Hz
mluis 13:618826a997e2 418 * @retval PaSelect RegPaConfig PaSelect value
mluis 13:618826a997e2 419 */
mluis 13:618826a997e2 420 virtual uint8_t GetPaSelect( uint32_t channel ) = 0;
GregCr 0:e6ceb13d2d05 421
mluis 13:618826a997e2 422 /*!
mluis 13:618826a997e2 423 * @brief Set the RF Switch I/Os pins in Low Power mode
mluis 13:618826a997e2 424 *
mluis 13:618826a997e2 425 * @param [IN] status enable or disable
mluis 13:618826a997e2 426 */
mluis 13:618826a997e2 427 virtual void SetAntSwLowPower( bool status ) = 0;
GregCr 0:e6ceb13d2d05 428
mluis 13:618826a997e2 429 /*!
mluis 13:618826a997e2 430 * @brief Initializes the RF Switch I/Os pins interface
mluis 13:618826a997e2 431 */
mluis 13:618826a997e2 432 virtual void AntSwInit( void ) = 0;
GregCr 0:e6ceb13d2d05 433
mluis 13:618826a997e2 434 /*!
mluis 13:618826a997e2 435 * @brief De-initializes the RF Switch I/Os pins interface
mluis 13:618826a997e2 436 *
mluis 13:618826a997e2 437 * \remark Needed to decrease the power consumption in MCU lowpower modes
mluis 13:618826a997e2 438 */
mluis 13:618826a997e2 439 virtual void AntSwDeInit( void ) = 0;
GregCr 0:e6ceb13d2d05 440
mluis 13:618826a997e2 441 /*!
mluis 26:d09a8ef807e2 442 * @brief Controls the antenna switch if necessary.
mluis 13:618826a997e2 443 *
mluis 13:618826a997e2 444 * \remark see errata note
mluis 13:618826a997e2 445 *
mluis 26:d09a8ef807e2 446 * @param [IN] opMode Current radio operating mode
mluis 13:618826a997e2 447 */
mluis 26:d09a8ef807e2 448 virtual void SetAntSw( uint8_t opMode ) = 0;
GregCr 0:e6ceb13d2d05 449 protected:
GregCr 0:e6ceb13d2d05 450
mluis 13:618826a997e2 451 /*!
mluis 13:618826a997e2 452 * @brief Sets the SX1276 operating mode
mluis 13:618826a997e2 453 *
mluis 13:618826a997e2 454 * @param [IN] opMode New operating mode
mluis 13:618826a997e2 455 */
mluis 13:618826a997e2 456 virtual void SetOpMode( uint8_t opMode );
GregCr 0:e6ceb13d2d05 457
mluis 13:618826a997e2 458 /*
mluis 13:618826a997e2 459 * SX1276 DIO IRQ callback functions prototype
mluis 13:618826a997e2 460 */
GregCr 0:e6ceb13d2d05 461
mluis 13:618826a997e2 462 /*!
mluis 13:618826a997e2 463 * @brief DIO 0 IRQ callback
mluis 13:618826a997e2 464 */
mluis 13:618826a997e2 465 virtual void OnDio0Irq( void );
GregCr 0:e6ceb13d2d05 466
mluis 13:618826a997e2 467 /*!
mluis 13:618826a997e2 468 * @brief DIO 1 IRQ callback
mluis 13:618826a997e2 469 */
mluis 13:618826a997e2 470 virtual void OnDio1Irq( void );
GregCr 0:e6ceb13d2d05 471
mluis 13:618826a997e2 472 /*!
mluis 13:618826a997e2 473 * @brief DIO 2 IRQ callback
mluis 13:618826a997e2 474 */
mluis 13:618826a997e2 475 virtual void OnDio2Irq( void );
GregCr 0:e6ceb13d2d05 476
mluis 13:618826a997e2 477 /*!
mluis 13:618826a997e2 478 * @brief DIO 3 IRQ callback
mluis 13:618826a997e2 479 */
mluis 13:618826a997e2 480 virtual void OnDio3Irq( void );
GregCr 0:e6ceb13d2d05 481
mluis 13:618826a997e2 482 /*!
mluis 13:618826a997e2 483 * @brief DIO 4 IRQ callback
mluis 13:618826a997e2 484 */
mluis 13:618826a997e2 485 virtual void OnDio4Irq( void );
GregCr 0:e6ceb13d2d05 486
mluis 13:618826a997e2 487 /*!
mluis 13:618826a997e2 488 * @brief DIO 5 IRQ callback
mluis 13:618826a997e2 489 */
mluis 13:618826a997e2 490 virtual void OnDio5Irq( void );
GregCr 0:e6ceb13d2d05 491
mluis 13:618826a997e2 492 /*!
mluis 13:618826a997e2 493 * @brief Tx & Rx timeout timer callback
mluis 13:618826a997e2 494 */
mluis 13:618826a997e2 495 virtual void OnTimeoutIrq( void );
mluis 26:d09a8ef807e2 496
mluis 13:618826a997e2 497 /*!
mluis 13:618826a997e2 498 * Returns the known FSK bandwidth registers value
mluis 13:618826a997e2 499 *
mluis 13:618826a997e2 500 * \param [IN] bandwidth Bandwidth value in Hz
mluis 13:618826a997e2 501 * \retval regValue Bandwidth register value.
mluis 13:618826a997e2 502 */
mluis 13:618826a997e2 503 static uint8_t GetFskBandwidthRegValue( uint32_t bandwidth );
GregCr 0:e6ceb13d2d05 504 };
GregCr 0:e6ceb13d2d05 505
mluis 22:7f3aab69cca9 506 #endif // __SX1276_H__