Skip to content

Commit 8a31f0f

Browse files
committed
rust: zephyr: time: Clarify docs
Rewrite the doc comment for `zephyr::time`. A little bit of LLM help and this is much clearer. Signed-off-by: David Brown <[email protected]>
1 parent 661ed0f commit 8a31f0f

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

zephyr/src/time.rs

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,28 @@
11
// Copyright (c) 2024 Linaro LTD
22
// SPDX-License-Identifier: Apache-2.0
33

4-
//! Time types similar to `std::time` types.
4+
//! Time types designed for Zephyr, inspired by `std::time`.
55
//!
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.
910
//!
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.
1215
//!
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.
1519
//!
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.
1721
//!
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.
2126
2227
use zephyr_sys::k_timeout_t;
2328

0 commit comments

Comments
 (0)