Skip to content

Commit dc7428c

Browse files
Sx126x: Print warnings before disabling IRQs
On some Arduino cores, printing with IRQs disabled is problematic (see e.g. arduino/ArduinoCore-samd#472). In general, disabling interrupts for shorter amounts of time is a good idea anyway.
1 parent 5011e02 commit dc7428c

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

lmic/radio-sx126x.c

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -656,6 +656,12 @@ static void rxfsk (bool rxcontinuous) {
656656
// enable IRQs in HAL
657657
hal_irqmask_set(HAL_IRQMASK_DIO1);
658658

659+
ostime_t now = os_getTime();
660+
if (!rxcontinuous && LMIC.rxtime - now < 0) {
661+
debug_printf("WARNING: rxtime is %ld ticks in the past! (ramp-up time %ld ms / %ld ticks)\r\n",
662+
now - LMIC.rxtime, osticks2ms(now - t0), now - t0);
663+
}
664+
659665
// now receive (lock interrupts only for final fine tuned rx timing...)
660666
hal_disableIRQs();
661667
if (rxcontinuous) { // continous rx
@@ -667,11 +673,6 @@ static void rxfsk (bool rxcontinuous) {
667673
} else { // single rx
668674
BACKTRACE();
669675
// busy wait until exact rx time
670-
ostime_t now = os_getTime();
671-
if (LMIC.rxtime - now < 0) {
672-
debug_printf("WARNING: rxtime is %ld ticks in the past! (ramp-up time %ld ms / %ld ticks)\r\n",
673-
now - LMIC.rxtime, osticks2ms(now - t0), now - t0);
674-
}
675676
hal_waitUntil(LMIC.rxtime);
676677
// enable antenna switch for RX (and account power consumption)
677678
hal_pin_rxtx(0);
@@ -705,6 +706,14 @@ static void rxlora (bool rxcontinuous) {
705706
// enable IRQs in HAL
706707
hal_irqmask_set(HAL_IRQMASK_DIO1);
707708

709+
ostime_t now = os_getTime();
710+
if (!rxcontinuous && LMIC.rxtime - now < 0) {
711+
// Print before disabling IRQs, to work around deadlock on some
712+
// Arduino cores that doe not really support printing without IRQs
713+
debug_printf("WARNING: rxtime is %ld ticks in the past! (ramp-up time %ld ms / %ld ticks)\r\n",
714+
now - LMIC.rxtime, osticks2ms(now - t0), now - t0);
715+
}
716+
708717
// now receive (lock interrupts only for final fine tuned rx timing...)
709718
hal_disableIRQs();
710719
if (rxcontinuous) { // continous rx
@@ -716,11 +725,6 @@ static void rxlora (bool rxcontinuous) {
716725
} else { // single rx
717726
BACKTRACE();
718727
// busy wait until exact rx time
719-
ostime_t now = os_getTime();
720-
if (LMIC.rxtime - now < 0) {
721-
debug_printf("WARNING: rxtime is %ld ticks in the past! (ramp-up time %ld ms / %ld ticks)\r\n",
722-
now - LMIC.rxtime, osticks2ms(now - t0), now - t0);
723-
}
724728
hal_waitUntil(LMIC.rxtime);
725729
// enable antenna switch for RX (and account power consumption)
726730
hal_pin_rxtx(0);

0 commit comments

Comments
 (0)