Skip to content

Commit

Permalink
Merge pull request #528 from mcci-catena/issue523
Browse files Browse the repository at this point in the history
Fix #523: workaround interrupt-disable issue in radio driver
  • Loading branch information
terrillmoore authored Feb 5, 2020
2 parents 98a1b35 + adb15b3 commit 27eb8f6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
15 changes: 15 additions & 0 deletions src/hal/hal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,10 +268,25 @@ u4_t hal_waitUntil (u4_t time) {
delta = delta_time(time);
}

// The radio driver runs with interrupt disabled, and this can
// mess up timing APIs on some platforms. If we know the BSP feature
// set, we can decide whether to use delta_time() [more exact,
// but not always possible with interrupts off], or fall back to
// delay_microseconds() [less exact, but more universal]

#if defined(_mcci_arduino_version)
// unluckily, delayMicroseconds() isn't very accurate.
// but delta_time() works with interrupts disabled.
// so spin using delta_time().
while (delta_time(time) > 0)
/* loop */;
#else // ! defined(_mcci_arduino_version)
// on other BSPs, we need to stick with the older way,
// until we fix the radio driver to run with interrupts
// enabled.
if (delta > 0)
delayMicroseconds(delta * US_PER_OSTICK);
#endif // ! defined(_mcci_arduino_version)

// we aren't "late". Callers are interested in gross delays, not
// necessarily delays due to poor timekeeping here.
Expand Down
2 changes: 1 addition & 1 deletion src/lmic/lmic.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ extern "C"{
#define ARDUINO_LMIC_VERSION_CALC(major, minor, patch, local) \
((((major)*UINT32_C(1)) << 24) | (((minor)*UINT32_C(1)) << 16) | (((patch)*UINT32_C(1)) << 8) | (((local)*UINT32_C(1)) << 0))

#define ARDUINO_LMIC_VERSION ARDUINO_LMIC_VERSION_CALC(3, 0, 99, 10) /* v3.0.99.10 */
#define ARDUINO_LMIC_VERSION ARDUINO_LMIC_VERSION_CALC(3, 0, 99, 20) /* v3.0.99.20 */

#define ARDUINO_LMIC_VERSION_GET_MAJOR(v) \
((((v)*UINT32_C(1)) >> 24u) & 0xFFu)
Expand Down

0 comments on commit 27eb8f6

Please sign in to comment.