#tick #timer #rate #driver #async #timing #duration

no-std embassy-time

Instant and Duration for embedded no-std systems, with async timer support

3 releases (breaking)

0.3.0 Jan 11, 2024
0.2.0 Dec 4, 2023
0.1.5 Oct 16, 2023
0.1.3 Aug 28, 2023
0.0.0 Oct 31, 2020

#45 in Embedded development

Download history 2739/week @ 2024-01-01 2810/week @ 2024-01-08 3293/week @ 2024-01-15 3740/week @ 2024-01-22 3195/week @ 2024-01-29 2592/week @ 2024-02-05 3087/week @ 2024-02-12 3887/week @ 2024-02-19 2964/week @ 2024-02-26 3760/week @ 2024-03-04 5150/week @ 2024-03-11 4947/week @ 2024-03-18 4262/week @ 2024-03-25 4560/week @ 2024-04-01 4528/week @ 2024-04-08 6156/week @ 2024-04-15

19,790 downloads per month
Used in 68 crates (57 directly)

MIT/Apache

135KB
2K SLoC

embassy-time

Timekeeping, delays and timeouts.

Timekeeping is done with elapsed time since system boot. Time is represented in ticks, where the tick rate is defined either by the driver (in the case of a fixed-rate tick) or chosen by the user with a tick rate feature. The chosen tick rate applies to everything in embassy-time and thus determines the maximum timing resolution of (1 / tick_rate) seconds.

Tick counts are 64 bits. The default tick rate of 1Mhz supports representing time spans of up to ~584558 years, which is big enough for all practical purposes and allows not having to worry about overflows.

Global time driver

The time module is backed by a global "time driver" specified at build time. Only one driver can be active in a program.

All methods and structs transparently call into the active driver. This makes it possible for libraries to use embassy_time in a driver-agnostic way without requiring generic parameters.

For more details, check the embassy_time_driver crate.

Instants and Durations

Instant represents a given instant of time (relative to system boot), and Duration represents the duration of a span of time. They implement the math operations you'd expect, like addition and substraction.

Delays and timeouts

Timer allows performing async delays. Ticker allows periodic delays without drifting over time.

An implementation of the embedded-hal delay traits is provided by Delay, for compatibility with libraries from the ecosystem.

Wall-clock time

The time module deals exclusively with a monotonically increasing tick count. Therefore it has no direct support for wall-clock time ("real life" datetimes like 2021-08-24 13:33:21).

If persistence across reboots is not needed, support can be built on top of embassy_time by storing the offset between "seconds elapsed since boot" and "seconds since unix epoch".

Dependencies

~1.3–3MB
~58K SLoC