Skip to content

✨ (minor) v6: Add hal::delay() for busy-waiting on a steady clock - #115

Closed
kammce wants to merge 1 commit into
mainfrom
v6-steady-clock-delay
Closed

kammce wants to merge 1 commit into
mainfrom
v6-steady-clock-delay

Conversation

@kammce

@kammce kammce commented Oct 19, 2026

Copy link
Copy Markdown
Member

Brings back hal::delay(hal::steady_clock&, hal::time_duration). libhal-util v5 has it; the v6 port dropped it.

hal::delay(clock, 500ms);  // spins on clock.uptime() until the deadline
  • Implementation: a busy-wait on future_deadline(), the same as v5. It doesn't need a waiter, so it works before one is installed. libhal-arm-mcu v2's demos need it until the SysTick timer and WFI waiter are ported (review comment on 💥 v2 Port GPIO and the DWT counter to libhal 5.0.0-alpha.1 libhal-arm-mcu#225). Once a waiter is installed, hal::sleep_for() is better, because it lets the CPU idle.
  • Zero or negative durations: these wait one tick, matching future_deadline().
  • Tests: two cases. One checks the delay runs until the deadline future_deadline() computes. The other checks that a zero duration waits one tick.

Testing

macOS, LLVM 23, against libhal 5.0.0-alpha.2: 16/16 test suites pass.

libhal-util v5 had delay(steady_clock&, time_duration); the v6 port
dropped it. Bring it back as a busy-wait on future_deadline(), for code
that runs before a waiter is installed, such as libhal-arm-mcu v2's
demos until its SysTick timer and WFI waiter are ported.
@kammce kammce closed this Oct 19, 2026
@kammce
kammce deleted the v6-steady-clock-delay branch October 19, 2026 13:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant