aboutsummaryrefslogtreecommitdiff
path: root/src/asm.rs
diff options
context:
space:
mode:
authorGravatar bors[bot] <26634292+bors[bot]@users.noreply.github.com> 2021-01-07 17:44:35 +0000
committerGravatar GitHub <noreply@github.com> 2021-01-07 17:44:35 +0000
commit86cd463788b97ca3894936101c6cf4f3512f0fbc (patch)
tree4ada31c00f8e44647975df3cf17ed601ed5a1e0b /src/asm.rs
parent126165331e14f92809656a76dfa351e42dfa1a68 (diff)
parent5a43c6e7927efb2658183929c69dd774c5f8d2c1 (diff)
downloadcortex-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.rs8
1 files changed, 3 insertions, 5 deletions
diff --git a/src/asm.rs b/src/asm.rs
index 297198b..4dc1ab0 100644
--- a/src/asm.rs
+++ b/src/asm.rs
@@ -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.