Skip to content

Commit

Permalink
samd/mphalport: Simplify mp_hal_delay_ms().
Browse files Browse the repository at this point in the history
Do NOT use `mp_hal_delay_us()` for short delays.  This was initially done
to make short delays precise, but it does not allow for scheduling.  Leave
using `mp_hal_delay_us()` to user code if needed.

Signed-off-by: robert-hh <[email protected]>
  • Loading branch information
robert-hh authored and dpgeorge committed Sep 6, 2024
1 parent ed86fdb commit 1a6279b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
2 changes: 2 additions & 0 deletions docs/samd/quickref.rst
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ Use the :mod:`time <time>` module::
start = time.ticks_ms() # get millisecond counter
delta = time.ticks_diff(time.ticks_ms(), start) # compute time difference

Note that :func:`time.sleep_us()` delays by busy waiting. During that time, other tasks are
not scheduled.

Clock and time
--------------
Expand Down
10 changes: 3 additions & 7 deletions ports/samd/mphalport.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,9 @@ void mp_hal_clr_pin_mux(mp_hal_pin_obj_t pin) {
}

void mp_hal_delay_ms(mp_uint_t ms) {
if (ms > 10) {
uint32_t t0 = systick_ms;
while (systick_ms - t0 < ms) {
MICROPY_EVENT_POLL_HOOK
}
} else {
mp_hal_delay_us(ms * 1000);
uint32_t t0 = systick_ms;
while (systick_ms - t0 < ms) {
MICROPY_EVENT_POLL_HOOK
}
}

Expand Down

0 comments on commit 1a6279b

Please sign in to comment.