Skip to main content

Manager

Struct Manager 

Source
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>

Source

pub fn new(source: &dyn RealtimeSource) -> Result<Self>

Source

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.

Source

pub fn unsynchronized() -> Self

Start with invalid UTC; elapsed time is available immediately.

Source

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.

Source

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.

Source

pub fn monotonic_resolution(&self) -> Duration

Source

pub fn uptime(&self) -> Duration

Elapsed time since this manager was initialized, independent of UTC.

Source

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.

Source

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.

Source

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.

Source

pub fn synchronize(&self, source: &dyn RealtimeSource) -> Result<()>

Sample a trusted source explicitly; failed reads leave existing UTC intact.

Source

pub fn status(&self) -> RealtimeStatus

Source

pub fn synchronization(&self) -> Option<Synchronization>

The current synchronization, or None while UTC is invalid.

Source

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.

Source

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.

Source

pub fn invalidate(&self)

Mark UTC invalid without disturbing the monotonic clock or its deadlines.

Source

pub fn realtime_resolution(&self) -> Duration

Nominal quantization; this remains queryable while UTC is invalid.

Auto Trait Implementations§

§

impl<'a> !Freeze for Manager<'a>

§

impl<'a> !RefUnwindSafe for Manager<'a>

§

impl<'a> Send for Manager<'a>

§

impl<'a> Sync for Manager<'a>

§

impl<'a> Unpin for Manager<'a>

§

impl<'a> UnsafeUnpin for Manager<'a>

§

impl<'a> !UnwindSafe for Manager<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.