|
1 | 1 | // Copyright (c) 2024 Linaro LTD
|
2 | 2 | // SPDX-License-Identifier: Apache-2.0
|
3 | 3 |
|
4 |
| -//! Time types similar to `std::time` types. |
| 4 | +//! Time types designed for Zephyr, inspired by `std::time`. |
5 | 5 | //!
|
6 |
| -//! However, the rust-embedded world tends to use `fugit` for time. This has a Duration and |
7 |
| -//! Instant type, but they are parameterized by the slice used, and try hard to do the conversion |
8 |
| -//! at compile time. |
| 6 | +//! In `std`, there are two primary time types: `Duration`, representing a span of time, and |
| 7 | +//! `Instant`, representing a specific point in time. Both have nanosecond precision, which is |
| 8 | +//! well-suited to more powerful machines. However, on embedded systems like Zephyr, this precision |
| 9 | +//! can lead to performance issues, often requiring divisions whenever timeouts are used. |
9 | 10 | //!
|
10 |
| -//! std has two time types, a Duration which represents an elapsed amount of time, and Instant, |
11 |
| -//! which represents a specific instance in time. |
| 11 | +//! In the Rust embedded ecosystem, the `fugit` crate is commonly used for handling time. It |
| 12 | +//! provides both `Duration` and `Instant` types, but with parameters that allow the representation |
| 13 | +//! to match the time slice used, enabling compile-time conversion and storing time directly as |
| 14 | +//! tick counts. |
12 | 15 | //!
|
13 |
| -//! Zephyr typically coordinates time in terms of a system tick interval, which comes from |
14 |
| -//! `sys_clock_hw_cycles_per_sec()`. |
| 16 | +//! Zephyr manages time in terms of system tick intervals, derived from |
| 17 | +//! `sys_clock_hw_cycles_per_sec()`. This model aligns well with `fugit`, especially when the |
| 18 | +//! types are properly parameterized. |
15 | 19 | //!
|
16 |
| -//! The Rust/std semantics require Instant to be monotonically increasing. |
| 20 | +//! It's important to note that Rust’s `std::Instant` requires time to be monotonically increasing. |
17 | 21 | //!
|
18 |
| -//! Zephyr's `sys/time_units.h` header contains numerous optimized macros for manipulating time in |
19 |
| -//! these units, specifically for converting between human time units and ticks, trying to avoid |
20 |
| -//! division, especially division by non-constants. |
| 22 | +//! Zephyr’s `sys/time_units.h` provides a variety of optimized macros for manipulating time |
| 23 | +//! values, converting between human-readable units and ticks, and minimizing divisions (especially |
| 24 | +//! by non-constant values). Similarly, the `fugit` crate offers constructors that aim to result |
| 25 | +//! in constants when possible, avoiding costly division operations. |
21 | 26 |
|
22 | 27 | use zephyr_sys::k_timeout_t;
|
23 | 28 |
|
|
0 commit comments