pub struct Manager<'a> { /* private fields */ }Expand description
System-owned UTC clock anchored to monotonic time, independent of shell lifetime.
with_clock/unsynchronized boot with zero correction and invalid UTC. Targets
without an RTC use these until manual or network initialization. new bootstraps
once from a trusted source (native/browser use the host clock); source failure is
returned so the runtime may explicitly fall back to an unsynchronized manager.
Nothing survives reset: persistence and source selection are runtime policy.
Corrections step immediately, in either direction; there is no slew. Monotonic deadlines and uptime are unchanged. UTC subsequently advances at the monotonic source’s rate, including its suspend behavior; resynchronize after suspend when that source stops during sleep. Nominal resolution is the coarser of the epoch sample and monotonic clock. Accuracy is unknown unless supplied by the source, and is not maintained as a bound as time elapses. No timezone or DST is applied.
State updates and reads are serialized with a short critical section, without allocation or I/O while locked. Custom monotonic sources must be nonblocking and safe to call in that critical section.
Every successful set_realtime and every invalidate also bumps
Manager::change_generation and signals Manager::wait_for_change after
the critical section is released, so a runtime service (for example the
real-time clock write-back task) can react to UTC changes without polling and
without holding the clock lock. The signal has a single consumer.
Implementations§
Source§impl<'a> Manager<'a>
impl<'a> Manager<'a>
pub fn new(source: &dyn RealtimeSource) -> Result<Self>
Sourcepub fn with_monotonic_clock(
source: &dyn RealtimeSource,
monotonic_clock: &'a dyn MonotonicClock,
) -> Result<Self>
pub fn with_monotonic_clock( source: &dyn RealtimeSource, monotonic_clock: &'a dyn MonotonicClock, ) -> Result<Self>
Construct a manager and initialize UTC once from a trusted epoch source. Its monotonic epoch must agree with the executor for absolute deadlines.
Sourcepub fn unsynchronized() -> Self
pub fn unsynchronized() -> Self
Start with invalid UTC; elapsed time is available immediately.
Sourcepub fn with_clock(monotonic_clock: &'a dyn MonotonicClock) -> Self
pub fn with_clock(monotonic_clock: &'a dyn MonotonicClock) -> Self
Start with invalid UTC and a platform-specific monotonic source.
The default resolution constant describes Embassy; custom implementations
must report their own resolution through MonotonicClock::resolution.
Sourcepub fn monotonic_now(&self) -> Duration
pub fn monotonic_now(&self) -> Duration
Monotonic time since the source’s arbitrary epoch, independent of UTC.
Use this epoch for absolute deadlines; use uptime for manager lifetime.
pub fn monotonic_resolution(&self) -> Duration
Sourcepub fn uptime(&self) -> Duration
pub fn uptime(&self) -> Duration
Elapsed time since this manager was initialized, independent of UTC.
Sourcepub fn monotonic_milliseconds_wrapping(&self) -> u32
pub fn monotonic_milliseconds_wrapping(&self) -> u32
Milliseconds modulo 2^32, for wrapping tick consumers such as LVGL. Wraps every ~49.7 days; compute differences with wrapping subtraction and sample at intervals shorter than one complete wrap.
Sourcepub fn realtime_now(&self) -> Result<Timestamp>
pub fn realtime_now(&self) -> Result<Timestamp>
Signed Unix UTC, or Unsynchronized until an epoch has been supplied. May jump in either direction; never use for elapsed time. Overflow is an error rather than a wrapped timestamp; a later set can recover the clock.
Sourcepub fn set_realtime(&self, sample: RealtimeSample) -> Result<()>
pub fn set_realtime(&self, sample: RealtimeSample) -> Result<()>
Replace UTC and its provenance atomically at the current monotonic instant. Invalid samples or correction overflow leave all prior state untouched. This runtime-owned API does not grant guest users permission to change time.
Sourcepub fn synchronize(&self, source: &dyn RealtimeSource) -> Result<()>
pub fn synchronize(&self, source: &dyn RealtimeSource) -> Result<()>
Sample a trusted source explicitly; failed reads leave existing UTC intact.
pub fn status(&self) -> RealtimeStatus
Sourcepub fn synchronization(&self) -> Option<Synchronization>
pub fn synchronization(&self) -> Option<Synchronization>
The current synchronization, or None while UTC is invalid.
Sourcepub fn change_generation(&self) -> u64
pub fn change_generation(&self) -> u64
Generation of the UTC state. Increases on every successful
Manager::set_realtime and every Manager::invalidate; read it to
then wait for the next change with Manager::wait_for_change.
Sourcepub async fn wait_for_change(&self, generation: u64) -> u64
pub async fn wait_for_change(&self, generation: u64) -> u64
Waits until the UTC state changed after generation and returns the new
generation. The signal has a single consumer: one waiter at a time.
Sourcepub fn invalidate(&self)
pub fn invalidate(&self)
Mark UTC invalid without disturbing the monotonic clock or its deadlines.
Sourcepub fn realtime_resolution(&self) -> Duration
pub fn realtime_resolution(&self) -> Duration
Nominal quantization; this remains queryable while UTC is invalid.