Clock — Wall-Clock Time (RTC)

Clock is wall-clock time: set it once and read it anywhere, in Unix epoch seconds. Underneath, it rides the board's RTC — a hardware calendar where the board ships one, and a synthesized counter-backed RTC everywhere else, so Clock exports on any board with a free counter.

singleton

Clock

Set and read the wall clock. Values are Unix epoch seconds — a time server's answer or a stamp from your build host are both fine sources. Invalid dates cannot occur: the conversion is pure arithmetic.

Example first

clock.ts
import { Clock, UART0 } from '@typecad/hal';

// set from a time server's answer, or a stamp your build host made
Clock.set(1765432100);

const now = Clock.now();
UART0.writeLine('epoch: ' + now);
MethodWhat it does
set(epochSeconds)Set the wall clock — Unix epoch seconds, e.g. a time server’s answer or a build-host stamp
now()Read it back, also epoch seconds — 0 before the first set()
reference

where the RTC comes from

Two paths, one class. Boards whose devicetree aliases a hardware calendar RTC export Clock backed by it. Every other board with a free counter gets a synthesized zephyr,rtc-counter shim — a child of the counter node, so the Counter class keeps the parent. Same facts that gate Counter, gating Clock.

Example first

BackingPersistence
Hardware calendar RTCThe rtc alias points at a backup-domain calendar node — the time survives power loss
Counter-backed (the shim)The synthesized rtc-counter keeps time only while its counter runs — a power loss resets it to 0

v1 semantics are session-scoped unless your board's rtc alias is a hardware calendar: on counter-backed boards, time lives while the counter runs. The generated overlay and build facts (CONFIG_RTC and the shim driver) are emitted automatically when your program uses Clock — nothing to wire by hand.

© 2026 typeCAD — code-defined electronics github