time: add more tick rates, use 1mhz as default.

This commit is contained in:
Dario Nieuwenhuis
2022-09-02 00:58:31 +02:00
parent 835b69456d
commit 5327b9c289
38 changed files with 418 additions and 135 deletions

View File

@@ -11,6 +11,7 @@ mod delay;
pub mod driver;
mod duration;
mod instant;
mod tick;
mod timer;
#[cfg(feature = "std")]
@@ -23,25 +24,13 @@ pub use duration::Duration;
pub use instant::Instant;
pub use timer::{with_timeout, Ticker, TimeoutError, Timer};
#[cfg(feature = "tick-1000hz")]
const TPS: u64 = 1_000;
#[cfg(feature = "tick-32768hz")]
const TPS: u64 = 32_768;
#[cfg(feature = "tick-1mhz")]
const TPS: u64 = 1_000_000;
#[cfg(feature = "tick-16mhz")]
const TPS: u64 = 16_000_000;
/// Ticks per second of the global timebase.
///
/// This value is specified by the `tick-*` Cargo features, which
/// should be set by the time driver. Some drivers support a fixed tick rate, others
/// allow you to choose a tick rate with Cargo features of their own. You should not
/// set the `tick-*` features for embassy yourself as an end user.
pub const TICKS_PER_SECOND: u64 = TPS;
pub const TICK_HZ: u64 = tick::TICK_HZ;
const fn gcd(a: u64, b: u64) -> u64 {
if b == 0 {
@@ -51,8 +40,8 @@ const fn gcd(a: u64, b: u64) -> u64 {
}
}
pub(crate) const GCD_1K: u64 = gcd(TICKS_PER_SECOND, 1_000);
pub(crate) const GCD_1M: u64 = gcd(TICKS_PER_SECOND, 1_000_000);
pub(crate) const GCD_1K: u64 = gcd(TICK_HZ, 1_000);
pub(crate) const GCD_1M: u64 = gcd(TICK_HZ, 1_000_000);
#[cfg(feature = "defmt-timestamp-uptime")]
defmt::timestamp! {"{=u64:us}", Instant::now().as_micros() }