aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLiam Murphy <[email protected]>2021-06-29 14:37:37 +1000
committerLiam Murphy <[email protected]>2021-06-29 14:37:37 +1000
commite6d0dba5ca6f986f6d4cd20df5334fe824c40dde (patch)
tree42639e7ffec1da630c39ed87ae7f53b709ac8877
parent87ca902e44099266b1de709857ba7d44bc4b471b (diff)
Write bits directly to intenset/clr + shorts
-rw-r--r--embassy-nrf/src/timer.rs165
1 files changed, 18 insertions, 147 deletions
diff --git a/embassy-nrf/src/timer.rs b/embassy-nrf/src/timer.rs
index 055c1d881..9c04e1580 100644
--- a/embassy-nrf/src/timer.rs
+++ b/embassy-nrf/src/timer.rs
@@ -197,27 +197,8 @@ impl<'d, T: Instance> Timer<'d, T> {
197 if regs.events_compare[n].read().bits() != 0 { 197 if regs.events_compare[n].read().bits() != 0 {
198 // 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.
199 // 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.
200 regs.intenclr.write(|w| match n { 200 regs.intenclr
201 0 => w.compare0().clear(), 201 .modify(|r, w| unsafe { w.bits(r.bits() | (1 << (16 + n))) });
202 1 => w.compare1().clear(),
203 2 => w.compare2().clear(),
204 3 => w.compare3().clear(),
205 #[cfg(any(
206 feature = "nrf52805",
207 feature = "nrf52811",
208 feature = "nrf52820",
209 feature = "nrf52833",
210 ))]
211 4 => w.compare4().clear(),
212 #[cfg(any(
213 feature = "nrf52805",
214 feature = "nrf52811",
215 feature = "nrf52820",
216 feature = "nrf52833",
217 ))]
218 5 => w.compare5().clear(),
219 _ => unreachable!("No timers have more than 6 CC registers"),
220 });
221 T::waker(n).wake(); 202 T::waker(n).wake();
222 } 203 }
223 } 204 }
@@ -294,52 +275,16 @@ impl<'a, T: Instance> Cc<'a, T> {
294 /// 275 ///
295 /// So, when the timer's counter reaches the value stored in this register, the timer's counter will be reset to 0. 276 /// So, when the timer's counter reaches the value stored in this register, the timer's counter will be reset to 0.
296 pub fn short_compare_clear(&self) { 277 pub fn short_compare_clear(&self) {
297 T::regs().shorts.write(|w| match self.n { 278 T::regs()
298 0 => w.compare0_clear().enabled(), 279 .shorts
299 1 => w.compare1_clear().enabled(), 280 .modify(|r, w| unsafe { w.bits(r.bits() | (1 << self.n)) })
300 2 => w.compare2_clear().enabled(),
301 3 => w.compare3_clear().enabled(),
302 #[cfg(any(
303 feature = "nrf52805",
304 feature = "nrf52811",
305 feature = "nrf52820",
306 feature = "nrf52833",
307 ))]
308 4 => w.compare4_clear().enabled(),
309 #[cfg(any(
310 feature = "nrf52805",
311 feature = "nrf52811",
312 feature = "nrf52820",
313 feature = "nrf52833",
314 ))]
315 5 => w.compare5_clear().enabled(),
316 _ => unreachable!("a `Cc` cannot be created with `n > 5`"),
317 })
318 } 281 }
319 282
320 /// Disable the shortcut between this CC register's COMPARE event and the timer's CLEAR task. 283 /// Disable the shortcut between this CC register's COMPARE event and the timer's CLEAR task.
321 pub fn unshort_compare_clear(&self) { 284 pub fn unshort_compare_clear(&self) {
322 T::regs().shorts.write(|w| match self.n { 285 T::regs()
323 0 => w.compare0_clear().disabled(), 286 .shorts
324 1 => w.compare1_clear().disabled(), 287 .modify(|r, w| unsafe { w.bits(r.bits() & (0 << self.n)) })
325 2 => w.compare2_clear().disabled(),
326 3 => w.compare3_clear().disabled(),
327 #[cfg(any(
328 feature = "nrf52805",
329 feature = "nrf52811",
330 feature = "nrf52820",
331 feature = "nrf52833",
332 ))]
333 4 => w.compare4_clear().disabled(),
334 #[cfg(any(
335 feature = "nrf52805",
336 feature = "nrf52811",
337 feature = "nrf52820",
338 feature = "nrf52833",
339 ))]
340 5 => w.compare5_clear().disabled(),
341 _ => unreachable!("a `Cc` cannot be created with `n > 5`"),
342 })
343 } 288 }
344 289
345 /// Enable the shortcut between this CC register's COMPARE event and the timer's STOP task. 290 /// Enable the shortcut between this CC register's COMPARE event and the timer's STOP task.
@@ -348,52 +293,16 @@ impl<'a, T: Instance> Cc<'a, T> {
348 /// 293 ///
349 /// So, when the timer's counter reaches the value stored in this register, the timer will stop counting up. 294 /// So, when the timer's counter reaches the value stored in this register, the timer will stop counting up.
350 pub fn short_compare_stop(&self) { 295 pub fn short_compare_stop(&self) {
351 T::regs().shorts.write(|w| match self.n { 296 T::regs()
352 0 => w.compare0_stop().enabled(), 297 .shorts
353 1 => w.compare1_stop().enabled(), 298 .modify(|r, w| unsafe { w.bits(r.bits() | (1 << (8 + self.n))) })
354 2 => w.compare2_stop().enabled(),
355 3 => w.compare3_stop().enabled(),
356 #[cfg(any(
357 feature = "nrf52805",
358 feature = "nrf52811",
359 feature = "nrf52820",
360 feature = "nrf52833",
361 ))]
362 4 => w.compare4_stop().enabled(),
363 #[cfg(any(
364 feature = "nrf52805",
365 feature = "nrf52811",
366 feature = "nrf52820",
367 feature = "nrf52833",
368 ))]
369 5 => w.compare5_stop().enabled(),
370 _ => unreachable!("a `Cc` cannot be created with `n > 5`"),
371 })
372 } 299 }
373 300
374 /// Disable the shortcut between this CC register's COMPARE event and the timer's STOP task. 301 /// Disable the shortcut between this CC register's COMPARE event and the timer's STOP task.
375 pub fn unshort_compare_stop(&self) { 302 pub fn unshort_compare_stop(&self) {
376 T::regs().shorts.write(|w| match self.n { 303 T::regs()
377 0 => w.compare0_stop().disabled(), 304 .shorts
378 1 => w.compare1_stop().disabled(), 305 .modify(|r, w| unsafe { w.bits(r.bits() & (0 << (8 + self.n))) })
379 2 => w.compare2_stop().disabled(),
380 3 => w.compare3_stop().disabled(),
381 #[cfg(any(
382 feature = "nrf52805",
383 feature = "nrf52811",
384 feature = "nrf52820",
385 feature = "nrf52833",
386 ))]
387 4 => w.compare4_stop().disabled(),
388 #[cfg(any(
389 feature = "nrf52805",
390 feature = "nrf52811",
391 feature = "nrf52820",
392 feature = "nrf52833",
393 ))]
394 5 => w.compare5_stop().disabled(),
395 _ => unreachable!("a `Cc` cannot be created with `n > 5`"),
396 })
397 } 306 }
398 307
399 /// Wait until the timer's counter reaches the value stored in this register. 308 /// Wait until the timer's counter reaches the value stored in this register.
@@ -403,51 +312,13 @@ impl<'a, T: Instance> Cc<'a, T> {
403 let regs = T::regs(); 312 let regs = T::regs();
404 313
405 // Enable the interrupt for this CC's COMPARE event. 314 // Enable the interrupt for this CC's COMPARE event.
406 regs.intenset.write(|w| match self.n { 315 regs.intenset
407 0 => w.compare0().set(), 316 .modify(|r, w| unsafe { w.bits(r.bits() | (1 << (16 + self.n))) });
408 1 => w.compare1().set(),
409 2 => w.compare2().set(),
410 3 => w.compare3().set(),
411 #[cfg(any(
412 feature = "nrf52805",
413 feature = "nrf52811",
414 feature = "nrf52820",
415 feature = "nrf52833",
416 ))]
417 4 => w.compare4().set(),
418 #[cfg(any(
419 feature = "nrf52805",
420 feature = "nrf52811",
421 feature = "nrf52820",
422 feature = "nrf52833",
423 ))]
424 5 => w.compare5().set(),
425 _ => unreachable!("a `Cc` cannot be created with `n > 5`"),
426 });
427 317
428 // Disable the interrupt if the future is dropped. 318 // Disable the interrupt if the future is dropped.
429 let on_drop = OnDrop::new(|| { 319 let on_drop = OnDrop::new(|| {
430 regs.intenclr.write(|w| match self.n { 320 regs.intenclr
431 0 => w.compare0().clear(), 321 .modify(|r, w| unsafe { w.bits(r.bits() | (1 << (16 + self.n))) });
432 1 => w.compare1().clear(),
433 2 => w.compare2().clear(),
434 3 => w.compare3().clear(),
435 #[cfg(any(
436 feature = "nrf52805",
437 feature = "nrf52811",
438 feature = "nrf52820",
439 feature = "nrf52833",
440 ))]
441 4 => w.compare4().clear(),
442 #[cfg(any(
443 feature = "nrf52805",
444 feature = "nrf52811",
445 feature = "nrf52820",
446 feature = "nrf52833",
447 ))]
448 5 => w.compare5().clear(),
449 _ => unreachable!("a `Cc` cannot be created with `n > 5`"),
450 });
451 }); 322 });
452 323
453 poll_fn(|cx| { 324 poll_fn(|cx| {