diff options
| author | Liam Murphy <[email protected]> | 2021-06-29 13:04:05 +1000 |
|---|---|---|
| committer | Liam Murphy <[email protected]> | 2021-06-29 13:04:05 +1000 |
| commit | 87ca902e44099266b1de709857ba7d44bc4b471b (patch) | |
| tree | be256bbd26dab212311820d7a8cdfb555c00a3e7 /embassy-nrf/src/timer.rs | |
| parent | 0c0597f775e3197b87e9370f390ccc3814b637a1 (diff) | |
Handle differences between PACs
Diffstat (limited to 'embassy-nrf/src/timer.rs')
| -rw-r--r-- | embassy-nrf/src/timer.rs | 22 |
1 files changed, 7 insertions, 15 deletions
diff --git a/embassy-nrf/src/timer.rs b/embassy-nrf/src/timer.rs index 0f37a6d65..055c1d881 100644 --- a/embassy-nrf/src/timer.rs +++ b/embassy-nrf/src/timer.rs | |||
| @@ -143,17 +143,17 @@ impl<'d, T: Instance> Timer<'d, T> { | |||
| 143 | 143 | ||
| 144 | /// Starts the timer. | 144 | /// Starts the timer. |
| 145 | pub fn start(&self) { | 145 | pub fn start(&self) { |
| 146 | T::regs().tasks_start.write(|w| w.tasks_start().trigger()) | 146 | T::regs().tasks_start.write(|w| unsafe { w.bits(1) }) |
| 147 | } | 147 | } |
| 148 | 148 | ||
| 149 | /// Stops the timer. | 149 | /// Stops the timer. |
| 150 | pub fn stop(&self) { | 150 | pub fn stop(&self) { |
| 151 | T::regs().tasks_stop.write(|w| w.tasks_stop().trigger()) | 151 | T::regs().tasks_stop.write(|w| unsafe { w.bits(1) }) |
| 152 | } | 152 | } |
| 153 | 153 | ||
| 154 | /// Reset the timer's counter to 0. | 154 | /// Reset the timer's counter to 0. |
| 155 | pub fn clear(&self) { | 155 | pub fn clear(&self) { |
| 156 | T::regs().tasks_clear.write(|w| w.tasks_clear().trigger()) | 156 | T::regs().tasks_clear.write(|w| unsafe { w.bits(1) }) |
| 157 | } | 157 | } |
| 158 | 158 | ||
| 159 | /// Returns the START task, for use with PPI. | 159 | /// Returns the START task, for use with PPI. |
| @@ -194,11 +194,7 @@ impl<'d, T: Instance> Timer<'d, T> { | |||
| 194 | fn on_interrupt(_: *mut ()) { | 194 | fn on_interrupt(_: *mut ()) { |
| 195 | let regs = T::regs(); | 195 | let regs = T::regs(); |
| 196 | for n in 0..T::CCS { | 196 | for n in 0..T::CCS { |
| 197 | if regs.events_compare[n] | 197 | if regs.events_compare[n].read().bits() != 0 { |
| 198 | .read() | ||
| 199 | .events_compare() | ||
| 200 | .is_generated() | ||
| 201 | { | ||
| 202 | // Clear the interrupt, otherwise the interrupt will be repeatedly raised as soon as the interrupt handler exits. | 198 | // Clear the interrupt, otherwise the interrupt will be repeatedly raised as soon as the interrupt handler exits. |
| 203 | // We can't clear the event, because it's used to poll whether the future is done or still pending. | 199 | // We can't clear the event, because it's used to poll whether the future is done or still pending. |
| 204 | regs.intenclr.write(|w| match n { | 200 | regs.intenclr.write(|w| match n { |
| @@ -274,7 +270,7 @@ impl<'a, T: Instance> Cc<'a, T> { | |||
| 274 | 270 | ||
| 275 | /// Capture the current value of the timer's counter in this register, and return it. | 271 | /// Capture the current value of the timer's counter in this register, and return it. |
| 276 | pub fn capture(&self) -> u32 { | 272 | pub fn capture(&self) -> u32 { |
| 277 | T::regs().tasks_capture[self.n].write(|w| w.tasks_capture().trigger()); | 273 | T::regs().tasks_capture[self.n].write(|w| unsafe { w.bits(1) }); |
| 278 | self.read() | 274 | self.read() |
| 279 | } | 275 | } |
| 280 | 276 | ||
| @@ -457,13 +453,9 @@ impl<'a, T: Instance> Cc<'a, T> { | |||
| 457 | poll_fn(|cx| { | 453 | poll_fn(|cx| { |
| 458 | T::waker(self.n).register(cx.waker()); | 454 | T::waker(self.n).register(cx.waker()); |
| 459 | 455 | ||
| 460 | if regs.events_compare[self.n] | 456 | if regs.events_compare[self.n].read().bits() != 0 { |
| 461 | .read() | ||
| 462 | .events_compare() | ||
| 463 | .is_generated() | ||
| 464 | { | ||
| 465 | // Reset the register for next time | 457 | // Reset the register for next time |
| 466 | regs.events_compare[self.n].write(|w| w.events_compare().not_generated()); | 458 | regs.events_compare[self.n].reset(); |
| 467 | Poll::Ready(()) | 459 | Poll::Ready(()) |
| 468 | } else { | 460 | } else { |
| 469 | Poll::Pending | 461 | Poll::Pending |
