File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -24,6 +24,30 @@ pub fn bkpt() {
24
24
}
25
25
}
26
26
27
+ /// Blocks the program for at least `n` instruction cycles
28
+ ///
29
+ /// This is implemented in assembly so its execution time is the same regardless of the optimization
30
+ /// level.
31
+ ///
32
+ /// NOTE that the delay can take much longer if interrupts are serviced during its execution.
33
+ #[ inline( never) ]
34
+ pub fn delay ( _n : u32 ) {
35
+ match ( ) {
36
+ #[ cfg( target_arch = "arm" ) ]
37
+ ( ) => unsafe {
38
+ asm ! ( "1:
39
+ subs $0, $$1
40
+ bne.n 1b"
41
+ :
42
+ : "r" ( _n / 3 + 1 )
43
+ :
44
+ : "volatile" ) ;
45
+ } ,
46
+ #[ cfg( not( target_arch = "arm" ) ) ]
47
+ ( ) => unimplemented ! ( ) ,
48
+ }
49
+ }
50
+
27
51
/// A no-operation. Useful to prevent delay loops from being optimized away.
28
52
#[ inline]
29
53
pub fn nop ( ) {
You can’t perform that action at this time.
0 commit comments