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