fholin fholin / Mbed 2 deprecated MiniMousetest

Dependencies:   mbed

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