XRange SX1272Lib
Dependents: XRangePingPong XRange-LoRaWAN-lmic-app lora-transceiver
Fork of SX1276Lib by
radio.h
00001 /* 00002 / _____) _ | | 00003 ( (____ _____ ____ _| |_ _____ ____| |__ 00004 \____ \| ___ | (_ _) ___ |/ ___) _ \ 00005 _____) ) ____| | | || |_| ____( (___| | | | 00006 (______/|_____)_|_|_| \__)_____)\____)_| |_| 00007 ( C )2014 Semtech 00008 00009 Description: Interface for the radios, contains the main functions that a radio needs, and 5 callback functions 00010 00011 License: Revised BSD License, see LICENSE.TXT file include in the project 00012 00013 Maintainers: Miguel Luis, Gregory Cristian and Nicolas Huguenin 00014 */ 00015 #ifndef __RADIO_H__ 00016 #define __RADIO_H__ 00017 00018 #include "mbed.h" 00019 00020 #include "./enums/enums.h" 00021 00022 /*! 00023 * Interface for the radios, contains the main functions that a radio needs, and 5 callback functions 00024 */ 00025 class Radio 00026 { 00027 protected: 00028 00029 //------------------------------------------------------------------------- 00030 // Callback functions pointers 00031 //------------------------------------------------------------------------- 00032 00033 /*! 00034 * @brief Tx Done callback prototype. 00035 */ 00036 void ( *txDone )( ); 00037 00038 /*! 00039 * @brief Tx Timeout callback prototype. 00040 */ 00041 void ( *txTimeout ) ( ); 00042 00043 /*! 00044 * @brief Rx Done callback prototype. 00045 * 00046 * @param [IN] payload Received buffer pointer 00047 * @param [IN] size Received buffer size 00048 * @param [IN] rssi RSSI value computed while receiving the frame [dBm] 00049 * @param [IN] snr Raw SNR value given by the radio hardware 00050 * FSK : N/A ( set to 0 ) 00051 * LoRa: SNR value in dB 00052 */ 00053 void ( *rxDone ) ( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ); 00054 00055 /*! 00056 * @brief Rx Timeout callback prototype. 00057 */ 00058 void ( *rxTimeout ) ( ); 00059 00060 /*! 00061 * @brief Rx Error callback prototype. 00062 */ 00063 void ( *rxError ) ( ); 00064 00065 /*! 00066 * \brief FHSS Change Channel callback prototype. 00067 * 00068 * \param [IN] CurrentChannel Index number of the current channel 00069 */ 00070 void ( *fhssChangeChannel )( uint8_t CurrentChannel ); 00071 00072 /*! 00073 * @brief CAD Done callback prototype. 00074 * 00075 * @param [IN] ChannelDetected Channel Activity detected during the CAD 00076 */ 00077 void ( *cadDone ) ( bool channelActivityDetected ); 00078 00079 public: 00080 //------------------------------------------------------------------------- 00081 // Constructor 00082 //------------------------------------------------------------------------- 00083 /*! 00084 * @brief Constructor of the radio object, the parameters are the callback functions described in the header. 00085 * @param [IN] txDone 00086 * @param [IN] txTimeout 00087 * @param [IN] rxDone 00088 * @param [IN] rxTimeout 00089 * @param [IN] rxError 00090 */ 00091 Radio( void ( *txDone )( ), void ( *txTimeout ) ( ), void ( *rxDone ) ( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ), 00092 void ( *rxTimeout ) ( ), void ( *rxError ) ( ), void ( *fhssChangeChannel ) ( uint8_t channelIndex ), void ( *cadDone ) ( bool channelActivityDetected ) ); 00093 virtual ~Radio ( ) {}; 00094 00095 //------------------------------------------------------------------------- 00096 // Pure virtual functions 00097 //------------------------------------------------------------------------- 00098 00099 /*! 00100 * Return current radio status 00101 * 00102 * @param status Radio status.[RF_IDLE, RF_RX_RUNNING, RF_TX_RUNNING] 00103 */ 00104 virtual RadioState GetState ( void ) = 0; 00105 00106 /*! 00107 * \brief Configures the radio with the given modem 00108 * 00109 * \param [IN] modem Modem to be used [0: FSK, 1: LoRa] 00110 */ 00111 virtual void SetModem( ModemType modem ) = 0; 00112 00113 /*! 00114 * @brief Sets the channel frequency 00115 * 00116 * @param [IN] freq Channel RF frequency 00117 */ 00118 virtual void SetChannel( uint32_t freq ) = 0; 00119 00120 /*! 00121 * @brief Sets the channels configuration 00122 * 00123 * @param [IN] modem Radio modem to be used [0: FSK, 1: LoRa] 00124 * @param [IN] freq Channel RF frequency 00125 * @param [IN] rssiThresh RSSI threshold 00126 * 00127 * @retval isFree [true: Channel is free, false: Channel is not free] 00128 */ 00129 virtual bool IsChannelFree( ModemType modem, uint32_t freq, int8_t rssiThresh ) = 0; 00130 00131 /*! 00132 * @brief Generates a 32 bits random value based on the RSSI readings 00133 * 00134 * \remark This function sets the radio in LoRa modem mode and disables 00135 * all interrupts. 00136 * After calling this function either Radio.SetRxConfig or 00137 * Radio.SetTxConfig functions must be called. 00138 * 00139 * @retval randomValue 32 bits random value 00140 */ 00141 virtual uint32_t Random( void )= 0; 00142 00143 /*! 00144 * @brief Sets the reception parameters 00145 * 00146 * @param [IN] modem Radio modem to be used [0: FSK, 1: LoRa] 00147 * @param [IN] bandwidth Sets the bandwidth 00148 * FSK : >= 2600 and <= 250000 Hz 00149 * LoRa: [0: 125 kHz, 1: 250 kHz, 00150 * 2: 500 kHz, 3: Reserved] 00151 * @param [IN] datarate Sets the Datarate 00152 * FSK : 600..300000 bits/s 00153 * LoRa: [6: 64, 7: 128, 8: 256, 9: 512, 00154 * 10: 1024, 11: 2048, 12: 4096 chips] 00155 * @param [IN] coderate Sets the coding rate ( LoRa only ) 00156 * FSK : N/A ( set to 0 ) 00157 * LoRa: [1: 4/5, 2: 4/6, 3: 4/7, 4: 4/8] 00158 * @param [IN] bandwidthAfc Sets the AFC Bandwidth ( FSK only ) 00159 * FSK : >= 2600 and <= 250000 Hz 00160 * LoRa: N/A ( set to 0 ) 00161 * @param [IN] preambleLen Sets the Preamble length ( LoRa only ) 00162 * FSK : N/A ( set to 0 ) 00163 * LoRa: Length in symbols ( the hardware adds 4 more symbols ) 00164 * @param [IN] symbTimeout Sets the RxSingle timeout value ( LoRa only ) 00165 * FSK : N/A ( set to 0 ) 00166 * LoRa: timeout in symbols 00167 * @param [IN] fixLen Fixed length packets [0: variable, 1: fixed] 00168 * @param [IN] payloadLen Sets payload length when fixed lenght is used 00169 * @param [IN] crcOn Enables/Disables the CRC [0: OFF, 1: ON] 00170 * @param [IN] freqHopOn Enables disables the intra-packet frequency hopping [0: OFF, 1: ON] (LoRa only) 00171 * @param [IN] hopPeriod Number of symbols bewteen each hop (LoRa only) 00172 * @param [IN] iqInverted Inverts IQ signals ( LoRa only ) 00173 * FSK : N/A ( set to 0 ) 00174 * LoRa: [0: not inverted, 1: inverted] 00175 * @param [IN] rxContinuous Sets the reception in continuous mode 00176 * [false: single mode, true: continuous mode] 00177 */ 00178 virtual void SetRxConfig ( ModemType modem, uint32_t bandwidth, 00179 uint32_t datarate, uint8_t coderate, 00180 uint32_t bandwidthAfc, uint16_t preambleLen, 00181 uint16_t symbTimeout, bool fixLen, 00182 uint8_t payloadLen, 00183 bool crcOn, bool freqHopOn, uint8_t hopPeriod, 00184 bool iqInverted, bool rxContinuous ) = 0; 00185 00186 /*! 00187 * @brief Sets the transmission parameters 00188 * 00189 * @param [IN] modem Radio modem to be used [0: FSK, 1: LoRa] 00190 * @param [IN] power Sets the output power [dBm] 00191 * @param [IN] fdev Sets the frequency deviation ( FSK only ) 00192 * FSK : [Hz] 00193 * LoRa: 0 00194 * @param [IN] bandwidth Sets the bandwidth ( LoRa only ) 00195 * FSK : 0 00196 * LoRa: [0: 125 kHz, 1: 250 kHz, 00197 * 2: 500 kHz, 3: Reserved] 00198 * @param [IN] datarate Sets the Datarate 00199 * FSK : 600..300000 bits/s 00200 * LoRa: [6: 64, 7: 128, 8: 256, 9: 512, 00201 * 10: 1024, 11: 2048, 12: 4096 chips] 00202 * @param [IN] coderate Sets the coding rate ( LoRa only ) 00203 * FSK : N/A ( set to 0 ) 00204 * LoRa: [1: 4/5, 2: 4/6, 3: 4/7, 4: 4/8] 00205 * @param [IN] preambleLen Sets the preamble length 00206 * @param [IN] fixLen Fixed length packets [0: variable, 1: fixed] 00207 * @param [IN] crcOn Enables disables the CRC [0: OFF, 1: ON] 00208 * @param [IN] freqHopOn Enables disables the intra-packet frequency hopping [0: OFF, 1: ON] (LoRa only) 00209 * @param [IN] hopPeriod Number of symbols bewteen each hop (LoRa only) 00210 * @param [IN] iqInverted Inverts IQ signals ( LoRa only ) 00211 * FSK : N/A ( set to 0 ) 00212 * LoRa: [0: not inverted, 1: inverted] 00213 * @param [IN] timeout Transmission timeout [us] 00214 */ 00215 virtual void SetTxConfig( ModemType modem, int8_t power, uint32_t fdev, 00216 uint32_t bandwidth, uint32_t datarate, 00217 uint8_t coderate, uint16_t preambleLen, 00218 bool fixLen, bool crcOn, bool freqHopOn, 00219 uint8_t hopPeriod, bool iqInverted, uint32_t timeout ) = 0; 00220 00221 /*! 00222 * @brief Checks if the given RF frequency is supported by the hardware 00223 * 00224 * @param [IN] frequency RF frequency to be checked 00225 * @retval isSupported [true: supported, false: unsupported] 00226 */ 00227 virtual bool CheckRfFrequency( uint32_t frequency ) = 0; 00228 00229 /*! 00230 * @brief Computes the packet time on air for the given payload 00231 * 00232 * \Remark Can only be called once SetRxConfig or SetTxConfig have been called 00233 * 00234 * @param [IN] modem Radio modem to be used [0: FSK, 1: LoRa] 00235 * @param [IN] pktLen Packet payload length 00236 * 00237 * @retval airTime Computed airTime for the given packet payload length 00238 */ 00239 virtual double TimeOnAir ( ModemType modem, uint8_t pktLen ) = 0; 00240 00241 /*! 00242 * @brief Sends the buffer of size. Prepares the packet to be sent and sets 00243 * the radio in transmission 00244 * 00245 * @param [IN]: buffer Buffer pointer 00246 * @param [IN]: size Buffer size 00247 */ 00248 virtual void Send( uint8_t *buffer, uint8_t size ) = 0; 00249 00250 /*! 00251 * @brief Sets the radio in sleep mode 00252 */ 00253 virtual void Sleep( void ) = 0; 00254 00255 /*! 00256 * @brief Sets the radio in standby mode 00257 */ 00258 virtual void Standby( void ) = 0; 00259 00260 /*! 00261 * @brief Sets the radio in CAD mode 00262 */ 00263 virtual void StartCad( void ) = 0; 00264 00265 /*! 00266 * @brief Sets the radio in reception mode for the given time 00267 * @param [IN] timeout Reception timeout [us] 00268 * [0: continuous, others timeout] 00269 */ 00270 virtual void Rx( uint32_t timeout ) = 0; 00271 00272 /*! 00273 * @brief Sets the radio in transmission mode for the given time 00274 * @param [IN] timeout Transmission timeout [us] 00275 * [0: continuous, others timeout] 00276 */ 00277 virtual void Tx( uint32_t timeout ) = 0; 00278 00279 /*! 00280 * @brief Reads the current RSSI value 00281 * 00282 * @retval rssiValue Current RSSI value in [dBm] 00283 */ 00284 virtual int16_t GetRssi ( ModemType modem ) = 0; 00285 00286 /*! 00287 * @brief Writes the radio register at the specified address 00288 * 00289 * @param [IN]: addr Register address 00290 * @param [IN]: data New register value 00291 */ 00292 virtual void Write ( uint8_t addr, uint8_t data ) = 0; 00293 00294 /*! 00295 * @brief Reads the radio register at the specified address 00296 * 00297 * @param [IN]: addr Register address 00298 * @retval data Register value 00299 */ 00300 virtual uint8_t Read ( uint8_t addr ) = 0; 00301 00302 /*! 00303 * @brief Writes multiple radio registers starting at address 00304 * 00305 * @param [IN] addr First Radio register address 00306 * @param [IN] buffer Buffer containing the new register's values 00307 * @param [IN] size Number of registers to be written 00308 */ 00309 virtual void Write( uint8_t addr, uint8_t *buffer, uint8_t size ) = 0; 00310 00311 /*! 00312 * @brief Reads multiple radio registers starting at address 00313 * 00314 * @param [IN] addr First Radio register address 00315 * @param [OUT] buffer Buffer where to copy the registers data 00316 * @param [IN] size Number of registers to be read 00317 */ 00318 virtual void Read ( uint8_t addr, uint8_t *buffer, uint8_t size ) = 0; 00319 00320 /*! 00321 * @brief Writes the buffer contents to the SX1276 FIFO 00322 * 00323 * @param [IN] buffer Buffer containing data to be put on the FIFO. 00324 * @param [IN] size Number of bytes to be written to the FIFO 00325 */ 00326 virtual void WriteFifo( uint8_t *buffer, uint8_t size ) = 0; 00327 00328 /*! 00329 * @brief Reads the contents of the SX1276 FIFO 00330 * 00331 * @param [OUT] buffer Buffer where to copy the FIFO read data. 00332 * @param [IN] size Number of bytes to be read from the FIFO 00333 */ 00334 virtual void ReadFifo( uint8_t *buffer, uint8_t size ) = 0; 00335 }; 00336 00337 #endif // __RADIO_H__ 00338
Generated on Wed Jul 13 2022 07:28:43 by 1.7.2