diff options
| author | Dario Nieuwenhuis <[email protected]> | 2022-09-02 00:58:31 +0200 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2022-09-02 00:59:34 +0200 |
| commit | 5327b9c289ee69bf07ed384253d03d29af291285 (patch) | |
| tree | 92c48f9f794b72e94b595bebd2ab21ec48accb14 /embassy-time/src/lib.rs | |
| parent | 835b69456d6a270e6d5c869da46c0df30fe54254 (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.rs | 19 |
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; | |||
| 11 | pub mod driver; | 11 | pub mod driver; |
| 12 | mod duration; | 12 | mod duration; |
| 13 | mod instant; | 13 | mod instant; |
| 14 | mod tick; | ||
| 14 | mod timer; | 15 | mod timer; |
| 15 | 16 | ||
| 16 | #[cfg(feature = "std")] | 17 | #[cfg(feature = "std")] |
| @@ -23,25 +24,13 @@ pub use duration::Duration; | |||
| 23 | pub use instant::Instant; | 24 | pub use instant::Instant; |
| 24 | pub use timer::{with_timeout, Ticker, TimeoutError, Timer}; | 25 | pub use timer::{with_timeout, Ticker, TimeoutError, Timer}; |
| 25 | 26 | ||
| 26 | #[cfg(feature = "tick-1000hz")] | ||
| 27 | const TPS: u64 = 1_000; | ||
| 28 | |||
| 29 | #[cfg(feature = "tick-32768hz")] | ||
| 30 | const TPS: u64 = 32_768; | ||
| 31 | |||
| 32 | #[cfg(feature = "tick-1mhz")] | ||
| 33 | const TPS: u64 = 1_000_000; | ||
| 34 | |||
| 35 | #[cfg(feature = "tick-16mhz")] | ||
| 36 | const 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. |
| 44 | pub const TICKS_PER_SECOND: u64 = TPS; | 33 | pub const TICK_HZ: u64 = tick::TICK_HZ; |
| 45 | 34 | ||
| 46 | const fn gcd(a: u64, b: u64) -> u64 { | 35 | const 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 | ||
| 54 | pub(crate) const GCD_1K: u64 = gcd(TICKS_PER_SECOND, 1_000); | 43 | pub(crate) const GCD_1K: u64 = gcd(TICK_HZ, 1_000); |
| 55 | pub(crate) const GCD_1M: u64 = gcd(TICKS_PER_SECOND, 1_000_000); | 44 | pub(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")] |
| 58 | defmt::timestamp! {"{=u64:us}", Instant::now().as_micros() } | 47 | defmt::timestamp! {"{=u64:us}", Instant::now().as_micros() } |
