diff options
| author | Ulf Lilleengen <[email protected]> | 2022-08-23 13:57:45 +0200 |
|---|---|---|
| committer | Ulf Lilleengen <[email protected]> | 2022-08-23 13:58:57 +0200 |
| commit | 189d4137ccff37fc9bbf889652f634f511f8cf83 (patch) | |
| tree | 5793e876ab37f8d2395151159e3c6f98fa86c625 /embassy-time/README.md | |
| parent | 7b3ae0446c7300e257db398c96ed21694bc002c4 (diff) | |
Add readme for embassy-time
Diffstat (limited to 'embassy-time/README.md')
| -rw-r--r-- | embassy-time/README.md | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/embassy-time/README.md b/embassy-time/README.md new file mode 100644 index 000000000..2be80ff9c --- /dev/null +++ b/embassy-time/README.md | |||
| @@ -0,0 +1,43 @@ | |||
| 1 | # embassy-time | ||
| 2 | |||
| 3 | Timekeeping, delays and timeouts. | ||
| 4 | |||
| 5 | Timekeeping is done with elapsed time since system boot. Time is represented in | ||
| 6 | ticks, where the tick rate is defined by the current driver, usually to match | ||
| 7 | the tick rate of the hardware. | ||
| 8 | |||
| 9 | Tick counts are 64 bits. At the highest supported tick rate of 1Mhz this supports | ||
| 10 | representing time spans of up to ~584558 years, which is big enough for all practical | ||
| 11 | purposes and allows not having to worry about overflows. | ||
| 12 | |||
| 13 | [`Instant`] represents a given instant of time (relative to system boot), and [`Duration`] | ||
| 14 | represents the duration of a span of time. They implement the math operations you'd expect, | ||
| 15 | like addition and substraction. | ||
| 16 | |||
| 17 | # Delays and timeouts | ||
| 18 | |||
| 19 | [`Timer`] allows performing async delays. [`Ticker`] allows periodic delays without drifting over time. | ||
| 20 | |||
| 21 | An implementation of the `embedded-hal` delay traits is provided by [`Delay`], for compatibility | ||
| 22 | with libraries from the ecosystem. | ||
| 23 | |||
| 24 | # Wall-clock time | ||
| 25 | |||
| 26 | The `time` module deals exclusively with a monotonically increasing tick count. | ||
| 27 | Therefore it has no direct support for wall-clock time ("real life" datetimes | ||
| 28 | like `2021-08-24 13:33:21`). | ||
| 29 | |||
| 30 | If persistence across reboots is not needed, support can be built on top of | ||
| 31 | `embassy_time` by storing the offset between "seconds elapsed since boot" | ||
| 32 | and "seconds since unix epoch". | ||
| 33 | |||
| 34 | # Time driver | ||
| 35 | |||
| 36 | The `time` module is backed by a global "time driver" specified at build time. | ||
| 37 | Only one driver can be active in a program. | ||
| 38 | |||
| 39 | All methods and structs transparently call into the active driver. This makes it | ||
| 40 | possible for libraries to use `embassy_time` in a driver-agnostic way without | ||
| 41 | requiring generic parameters. | ||
| 42 | |||
| 43 | For more details, check the [`driver`] module. | ||
