Skip to content

Commit

Permalink
Fix #508: don't depend on delayMicroseconds()
Browse files Browse the repository at this point in the history
  • Loading branch information
terrillmoore committed Dec 30, 2019
1 parent 4a267e5 commit 306330f
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/hal/hal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ u4_t hal_waitUntil (u4_t time) {
// From delayMicroseconds docs: Currently, the largest value that
// will produce an accurate delay is 16383. Also, STM32 does a better
// job with delay is less than 10,000 us; so reduce in steps.
// It's nice to use delay() for the longer times.
while (delta > (9000 / US_PER_OSTICK)) {
// deliberately delay 8ms rather than 9ms, so we
// will exit loop with delta typically positive.
Expand All @@ -266,8 +267,11 @@ u4_t hal_waitUntil (u4_t time) {
// re-synchronize.
delta = delta_time(time);
}
if (delta > 0)
delayMicroseconds(delta * US_PER_OSTICK);

// unluckily, delayMicroseconds() isn't very accurate.
// so spin using delta_time().
while (delta_time(time) > 0)
/* loop */;

// we aren't "late". Callers are interested in gross delays, not
// necessarily delays due to poor timekeeping here.
Expand Down

1 comment on commit 306330f

@terrillmoore
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not work on BSPs that can't keep time when interrupts are disabled. See #521, #523, #524.

Please sign in to comment.