diff options
| author | Matous Hybl <[email protected]> | 2022-02-28 16:20:42 +0100 |
|---|---|---|
| committer | Matous Hybl <[email protected]> | 2022-02-28 16:20:42 +0100 |
| commit | a88c5e716e7a374e2fc7a602b0c70dea267a2e8a (patch) | |
| tree | e87527f950a1a2092af667a923a6c1b730155cc4 /embassy-stm32/src/time_driver.rs | |
| parent | 141e007acf5f3c91a9cbd13196c32867bfddd78d (diff) | |
stm32: Register access for timers now doesn't require self
Diffstat (limited to 'embassy-stm32/src/time_driver.rs')
| -rw-r--r-- | embassy-stm32/src/time_driver.rs | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/embassy-stm32/src/time_driver.rs b/embassy-stm32/src/time_driver.rs index 009c62030..08796acd5 100644 --- a/embassy-stm32/src/time_driver.rs +++ b/embassy-stm32/src/time_driver.rs | |||
| @@ -103,7 +103,6 @@ impl AlarmState { | |||
| 103 | } | 103 | } |
| 104 | 104 | ||
| 105 | struct RtcDriver { | 105 | struct RtcDriver { |
| 106 | timer: T, | ||
| 107 | /// Number of 2^15 periods elapsed since boot. | 106 | /// Number of 2^15 periods elapsed since boot. |
| 108 | period: AtomicU32, | 107 | period: AtomicU32, |
| 109 | alarm_count: AtomicU8, | 108 | alarm_count: AtomicU8, |
| @@ -114,7 +113,6 @@ struct RtcDriver { | |||
| 114 | const ALARM_STATE_NEW: AlarmState = AlarmState::new(); | 113 | const ALARM_STATE_NEW: AlarmState = AlarmState::new(); |
| 115 | 114 | ||
| 116 | embassy::time_driver_impl!(static DRIVER: RtcDriver = RtcDriver { | 115 | embassy::time_driver_impl!(static DRIVER: RtcDriver = RtcDriver { |
| 117 | timer: unsafe { core::mem::transmute(()) }, // steal is not const | ||
| 118 | period: AtomicU32::new(0), | 116 | period: AtomicU32::new(0), |
| 119 | alarm_count: AtomicU8::new(0), | 117 | alarm_count: AtomicU8::new(0), |
| 120 | alarms: Mutex::const_new(CriticalSectionRawMutex::new(), [ALARM_STATE_NEW; ALARM_COUNT]), | 118 | alarms: Mutex::const_new(CriticalSectionRawMutex::new(), [ALARM_STATE_NEW; ALARM_COUNT]), |
| @@ -122,7 +120,7 @@ embassy::time_driver_impl!(static DRIVER: RtcDriver = RtcDriver { | |||
| 122 | 120 | ||
| 123 | impl RtcDriver { | 121 | impl RtcDriver { |
| 124 | fn init(&'static self) { | 122 | fn init(&'static self) { |
| 125 | let r = self.timer.regs_gp16(); | 123 | let r = T::regs_gp16(); |
| 126 | 124 | ||
| 127 | <T as RccPeripheral>::enable(); | 125 | <T as RccPeripheral>::enable(); |
| 128 | <T as RccPeripheral>::reset(); | 126 | <T as RccPeripheral>::reset(); |
| @@ -163,7 +161,7 @@ impl RtcDriver { | |||
| 163 | } | 161 | } |
| 164 | 162 | ||
| 165 | fn on_interrupt(&self) { | 163 | fn on_interrupt(&self) { |
| 166 | let r = self.timer.regs_gp16(); | 164 | let r = T::regs_gp16(); |
| 167 | 165 | ||
| 168 | // NOTE(unsafe) Use critical section to access the methods | 166 | // NOTE(unsafe) Use critical section to access the methods |
| 169 | // XXX: reduce the size of this critical section ? | 167 | // XXX: reduce the size of this critical section ? |
| @@ -194,7 +192,7 @@ impl RtcDriver { | |||
| 194 | } | 192 | } |
| 195 | 193 | ||
| 196 | fn next_period(&self) { | 194 | fn next_period(&self) { |
| 197 | let r = self.timer.regs_gp16(); | 195 | let r = T::regs_gp16(); |
| 198 | 196 | ||
| 199 | let period = self.period.fetch_add(1, Ordering::Relaxed) + 1; | 197 | let period = self.period.fetch_add(1, Ordering::Relaxed) + 1; |
| 200 | let t = (period as u64) << 15; | 198 | let t = (period as u64) << 15; |
| @@ -236,7 +234,7 @@ impl RtcDriver { | |||
| 236 | 234 | ||
| 237 | impl Driver for RtcDriver { | 235 | impl Driver for RtcDriver { |
| 238 | fn now(&self) -> u64 { | 236 | fn now(&self) -> u64 { |
| 239 | let r = self.timer.regs_gp16(); | 237 | let r = T::regs_gp16(); |
| 240 | 238 | ||
| 241 | let period = self.period.load(Ordering::Relaxed); | 239 | let period = self.period.load(Ordering::Relaxed); |
| 242 | compiler_fence(Ordering::Acquire); | 240 | compiler_fence(Ordering::Acquire); |
| @@ -273,7 +271,7 @@ impl Driver for RtcDriver { | |||
| 273 | 271 | ||
| 274 | fn set_alarm(&self, alarm: AlarmHandle, timestamp: u64) { | 272 | fn set_alarm(&self, alarm: AlarmHandle, timestamp: u64) { |
| 275 | critical_section::with(|cs| { | 273 | critical_section::with(|cs| { |
| 276 | let r = self.timer.regs_gp16(); | 274 | let r = T::regs_gp16(); |
| 277 | 275 | ||
| 278 | let n = alarm.id() as _; | 276 | let n = alarm.id() as _; |
| 279 | let alarm = self.get_alarm(cs, alarm); | 277 | let alarm = self.get_alarm(cs, alarm); |
