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