With error debug.h

Fork of SX1272Lib by Semtech

Committer:
mluis
Date:
Fri May 13 14:49:34 2016 +0000
Revision:
4:90bd79f1b458
Parent:
3:5baff45eb3c5
Synchronized with https://github.com/Lora-net/LoRaMac-node radio drivers git revision 55d16ca8949c09ee241c87b7600e2a8bc90d3743

Who changed what in which revision?

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