SX1276Lib
Fork of SX1276Lib by
Revision 6:e7f02929cd3d, committed 2014-09-04
- Comitter:
- GregCr
- Date:
- Thu Sep 04 14:03:20 2014 +0000
- Parent:
- 5:11ec8a6ba4f0
- Child:
- 7:2b555111463f
- Commit message:
- Added support for FHSS
Changed in this revision
--- a/enums/enums.h Thu Aug 21 11:58:28 2014 +0000 +++ b/enums/enums.h Thu Sep 04 14:03:20 2014 +0000 @@ -99,6 +99,8 @@ uint16_t PreambleLen; bool FixLen; bool CrcOn; + bool FreqHopOn; + uint8_t HopPeriod; bool IqInverted; bool RxContinuous; uint32_t TxTimeout;
--- a/radio/radio.cpp Thu Aug 21 11:58:28 2014 +0000 +++ b/radio/radio.cpp Thu Sep 04 14:03:20 2014 +0000 @@ -14,12 +14,14 @@ */ #include "radio.h" -Radio::Radio( void ( *txDone )( ), void ( *txTimeout ) ( ), void ( *rxDone ) ( uint8_t *payload, uint16_t size, int8_t rssi, int8_t snr ), void ( *rxTimeout ) ( ), void ( *rxError ) ( ) ) +Radio::Radio( void ( *txDone )( ), void ( *txTimeout ) ( ), void ( *rxDone ) ( uint8_t *payload, uint16_t size, int8_t rssi, int8_t snr ), + void ( *rxTimeout ) ( ), void ( *rxError ) ( ), void ( *fhssChangeChannel ) ( uint8_t channelIndex ) ) { this->txDone = txDone; this->txTimeout = txTimeout; this->rxDone = rxDone; this->rxTimeout = rxTimeout; this->rxError = rxError; + this->fhssChangeChannel = fhssChangeChannel; }
--- a/radio/radio.h Thu Aug 21 11:58:28 2014 +0000 +++ b/radio/radio.h Thu Sep 04 14:03:20 2014 +0000 @@ -62,6 +62,13 @@ */ void ( *rxError ) ( ); + /*! + * \brief FHSS Change Channel callback prototype. + * + * \param [IN] CurrentChannel Index number of the current channel + */ + void ( *fhssChangeChannel )( uint8_t CurrentChannel ); + public: //------------------------------------------------------------------------- // Constructor @@ -74,7 +81,8 @@ * @param [IN] rxTimeout * @param [IN] rxError */ - Radio( void ( *txDone )( ), void ( *txTimeout ) ( ), void ( *rxDone ) ( uint8_t *payload, uint16_t size, int8_t rssi, int8_t snr ), void ( *rxTimeout ) ( ), void ( *rxError ) ( ) ); + Radio( void ( *txDone )( ), void ( *txTimeout ) ( ), void ( *rxDone ) ( uint8_t *payload, uint16_t size, int8_t rssi, int8_t snr ), + void ( *rxTimeout ) ( ), void ( *rxError ) ( ), void ( *fhssChangeChannel ) ( uint8_t channelIndex ) ); virtual ~Radio( ) {}; //------------------------------------------------------------------------- @@ -144,6 +152,8 @@ * LoRa: timeout in symbols * @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] iqInverted Inverts IQ signals ( LoRa only ) * FSK : N/A ( set to 0 ) * LoRa: [0: not inverted, 1: inverted] @@ -154,7 +164,8 @@ uint32_t datarate, uint8_t coderate, uint32_t bandwidthAfc, uint16_t preambleLen, uint16_t symbTimeout, bool fixLen, - bool crcOn, bool iqInverted, bool rxContinuous ) = 0; + bool crcOn, bool FreqHopOn, uint8_t HopPeriod, + bool iqInverted, bool rxContinuous ) = 0; /*! * @brief Sets the transmission parameters @@ -178,16 +189,18 @@ * @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] iqInverted Inverts IQ signals ( LoRa only ) * FSK : N/A ( set to 0 ) * LoRa: [0: not inverted, 1: inverted] * @param [IN] timeout Transmission timeout [us] */ 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 iqInverted, uint32_t timeout ) = 0; + 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 ) = 0; /*! * @brief Checks if the given RF frequency is supported by the hardware
--- a/sx1276/sx1276-hal.cpp Thu Aug 21 11:58:28 2014 +0000 +++ b/sx1276/sx1276-hal.cpp Thu Sep 04 14:03:20 2014 +0000 @@ -33,11 +33,12 @@ { MODEM_LORA, REG_LR_PAYLOADMAXLENGTH, 0x40 }, }; -SX1276MB1xAS::SX1276MB1xAS( void ( *txDone )( ), void ( *txTimeout ) ( ), void ( *rxDone ) ( uint8_t *payload, uint16_t size, int8_t rssi, int8_t snr ), void ( *rxTimeout ) ( ), void ( *rxError ) ( ), +SX1276MB1xAS::SX1276MB1xAS( void ( *txDone )( ), void ( *txTimeout ) ( ), void ( *rxDone ) ( uint8_t *payload, uint16_t size, int8_t rssi, int8_t snr ), + void ( *rxTimeout ) ( ), void ( *rxError ) ( ), void ( *fhssChangeChannel ) ( uint8_t channelIndex ), PinName mosi, PinName miso, PinName sclk, PinName nss, PinName reset, PinName dio0, PinName dio1, PinName dio2, PinName dio3, PinName dio4, PinName dio5, PinName antSwitch ) - : SX1276( txDone, txTimeout, rxDone, rxTimeout, rxError, mosi, miso, sclk, nss, reset, dio0, dio1, dio2, dio3, dio4, dio5), + : SX1276( txDone, txTimeout, rxDone, rxTimeout, rxError, fhssChangeChannel, mosi, miso, sclk, nss, reset, dio0, dio1, dio2, dio3, dio4, dio5), antSwitch( antSwitch ), #if( defined ( TARGET_KL25Z ) || defined ( TARGET_LPC11U6X ) ) fake( A3 ) @@ -64,13 +65,14 @@ this->settings.State = IDLE ; } -SX1276MB1xAS::SX1276MB1xAS( void ( *txDone )( ), void ( *txTimeout ) ( ), void ( *rxDone ) ( uint8_t *payload, uint16_t size, int8_t rssi, int8_t snr ), void ( *rxTimeout ) ( ), void ( *rxError ) ( ) ) +SX1276MB1xAS::SX1276MB1xAS( void ( *txDone )( ), void ( *txTimeout ) ( ), void ( *rxDone ) ( uint8_t *payload, uint16_t size, int8_t rssi, int8_t snr ), + void ( *rxTimeout ) ( ), void ( *rxError ) ( ), void ( *fhssChangeChannel ) ( uint8_t channelIndex ) ) #if( defined ( TARGET_KL25Z ) || defined ( TARGET_LPC11U6X ) ) - : SX1276( txDone, txTimeout, rxDone, rxTimeout, rxError, D11, D12, D13, D10, A0, D2, D3, D4, D5, D8, D9 ), + : SX1276( txDone, txTimeout, rxDone, rxTimeout, rxError, fhssChangeChannel, D11, D12, D13, D10, A0, D2, D3, D4, D5, D8, D9 ), antSwitch( A4 ), fake( A3 ) #elif defined ( TARGET_NUCLEO_L152RE ) - : SX1276( txDone, txTimeout, rxDone, rxTimeout, rxError, D11, D12, D13, D10, A0, D2, D3, D4, D5, A3, D9 ), // For NUCLEO L152RE dio4 is on port A3 + : SX1276( txDone, txTimeout, rxDone, rxTimeout, rxError, fhssChangeChannel, D11, D12, D13, D10, A0, D2, D3, D4, D5, A3, D9 ), // For NUCLEO L152RE dio4 is on port A3 antSwitch( A4 ), fake( D8 ) #else
--- a/sx1276/sx1276-hal.h Thu Aug 21 11:58:28 2014 +0000 +++ b/sx1276/sx1276-hal.h Thu Sep 04 14:03:20 2014 +0000 @@ -33,11 +33,12 @@ static const RadioRegisters_t RadioRegsInit[]; public: - SX1276MB1xAS( void ( *txDone )( ), void ( *txTimeout ) ( ), void ( *rxDone ) ( uint8_t *payload, uint16_t size, int8_t rssi, int8_t snr ), void ( *rxTimeout ) ( ), void ( *rxError ) ( ), + SX1276MB1xAS( void ( *txDone )( ), void ( *txTimeout ) ( ), void ( *rxDone ) ( uint8_t *payload, uint16_t size, int8_t rssi, int8_t snr ), + void ( *rxTimeout ) ( ), void ( *rxError ) ( ), void ( *fhssChangeChannel ) ( uint8_t channelIndex ), PinName mosi, PinName miso, PinName sclk, PinName nss, PinName reset, PinName dio0, PinName dio1, PinName dio2, PinName dio3, PinName dio4, PinName dio5, PinName antSwitch ); - SX1276MB1xAS( void ( *txDone )( ), void ( *txTimeout ) ( ), void ( *rxDone ) ( uint8_t *payload, uint16_t size, int8_t rssi, int8_t snr ), void ( *rxTimeout ) ( ), void ( *rxError ) ( ) ); + SX1276MB1xAS( void ( *txDone )( ), void ( *txTimeout ) ( ), void ( *rxDone ) ( uint8_t *payload, uint16_t size, int8_t rssi, int8_t snr ), void ( *rxTimeout ) ( ), void ( *rxError ) ( ), void ( *fhssChangeChannel ) ( uint8_t channelIndex ) ); virtual ~SX1276MB1xAS( ) { }; protected:
--- a/sx1276/sx1276.cpp Thu Aug 21 11:58:28 2014 +0000 +++ b/sx1276/sx1276.cpp Thu Sep 04 14:03:20 2014 +0000 @@ -40,10 +40,11 @@ }; -SX1276::SX1276( void ( *txDone )( ), void ( *txTimeout ) ( ), void ( *rxDone ) ( uint8_t *payload, uint16_t size, int8_t rssi, int8_t snr ), void ( *rxTimeout ) ( ), void ( *rxError ) ( ), +SX1276::SX1276( void ( *txDone )( ), void ( *txTimeout ) ( ), void ( *rxDone ) ( uint8_t *payload, uint16_t size, int8_t rssi, int8_t snr ), + void ( *rxTimeout ) ( ), void ( *rxError ) ( ), void ( *fhssChangeChannel ) ( uint8_t channelIndex ), PinName mosi, PinName miso, PinName sclk, PinName nss, PinName reset, PinName dio0, PinName dio1, PinName dio2, PinName dio3, PinName dio4, PinName dio5 ) - : Radio( txDone, txTimeout, rxDone, rxTimeout, rxError ), + : Radio( txDone, txTimeout, rxDone, rxTimeout, rxError, fhssChangeChannel ), spi( mosi, miso, sclk ), nss( nss ), reset( reset ), @@ -205,7 +206,8 @@ uint32_t datarate, uint8_t coderate, uint32_t bandwidthAfc, uint16_t preambleLen, uint16_t symbTimeout, bool fixLen, - bool crcOn, bool iqInverted, bool rxContinuous ) + bool crcOn, bool FreqHopOn, uint8_t HopPeriod, + bool iqInverted, bool rxContinuous ) { SetModem( modem ); @@ -253,6 +255,8 @@ this->settings.LoRa.Coderate = coderate; this->settings.LoRa.FixLen = fixLen; this->settings.LoRa.CrcOn = crcOn; + this->settings.LoRa.FreqHopOn = FreqHopOn; + this->settings.LoRa.HopPeriod = HopPeriod; this->settings.LoRa.IqInverted = iqInverted; this->settings.LoRa.RxContinuous = rxContinuous; @@ -301,6 +305,12 @@ Write( REG_LR_PREAMBLEMSB, ( uint8_t )( ( preambleLen >> 8 ) & 0xFF ) ); Write( REG_LR_PREAMBLELSB, ( uint8_t )( preambleLen & 0xFF ) ); + if( this->settings.LoRa.FreqHopOn == true ) + { + Write( REG_LR_PLLHOP, ( Read( REG_LR_PLLHOP ) & RFLR_PLLHOP_FASTHOP_MASK ) | RFLR_PLLHOP_FASTHOP_ON ); + Write( REG_LR_HOPPERIOD, this->settings.LoRa.HopPeriod ); + } + if( datarate == 6 ) { Write( REG_LR_DETECTOPTIMIZE, @@ -327,8 +337,8 @@ void SX1276::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 iqInverted, uint32_t timeout ) + bool fixLen, bool crcOn, bool FreqHopOn, + uint8_t HopPeriod, bool iqInverted, uint32_t timeout ) { uint8_t paConfig = 0; uint8_t paDac = 0; @@ -440,6 +450,8 @@ this->settings.LoRa.PreambleLen = preambleLen; this->settings.LoRa.FixLen = fixLen; this->settings.LoRa.CrcOn = crcOn; + this->settings.LoRa.FreqHopOn = FreqHopOn; + this->settings.LoRa.HopPeriod = HopPeriod; this->settings.LoRa.IqInverted = iqInverted; this->settings.LoRa.TxTimeout = timeout; @@ -460,7 +472,13 @@ { this->settings.LoRa.LowDatarateOptimize = 0x00; } - + + if( this->settings.LoRa.FreqHopOn == true ) + { + Write( REG_LR_PLLHOP, ( Read( REG_LR_PLLHOP ) & RFLR_PLLHOP_FASTHOP_MASK ) | RFLR_PLLHOP_FASTHOP_ON ); + Write( REG_LR_HOPPERIOD, this->settings.LoRa.HopPeriod ); + } + Write( REG_LR_MODEMCONFIG1, ( Read( REG_LR_MODEMCONFIG1 ) & RFLR_MODEMCONFIG1_BW_MASK & @@ -676,7 +694,7 @@ void SX1276::Rx( uint32_t timeout ) { bool rxContinuous = false; - + switch( this->settings.Modem ) { case MODEM_FSK: @@ -720,17 +738,37 @@ rxContinuous = this->settings.LoRa.RxContinuous; - Write( REG_LR_IRQFLAGSMASK, //RFLR_IRQFLAGS_RXTIMEOUT | + if( this->settings.LoRa.FreqHopOn == true ) + { + Write( REG_LR_IRQFLAGSMASK, //RFLR_IRQFLAGS_RXTIMEOUT | //RFLR_IRQFLAGS_RXDONE | //RFLR_IRQFLAGS_PAYLOADCRCERROR | RFLR_IRQFLAGS_VALIDHEADER | RFLR_IRQFLAGS_TXDONE | RFLR_IRQFLAGS_CADDONE | - RFLR_IRQFLAGS_FHSSCHANGEDCHANNEL | + //RFLR_IRQFLAGS_FHSSCHANGEDCHANNEL | RFLR_IRQFLAGS_CADDETECTED ); + + // DIO0=RxDone + Write( REG_DIOMAPPING1, ( Read( REG_DIOMAPPING1 ) & RFLR_DIOMAPPING1_DIO0_MASK ) | RFLR_DIOMAPPING1_DIO0_00 ); + // DIO2=FhssChangeChannel + Write( REG_DIOMAPPING1, ( Read( REG_DIOMAPPING1 ) & RFLR_DIOMAPPING1_DIO2_MASK ) | RFLR_DIOMAPPING1_DIO2_00 ); + } + else + { + Write( REG_LR_IRQFLAGSMASK, //RFLR_IRQFLAGS_RXTIMEOUT | + //RFLR_IRQFLAGS_RXDONE | + //RFLR_IRQFLAGS_PAYLOADCRCERROR | + RFLR_IRQFLAGS_VALIDHEADER | + RFLR_IRQFLAGS_TXDONE | + RFLR_IRQFLAGS_CADDONE | + //RFLR_IRQFLAGS_FHSSCHANGEDCHANNEL | + RFLR_IRQFLAGS_CADDETECTED ); + + // DIO0=RxDone + Write( REG_DIOMAPPING1, ( Read( REG_DIOMAPPING1 ) & RFLR_DIOMAPPING1_DIO0_MASK ) | RFLR_DIOMAPPING1_DIO0_00 ); + } - // DIO0=RxDone - Write( REG_DIOMAPPING1, ( Read( REG_DIOMAPPING1 ) & RFLR_DIOMAPPING1_DIO0_MASK ) | RFLR_DIOMAPPING1_DIO0_00 ); Write( REG_LR_FIFORXBASEADDR, 0 ); Write( REG_LR_FIFOADDRPTR, 0 ); } @@ -793,7 +831,26 @@ break; case MODEM_LORA: { - Write( REG_LR_IRQFLAGSMASK, RFLR_IRQFLAGS_RXTIMEOUT | + + if( this->settings.LoRa.FreqHopOn == true ) + { + Write( REG_LR_IRQFLAGSMASK, RFLR_IRQFLAGS_RXTIMEOUT | + RFLR_IRQFLAGS_RXDONE | + RFLR_IRQFLAGS_PAYLOADCRCERROR | + RFLR_IRQFLAGS_VALIDHEADER | + //RFLR_IRQFLAGS_TXDONE | + RFLR_IRQFLAGS_CADDONE | + //RFLR_IRQFLAGS_FHSSCHANGEDCHANNEL | + RFLR_IRQFLAGS_CADDETECTED ); + + // DIO0=TxDone + Write( REG_DIOMAPPING1, ( Read( REG_DIOMAPPING1 ) & RFLR_DIOMAPPING1_DIO0_MASK ) | RFLR_DIOMAPPING1_DIO0_00 ); + // DIO2=FhssChangeChannel + Write( REG_DIOMAPPING1, ( Read( REG_DIOMAPPING1 ) & RFLR_DIOMAPPING1_DIO2_MASK ) | RFLR_DIOMAPPING1_DIO2_00 ); + } + else + { + Write( REG_LR_IRQFLAGSMASK, RFLR_IRQFLAGS_RXTIMEOUT | RFLR_IRQFLAGS_RXDONE | RFLR_IRQFLAGS_PAYLOADCRCERROR | RFLR_IRQFLAGS_VALIDHEADER | @@ -801,9 +858,10 @@ RFLR_IRQFLAGS_CADDONE | RFLR_IRQFLAGS_FHSSCHANGEDCHANNEL | RFLR_IRQFLAGS_CADDETECTED ); - - // DIO0=TxDone - Write( REG_DIOMAPPING1, ( Read( REG_DIOMAPPING1 ) & RFLR_DIOMAPPING1_DIO0_MASK ) | RFLR_DIOMAPPING1_DIO0_01 ); + + // DIO0=TxDone + Write( REG_DIOMAPPING1, ( Read( REG_DIOMAPPING1 ) & RFLR_DIOMAPPING1_DIO0_MASK ) | RFLR_DIOMAPPING1_DIO0_01 ); + } } break; } @@ -1234,6 +1292,16 @@ } break; case MODEM_LORA: + if( this->settings.LoRa.FreqHopOn == true ) + { + // Clear Irq + Write( REG_LR_IRQFLAGS, RFLR_IRQFLAGS_FHSSCHANGEDCHANNEL ); + + if( ( fhssChangeChannel != NULL ) ) + { + fhssChangeChannel( ( Read( REG_LR_HOPCHANNEL ) & RFLR_HOPCHANNEL_CHANNEL_MASK ) ); + } + } break; default: break; @@ -1245,6 +1313,16 @@ case MODEM_FSK: break; case MODEM_LORA: + if( this->settings.LoRa.FreqHopOn == true ) + { + // Clear Irq + Write( REG_LR_IRQFLAGS, RFLR_IRQFLAGS_FHSSCHANGEDCHANNEL ); + + if( ( fhssChangeChannel != NULL ) ) + { + fhssChangeChannel( ( Read( REG_LR_HOPCHANNEL ) & RFLR_HOPCHANNEL_CHANNEL_MASK ) ); + } + } break; default: break;
--- a/sx1276/sx1276.h Thu Aug 21 11:58:28 2014 +0000 +++ b/sx1276/sx1276.h Thu Sep 04 14:03:20 2014 +0000 @@ -105,7 +105,8 @@ void RxChainCalibration( void ); public: - SX1276( void ( *txDone )( ), void ( *txTimeout ) ( ), void ( *rxDone ) ( uint8_t *payload, uint16_t size, int8_t rssi, int8_t snr ), void ( *rxTimeout ) ( ), void ( *rxError ) ( ), + SX1276( void ( *txDone )( ), void ( *txTimeout ) ( ), void ( *rxDone ) ( uint8_t *payload, uint16_t size, int8_t rssi, int8_t snr ), + void ( *rxTimeout ) ( ), void ( *rxError ) ( ), void ( *fhssChangeChannel ) ( uint8_t channelIndex ), 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, int8_t rssi, int8_t snr ), void ( *rxTimeout ) ( ), void ( *rxError ) ( ) ); @@ -177,6 +178,8 @@ * LoRa: timeout in symbols * @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] iqInverted Inverts IQ signals ( LoRa only ) * FSK : N/A ( set to 0 ) * LoRa: [0: not inverted, 1: inverted] @@ -187,7 +190,8 @@ uint32_t datarate, uint8_t coderate, uint32_t bandwidthAfc, uint16_t preambleLen, uint16_t symbTimeout, bool fixLen, - bool crcOn, bool iqInverted, bool rxContinuous ); + bool crcOn, bool FreqHopOn, uint8_t HopPeriod, + bool iqInverted, bool rxContinuous ); /*! * @brief Sets the transmission parameters @@ -211,6 +215,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] iqInverted Inverts IQ signals ( LoRa only ) * FSK : N/A ( set to 0 ) * LoRa: [0: not inverted, 1: inverted] @@ -219,8 +225,8 @@ 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 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