@@ -410,11 +410,11 @@ LOCAL int16_t RF24_getSendingRSSI(void)
410
410
LOCAL void RF24_irqHandler (void )
411
411
{
412
412
if (RF24_receiveCallback) {
413
+ #if defined(MY_GATEWAY_SERIAL) && !defined(__linux__)
413
414
// Will stay for a while (several 100us) in this interrupt handler. Any interrupts from serial
414
415
// rx coming in during our stay will not be handled and will cause characters to be lost.
415
416
// As a workaround we re-enable interrupts to allow nested processing of other interrupts.
416
417
// Our own handler is disconnected to prevent recursive calling of this handler.
417
- #if defined(MY_GATEWAY_SERIAL) && !defined(__linux__)
418
418
detachInterrupt (digitalPinToInterrupt (MY_RF24_IRQ_PIN));
419
419
interrupts ();
420
420
#endif
@@ -423,13 +423,28 @@ LOCAL void RF24_irqHandler(void)
423
423
// 1.Read payload, 2.Clear RX_DR IRQ, 3.Read FIFO_status, 4.Repeat when more data available.
424
424
// Datasheet (ch. 8.5) states, that the nRF de-asserts IRQ after reading STATUS.
425
425
426
+ #if defined(__linux__)
427
+ // Start checking if RX-FIFO is not empty, as we might end up here from an interrupt
428
+ // for a message we've already read.
429
+ if (RF24_isDataAvailable ()) {
430
+ do {
431
+ RF24_receiveCallback (); // Must call RF24_readMessage(), which will clear RX_DR IRQ !
432
+ } while (RF24_isDataAvailable ());
433
+ } else {
434
+ // Occasionally interrupt is triggered but no data is available - clear RX interrupt only
435
+ RF24_setStatus (_BV (RF24_RX_DR));
436
+ logNotice (" RF24: Recovered from a bad interrupt trigger.\n " );
437
+ }
438
+ #else
426
439
// Start checking if RX-FIFO is not empty, as we might end up here from an interrupt
427
440
// for a message we've already read.
428
441
while (RF24_isDataAvailable ()) {
429
442
RF24_receiveCallback (); // Must call RF24_readMessage(), which will clear RX_DR IRQ !
430
443
}
431
- // Restore our interrupt handler.
444
+ #endif
445
+
432
446
#if defined(MY_GATEWAY_SERIAL) && !defined(__linux__)
447
+ // Restore our interrupt handler.
433
448
noInterrupts ();
434
449
attachInterrupt (digitalPinToInterrupt (MY_RF24_IRQ_PIN), RF24_irqHandler, FALLING);
435
450
#endif
0 commit comments