aboutsummaryrefslogtreecommitdiff
path: root/src/asm.rs
diff options
context:
space:
mode:
authorGravatar Jorge Aparicio <jorge@japaric.io> 2018-05-18 19:47:53 +0200
committerGravatar Jorge Aparicio <jorge@japaric.io> 2018-05-18 19:48:06 +0200
commitf04e448e35d92a446a089f2fb2b7dcbd00454306 (patch)
tree5ebac95b81adc083091c98c7dbc63af06792b693 /src/asm.rs
parentfce677de07af0fc11ec259e1ba2fbc2f017e6f13 (diff)
downloadcortex-m-f04e448e35d92a446a089f2fb2b7dcbd00454306.tar.gz
cortex-m-f04e448e35d92a446a089f2fb2b7dcbd00454306.tar.zst
cortex-m-f04e448e35d92a446a089f2fb2b7dcbd00454306.zip
fix asm! clobber, no inline-asm support, 4 insn per cycle
Diffstat (limited to 'src/asm.rs')
-rw-r--r--src/asm.rs21
1 files changed, 16 insertions, 5 deletions
diff --git a/src/asm.rs b/src/asm.rs
index 4b5d88c..fd1ce7c 100644
--- a/src/asm.rs
+++ b/src/asm.rs
@@ -24,26 +24,37 @@ pub fn bkpt() {
}
}
-/// Blocks the program for at least `n` instruction cycles
+/// Blocks the program for *at least* `n` instruction cycles
///
/// This is implemented in assembly so its execution time is the same regardless of the optimization
/// level.
///
/// NOTE that the delay can take much longer if interrupts are serviced during its execution.
-#[inline(never)]
+#[inline]
pub fn delay(_n: u32) {
match () {
- #[cfg(target_arch = "arm")]
+ #[cfg(all(cortex_m, feature = "inline-asm"))]
() => unsafe {
asm!("1:
+ nop
subs $0, $$1
bne.n 1b"
+ : "+r"(_n / 4 + 1)
:
- : "r"(_n / 3 + 1)
:
: "volatile");
},
- #[cfg(not(target_arch = "arm"))]
+
+ #[cfg(all(cortex_m, not(feature = "inline-asm")))]
+ () => unsafe {
+ extern "C" {
+ fn __delay(n: u32);
+ }
+
+ __delay(_n / 4 + 1);
+ },
+
+ #[cfg(not(cortex_m))]
() => unimplemented!(),
}
}