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.
Fork of libmDot-custom by
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 }RadioState_t ; 00047 00048 SxRadio(uint32_t WakeupTime) : WakeupTime(WakeupTime), State(RF_IDLE), Modem(MODEM_LORA) { } 00049 virtual ~SxRadio() {}; 00050 00051 /*! 00052 * \brief Initializes the radio 00053 * 00054 * \param [IN] events Structure containing the driver callback functions 00055 */ 00056 virtual void Init( SxRadioEvents *events ) = 0; 00057 /*! 00058 * \brief Prepares the radio for destruction 00059 */ 00060 virtual void Terminate( void ) = 0; 00061 /*! 00062 * Return current radio status 00063 * 00064 * \param status Radio status.[RF_IDLE, RF_RX_RUNNING, RF_TX_RUNNING] 00065 */ 00066 virtual RadioState_t Status ( void ) { return State; } 00067 /*! 00068 * \brief Configures the radio with the given modem 00069 * 00070 * \param [IN] modem Modem to be used [0: FSK, 1: LoRa] 00071 */ 00072 virtual void SetModem( RadioModems_t modem ) = 0; 00073 /*! 00074 * \brief Sets the channel frequency 00075 * 00076 * \param [IN] freq Channel RF frequency 00077 */ 00078 virtual void SetChannel( uint32_t freq ) = 0; 00079 /*! 00080 * \brief Sets the channels configuration 00081 * 00082 * \param [IN] modem Radio modem to be used [0: FSK, 1: LoRa] 00083 * \param [IN] freq Channel RF frequency 00084 * \param [IN] rssiThresh RSSI threshold 00085 * 00086 * \retval isFree [true: Channel is free, false: Channel is not free] 00087 */ 00088 virtual bool IsChannelFree( RadioModems_t modem, uint32_t freq, uint8_t datarate, int16_t rssiThresh, uint8_t bandwidth, uint32_t timeout = 5 ) = 0; 00089 /*! 00090 * \brief Generates a 32 bits random value based on the RSSI readings 00091 * 00092 * \remark This function sets the radio in LoRa modem mode and disables 00093 * all interrupts. 00094 * After calling this function either Radio.SetRxConfig or 00095 * Radio.SetTxConfig functions must be called. 00096 * 00097 * \retval randomValue 32 bits random value 00098 */ 00099 virtual uint32_t Random( void ) = 0; 00100 /*! 00101 * \brief Sets the reception parameters 00102 * 00103 * \param [IN] modem Radio modem to be used [0: FSK, 1: LoRa] 00104 * \param [IN] bandwidth Sets the bandwidth 00105 * FSK : >= 2600 and <= 250000 Hz 00106 * LoRa: [0: 125 kHz, 1: 250 kHz, 00107 * 2: 500 kHz, 3: Reserved] 00108 * \param [IN] datarate Sets the Datarate 00109 * FSK : 600..300000 bits/s 00110 * LoRa: [6: 64, 7: 128, 8: 256, 9: 512, 00111 * 10: 1024, 11: 2048, 12: 4096 chips] 00112 * \param [IN] coderate Sets the coding rate (LoRa only) 00113 * FSK : N/A ( set to 0 ) 00114 * LoRa: [1: 4/5, 2: 4/6, 3: 4/7, 4: 4/8] 00115 * \param [IN] bandwidthAfc Sets the AFC Bandwidth (FSK only) 00116 * FSK : >= 2600 and <= 250000 Hz 00117 * LoRa: N/A ( set to 0 ) 00118 * \param [IN] preambleLen Sets the Preamble length 00119 * FSK : Number of bytes 00120 * LoRa: Length in symbols (the hardware adds 4 more symbols) 00121 * \param [IN] symbTimeout Sets the RxSingle timeout value (LoRa only) 00122 * FSK : N/A ( set to 0 ) 00123 * LoRa: timeout in symbols 00124 * \param [IN] fixLen Fixed length packets [0: variable, 1: fixed] 00125 * \param [IN] payloadLen Sets payload length when fixed length is used 00126 * \param [IN] crcOn Enables/Disables the CRC [0: OFF, 1: ON] 00127 * \param [IN] FreqHopOn Enables disables the intra-packet frequency hopping 00128 * FSK : N/A ( set to 0 ) 00129 * LoRa: [0: OFF, 1: ON] 00130 * \param [IN] HopPeriod Number of symbols bewteen each hop 00131 * FSK : N/A ( set to 0 ) 00132 * LoRa: Number of symbols 00133 * \param [IN] iqInverted Inverts IQ signals (LoRa only) 00134 * FSK : N/A ( set to 0 ) 00135 * LoRa: [0: not inverted, 1: inverted] 00136 * \param [IN] rxContinuous Sets the reception in continuous mode 00137 * [false: single mode, true: continuous mode] 00138 */ 00139 virtual void SetRxConfig( RadioModems_t modem, uint32_t bandwidth, 00140 uint32_t datarate, uint8_t coderate, 00141 uint32_t bandwidthAfc, uint16_t preambleLen, 00142 uint16_t symbTimeout, bool fixLen, 00143 uint8_t payloadLen, 00144 bool crcOn, bool FreqHopOn, uint8_t HopPeriod, 00145 bool iqInverted, bool rxContinuous ) = 0; 00146 /*! 00147 * \brief Sets the transmission parameters 00148 * 00149 * \param [IN] modem Radio modem to be used [0: FSK, 1: LoRa] 00150 * \param [IN] power Sets the output power [dBm] 00151 * \param [IN] fdev Sets the frequency deviation (FSK only) 00152 * FSK : [Hz] 00153 * LoRa: 0 00154 * \param [IN] bandwidth Sets the bandwidth (LoRa only) 00155 * FSK : 0 00156 * LoRa: [0: 125 kHz, 1: 250 kHz, 00157 * 2: 500 kHz, 3: Reserved] 00158 * \param [IN] datarate Sets the Datarate 00159 * FSK : 600..300000 bits/s 00160 * LoRa: [6: 64, 7: 128, 8: 256, 9: 512, 00161 * 10: 1024, 11: 2048, 12: 4096 chips] 00162 * \param [IN] coderate Sets the coding rate (LoRa only) 00163 * FSK : N/A ( set to 0 ) 00164 * LoRa: [1: 4/5, 2: 4/6, 3: 4/7, 4: 4/8] 00165 * \param [IN] preambleLen Sets the preamble length 00166 * FSK : Number of bytes 00167 * LoRa: Length in symbols (the hardware adds 4 more symbols) 00168 * \param [IN] fixLen Fixed length packets [0: variable, 1: fixed] 00169 * \param [IN] crcOn Enables disables the CRC [0: OFF, 1: ON] 00170 * \param [IN] FreqHopOn Enables disables the intra-packet frequency hopping 00171 * FSK : N/A ( set to 0 ) 00172 * LoRa: [0: OFF, 1: ON] 00173 * \param [IN] HopPeriod Number of symbols bewteen each hop 00174 * FSK : N/A ( set to 0 ) 00175 * LoRa: Number of symbols 00176 * \param [IN] iqInverted Inverts IQ signals (LoRa only) 00177 * FSK : N/A ( set to 0 ) 00178 * LoRa: [0: not inverted, 1: inverted] 00179 * \param [IN] timeout Transmission timeout [us] 00180 */ 00181 virtual void SetTxConfig( RadioModems_t modem, int8_t power, uint32_t fdev, 00182 uint32_t bandwidth, uint32_t datarate, 00183 uint8_t coderate, uint16_t preambleLen, 00184 bool fixLen, bool crcOn, bool FreqHopOn, 00185 uint8_t HopPeriod, bool iqInverted, uint32_t timeout ) = 0; 00186 00187 virtual void SetTxContinuous(bool enable) = 0; 00188 00189 /*! 00190 * \brief Checks if the given RF frequency is supported by the hardware 00191 * 00192 * \param [IN] frequency RF frequency to be checked 00193 * \retval isSupported [true: supported, false: unsupported] 00194 */ 00195 virtual bool CheckRfFrequency( uint32_t frequency ) { return true; } 00196 /*! 00197 * \brief Computes the packet time on air for the given payload 00198 * 00199 * \Remark Can only be called once SetRxConfig or SetTxConfig have been called 00200 * 00201 * \param [IN] modem Radio modem to be used [0: FSK, 1: LoRa] 00202 * \param [IN] pktLen Packet payload length 00203 * 00204 * \retval airTime Computed airTime for the given packet payload length 00205 */ 00206 virtual double TimeOnAir( RadioModems_t modem, uint8_t pktLen ) = 0; 00207 /*! 00208 * \brief Sends the buffer of size. Prepares the packet to be sent and sets 00209 * the radio in transmission 00210 * 00211 * \param [IN]: buffer Buffer pointer 00212 * \param [IN]: size Buffer size 00213 */ 00214 virtual void Send( const uint8_t *buffer, uint8_t size ) = 0; 00215 /*! 00216 * \brief Sets the radio in sleep mode 00217 */ 00218 virtual void Sleep( void ) = 0; 00219 /*! 00220 * \brief Sets the radio in standby mode 00221 */ 00222 virtual void Standby( void ) = 0; 00223 /*! 00224 * \brief Sets the radio in reception mode for the given time 00225 * \param [IN] timeout Reception timeout [us] 00226 * [0: continuous, others timeout] 00227 */ 00228 virtual void Rx( uint32_t timeout ) = 0; 00229 /*! 00230 * \brief Start a Channel Activity Detection 00231 */ 00232 virtual void StartCad( void ) = 0; 00233 /*! 00234 * \brief Reads the current RSSI value 00235 * 00236 * \retval rssiValue Current RSSI value in [dBm] 00237 */ 00238 virtual int16_t Rssi( RadioModems_t modem ) = 0; 00239 /*! 00240 * \brief Writes the radio register at the specified address 00241 * 00242 * \param [IN]: addr Register address 00243 * \param [IN]: data New register value 00244 */ 00245 virtual void Write( uint8_t addr, uint8_t data ) = 0; 00246 /*! 00247 * \brief Reads the radio register at the specified address 00248 * 00249 * \param [IN]: addr Register address 00250 * \retval data Register value 00251 */ 00252 virtual uint8_t Read ( uint8_t addr ) = 0; 00253 /*! 00254 * \brief Writes multiple radio registers starting at address 00255 * 00256 * \param [IN] addr First Radio register address 00257 * \param [IN] buffer Buffer containing the new register's values 00258 * \param [IN] size Number of registers to be written 00259 */ 00260 virtual void WriteBuffer( uint8_t addr, const uint8_t *buffer, uint8_t size ) = 0; 00261 /*! 00262 * \brief Reads multiple radio registers starting at address 00263 * 00264 * \param [IN] addr First Radio register address 00265 * \param [OUT] buffer Buffer where to copy the registers data 00266 * \param [IN] size Number of registers to be read 00267 */ 00268 virtual void ReadBuffer( uint8_t addr, uint8_t *buffer, uint8_t size ) = 0; 00269 00270 virtual void SignalMacEvent(void) {}; 00271 00272 void GrabMutex(void) { mutex .lock(); } 00273 void ReleaseMutex(void) { mutex .unlock(); } 00274 00275 const uint32_t WakeupTime; 00276 00277 protected: 00278 RadioState_t State; 00279 00280 RadioModems_t Modem; 00281 00282 /*! 00283 * Access protection 00284 */ 00285 Mutex mutex ; 00286 }; 00287 00288 #endif // __SXRADIO_H__ 00289 00290
Generated on Tue Jul 12 2022 22:21:41 by
