File tree Expand file tree Collapse file tree 3 files changed +25
-5
lines changed Expand file tree Collapse file tree 3 files changed +25
-5
lines changed Original file line number Diff line number Diff line change
1
+ .global __delay
2
+ .syntax unified
3
+ .thumb_func
4
+ __delay:
5
+ nop
6
+ subs r0, #1
7
+ bne __delay
8
+ bx lr
Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ fn main() {
15
15
. file ( "asm/control.s" )
16
16
. file ( "asm/cpsid.s" )
17
17
. file ( "asm/cpsie.s" )
18
+ . file ( "asm/delay.s" )
18
19
. file ( "asm/dmb.s" )
19
20
. file ( "asm/dsb.s" )
20
21
. file ( "asm/faultmask.s" )
Original file line number Diff line number Diff line change @@ -24,26 +24,37 @@ pub fn bkpt() {
24
24
}
25
25
}
26
26
27
- /// Blocks the program for at least `n` instruction cycles
27
+ /// Blocks the program for * at least* `n` instruction cycles
28
28
///
29
29
/// This is implemented in assembly so its execution time is the same regardless of the optimization
30
30
/// level.
31
31
///
32
32
/// NOTE that the delay can take much longer if interrupts are serviced during its execution.
33
- #[ inline( never ) ]
33
+ #[ inline]
34
34
pub fn delay ( _n : u32 ) {
35
35
match ( ) {
36
- #[ cfg( target_arch = "arm" ) ]
36
+ #[ cfg( all ( cortex_m , feature = "inline-asm" ) ) ]
37
37
( ) => unsafe {
38
38
asm ! ( "1:
39
+ nop
39
40
subs $0, $$1
40
41
bne.n 1b"
42
+ : "+r" ( _n / 4 + 1 )
41
43
:
42
- : "r" ( _n / 3 + 1 )
43
44
:
44
45
: "volatile" ) ;
45
46
} ,
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) ) ]
47
58
( ) => unimplemented ! ( ) ,
48
59
}
49
60
}
You can’t perform that action at this time.
0 commit comments