Skip to content

Commit 5532d9d

Browse files
author
Hasnain Virk
committed
TX timeout issue fix
In case of catastrophic bus failure at radio end, we shouldn't reset the chip as it will cause the chip to hang and then burst out interrupts in a fury resulting in an ISR queue overflow. rather than that we gracefully accept the failure and set the radio to sleep and set the state to idle. In addition to that we inform the upper layers about the failure. A little touch up to the FHSS case, was actually a leftover from the previous PR. We don't use FHSS mode, that was why we didn't catch in the testing.
1 parent 1a5f2fc commit 5532d9d

File tree

2 files changed

+34
-71
lines changed

2 files changed

+34
-71
lines changed

SX1272/SX1272_LoRaRadio.cpp

Lines changed: 28 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -833,7 +833,7 @@ void SX1272_LoRaRadio::transmit(uint32_t timeout)
833833
RFLR_DIOMAPPING1_DIO0_MASK &
834834
RFLR_DIOMAPPING1_DIO2_MASK) |
835835
RFLR_DIOMAPPING1_DIO0_01 |
836-
RFLR_DIOMAPPING1_DIO2_00);
836+
RFLR_DIOMAPPING1_DIO2_01);
837837
} else {
838838
write_to_register(REG_LR_IRQFLAGSMASK,
839839
RFLR_IRQFLAGS_RXTIMEOUT |
@@ -854,7 +854,8 @@ void SX1272_LoRaRadio::transmit(uint32_t timeout)
854854
}
855855

856856
_rf_settings.state = RF_TX_RUNNING;
857-
tx_timeout_timer.attach_us(callback(this, &SX1272_LoRaRadio::timeout_irq_isr), timeout*1e3);
857+
tx_timeout_timer.attach_us(callback(this, &SX1272_LoRaRadio::timeout_irq_isr),
858+
timeout * 1000);
858859
set_operation_mode(RF_OPMODE_TRANSMITTER);
859860
}
860861

@@ -2082,69 +2083,31 @@ void SX1272_LoRaRadio::handle_dio5_irq()
20822083
}
20832084
}
20842085

2085-
20862086
void SX1272_LoRaRadio::handle_timeout_irq()
20872087
{
2088-
switch(_rf_settings.state )
2089-
{
2090-
case RF_RX_RUNNING:
2091-
if( _rf_settings.modem == MODEM_FSK ) {
2092-
_rf_settings.fsk_packet_handler.preamble_detected = 0;
2093-
_rf_settings.fsk_packet_handler.sync_word_detected = 0;
2094-
_rf_settings.fsk_packet_handler.nb_bytes = 0;
2095-
_rf_settings.fsk_packet_handler.size = 0;
2096-
2097-
// Clear Irqs
2098-
write_to_register(REG_IRQFLAGS1, RF_IRQFLAGS1_RSSI |
2099-
RF_IRQFLAGS1_PREAMBLEDETECT |
2100-
RF_IRQFLAGS1_SYNCADDRESSMATCH);
2101-
write_to_register( REG_IRQFLAGS2, RF_IRQFLAGS2_FIFOOVERRUN);
2102-
2103-
if( _rf_settings.fsk.rx_continuous == true )
2104-
{
2105-
// Continuous mode restart Rx chain
2106-
write_to_register( REG_RXCONFIG, read_register(REG_RXCONFIG) |
2107-
RF_RXCONFIG_RESTARTRXWITHOUTPLLLOCK);
2108-
}
2109-
else
2110-
{
2111-
_rf_settings.state = RF_IDLE;
2112-
}
2113-
}
2114-
2115-
if((_radio_events != NULL) && (_radio_events->rx_timeout)) {
2116-
_radio_events->rx_timeout();
2117-
}
2118-
2119-
break;
2120-
2121-
case RF_TX_RUNNING:
2122-
// Tx timeout shouldn't happen.
2123-
// But it has been observed that when it happens it is a result of a
2124-
// corrupted SPI transfer
2125-
// The workaround is to put the radio in a known state.
2126-
// Thus, we re-initialize it.
2127-
2128-
// Reset the radio
2129-
radio_reset( );
2130-
2131-
// Initialize radio default values
2132-
set_operation_mode( RF_OPMODE_SLEEP );
2133-
2134-
setup_registers();
2135-
2136-
set_modem(MODEM_FSK);
2137-
2138-
// Restore previous network type setting.
2139-
set_public_network(_rf_settings.lora.public_network);
2140-
2141-
_rf_settings.state = RF_IDLE;
2142-
if( ( _radio_events != NULL ) && ( _radio_events->tx_timeout ) )
2143-
{
2144-
_radio_events->tx_timeout( );
2145-
}
2146-
break;
2147-
default:
2148-
break;
2149-
}
2088+
tx_timeout_timer.detach();
2089+
2090+
if (_rf_settings.state == RF_TX_RUNNING) {
2091+
// Tx timeout shouldn't happen.
2092+
// But it has been observed that when it happens it is a result of a
2093+
// corrupted SPI transfer
2094+
// The workaround is to put the radio in a known state.
2095+
// Thus, we re-initialize it.
2096+
2097+
// Initialize radio default values
2098+
set_operation_mode(RF_OPMODE_SLEEP);
2099+
2100+
setup_registers();
2101+
2102+
set_modem(MODEM_FSK);
2103+
2104+
// Restore previous network type setting.
2105+
set_public_network(_rf_settings.lora.public_network);
2106+
2107+
_rf_settings.state = RF_IDLE;
2108+
2109+
if ((_radio_events != NULL) && (_radio_events->tx_timeout)) {
2110+
_radio_events->tx_timeout();
2111+
}
2112+
}
21502113
}

SX1276/SX1276_LoRaRadio.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1562,7 +1562,7 @@ void SX1276_LoRaRadio::transmit(uint32_t timeout)
15621562
RFLR_DIOMAPPING1_DIO0_MASK &
15631563
RFLR_DIOMAPPING1_DIO2_MASK) |
15641564
RFLR_DIOMAPPING1_DIO0_01 |
1565-
RFLR_DIOMAPPING1_DIO2_00);
1565+
RFLR_DIOMAPPING1_DIO2_01);
15661566
} else {
15671567
write_to_register(REG_LR_IRQFLAGSMASK,
15681568
RFLR_IRQFLAGS_RXTIMEOUT |
@@ -1583,8 +1583,10 @@ void SX1276_LoRaRadio::transmit(uint32_t timeout)
15831583
}
15841584

15851585
_rf_settings.state = RF_TX_RUNNING;
1586+
15861587
tx_timeout_timer.attach_us(callback(this,
15871588
&SX1276_LoRaRadio::timeout_irq_isr), timeout * 1000);
1589+
15881590
set_operation_mode(RF_OPMODE_TRANSMITTER);
15891591
}
15901592

@@ -2242,19 +2244,17 @@ void SX1276_LoRaRadio::handle_dio5_irq()
22422244
}
22432245
}
22442246

2245-
22462247
void SX1276_LoRaRadio::handle_timeout_irq()
22472248
{
2249+
tx_timeout_timer.detach();
2250+
22482251
if (_rf_settings.state == RF_TX_RUNNING) {
22492252
// Tx timeout shouldn't happen.
22502253
// But it has been observed that when it happens it is a result of a
22512254
// corrupted SPI transfer
22522255
// The workaround is to put the radio in a known state.
22532256
// Thus, we re-initialize it.
22542257

2255-
// Reset the radio
2256-
radio_reset();
2257-
22582258
// Initialize radio default values
22592259
set_operation_mode(RF_OPMODE_SLEEP);
22602260

@@ -2266,10 +2266,10 @@ void SX1276_LoRaRadio::handle_timeout_irq()
22662266
set_public_network(_rf_settings.lora.public_network);
22672267

22682268
_rf_settings.state = RF_IDLE;
2269+
22692270
if ((_radio_events != NULL) && (_radio_events->tx_timeout)) {
22702271
_radio_events->tx_timeout();
22712272
}
2272-
22732273
}
22742274
}
22752275
// EOF

0 commit comments

Comments
 (0)