Skip to content

Commit

Permalink
Fix RFMxx deadlock and minor optimization (#1099)
Browse files Browse the repository at this point in the history
  • Loading branch information
tekka007 authored and henrikekblad committed May 1, 2018
1 parent 1c5853c commit 3c07390
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
8 changes: 3 additions & 5 deletions drivers/RFM69/new/RFM69_new.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,6 @@ LOCAL bool RFM69_initialise(const uint32_t frequencyHz)
RFM69_DEBUG(PSTR("!RFM69:INIT:SANCHK FAIL\n"));
return false;
}
// clear FIFO and flags
RFM69_clearFIFO();
// IRQ
RFM69_irq = false;
hwPinMode(MY_RFM69_IRQ_PIN, INPUT);
Expand All @@ -235,7 +233,7 @@ LOCAL bool RFM69_initialise(const uint32_t frequencyHz)

LOCAL void RFM69_clearFIFO(void)
{
(void)RFM69_writeReg(RFM69_REG_IRQFLAGS2, 0x10u);
(void)RFM69_writeReg(RFM69_REG_IRQFLAGS2, RFM69_IRQFLAGS2_FIFOOVERRUN);
}
// IRQ handler: PayloadReady (RX) & PacketSent (TX) mapped to DI0
LOCAL void RFM69_interruptHandler(void)
Expand Down Expand Up @@ -621,7 +619,7 @@ LOCAL bool RFM69_sendWithRetry(const uint8_t recipient, const void *buffer,
}
// radio is in RX
const uint32_t enterMS = hwMillis();
while (hwMillis() - enterMS < retryWaitTimeMS) {
while (hwMillis() - enterMS < retryWaitTimeMS && !RFM69.dataReceived) {
RFM69_handler();
if (RFM69.ackReceived) {
// radio is in stdby
Expand Down Expand Up @@ -719,7 +717,7 @@ LOCAL void RFM69_setConfiguration(void)
{ RFM69_REG_AFCBW, rfm69_modem_config[5] }, // same as rxbw, experimental, based on datasheet
//{ RFM69_REG_DIOMAPPING1, RFM69_DIOMAPPING1_DIO0_01 },
{ RFM69_REG_DIOMAPPING2, RFM69_DIOMAPPING2_CLKOUT_OFF },
{ RFM69_REG_IRQFLAGS2, RFM69_IRQFLAGS2_FIFOOVERRUN },
{ RFM69_REG_IRQFLAGS2, RFM69_IRQFLAGS2_FIFOOVERRUN }, // clear FIFO and flags
{ RFM69_REG_RSSITHRESH, RFM69_RSSITHRESH_VALUE },
{ RFM69_REG_PREAMBLEMSB, RFM69_PREAMBLESIZE_MSB_VALUE },
{ RFM69_REG_PREAMBLELSB, RFM69_PREAMBLESIZE_LSB_VALUE },
Expand Down
2 changes: 1 addition & 1 deletion drivers/RFM95/RFM95.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ LOCAL bool RFM95_sendWithRetry(const uint8_t recipient, const void *buffer,
return true;
}
const uint32_t enterMS = hwMillis();
while (hwMillis() - enterMS < retryWaitTime) {
while (hwMillis() - enterMS < retryWaitTime && !RFM95.dataReceived) {
RFM95_handler();
if (RFM95.ackReceived) {
const uint8_t sender = RFM95.currentPacket.header.sender;
Expand Down

0 comments on commit 3c07390

Please sign in to comment.