Fork of SX1276Lib for the NiceRF SX1276 module.

Fork of SX1276Lib by Semtech

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers radio.h Source File

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