19#ifndef SBL_SYSTEM_TIMER_HPP_
20#define SBL_SYSTEM_TIMER_HPP_
24#include <sbl/system/port/tick.hpp>
29using Port = sbl::driver::Tick;
31static_assert(port::tick_port_valid<Port>,
"SBL ERROR: the target's tick port does not meet its contract");
34inline constexpr uint32_t
rate() {
return Port::rate(); }
37inline uint32_t
count() {
return Port::count(); }
51 const uint32_t start =
count();
52 const uint32_t counts =
static_cast<uint32_t
>(
static_cast<uint64_t
>(us) *
rate() / 1'000'000u);
53 while (
count() - start < counts) {
65inline uint32_t
millis() {
return static_cast<uint32_t
>(detail::to_millis(
count64(),
rate())); }
69 static uint32_t now() {
return millis(); }
static uint64_t count64()
A 32-bit counter extended to 64 bits by counting its overflows.
The system timer over the tick port: the count, the 64-bit count, busy waits and milliseconds.
void busy_wait_ms(uint32_t ms)
constexpr uint32_t rate()
void busy_wait_us(uint32_t us)
The tick port: the hardware timer under the system timer.