Skip to content

Commit 98be617

Browse files
authored
Merge pull request #531 from mcci-catena/issue529
Further hack for timing while interrupts are disabled
2 parents 27eb8f6 + 6af0b8f commit 98be617

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/hal/hal.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,15 @@ static s4_t delta_time(u4_t time) {
248248
return (s4_t)(time - hal_ticks());
249249
}
250250

251+
// deal with boards that are stressed by no-interrupt delays #529, etc.
252+
#if defined(ARDUINO_DISCO_L072CZ_LRWAN1)
253+
# define HAL_WAITUNTIL_DOWNCOUNT_MS 16 // on this board, 16 ms works better
254+
# define HAL_WAITUNTIL_DOWNCOUNT_THRESH ms2osticks(16) // as does this threashold.
255+
#else
256+
# define HAL_WAITUNTIL_DOWNCOUNT_MS 8 // on most boards, delay for 8 ms
257+
# define HAL_WAITUNTIL_DOWNCOUNT_THRESH ms2osticks(9) // but try to leave a little slack for final timing.
258+
#endif
259+
251260
u4_t hal_waitUntil (u4_t time) {
252261
s4_t delta = delta_time(time);
253262
// check for already too late.
@@ -258,12 +267,12 @@ u4_t hal_waitUntil (u4_t time) {
258267
// will produce an accurate delay is 16383. Also, STM32 does a better
259268
// job with delay is less than 10,000 us; so reduce in steps.
260269
// It's nice to use delay() for the longer times.
261-
while (delta > (9000 / US_PER_OSTICK)) {
270+
while (delta > HAL_WAITUNTIL_DOWNCOUNT_THRESH) {
262271
// deliberately delay 8ms rather than 9ms, so we
263272
// will exit loop with delta typically positive.
264273
// Depends on BSP keeping time accurately even if interrupts
265274
// are disabled.
266-
delay(8);
275+
delay(HAL_WAITUNTIL_DOWNCOUNT_MS);
267276
// re-synchronize.
268277
delta = delta_time(time);
269278
}

0 commit comments

Comments
 (0)