input_capture: tweak for speed
This commit is contained in:
parent
1787daacaa
commit
c85cbb7aa2
|
@ -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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue