input_capture: tweak for speed

This commit is contained in:
Robert Jördens 2021-07-28 11:27:52 +00:00
parent 1787daacaa
commit c85cbb7aa2
1 changed files with 13 additions and 11 deletions

View File

@ -297,21 +297,23 @@ macro_rules! timer_channels {
// Only atomic operations on completed on the timer registers. // Only atomic operations on completed on the timer registers.
let regs = unsafe { &*<$TY>::ptr() }; let regs = unsafe { &*<$TY>::ptr() };
let result = if regs.sr.read().[< cc $index if >]().bit_is_set() { if regs.sr.read().[< cc $index if >]().bit_is_set() {
// Read the capture value. Reading the captured value clears the flag in the // Read the capture value. Reading the captured value clears the flag in the
// status register automatically. // status register automatically.
Some(regs.[< ccr $index >].read().ccr().bits()) let result = regs.[< ccr $index >].read().ccr().bits();
} else {
None
};
// Read SR again to check for a potential over-capture. If there is an // Read SR again to check for a potential over-capture. Return an error in
// overcapture, return an error. // that case.
if regs.sr.read().[< cc $index of >]().bit_is_set() { let sr = regs.sr.read();
regs.sr.modify(|_, w| w.[< cc $index of >]().clear_bit()); if sr.[< cc $index of >]().bit_is_set() {
Err(result) // NOTE(unsafe) write-back is safe
regs.sr.write(|w| unsafe { w.bits(sr.bits()) }.[< cc $index of >]().clear_bit());
Err(Some(result))
} else {
Ok(Some(result))
}
} else { } else {
Ok(result) Ok(None)
} }
} }