Expand description
The device’s wall clock: what time it is, where that came from, and whether it is known at all.
A device of this class has a monotonic timer and, usually, nothing else. Wall-clock time arrives from outside — a GNSS fix, a battery-backed real-time clock, a host that was asked — and is held as an offset from the monotonic timer rather than as a counter of its own, so it costs nothing to maintain and cannot drift relative to everything else the device schedules.
Two things here are policy rather than mechanism, and both are deliberately in one place:
- Not knowing is a state.
WallClockState::nowreturnsNoneuntil something sets the clock. Callers must not substitute zero, a build timestamp, or any other plausible-looking value — a device that does not know the time must not display one. - Sources outrank each other.
WallClockState::applyholds the whole precedence rule, so no caller has to remember it and no two callers can disagree about it.
WallClockState is pure and testable on any host. The module-level
statics behind the embassy feature are the single live instance the
firmware shares.
Structs§
- Wall
Clock State - The wall clock, as an offset from a monotonic millisecond timer.
Enums§
- Time
Source - Where a wall-clock reading came from.
- Update
- What
WallClockState::applydid.
Constants§
- NOTABLE_
STEP_ SECS - How far the clock must move for the change to be worth telling anyone about, in seconds.
Functions§
- apply
- Offer a reading, applying the precedence rule. See
WallClockState::apply. - clear
- Return the device to not knowing what time it is.
- is_set
- Whether the device knows what time it is.
- local_
hhmm - The local hour and minute, or
Nonewhen the time is unknown. - millis_
to_ next_ minute - Milliseconds until the next minute boundary, or
Nonewhen the time is unknown. - now
- The current time in Unix seconds, or
Nonewhen the device does not know what time it is. - set_
manual - Set the clock from a host or an operator.
- set_tz
- Set the time zone.
- snapshot
- The whole clock, for a caller that wants the reading, the zone, and the source without three separate critical sections.
- tz_
offset_ min - Minutes east of UTC.