Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
SxRadio.h
00001 /* 00002 / _____) _ | | 00003 ( (____ _____ ____ _| |_ _____ ____| |__ 00004 \____ \| ___ | (_ _) ___ |/ ___) _ \ 00005 _____) ) ____| | | || |_| ____( (___| | | | 00006 (______/|_____)_|_|_| \__)_____)\____)_| |_| 00007 (C)2013 Semtech 00008 00009 Description: Generic radio driver definition 00010 00011 License: Revised BSD License, see LICENSE.TXT file include in the project 00012 00013 Maintainer: Miguel Luis and Gregory Cristian 00014 */ 00015 #ifndef __SXRADIO_H__ 00016 #define __SXRADIO_H__ 00017 00018 #include <stdint.h> 00019 #include "rtos.h" 00020 #include "SxRadioEvents.h" 00021 00022 /*! 00023 * \brief Radio driver definition 00024 */ 00025 class SxRadio 00026 { 00027 public: 00028 /*! 00029 * Radio driver supported modems 00030 */ 00031 typedef enum 00032 { 00033 MODEM_FSK = 0, 00034 MODEM_LORA, 00035 }RadioModems_t ; 00036 00037 /*! 00038 * Radio driver internal state machine states definition 00039 */ 00040 typedef enum 00041 { 00042 RF_IDLE = 0, 00043 RF_RX_RUNNING, 00044 RF_TX_RUNNING, 00045 RF_CAD, 00046 RF_LBT 00047 }RadioState_t ; 00048 00049 SxRadio(uint32_t WakeupTime) : WakeupTime(WakeupTime), freq_offset(0), State(RF_IDLE), Modem(MODEM_LORA) { } 00050 virtual ~SxRadio() {}; 00051 00052 /*! 00053 * \brief Initializes the radio 00054 * 00055 * \param [IN] events Structure containing the driver callback functions 00056 */ 00057 virtual void Init( SxRadioEvents *events ) = 0; 00058 /*! 00059 * \brief Prepares the radio for destruction 00060 */ 00061 virtual void Terminate( void ) = 0; 00062 /*! 00063 * Return current radio status 00064 * 00065 * \param status Radio status.[RF_IDLE, RF_RX_RUNNING, RF_TX_RUNNING] 00066 */ 00067 virtual RadioState_t Status ( void ) { return State; } 00068 /*! 00069 * \brief Configures the radio with the given modem 00070 * 00071 * \param [IN] modem Modem to be used [0: FSK, 1: LoRa] 00072 */ 00073 virtual void SetModem( RadioModems_t modem ) = 0; 00074 virtual RadioModems_t GetModem( void ) { return Modem; } 00075 /*! 00076 * \brief Sets the channel frequency 00077 * 00078 * \param [IN] freq Channel RF frequency 00079 */ 00080 virtual void SetChannel( uint32_t freq ) = 0; 00081 /*! 00082 * \brief Sets the channels configuration 00083 * 00084 * \param [IN] modem Radio modem to be used [0: FSK, 1: LoRa] 00085 * \param [IN] freq Channel RF frequency 00086 * \param [IN] rssiThresh RSSI threshold 00087 * \param [IN] rssiVal pointer to variable to hold RSSI value if desired - ignored if NULL 00088 * 00089 * \retval isFree [true: Channel is free, false: Channel is not free] 00090 */ 00091 virtual bool IsChannelFree( RadioModems_t modem, uint32_t freq, int16_t rssiThresh, uint32_t timeout = 5000, int16_t *rssiVal = NULL ) = 0; 00092 /*! 00093 * \brief Generates a 32 bits random value based on the RSSI readings 00094 * 00095 * \remark This function sets the radio in LoRa modem mode and disables 00096 * all interrupts. 00097 * After calling this function either Radio.SetRxConfig or 00098 * Radio.SetTxConfig functions must be called. 00099 * 00100 * \retval randomValue 32 bits random value 00101 */ 00102 virtual uint32_t Random( void ) = 0; 00103 /*! 00104 * \brief Sets the reception parameters 00105 * 00106 * \param [IN] modem Radio modem to be used [0: FSK, 1: LoRa] 00107 * \param [IN] bandwidth Sets the bandwidth 00108 * FSK : >= 2600 and <= 250000 Hz 00109 * LoRa: [0: 125 kHz, 1: 250 kHz, 00110 * 2: 500 kHz, 3: Reserved] 00111 * \param [IN] datarate Sets the Datarate 00112 * FSK : 600..300000 bits/s 00113 * LoRa: [6: 64, 7: 128, 8: 256, 9: 512, 00114 * 10: 1024, 11: 2048, 12: 4096 chips] 00115 * \param [IN] coderate Sets the coding rate (LoRa only) 00116 * FSK : N/A ( set to 0 ) 00117 * LoRa: [1: 4/5, 2: 4/6, 3: 4/7, 4: 4/8] 00118 * \param [IN] bandwidthAfc Sets the AFC Bandwidth (FSK only) 00119 * FSK : >= 2600 and <= 250000 Hz 00120 * LoRa: N/A ( set to 0 ) 00121 * \param [IN] preambleLen Sets the Preamble length 00122 * FSK : Number of bytes 00123 * LoRa: Length in symbols (the hardware adds 4 more symbols) 00124 * \param [IN] symbTimeout Sets the RxSingle timeout value (LoRa only) 00125 * FSK : N/A ( set to 0 ) 00126 * LoRa: timeout in symbols 00127 * \param [IN] fixLen Fixed length packets [0: variable, 1: fixed] 00128 * \param [IN] payloadLen Sets payload length when fixed length is used 00129 * \param [IN] crcOn Enables/Disables the CRC [0: OFF, 1: ON] 00130 * \param [IN] FreqHopOn Enables disables the intra-packet frequency hopping 00131 * FSK : N/A ( set to 0 ) 00132 * LoRa: [0: OFF, 1: ON] 00133 * \param [IN] HopPeriod Number of symbols bewteen each hop 00134 * FSK : N/A ( set to 0 ) 00135 * LoRa: Number of symbols 00136 * \param [IN] iqInverted Inverts IQ signals (LoRa only) 00137 * FSK : N/A ( set to 0 ) 00138 * LoRa: [0: not inverted, 1: inverted] 00139 * \param [IN] rxContinuous Sets the reception in continuous mode 00140 * [false: single mode, true: continuous mode] 00141 * \param [IN] fskPad Duration in ms to increase FSK rx window 00142 * FSK: time in ms to increase FSK rx window duration 00143 * LoRa: N/A 00144 */ 00145 virtual void SetRxConfig( RadioModems_t modem, uint32_t bandwidth, 00146 uint32_t datarate, uint8_t coderate, 00147 uint32_t bandwidthAfc, uint16_t preambleLen, 00148 uint16_t symbTimeout, bool fixLen, 00149 uint8_t payloadLen, 00150 bool crcOn, bool FreqHopOn, uint8_t HopPeriod, 00151 bool iqInverted, bool rxContinuous , uint32_t fskPad = 0) = 0; 00152 /*! 00153 * \brief Sets the transmission parameters 00154 * 00155 * \param [IN] modem Radio modem to be used [0: FSK, 1: LoRa] 00156 * \param [IN] power Sets the output power [dBm] 00157 * \param [IN] fdev Sets the frequency deviation (FSK only) 00158 * FSK : [Hz] 00159 * LoRa: 0 00160 * \param [IN] bandwidth Sets the bandwidth (LoRa only) 00161 * FSK : 0 00162 * LoRa: [0: 125 kHz, 1: 250 kHz, 00163 * 2: 500 kHz, 3: Reserved] 00164 * \param [IN] datarate Sets the Datarate 00165 * FSK : 600..300000 bits/s 00166 * LoRa: [6: 64, 7: 128, 8: 256, 9: 512, 00167 * 10: 1024, 11: 2048, 12: 4096 chips] 00168 * \param [IN] coderate Sets the coding rate (LoRa only) 00169 * FSK : N/A ( set to 0 ) 00170 * LoRa: [1: 4/5, 2: 4/6, 3: 4/7, 4: 4/8] 00171 * \param [IN] preambleLen Sets the preamble length 00172 * FSK : Number of bytes 00173 * LoRa: Length in symbols (the hardware adds 4 more symbols) 00174 * \param [IN] fixLen Fixed length packets [0: variable, 1: fixed] 00175 * \param [IN] crcOn Enables disables the CRC [0: OFF, 1: ON] 00176 * \param [IN] FreqHopOn Enables disables the intra-packet frequency hopping 00177 * FSK : N/A ( set to 0 ) 00178 * LoRa: [0: OFF, 1: ON] 00179 * \param [IN] HopPeriod Number of symbols bewteen each hop 00180 * FSK : N/A ( set to 0 ) 00181 * LoRa: Number of symbols 00182 * \param [IN] iqInverted Inverts IQ signals (LoRa only) 00183 * FSK : N/A ( set to 0 ) 00184 * LoRa: [0: not inverted, 1: inverted] 00185 * \param [IN] timeout Transmission timeout [us] 00186 */ 00187 virtual void SetTxConfig( RadioModems_t modem, int8_t power, uint32_t fdev, 00188 uint32_t bandwidth, uint32_t datarate, 00189 uint8_t coderate, uint16_t preambleLen, 00190 bool fixLen, bool crcOn, bool FreqHopOn, 00191 uint8_t HopPeriod, bool iqInverted, uint32_t timeout ) = 0; 00192 00193 virtual void SetTxPower(int8_t power) = 0; 00194 00195 virtual void SetTxContinuousWave( uint32_t freq, int8_t power, uint16_t time ) = 0; 00196 00197 /*! 00198 * \brief Checks if the given RF frequency is supported by the hardware 00199 * 00200 * \param [IN] frequency RF frequency to be checked 00201 * \retval isSupported [true: supported, false: unsupported] 00202 */ 00203 virtual bool CheckRfFrequency( uint32_t frequency ) { return true; } 00204 /*! 00205 * \brief Computes the packet time on air for the given payload 00206 * 00207 * \Remark Can only be called once SetRxConfig or SetTxConfig have been called 00208 * 00209 * \param [IN] modem Radio modem to be used [0: FSK, 1: LoRa] 00210 * \param [IN] pktLen Packet payload length 00211 * 00212 * \retval airTime Computed airTime for the given packet payload length 00213 */ 00214 virtual double TimeOnAir( RadioModems_t modem, uint8_t pktLen ) = 0; 00215 /*! 00216 * \brief Sends the buffer of size. Prepares the packet to be sent and sets 00217 * the radio in transmission 00218 * 00219 * \param [IN]: buffer Buffer pointer 00220 * \param [IN]: size Buffer size 00221 */ 00222 virtual void Send( const uint8_t *buffer, uint8_t size ) = 0; 00223 /*! 00224 * \brief Sets the radio in sleep mode 00225 */ 00226 virtual void Sleep( void ) = 0; 00227 /*! 00228 * \brief Sets the radio in standby mode 00229 */ 00230 virtual void Standby( void ) = 0; 00231 /*! 00232 * \brief Sets the radio in reception mode for the given time 00233 * \param [IN] timeout Reception timeout [us] 00234 * [0: continuous, others timeout] 00235 */ 00236 virtual void Rx( uint32_t timeout ) = 0; 00237 /*! 00238 * \brief Start a Channel Activity Detection 00239 */ 00240 virtual void StartCad( void ) = 0; 00241 /*! 00242 * \brief Reads the current RSSI value 00243 * 00244 * \retval rssiValue Current RSSI value in [dBm] 00245 */ 00246 virtual int16_t Rssi( RadioModems_t modem ) = 0; 00247 /*! 00248 * \brief Writes the radio register at the specified address 00249 * 00250 * \param [IN]: addr Register address 00251 * \param [IN]: data New register value 00252 */ 00253 virtual void Write( uint8_t addr, uint8_t data ) = 0; 00254 /*! 00255 * \brief Reads the radio register at the specified address 00256 * 00257 * \param [IN]: addr Register address 00258 * \retval data Register value 00259 */ 00260 virtual uint8_t Read ( uint8_t addr ) = 0; 00261 /*! 00262 * \brief Writes multiple radio registers starting at address 00263 * 00264 * \param [IN] addr First Radio register address 00265 * \param [IN] buffer Buffer containing the new register's values 00266 * \param [IN] size Number of registers to be written 00267 */ 00268 virtual void WriteBuffer( uint8_t addr, const uint8_t *buffer, uint8_t size ) = 0; 00269 /*! 00270 * \brief Reads multiple radio registers starting at address 00271 * 00272 * \param [IN] addr First Radio register address 00273 * \param [OUT] buffer Buffer where to copy the registers data 00274 * \param [IN] size Number of registers to be read 00275 */ 00276 virtual void ReadBuffer( uint8_t addr, uint8_t *buffer, uint8_t size ) = 0; 00277 00278 virtual void SignalMacEvent(void) {}; 00279 virtual void SignalLinkEvent(void) {}; 00280 00281 virtual void ResetRadio(void) {}; 00282 00283 virtual uint32_t GetTimeOnAir(void) = 0; 00284 00285 void GrabMutex(void) { mutex .lock(); } 00286 void ReleaseMutex(void) { mutex .unlock(); } 00287 00288 int32_t GetFrequencyOffset() { return freq_offset; } 00289 void SetFrequencyOffset(int32_t offset) { freq_offset = offset; } 00290 00291 const uint32_t WakeupTime; 00292 00293 00294 00295 00296 protected: 00297 int32_t freq_offset; 00298 00299 RadioState_t State; 00300 00301 RadioModems_t Modem; 00302 00303 /*! 00304 * Access protection 00305 */ 00306 Mutex mutex ; 00307 00308 }; 00309 00310 #endif // __SXRADIO_H__ 00311
Generated on Fri Jul 15 2022 21:40:31 by
1.7.2