Skip to content

TX timeout issue fix #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 28 additions & 65 deletions SX1272/SX1272_LoRaRadio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -833,7 +833,7 @@ void SX1272_LoRaRadio::transmit(uint32_t timeout)
RFLR_DIOMAPPING1_DIO0_MASK &
RFLR_DIOMAPPING1_DIO2_MASK) |
RFLR_DIOMAPPING1_DIO0_01 |
RFLR_DIOMAPPING1_DIO2_00);
RFLR_DIOMAPPING1_DIO2_01);
} else {
write_to_register(REG_LR_IRQFLAGSMASK,
RFLR_IRQFLAGS_RXTIMEOUT |
Expand All @@ -854,7 +854,8 @@ void SX1272_LoRaRadio::transmit(uint32_t timeout)
}

_rf_settings.state = RF_TX_RUNNING;
tx_timeout_timer.attach_us(callback(this, &SX1272_LoRaRadio::timeout_irq_isr), timeout*1e3);
tx_timeout_timer.attach_us(callback(this, &SX1272_LoRaRadio::timeout_irq_isr),
timeout * 1000);
set_operation_mode(RF_OPMODE_TRANSMITTER);
}

Expand Down Expand Up @@ -2082,69 +2083,31 @@ void SX1272_LoRaRadio::handle_dio5_irq()
}
}


void SX1272_LoRaRadio::handle_timeout_irq()
{
switch(_rf_settings.state )
{
case RF_RX_RUNNING:
if( _rf_settings.modem == MODEM_FSK ) {
_rf_settings.fsk_packet_handler.preamble_detected = 0;
_rf_settings.fsk_packet_handler.sync_word_detected = 0;
_rf_settings.fsk_packet_handler.nb_bytes = 0;
_rf_settings.fsk_packet_handler.size = 0;

// Clear Irqs
write_to_register(REG_IRQFLAGS1, RF_IRQFLAGS1_RSSI |
RF_IRQFLAGS1_PREAMBLEDETECT |
RF_IRQFLAGS1_SYNCADDRESSMATCH);
write_to_register( REG_IRQFLAGS2, RF_IRQFLAGS2_FIFOOVERRUN);

if( _rf_settings.fsk.rx_continuous == true )
{
// Continuous mode restart Rx chain
write_to_register( REG_RXCONFIG, read_register(REG_RXCONFIG) |
RF_RXCONFIG_RESTARTRXWITHOUTPLLLOCK);
}
else
{
_rf_settings.state = RF_IDLE;
}
}

if((_radio_events != NULL) && (_radio_events->rx_timeout)) {
_radio_events->rx_timeout();
}

break;

case RF_TX_RUNNING:
// Tx timeout shouldn't happen.
// But it has been observed that when it happens it is a result of a
// corrupted SPI transfer
// The workaround is to put the radio in a known state.
// Thus, we re-initialize it.

// Reset the radio
radio_reset( );

// Initialize radio default values
set_operation_mode( RF_OPMODE_SLEEP );

setup_registers();

set_modem(MODEM_FSK);

// Restore previous network type setting.
set_public_network(_rf_settings.lora.public_network);

_rf_settings.state = RF_IDLE;
if( ( _radio_events != NULL ) && ( _radio_events->tx_timeout ) )
{
_radio_events->tx_timeout( );
}
break;
default:
break;
}
tx_timeout_timer.detach();

if (_rf_settings.state == RF_TX_RUNNING) {
// Tx timeout shouldn't happen.
// But it has been observed that when it happens it is a result of a
// corrupted SPI transfer
// The workaround is to put the radio in a known state.
// Thus, we re-initialize it.

// Initialize radio default values
set_operation_mode(RF_OPMODE_SLEEP);

setup_registers();

set_modem(MODEM_FSK);

// Restore previous network type setting.
set_public_network(_rf_settings.lora.public_network);

_rf_settings.state = RF_IDLE;

if ((_radio_events != NULL) && (_radio_events->tx_timeout)) {
_radio_events->tx_timeout();
}
}
}
12 changes: 6 additions & 6 deletions SX1276/SX1276_LoRaRadio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1562,7 +1562,7 @@ void SX1276_LoRaRadio::transmit(uint32_t timeout)
RFLR_DIOMAPPING1_DIO0_MASK &
RFLR_DIOMAPPING1_DIO2_MASK) |
RFLR_DIOMAPPING1_DIO0_01 |
RFLR_DIOMAPPING1_DIO2_00);
RFLR_DIOMAPPING1_DIO2_01);
} else {
write_to_register(REG_LR_IRQFLAGSMASK,
RFLR_IRQFLAGS_RXTIMEOUT |
Expand All @@ -1583,8 +1583,10 @@ void SX1276_LoRaRadio::transmit(uint32_t timeout)
}

_rf_settings.state = RF_TX_RUNNING;

tx_timeout_timer.attach_us(callback(this,
&SX1276_LoRaRadio::timeout_irq_isr), timeout * 1000);

set_operation_mode(RF_OPMODE_TRANSMITTER);
}

Expand Down Expand Up @@ -2242,19 +2244,17 @@ void SX1276_LoRaRadio::handle_dio5_irq()
}
}


void SX1276_LoRaRadio::handle_timeout_irq()
{
tx_timeout_timer.detach();

if (_rf_settings.state == RF_TX_RUNNING) {
// Tx timeout shouldn't happen.
// But it has been observed that when it happens it is a result of a
// corrupted SPI transfer
// The workaround is to put the radio in a known state.
// Thus, we re-initialize it.

// Reset the radio
radio_reset();

// Initialize radio default values
set_operation_mode(RF_OPMODE_SLEEP);

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

_rf_settings.state = RF_IDLE;

if ((_radio_events != NULL) && (_radio_events->tx_timeout)) {
_radio_events->tx_timeout();
}

}
}
// EOF