aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThales Fragoso <[email protected]>2021-05-23 17:09:11 -0300
committerThales Fragoso <[email protected]>2021-05-23 17:09:11 -0300
commit66f232574addfa12438fe3303e599039f56a4437 (patch)
tree729f79beeec1b7e79d2984a717e815dfc8c9102a
parent90b25e70d799b78a20693c37be10dd99d9a0792f (diff)
Update stm32-data and rename RTC to Clock
-rw-r--r--embassy-stm32/src/clock.rs (renamed from embassy-stm32/src/rtc.rs)36
-rw-r--r--embassy-stm32/src/lib.rs4
m---------embassy-stm32/stm32-data0
3 files changed, 19 insertions, 21 deletions
diff --git a/embassy-stm32/src/rtc.rs b/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;
5use core::sync::atomic::{compiler_fence, AtomicU32, Ordering}; 5use core::sync::atomic::{compiler_fence, AtomicU32, Ordering};
6 6
7use embassy::interrupt::InterruptExt; 7use embassy::interrupt::InterruptExt;
8use embassy::time::{Clock, TICKS_PER_SECOND}; 8use embassy::time::{Clock as EmbassyClock, TICKS_PER_SECOND};
9 9
10use crate::interrupt::{CriticalSection, Interrupt, Mutex}; 10use crate::interrupt::{CriticalSection, Interrupt, Mutex};
11use crate::pac::timer::TimGp16; 11use crate::pac::timer::TimGp16;
12use crate::time::Hertz; 12use crate::time::Hertz;
13 13
14// RTC timekeeping works with something we call "periods", which are time intervals 14// Clock timekeeping works with something we call "periods", which are time intervals
15// of 2^15 ticks. The RTC counter value is 16 bits, so one "overflow cycle" is 2 periods. 15// of 2^15 ticks. The Clock counter value is 16 bits, so one "overflow cycle" is 2 periods.
16// 16//
17// A `period` count is maintained in parallel to the RTC hardware `counter`, like this: 17// A `period` count is maintained in parallel to the Timer hardware `counter`, like this:
18// - `period` and `counter` start at 0 18// - `period` and `counter` start at 0
19// - `period` is incremented on overflow (at counter value 0) 19// - `period` is incremented on overflow (at counter value 0)
20// - `period` is incremented "midway" between overflows (at counter value 0x8000) 20// - `period` is incremented "midway" between overflows (at counter value 0x8000)
@@ -47,17 +47,15 @@ impl AlarmState {
47 } 47 }
48} 48}
49 49
50// TODO: This is sometimes wasteful, try to find a better way
51const ALARM_COUNT: usize = 3; 50const ALARM_COUNT: usize = 3;
52 51
53/// RTC timer that can be used by the executor and to set alarms. 52/// Clock timer that can be used by the executor and to set alarms.
54/// 53///
55/// It can work with Timers 2, 3, 4, 5, 9 and 12. Timers 9 and 12 only have one alarm available, 54/// It can work with Timers 2, 3, 4, 5. This timer works internally with a unit of 2^15 ticks, which
56/// while the others have three each. 55/// means that if a call to [`embassy::time::Clock::now`] is blocked for that amount of ticks the
57/// This timer works internally with a unit of 2^15 ticks, which means that if a call to 56/// returned value will be wrong (an old value). The current default tick rate is 32768 ticks per
58/// [`embassy::time::Clock::now`] is blocked for that amount of ticks the returned value will be 57/// second.
59/// wrong (an old value). The current default tick rate is 32768 ticks per second. 58pub struct Clock<T: Instance> {
60pub struct RTC<T: Instance> {
61 _inner: T, 59 _inner: T,
62 irq: T::Interrupt, 60 irq: T::Interrupt,
63 /// Number of 2^23 periods elapsed since boot. 61 /// Number of 2^23 periods elapsed since boot.
@@ -66,7 +64,7 @@ pub struct RTC<T: Instance> {
66 alarms: Mutex<[AlarmState; ALARM_COUNT]>, 64 alarms: Mutex<[AlarmState; ALARM_COUNT]>,
67} 65}
68 66
69impl<T: Instance> RTC<T> { 67impl<T: Instance> Clock<T> {
70 pub fn new(peripheral: T, irq: T::Interrupt) -> Self { 68 pub fn new(peripheral: T, irq: T::Interrupt) -> Self {
71 Self { 69 Self {
72 _inner: peripheral, 70 _inner: peripheral,
@@ -212,7 +210,7 @@ impl<T: Instance> RTC<T> {
212 } 210 }
213} 211}
214 212
215impl<T: Instance> embassy::time::Clock for RTC<T> { 213impl<T: Instance> EmbassyClock for Clock<T> {
216 fn now(&self) -> u64 { 214 fn now(&self) -> u64 {
217 let inner = T::inner(); 215 let inner = T::inner();
218 216
@@ -225,7 +223,7 @@ impl<T: Instance> embassy::time::Clock for RTC<T> {
225 223
226pub struct Alarm<T: Instance> { 224pub struct Alarm<T: Instance> {
227 n: usize, 225 n: usize,
228 rtc: &'static RTC<T>, 226 rtc: &'static Clock<T>,
229} 227}
230 228
231impl<T: Instance> embassy::time::Alarm for Alarm<T> { 229impl<T: Instance> embassy::time::Alarm for Alarm<T> {
@@ -345,15 +343,15 @@ pub trait Instance: sealed::Instance + Sized + 'static {}
345 343
346macro_rules! impl_timer { 344macro_rules! impl_timer {
347 ($inst:ident) => { 345 ($inst:ident) => {
348 impl crate::rtc::sealed::Instance for peripherals::$inst { 346 impl crate::clock::sealed::Instance for peripherals::$inst {
349 type Interrupt = interrupt::$inst; 347 type Interrupt = interrupt::$inst;
350 348
351 fn inner() -> crate::rtc::TimerInner { 349 fn inner() -> crate::clock::TimerInner {
352 const INNER: crate::rtc::TimerInner = crate::rtc::TimerInner($inst); 350 const INNER: crate::clock::TimerInner = crate::clock::TimerInner($inst);
353 INNER 351 INNER
354 } 352 }
355 } 353 }
356 354
357 impl crate::rtc::Instance for peripherals::$inst {} 355 impl crate::clock::Instance for peripherals::$inst {}
358 }; 356 };
359} 357}
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 @@
9// This must go FIRST so that all the other modules see its macros. 9// This must go FIRST so that all the other modules see its macros.
10pub mod fmt; 10pub mod fmt;
11 11
12#[cfg(feature = "_timer")]
13pub mod clock;
12#[cfg(feature = "_dma")] 14#[cfg(feature = "_dma")]
13pub mod dma; 15pub mod dma;
14pub mod exti; 16pub mod exti;
@@ -17,8 +19,6 @@ pub mod pwr;
17pub mod rcc; 19pub mod rcc;
18#[cfg(feature = "_rng")] 20#[cfg(feature = "_rng")]
19pub mod rng; 21pub mod rng;
20#[cfg(feature = "_timer")]
21pub mod rtc;
22#[cfg(feature = "_sdmmc")] 22#[cfg(feature = "_sdmmc")]
23pub mod sdmmc; 23pub mod sdmmc;
24#[cfg(feature = "_spi")] 24#[cfg(feature = "_spi")]
diff --git a/embassy-stm32/stm32-data b/embassy-stm32/stm32-data
Subproject 3f85766a0f97889788059e71d62d13950d6d710 Subproject c5db875ec2ce8568cfac018ecbdf288fc4b63ba