Skip to content

Commit

Permalink
Sx126x: Print warning before disabling IRQs
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
matthijskooijman committed Feb 12, 2020
1 parent 0f4352d commit cd4bb62
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions lmic/radio-sx126x.c
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,12 @@ static void rxfsk (bool rxcontinuous) {
// enable IRQs in HAL
hal_irqmask_set(HAL_IRQMASK_DIO1);

ostime_t now = os_getTime();
if (!rxcontinuous && LMIC.rxtime - now < 0) {
debug_printf("WARNING: rxtime is %d ticks in the past! (ramp-up time %d ms / %d ticks)\r\n",
now - LMIC.rxtime, osticks2ms(now - t0), now - t0);
}

// now receive (lock interrupts only for final fine tuned rx timing...)
hal_disableIRQs();
if (rxcontinuous) { // continous rx
Expand All @@ -650,11 +656,6 @@ static void rxfsk (bool rxcontinuous) {
} else { // single rx
BACKTRACE();
// busy wait until exact rx time
ostime_t now = os_getTime();
if (LMIC.rxtime - now < 0) {
debug_printf("WARNING: rxtime is %d ticks in the past! (ramp-up time %d ms / %d ticks)\r\n",
now - LMIC.rxtime, osticks2ms(now - t0), now - t0);
}
hal_waitUntil(LMIC.rxtime);
// enable antenna switch for RX (and account power consumption)
hal_pin_rxtx(0);
Expand Down Expand Up @@ -688,6 +689,14 @@ static void rxlora (bool rxcontinuous) {
// enable IRQs in HAL
hal_irqmask_set(HAL_IRQMASK_DIO1);

ostime_t now = os_getTime();
if (!rxcontinuous && LMIC.rxtime - now < 0) {
// Print before disabling IRQs, to work around deadlock on some
// Arduino cores that doe not really support printing without IRQs
debug_printf("WARNING: rxtime is %d ticks in the past! (ramp-up time %d ms / %d ticks)\r\n",
now - LMIC.rxtime, osticks2ms(now - t0), now - t0);
}

// now receive (lock interrupts only for final fine tuned rx timing...)
hal_disableIRQs();
if (rxcontinuous) { // continous rx
Expand All @@ -699,11 +708,6 @@ static void rxlora (bool rxcontinuous) {
} else { // single rx
BACKTRACE();
// busy wait until exact rx time
ostime_t now = os_getTime();
if (LMIC.rxtime - now < 0) {
debug_printf("WARNING: rxtime is %d ticks in the past! (ramp-up time %d ms / %d ticks)\r\n",
now - LMIC.rxtime, osticks2ms(now - t0), now - t0);
}
hal_waitUntil(LMIC.rxtime);
// enable antenna switch for RX (and account power consumption)
hal_pin_rxtx(0);
Expand Down

0 comments on commit cd4bb62

Please sign in to comment.