Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: SX127x sx12xx_hal TSL2561
Diff: radio/sx1272/sx1272.cpp
- Revision:
- 20:42839629a5dc
- Parent:
- 18:9ac71c0eb70d
- Child:
- 21:500ff43d8424
--- a/radio/sx1272/sx1272.cpp Wed Aug 02 18:47:08 2017 +0000 +++ b/radio/sx1272/sx1272.cpp Fri Aug 04 13:23:38 2017 -0700 @@ -17,6 +17,11 @@ extern LowPowerTimer lp_timer; // from LoRaMac +static volatile struct { + uint8_t dio0 : 1; + uint8_t dio1 : 1; +} flags; + const FskBandwidth_t SX1272::FskBandwidths[] = { { 2600 , 0x17 }, @@ -848,7 +853,7 @@ void SX1272::SetOpMode( uint8_t opMode ) { - if ((opMode == RF_OPMODE_RECEIVER || opMode == RFLR_OPMODE_RECEIVER_SINGLE) && expecting_beacon) + if ((opMode == RF_OPMODE_RECEIVER || opMode == RFLR_OPMODE_RECEIVER_SINGLE) /*&& expecting_beacon*/) rx_debug_pin = 1; else rx_debug_pin = 0; @@ -1006,10 +1011,9 @@ } } -void SX1272::OnDio0Irq( void ) +void SX1272::dio0_bh( void ) { volatile uint8_t irqFlags = 0; - unsigned int now_us = lp_timer.read_us(); switch( this->settings.State ) { @@ -1094,7 +1098,7 @@ if( ( this->RadioEvents != NULL ) && ( this->RadioEvents->RxDone != NULL ) ) { - this->RadioEvents->RxDone(now_us, rxtxBuffer, this->settings.FskPacketHandler.Size, this->settings.FskPacketHandler.RssiValue, 0 ); + this->RadioEvents->RxDone(dio0_us, rxtxBuffer, this->settings.FskPacketHandler.Size, this->settings.FskPacketHandler.RssiValue, 0 ); } this->settings.FskPacketHandler.PreambleDetected = false; this->settings.FskPacketHandler.SyncWordDetected = false; @@ -1105,10 +1109,11 @@ { int8_t snr = 0; + irqFlags = Read( REG_LR_IRQFLAGS ); // Clear Irq Write( REG_LR_IRQFLAGS, RFLR_IRQFLAGS_RXDONE ); - irqFlags = Read( REG_LR_IRQFLAGS ); + //irqFlags = Read( REG_LR_IRQFLAGS ); if( ( irqFlags & RFLR_IRQFLAGS_PAYLOADCRCERROR_MASK ) == RFLR_IRQFLAGS_PAYLOADCRCERROR ) { // Clear Irq @@ -1162,7 +1167,7 @@ if( ( this->RadioEvents != NULL ) && ( this->RadioEvents->RxDone != NULL ) ) { - this->RadioEvents->RxDone(now_us, rxtxBuffer, this->settings.LoRaPacketHandler.Size, this->settings.LoRaPacketHandler.RssiValue, this->settings.LoRaPacketHandler.SnrValue ); + this->RadioEvents->RxDone(dio0_us, rxtxBuffer, this->settings.LoRaPacketHandler.Size, this->settings.LoRaPacketHandler.RssiValue, this->settings.LoRaPacketHandler.SnrValue ); } } break; @@ -1184,7 +1189,7 @@ this->settings.State = RF_IDLE; if( ( this->RadioEvents != NULL ) && ( this->RadioEvents->TxDone != NULL ) ) { - this->RadioEvents->TxDone( now_us ); + this->RadioEvents->TxDone( dio0_us ); } break; } @@ -1194,7 +1199,14 @@ } } -void SX1272::OnDio1Irq( void ) +void SX1272::OnDio0Irq( void ) +{ + dio0_us = lp_timer.read_us(); + + flags.dio0 = 1; +} + +void SX1272::dio1_bh( void ) { switch( this->settings.State ) { @@ -1271,6 +1283,11 @@ } } +void SX1272::OnDio1Irq( void ) +{ + flags.dio1 = 1; +} + void SX1272::OnDio2Irq( void ) { switch( this->settings.State ) @@ -1403,4 +1420,17 @@ break; } } + +void SX1272::BottomHalf() +{ + if (flags.dio0) { + dio0_bh(); + flags.dio0 = 0; + } + + if (flags.dio1) { + dio1_bh(); + flags.dio1 = 0; + } +} #endif /* ENABLE_SX1272 */