From 66f232574addfa12438fe3303e599039f56a4437 Mon Sep 17 00:00:00 2001 From: Thales Fragoso Date: Sun, 23 May 2021 17:09:11 -0300 Subject: [PATCH] Update stm32-data and rename RTC to Clock --- embassy-stm32/src/{rtc.rs => clock.rs} | 36 ++++++++++++-------------- embassy-stm32/src/lib.rs | 4 +-- embassy-stm32/stm32-data | 2 +- 3 files changed, 20 insertions(+), 22 deletions(-) rename embassy-stm32/src/{rtc.rs => clock.rs} (88%) diff --git a/embassy-stm32/src/rtc.rs b/embassy-stm32/src/clock.rs similarity index 88% rename from embassy-stm32/src/rtc.rs rename to embassy-stm32/src/clock.rs index 05e22cd1b..b4f735efa 100644 --- a/embassy-stm32/src/rtc.rs +++ b/embassy-stm32/src/clock.rs @@ -5,16 +5,16 @@ use core::convert::TryInto; use core::sync::atomic::{compiler_fence, AtomicU32, Ordering}; use embassy::interrupt::InterruptExt; -use embassy::time::{Clock, TICKS_PER_SECOND}; +use embassy::time::{Clock as EmbassyClock, TICKS_PER_SECOND}; use crate::interrupt::{CriticalSection, Interrupt, Mutex}; use crate::pac::timer::TimGp16; use crate::time::Hertz; -// RTC timekeeping works with something we call "periods", which are time intervals -// of 2^15 ticks. The RTC counter value is 16 bits, so one "overflow cycle" is 2 periods. +// Clock timekeeping works with something we call "periods", which are time intervals +// of 2^15 ticks. The Clock counter value is 16 bits, so one "overflow cycle" is 2 periods. // -// A `period` count is maintained in parallel to the RTC hardware `counter`, like this: +// A `period` count is maintained in parallel to the Timer hardware `counter`, like this: // - `period` and `counter` start at 0 // - `period` is incremented on overflow (at counter value 0) // - `period` is incremented "midway" between overflows (at counter value 0x8000) @@ -47,17 +47,15 @@ impl AlarmState { } } -// TODO: This is sometimes wasteful, try to find a better way const ALARM_COUNT: usize = 3; -/// RTC timer that can be used by the executor and to set alarms. +/// Clock timer that can be used by the executor and to set alarms. /// -/// It can work with Timers 2, 3, 4, 5, 9 and 12. Timers 9 and 12 only have one alarm available, -/// while the others have three each. -/// This timer works internally with a unit of 2^15 ticks, which means that if a call to -/// [`embassy::time::Clock::now`] is blocked for that amount of ticks the returned value will be -/// wrong (an old value). The current default tick rate is 32768 ticks per second. -pub struct RTC { +/// It can work with Timers 2, 3, 4, 5. This timer works internally with a unit of 2^15 ticks, which +/// means that if a call to [`embassy::time::Clock::now`] is blocked for that amount of ticks the +/// returned value will be wrong (an old value). The current default tick rate is 32768 ticks per +/// second. +pub struct Clock { _inner: T, irq: T::Interrupt, /// Number of 2^23 periods elapsed since boot. @@ -66,7 +64,7 @@ pub struct RTC { alarms: Mutex<[AlarmState; ALARM_COUNT]>, } -impl RTC { +impl Clock { pub fn new(peripheral: T, irq: T::Interrupt) -> Self { Self { _inner: peripheral, @@ -212,7 +210,7 @@ impl RTC { } } -impl embassy::time::Clock for RTC { +impl EmbassyClock for Clock { fn now(&self) -> u64 { let inner = T::inner(); @@ -225,7 +223,7 @@ impl embassy::time::Clock for RTC { pub struct Alarm { n: usize, - rtc: &'static RTC, + rtc: &'static Clock, } impl embassy::time::Alarm for Alarm { @@ -345,15 +343,15 @@ pub trait Instance: sealed::Instance + Sized + 'static {} macro_rules! impl_timer { ($inst:ident) => { - impl crate::rtc::sealed::Instance for peripherals::$inst { + impl crate::clock::sealed::Instance for peripherals::$inst { type Interrupt = interrupt::$inst; - fn inner() -> crate::rtc::TimerInner { - const INNER: crate::rtc::TimerInner = crate::rtc::TimerInner($inst); + fn inner() -> crate::clock::TimerInner { + const INNER: crate::clock::TimerInner = crate::clock::TimerInner($inst); INNER } } - impl crate::rtc::Instance for peripherals::$inst {} + impl crate::clock::Instance for peripherals::$inst {} }; } diff --git a/embassy-stm32/src/lib.rs b/embassy-stm32/src/lib.rs index 7bcae9f90..0ab998a87 100644 --- a/embassy-stm32/src/lib.rs +++ b/embassy-stm32/src/lib.rs @@ -9,6 +9,8 @@ // This must go FIRST so that all the other modules see its macros. pub mod fmt; +#[cfg(feature = "_timer")] +pub mod clock; #[cfg(feature = "_dma")] pub mod dma; pub mod exti; @@ -17,8 +19,6 @@ pub mod pwr; pub mod rcc; #[cfg(feature = "_rng")] pub mod rng; -#[cfg(feature = "_timer")] -pub mod rtc; #[cfg(feature = "_sdmmc")] pub mod sdmmc; #[cfg(feature = "_spi")] diff --git a/embassy-stm32/stm32-data b/embassy-stm32/stm32-data index 3f85766a0..c5db875ec 160000 --- a/embassy-stm32/stm32-data +++ b/embassy-stm32/stm32-data @@ -1 +1 @@ -Subproject commit 3f85766a0f97889788059e71d62d13950d6d7105 +Subproject commit c5db875ec2ce8568cfac018ecbdf288fc4b63ba0