Skip to content

Commit 3c07390

Browse files
tekka007henrikekblad
authored andcommitted
Fix RFMxx deadlock and minor optimization (#1099)
1 parent 1c5853c commit 3c07390

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

drivers/RFM69/new/RFM69_new.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,6 @@ LOCAL bool RFM69_initialise(const uint32_t frequencyHz)
224224
RFM69_DEBUG(PSTR("!RFM69:INIT:SANCHK FAIL\n"));
225225
return false;
226226
}
227-
// clear FIFO and flags
228-
RFM69_clearFIFO();
229227
// IRQ
230228
RFM69_irq = false;
231229
hwPinMode(MY_RFM69_IRQ_PIN, INPUT);
@@ -235,7 +233,7 @@ LOCAL bool RFM69_initialise(const uint32_t frequencyHz)
235233

236234
LOCAL void RFM69_clearFIFO(void)
237235
{
238-
(void)RFM69_writeReg(RFM69_REG_IRQFLAGS2, 0x10u);
236+
(void)RFM69_writeReg(RFM69_REG_IRQFLAGS2, RFM69_IRQFLAGS2_FIFOOVERRUN);
239237
}
240238
// IRQ handler: PayloadReady (RX) & PacketSent (TX) mapped to DI0
241239
LOCAL void RFM69_interruptHandler(void)
@@ -621,7 +619,7 @@ LOCAL bool RFM69_sendWithRetry(const uint8_t recipient, const void *buffer,
621619
}
622620
// radio is in RX
623621
const uint32_t enterMS = hwMillis();
624-
while (hwMillis() - enterMS < retryWaitTimeMS) {
622+
while (hwMillis() - enterMS < retryWaitTimeMS && !RFM69.dataReceived) {
625623
RFM69_handler();
626624
if (RFM69.ackReceived) {
627625
// radio is in stdby
@@ -719,7 +717,7 @@ LOCAL void RFM69_setConfiguration(void)
719717
{ RFM69_REG_AFCBW, rfm69_modem_config[5] }, // same as rxbw, experimental, based on datasheet
720718
//{ RFM69_REG_DIOMAPPING1, RFM69_DIOMAPPING1_DIO0_01 },
721719
{ RFM69_REG_DIOMAPPING2, RFM69_DIOMAPPING2_CLKOUT_OFF },
722-
{ RFM69_REG_IRQFLAGS2, RFM69_IRQFLAGS2_FIFOOVERRUN },
720+
{ RFM69_REG_IRQFLAGS2, RFM69_IRQFLAGS2_FIFOOVERRUN }, // clear FIFO and flags
723721
{ RFM69_REG_RSSITHRESH, RFM69_RSSITHRESH_VALUE },
724722
{ RFM69_REG_PREAMBLEMSB, RFM69_PREAMBLESIZE_MSB_VALUE },
725723
{ RFM69_REG_PREAMBLELSB, RFM69_PREAMBLESIZE_LSB_VALUE },

drivers/RFM95/RFM95.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ LOCAL bool RFM95_sendWithRetry(const uint8_t recipient, const void *buffer,
550550
return true;
551551
}
552552
const uint32_t enterMS = hwMillis();
553-
while (hwMillis() - enterMS < retryWaitTime) {
553+
while (hwMillis() - enterMS < retryWaitTime && !RFM95.dataReceived) {
554554
RFM95_handler();
555555
if (RFM95.ackReceived) {
556556
const uint8_t sender = RFM95.currentPacket.header.sender;

0 commit comments

Comments
 (0)