aboutsummaryrefslogtreecommitdiff
path: root/embassy-time/src/lib.rs
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2022-09-02 00:58:31 +0200
committerDario Nieuwenhuis <[email protected]>2022-09-02 00:59:34 +0200
commit5327b9c289ee69bf07ed384253d03d29af291285 (patch)
tree92c48f9f794b72e94b595bebd2ab21ec48accb14 /embassy-time/src/lib.rs
parent835b69456d6a270e6d5c869da46c0df30fe54254 (diff)
time: add more tick rates, use 1mhz as default.
Diffstat (limited to 'embassy-time/src/lib.rs')
-rw-r--r--embassy-time/src/lib.rs19
1 files changed, 4 insertions, 15 deletions
diff --git a/embassy-time/src/lib.rs b/embassy-time/src/lib.rs
index a6c5d78cc..5b2620986 100644
--- a/embassy-time/src/lib.rs
+++ b/embassy-time/src/lib.rs
@@ -11,6 +11,7 @@ mod delay;
11pub mod driver; 11pub mod driver;
12mod duration; 12mod duration;
13mod instant; 13mod instant;
14mod tick;
14mod timer; 15mod timer;
15 16
16#[cfg(feature = "std")] 17#[cfg(feature = "std")]
@@ -23,25 +24,13 @@ pub use duration::Duration;
23pub use instant::Instant; 24pub use instant::Instant;
24pub use timer::{with_timeout, Ticker, TimeoutError, Timer}; 25pub use timer::{with_timeout, Ticker, TimeoutError, Timer};
25 26
26#[cfg(feature = "tick-1000hz")]
27const TPS: u64 = 1_000;
28
29#[cfg(feature = "tick-32768hz")]
30const TPS: u64 = 32_768;
31
32#[cfg(feature = "tick-1mhz")]
33const TPS: u64 = 1_000_000;
34
35#[cfg(feature = "tick-16mhz")]
36const TPS: u64 = 16_000_000;
37
38/// Ticks per second of the global timebase. 27/// Ticks per second of the global timebase.
39/// 28///
40/// This value is specified by the `tick-*` Cargo features, which 29/// This value is specified by the `tick-*` Cargo features, which
41/// should be set by the time driver. Some drivers support a fixed tick rate, others 30/// should be set by the time driver. Some drivers support a fixed tick rate, others
42/// allow you to choose a tick rate with Cargo features of their own. You should not 31/// allow you to choose a tick rate with Cargo features of their own. You should not
43/// set the `tick-*` features for embassy yourself as an end user. 32/// set the `tick-*` features for embassy yourself as an end user.
44pub const TICKS_PER_SECOND: u64 = TPS; 33pub const TICK_HZ: u64 = tick::TICK_HZ;
45 34
46const fn gcd(a: u64, b: u64) -> u64 { 35const fn gcd(a: u64, b: u64) -> u64 {
47 if b == 0 { 36 if b == 0 {
@@ -51,8 +40,8 @@ const fn gcd(a: u64, b: u64) -> u64 {
51 } 40 }
52} 41}
53 42
54pub(crate) const GCD_1K: u64 = gcd(TICKS_PER_SECOND, 1_000); 43pub(crate) const GCD_1K: u64 = gcd(TICK_HZ, 1_000);
55pub(crate) const GCD_1M: u64 = gcd(TICKS_PER_SECOND, 1_000_000); 44pub(crate) const GCD_1M: u64 = gcd(TICK_HZ, 1_000_000);
56 45
57#[cfg(feature = "defmt-timestamp-uptime")] 46#[cfg(feature = "defmt-timestamp-uptime")]
58defmt::timestamp! {"{=u64:us}", Instant::now().as_micros() } 47defmt::timestamp! {"{=u64:us}", Instant::now().as_micros() }