Skip to content

Commit a418bf3

Browse files
Sx126x: Print warning 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 caf678b commit a418bf3

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
@@ -639,6 +639,12 @@ static void rxfsk (bool rxcontinuous) {
639639
// enable IRQs in HAL
640640
hal_irqmask_set(HAL_IRQMASK_DIO1);
641641

642+
ostime_t now = os_getTime();
643+
if (!rxcontinuous && LMIC.rxtime - now < 0) {
644+
debug_printf("WARNING: rxtime is %d ticks in the past! (ramp-up time %d ms / %d ticks)\r\n",
645+
now - LMIC.rxtime, osticks2ms(now - t0), now - t0);
646+
}
647+
642648
// now receive (lock interrupts only for final fine tuned rx timing...)
643649
hal_disableIRQs();
644650
if (rxcontinuous) { // continous rx
@@ -650,11 +656,6 @@ static void rxfsk (bool rxcontinuous) {
650656
} else { // single rx
651657
BACKTRACE();
652658
// busy wait until exact rx time
653-
ostime_t now = os_getTime();
654-
if (LMIC.rxtime - now < 0) {
655-
debug_printf("WARNING: rxtime is %d ticks in the past! (ramp-up time %d ms / %d ticks)\r\n",
656-
now - LMIC.rxtime, osticks2ms(now - t0), now - t0);
657-
}
658659
hal_waitUntil(LMIC.rxtime);
659660
// enable antenna switch for RX (and account power consumption)
660661
hal_pin_rxtx(0);
@@ -688,6 +689,14 @@ static void rxlora (bool rxcontinuous) {
688689
// enable IRQs in HAL
689690
hal_irqmask_set(HAL_IRQMASK_DIO1);
690691

692+
ostime_t now = os_getTime();
693+
if (!rxcontinuous && LMIC.rxtime - now < 0) {
694+
// Print before disabling IRQs, to work around deadlock on some
695+
// Arduino cores that doe not really support printing without IRQs
696+
debug_printf("WARNING: rxtime is %d ticks in the past! (ramp-up time %d ms / %d ticks)\r\n",
697+
now - LMIC.rxtime, osticks2ms(now - t0), now - t0);
698+
}
699+
691700
// now receive (lock interrupts only for final fine tuned rx timing...)
692701
hal_disableIRQs();
693702
if (rxcontinuous) { // continous rx
@@ -699,11 +708,6 @@ static void rxlora (bool rxcontinuous) {
699708
} else { // single rx
700709
BACKTRACE();
701710
// busy wait until exact rx time
702-
ostime_t now = os_getTime();
703-
if (LMIC.rxtime - now < 0) {
704-
debug_printf("WARNING: rxtime is %d ticks in the past! (ramp-up time %d ms / %d ticks)\r\n",
705-
now - LMIC.rxtime, osticks2ms(now - t0), now - t0);
706-
}
707711
hal_waitUntil(LMIC.rxtime);
708712
// enable antenna switch for RX (and account power consumption)
709713
hal_pin_rxtx(0);

0 commit comments

Comments
 (0)