Skip to content

Commit f04e448

Browse files
committed
fix asm! clobber, no inline-asm support, 4 insn per cycle
1 parent fce677d commit f04e448

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed

asm/delay.s

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.global __delay
2+
.syntax unified
3+
.thumb_func
4+
__delay:
5+
nop
6+
subs r0, #1
7+
bne __delay
8+
bx lr

build.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ fn main() {
1515
.file("asm/control.s")
1616
.file("asm/cpsid.s")
1717
.file("asm/cpsie.s")
18+
.file("asm/delay.s")
1819
.file("asm/dmb.s")
1920
.file("asm/dsb.s")
2021
.file("asm/faultmask.s")

src/asm.rs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,26 +24,37 @@ pub fn bkpt() {
2424
}
2525
}
2626

27-
/// Blocks the program for at least `n` instruction cycles
27+
/// Blocks the program for *at least* `n` instruction cycles
2828
///
2929
/// This is implemented in assembly so its execution time is the same regardless of the optimization
3030
/// level.
3131
///
3232
/// NOTE that the delay can take much longer if interrupts are serviced during its execution.
33-
#[inline(never)]
33+
#[inline]
3434
pub fn delay(_n: u32) {
3535
match () {
36-
#[cfg(target_arch = "arm")]
36+
#[cfg(all(cortex_m, feature = "inline-asm"))]
3737
() => unsafe {
3838
asm!("1:
39+
nop
3940
subs $0, $$1
4041
bne.n 1b"
42+
: "+r"(_n / 4 + 1)
4143
:
42-
: "r"(_n / 3 + 1)
4344
:
4445
: "volatile");
4546
},
46-
#[cfg(not(target_arch = "arm"))]
47+
48+
#[cfg(all(cortex_m, not(feature = "inline-asm")))]
49+
() => unsafe {
50+
extern "C" {
51+
fn __delay(n: u32);
52+
}
53+
54+
__delay(_n / 4 + 1);
55+
},
56+
57+
#[cfg(not(cortex_m))]
4758
() => unimplemented!(),
4859
}
4960
}

0 commit comments

Comments
 (0)