diff options
author | 2021-01-07 17:44:35 +0000 | |
---|---|---|
committer | 2021-01-07 17:44:35 +0000 | |
commit | 86cd463788b97ca3894936101c6cf4f3512f0fbc (patch) | |
tree | 4ada31c00f8e44647975df3cf17ed601ed5a1e0b /asm/inline.rs | |
parent | 126165331e14f92809656a76dfa351e42dfa1a68 (diff) | |
parent | 5a43c6e7927efb2658183929c69dd774c5f8d2c1 (diff) | |
download | cortex-m-86cd463788b97ca3894936101c6cf4f3512f0fbc.tar.gz cortex-m-86cd463788b97ca3894936101c6cf4f3512f0fbc.tar.zst cortex-m-86cd463788b97ca3894936101c6cf4f3512f0fbc.zip |
Merge #312
312: Fix timing of asm-based delay implementation r=adamgreig a=jonas-schievink
Should fix https://github.com/rust-embedded/cortex-m/issues/236
I've also moved the cycle adjustment into the assembly implementation, since it seems more appropriate there (and this will be useful if we make `cortex-m-asm` its own crate).
Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
Diffstat (limited to 'asm/inline.rs')
-rw-r--r-- | asm/inline.rs | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/asm/inline.rs b/asm/inline.rs index 9150c9c..5e2fbc1 100644 --- a/asm/inline.rs +++ b/asm/inline.rs @@ -52,13 +52,16 @@ pub unsafe fn __cpsie() { #[inline(always)] pub unsafe fn __delay(cyc: u32) { - // Use local labels to avoid R_ARM_THM_JUMP8 relocations which fail on thumbv6m. + // The loop will normally take 3 to 4 CPU cycles per iteration, but superscalar cores + // (eg. Cortex-M7) can potentially do it in 2, so we use that as the lower bound, since delaying + // for more cycles is okay. + let real_cyc = cyc / 2; asm!( + // Use local labels to avoid R_ARM_THM_JUMP8 relocations which fail on thumbv6m. "1:", - "nop", "subs {}, #1", "bne 1b", - in(reg) cyc + in(reg) real_cyc ); } |