Change divider delay to explicit NOPs

Use explicit NOPs since cortex_m::asm::delay actually delays for
longer than we need to.
This commit is contained in:
Derek Hageman 2022-01-25 15:45:54 -07:00
parent c2d3b21d91
commit 35704d9799

View file

@ -215,6 +215,21 @@ where
} }
} }
// Don't use cortex_m::asm::delay(8) because that ends up delaying 15 cycles
// on Cortex-M0. Each iteration of the inner loop is 3 cycles and it adds
// one extra iteration.
#[inline(always)]
fn divider_delay() {
cortex_m::asm::nop();
cortex_m::asm::nop();
cortex_m::asm::nop();
cortex_m::asm::nop();
cortex_m::asm::nop();
cortex_m::asm::nop();
cortex_m::asm::nop();
cortex_m::asm::nop();
}
impl HwDivider { impl HwDivider {
/// Perform hardware unsigned divide/modulo operation /// Perform hardware unsigned divide/modulo operation
pub fn unsigned(&self, dividend: u32, divisor: u32) -> DivResult<u32> { pub fn unsigned(&self, dividend: u32, divisor: u32) -> DivResult<u32> {
@ -222,7 +237,7 @@ impl HwDivider {
sio.div_udividend.write(|w| unsafe { w.bits(dividend) }); sio.div_udividend.write(|w| unsafe { w.bits(dividend) });
sio.div_udivisor.write(|w| unsafe { w.bits(divisor) }); sio.div_udivisor.write(|w| unsafe { w.bits(divisor) });
cortex_m::asm::delay(8); divider_delay();
// Note: quotient must be read last // Note: quotient must be read last
let remainder = sio.div_remainder.read().bits(); let remainder = sio.div_remainder.read().bits();
@ -243,7 +258,7 @@ impl HwDivider {
sio.div_sdivisor sio.div_sdivisor
.write(|w| unsafe { w.bits(divisor as u32) }); .write(|w| unsafe { w.bits(divisor as u32) });
cortex_m::asm::delay(8); divider_delay();
// Note: quotient must be read last // Note: quotient must be read last
let remainder = sio.div_remainder.read().bits() as i32; let remainder = sio.div_remainder.read().bits() as i32;