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