diff options
author | 2021-01-07 17:44:35 +0000 | |
---|---|---|
committer | 2021-01-07 17:44:35 +0000 | |
commit | 86cd463788b97ca3894936101c6cf4f3512f0fbc (patch) | |
tree | 4ada31c00f8e44647975df3cf17ed601ed5a1e0b /src/asm.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 'src/asm.rs')
-rw-r--r-- | src/asm.rs | 8 |
1 files changed, 3 insertions, 5 deletions
@@ -15,7 +15,7 @@ pub fn bkpt() { call_asm!(__bkpt()); } -/// Blocks the program for *at least* `n` instruction cycles +/// Blocks the program for *at least* `cycles` CPU cycles. /// /// This is implemented in assembly so its execution time is independent of the optimization /// level, however it is dependent on the specific architecture and core configuration. @@ -25,10 +25,8 @@ pub fn bkpt() { /// timer-less initialization of peripherals if and only if accurate timing is not essential. In /// any other case please use a more accurate method to produce a delay. #[inline] -pub fn delay(n: u32) { - // NOTE(divide by 4) is easier to compute than `/ 3` because it's just a shift (`>> 2`). - let real_cyc = n / 4 + 1; - call_asm!(__delay(real_cyc: u32)); +pub fn delay(cycles: u32) { + call_asm!(__delay(cycles: u32)); } /// A no-operation. Useful to prevent delay loops from being optimized away. |