Modtronix inAir9 driver based on SX1276 standard driver
Dependents: SX1276PingPong_inAir Sensors LoRaTerminal
Fork of SX1276Lib by
Diff: sx1276/sx1276.h
- Revision:
- 13:618826a997e2
- Parent:
- 12:aa5b3bf7fdf4
- Child:
- 16:d447f8d2d2d6
--- a/sx1276/sx1276.h Mon Oct 13 07:33:11 2014 +0000 +++ b/sx1276/sx1276.h Tue Dec 16 10:02:45 2014 +0000 @@ -25,7 +25,7 @@ #define RX_BUFFER_SIZE 256 -#define DEFAULT_TIMEOUT 200 //usec +#define DEFAULT_TIMEOUT 200 //usec #define RSSI_OFFSET -139.0 @@ -57,77 +57,84 @@ /*! * SX1276 DIO pins */ - InterruptIn dio0; - InterruptIn dio1; - InterruptIn dio2; - InterruptIn dio3; - InterruptIn dio4; - DigitalIn dio5; - - bool isRadioActive; - - uint8_t boardConnected; //1 = SX1276MB1LAS; 0 = SX1276MB1MAS - - uint8_t *rxBuffer; - - uint8_t previousOpMode; - - /*! - * Hardware DIO IRQ functions - */ - DioIrqHandler *dioIrq; - - /*! - * Tx and Rx timers - */ - Timeout txTimeoutTimer; - Timeout rxTimeoutTimer; - Timeout rxTimeoutSyncWord; - - /*! - * rxTx: [1: Tx, 0: Rx] - */ - uint8_t rxTx; - - RadioSettings_t settings; - - static const FskBandwidth_t FskBandwidths[] ; + InterruptIn dio0; + InterruptIn dio1; + InterruptIn dio2; + InterruptIn dio3; + InterruptIn dio4; + DigitalIn dio5; + + bool isRadioActive; + + uint8_t boardConnected; //1 = SX1276MB1LAS; 0 = SX1276MB1MAS + + uint8_t *rxBuffer; + + uint8_t previousOpMode; + + /*! + * Hardware DIO IRQ functions + */ + DioIrqHandler *dioIrq; + + /*! + * Tx and Rx timers + */ + Timeout txTimeoutTimer; + Timeout rxTimeoutTimer; + Timeout rxTimeoutSyncWord; + + /*! + * rxTx: [1: Tx, 0: Rx] + */ + uint8_t rxTx; + + RadioSettings_t settings; + + static const FskBandwidth_t FskBandwidths[] ; protected: - /*! - * Performs the Rx chain calibration for LF and HF bands - * \remark Must be called just after the reset so all registers are at their - * default values - */ - void RxChainCalibration( void ); + /*! + * Performs the Rx chain calibration for LF and HF bands + * \remark Must be called just after the reset so all registers are at their + * default values + */ + void RxChainCalibration( void ); public: - SX1276( void ( *txDone )( ), void ( *txTimeout ) ( ), void ( *rxDone ) ( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ), - void ( *rxTimeout ) ( ), void ( *rxError ) ( ), void ( *fhssChangeChannel ) ( uint8_t channelIndex ), void ( *cadDone ) ( bool ChannelActivityDetected ), - PinName mosi, PinName miso, PinName sclk, PinName nss, PinName reset, + SX1276( void ( *txDone )( ), void ( *txTimeout ) ( ), void ( *rxDone ) ( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ), + void ( *rxTimeout ) ( ), void ( *rxError ) ( ), void ( *fhssChangeChannel ) ( uint8_t channelIndex ), void ( *cadDone ) ( bool channelActivityDetected ), + PinName mosi, PinName miso, PinName sclk, PinName nss, PinName reset, PinName dio0, PinName dio1, PinName dio2, PinName dio3, PinName dio4, PinName dio5 ); SX1276( void ( *txDone )( ), void ( *txTimeout ) ( ), void ( *rxDone ) ( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ), - void ( *rxTimeout ) ( ), void ( *rxError ) ( ), void ( *fhssChangeChannel ) ( uint8_t channelIndex ), void ( *cadDone ) ( bool ChannelActivityDetected ) ); - virtual ~SX1276( ); - - //------------------------------------------------------------------------- - // Redefined Radio functions - //------------------------------------------------------------------------- - /*! + void ( *rxTimeout ) ( ), void ( *rxError ) ( ), void ( *fhssChangeChannel ) ( uint8_t channelIndex ), void ( *cadDone ) ( bool channelActivityDetected ) ); + virtual ~SX1276( ); + + //------------------------------------------------------------------------- + // Redefined Radio functions + //------------------------------------------------------------------------- + /*! * Return current radio status * * @param status Radio status. [IDLE, RX_RUNNING, TX_RUNNING] */ virtual RadioState GetState( void ); - /*! + /*! + * @brief Configures the SX1276 with the given modem + * + * @param [IN] modem Modem to be used [0: FSK, 1: LoRa] + */ + virtual void SetModem( ModemType modem ); + + /*! * @brief Sets the channel frequency * * @param [IN] freq Channel RF frequency */ virtual void SetChannel( uint32_t freq ); - /*! + /*! * @brief Sets the channels configuration * * @param [IN] modem Radio modem to be used [0: FSK, 1: LoRa] @@ -138,7 +145,7 @@ */ virtual bool IsChannelFree( ModemType modem, uint32_t freq, int8_t rssiThresh ); - /*! + /*! * @brief Generates a 32 bits random value based on the RSSI readings * * \remark This function sets the radio in LoRa modem mode and disables @@ -150,7 +157,7 @@ */ virtual uint32_t Random( void ); - /*! + /*! * @brief Sets the reception parameters * * @param [IN] modem Radio modem to be used [0: FSK, 1: LoRa] @@ -175,9 +182,10 @@ * FSK : N/A ( set to 0 ) * LoRa: timeout in symbols * @param [IN] fixLen Fixed length packets [0: variable, 1: fixed] + * @param [IN] payloadLen Sets payload length when fixed lenght is used * @param [IN] crcOn Enables/Disables the CRC [0: OFF, 1: ON] - * @param [IN] FreqHopOn Enables disables the intra-packet frequency hopping [0: OFF, 1: ON] (LoRa only) - * @param [IN] HopPeriod Number of symbols bewteen each hop (LoRa only) + * @param [IN] freqHopOn Enables disables the intra-packet frequency hopping [0: OFF, 1: ON] (LoRa only) + * @param [IN] hopPeriod Number of symbols bewteen each hop (LoRa only) * @param [IN] iqInverted Inverts IQ signals ( LoRa only ) * FSK : N/A ( set to 0 ) * LoRa: [0: not inverted, 1: inverted] @@ -188,10 +196,11 @@ uint32_t datarate, uint8_t coderate, uint32_t bandwidthAfc, uint16_t preambleLen, uint16_t symbTimeout, bool fixLen, - bool crcOn, bool FreqHopOn, uint8_t HopPeriod, + uint8_t payloadLen, + bool crcOn, bool freqHopOn, uint8_t hopPeriod, bool iqInverted, bool rxContinuous ); - /*! + /*! * @brief Sets the transmission parameters * * @param [IN] modem Radio modem to be used [0: FSK, 1: LoRa] @@ -213,8 +222,8 @@ * @param [IN] preambleLen Sets the preamble length * @param [IN] fixLen Fixed length packets [0: variable, 1: fixed] * @param [IN] crcOn Enables disables the CRC [0: OFF, 1: ON] - * @param [IN] FreqHopOn Enables disables the intra-packet frequency hopping [0: OFF, 1: ON] (LoRa only) - * @param [IN] HopPeriod Number of symbols bewteen each hop (LoRa only) + * @param [IN] freqHopOn Enables disables the intra-packet frequency hopping [0: OFF, 1: ON] (LoRa only) + * @param [IN] hopPeriod Number of symbols bewteen each hop (LoRa only) * @param [IN] iqInverted Inverts IQ signals ( LoRa only ) * FSK : N/A ( set to 0 ) * LoRa: [0: not inverted, 1: inverted] @@ -223,10 +232,10 @@ virtual void SetTxConfig( ModemType modem, int8_t power, uint32_t fdev, uint32_t bandwidth, uint32_t datarate, uint8_t coderate, uint16_t preambleLen, - bool fixLen, bool crcOn, bool FreqHopOn, - uint8_t HopPeriod, bool iqInverted, uint32_t timeout ); + bool fixLen, bool crcOn, bool freqHopOn, + uint8_t hopPeriod, bool iqInverted, uint32_t timeout ); - /*! + /*! * @brief Computes the packet time on air for the given payload * * \Remark Can only be called once SetRxConfig or SetTxConfig have been called @@ -238,7 +247,7 @@ */ virtual double TimeOnAir ( ModemType modem, uint8_t pktLen ); - /*! + /*! * @brief Sends the buffer of size. Prepares the packet to be sent and sets * the radio in transmission * @@ -247,43 +256,43 @@ */ virtual void Send( uint8_t *buffer, uint8_t size ); - /*! + /*! * @brief Sets the radio in sleep mode */ virtual void Sleep( void ); - /*! + /*! * @brief Sets the radio in standby mode */ virtual void Standby( void ); - /*! + /*! * @brief Sets the radio in reception mode for the given time * @param [IN] timeout Reception timeout [us] * [0: continuous, others timeout] */ virtual void Rx( uint32_t timeout ); - /*! + /*! * @brief Sets the radio in transmission mode for the given time * @param [IN] timeout Transmission timeout [us] * [0: continuous, others timeout] */ virtual void Tx( uint32_t timeout ); - /*! + /*! * @brief Start a Channel Activity Detection */ - virtual void StartCad( void ); - - /*! + virtual void StartCad( void ); + + /*! * @brief Reads the current RSSI value * * @retval rssiValue Current RSSI value in [dBm] */ virtual int16_t GetRssi ( ModemType modem ); - /*! + /*! * @brief Writes the radio register at the specified address * * @param [IN]: addr Register address @@ -291,7 +300,7 @@ */ virtual void Write ( uint8_t addr, uint8_t data ) = 0; - /*! + /*! * @brief Reads the radio register at the specified address * * @param [IN]: addr Register address @@ -299,7 +308,7 @@ */ virtual uint8_t Read ( uint8_t addr ) = 0; - /*! + /*! * @brief Writes multiple radio registers starting at address * * @param [IN] addr First Radio register address @@ -308,7 +317,7 @@ */ virtual void Write( uint8_t addr, uint8_t *buffer, uint8_t size ) = 0; - /*! + /*! * @brief Reads multiple radio registers starting at address * * @param [IN] addr First Radio register address @@ -316,98 +325,98 @@ * @param [IN] size Number of registers to be read */ virtual void Read ( uint8_t addr, uint8_t *buffer, uint8_t size ) = 0; - - /*! - * @brief Writes the buffer contents to the SX1276 FIFO - * - * @param [IN] buffer Buffer containing data to be put on the FIFO. - * @param [IN] size Number of bytes to be written to the FIFO - */ - virtual void WriteFifo( uint8_t *buffer, uint8_t size ) = 0; + + /*! + * @brief Writes the buffer contents to the SX1276 FIFO + * + * @param [IN] buffer Buffer containing data to be put on the FIFO. + * @param [IN] size Number of bytes to be written to the FIFO + */ + virtual void WriteFifo( uint8_t *buffer, uint8_t size ) = 0; - /*! - * @brief Reads the contents of the SX1276 FIFO - * - * @param [OUT] buffer Buffer where to copy the FIFO read data. - * @param [IN] size Number of bytes to be read from the FIFO - */ - virtual void ReadFifo( uint8_t *buffer, uint8_t size ) = 0; - /*! - * @brief Resets the SX1276 - */ - virtual void Reset( void ) = 0; - - //------------------------------------------------------------------------- - // Board relative functions - //------------------------------------------------------------------------- - + /*! + * @brief Reads the contents of the SX1276 FIFO + * + * @param [OUT] buffer Buffer where to copy the FIFO read data. + * @param [IN] size Number of bytes to be read from the FIFO + */ + virtual void ReadFifo( uint8_t *buffer, uint8_t size ) = 0; + /*! + * @brief Resets the SX1276 + */ + virtual void Reset( void ) = 0; + + //------------------------------------------------------------------------- + // Board relative functions + //------------------------------------------------------------------------- + protected: - /*! - * @brief Initializes the radio I/Os pins interface - */ - virtual void IoInit( void ) = 0; - - /*! - * @brief Initializes the radio registers - */ - virtual void RadioRegistersInit( ) = 0; - - /*! - * @brief Initializes the radio SPI - */ - virtual void SpiInit( void ) = 0; - - /*! - * @brief Initializes DIO IRQ handlers - * - * @param [IN] irqHandlers Array containing the IRQ callback functions - */ - virtual void IoIrqInit( DioIrqHandler *irqHandlers ) = 0; + /*! + * @brief Initializes the radio I/Os pins interface + */ + virtual void IoInit( void ) = 0; + + /*! + * @brief Initializes the radio registers + */ + virtual void RadioRegistersInit( ) = 0; + + /*! + * @brief Initializes the radio SPI + */ + virtual void SpiInit( void ) = 0; + + /*! + * @brief Initializes DIO IRQ handlers + * + * @param [IN] irqHandlers Array containing the IRQ callback functions + */ + virtual void IoIrqInit( DioIrqHandler *irqHandlers ) = 0; - /*! - * @brief De-initializes the radio I/Os pins interface. - * - * \remark Useful when going in MCU lowpower modes - */ - virtual void IoDeInit( void ) = 0; + /*! + * @brief De-initializes the radio I/Os pins interface. + * + * \remark Useful when going in MCU lowpower modes + */ + virtual void IoDeInit( void ) = 0; - /*! - * @brief Gets the board PA selection configuration - * - * @param [IN] channel Channel frequency in Hz - * @retval PaSelect RegPaConfig PaSelect value - */ - virtual uint8_t GetPaSelect( uint32_t channel ) = 0; + /*! + * @brief Gets the board PA selection configuration + * + * @param [IN] channel Channel frequency in Hz + * @retval PaSelect RegPaConfig PaSelect value + */ + virtual uint8_t GetPaSelect( uint32_t channel ) = 0; - /*! - * @brief Set the RF Switch I/Os pins in Low Power mode - * - * @param [IN] status enable or disable - */ - virtual void SetAntSwLowPower( bool status ) = 0; + /*! + * @brief Set the RF Switch I/Os pins in Low Power mode + * + * @param [IN] status enable or disable + */ + virtual void SetAntSwLowPower( bool status ) = 0; - /*! - * @brief Initializes the RF Switch I/Os pins interface - */ - virtual void AntSwInit( void ) = 0; + /*! + * @brief Initializes the RF Switch I/Os pins interface + */ + virtual void AntSwInit( void ) = 0; - /*! - * @brief De-initializes the RF Switch I/Os pins interface - * - * \remark Needed to decrease the power consumption in MCU lowpower modes - */ - virtual void AntSwDeInit( void ) = 0; + /*! + * @brief De-initializes the RF Switch I/Os pins interface + * + * \remark Needed to decrease the power consumption in MCU lowpower modes + */ + virtual void AntSwDeInit( void ) = 0; - /*! - * @brief Controls the antena switch if necessary. - * - * \remark see errata note - * - * @param [IN] rxTx [1: Tx, 0: Rx] - */ - virtual void SetAntSw( uint8_t rxTx ) = 0; - - /*! + /*! + * @brief Controls the antena switch if necessary. + * + * \remark see errata note + * + * @param [IN] rxTx [1: Tx, 0: Rx] + */ + virtual void SetAntSw( uint8_t rxTx ) = 0; + + /*! * @brief Checks if the given RF frequency is supported by the hardware * * @param [IN] frequency RF frequency to be checked @@ -416,66 +425,59 @@ virtual bool CheckRfFrequency( uint32_t frequency ) = 0; protected: - /*! - * @brief Sets the SX1276 operating mode - * - * @param [IN] opMode New operating mode - */ - virtual void SetOpMode( uint8_t opMode ); + /*! + * @brief Sets the SX1276 operating mode + * + * @param [IN] opMode New operating mode + */ + virtual void SetOpMode( uint8_t opMode ); - /*! - * @brief Configures the SX1276 with the given modem - * - * @param [IN] modem Modem to be used [0: FSK, 1: LoRa] - */ - virtual void SetModem( ModemType modem ); + /* + * SX1276 DIO IRQ callback functions prototype + */ - /* - * SX1276 DIO IRQ callback functions prototype - */ + /*! + * @brief DIO 0 IRQ callback + */ + virtual void OnDio0Irq( void ); - /*! - * @brief DIO 0 IRQ callback - */ - virtual void OnDio0Irq( void ); + /*! + * @brief DIO 1 IRQ callback + */ + virtual void OnDio1Irq( void ); - /*! - * @brief DIO 1 IRQ callback - */ - virtual void OnDio1Irq( void ); + /*! + * @brief DIO 2 IRQ callback + */ + virtual void OnDio2Irq( void ); - /*! - * @brief DIO 2 IRQ callback - */ - virtual void OnDio2Irq( void ); + /*! + * @brief DIO 3 IRQ callback + */ + virtual void OnDio3Irq( void ); - /*! - * @brief DIO 3 IRQ callback - */ - virtual void OnDio3Irq( void ); - - /*! - * @brief DIO 4 IRQ callback - */ - virtual void OnDio4Irq( void ); + /*! + * @brief DIO 4 IRQ callback + */ + virtual void OnDio4Irq( void ); - /*! - * @brief DIO 5 IRQ callback - */ - virtual void OnDio5Irq( void ); + /*! + * @brief DIO 5 IRQ callback + */ + virtual void OnDio5Irq( void ); - /*! - * @brief Tx & Rx timeout timer callback - */ - virtual void OnTimeoutIrq( void ); - - /*! - * Returns the known FSK bandwidth registers value - * - * \param [IN] bandwidth Bandwidth value in Hz - * \retval regValue Bandwidth register value. - */ - static uint8_t GetFskBandwidthRegValue( uint32_t bandwidth ); + /*! + * @brief Tx & Rx timeout timer callback + */ + virtual void OnTimeoutIrq( void ); + + /*! + * Returns the known FSK bandwidth registers value + * + * \param [IN] bandwidth Bandwidth value in Hz + * \retval regValue Bandwidth register value. + */ + static uint8_t GetFskBandwidthRegValue( uint32_t bandwidth ); }; #endif //__SX1276_H__