MultiTech / libxDot-dev-mbed5-deprecated

Dependents:   Dot-Examples Dot-AT-Firmware Dot-Examples TEST_FF1705 ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers SxRadio.h Source File

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