test

Dependents:   LoRaWAN-lmic-app_tjm

Fork of SX1276Lib by Semtech

Committer:
tmulrooney
Date:
Thu Feb 25 21:28:39 2016 +0000
Revision:
25:856779ac8921
Parent:
23:952530fa968d
first successful join

Who changed what in which revision?

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