Skip to content

Commit ac708f9

Browse files
committed
Use nrf_delay_us in delayMicroseconds
1 parent 9e64438 commit ac708f9

File tree

1 file changed

+3
-27
lines changed

1 file changed

+3
-27
lines changed

cores/nRF5/delay.h

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ extern "C" {
2525

2626
#include <stdint.h>
2727

28+
#include "nrf_delay.h"
29+
2830
#include "variant.h"
2931

3032
/**
@@ -69,33 +71,7 @@ static __inline__ void delayMicroseconds( uint32_t usec )
6971
return ;
7072
}
7173

72-
/*
73-
* The following loop:
74-
*
75-
* for (; ul; ul--) {
76-
* __asm__ volatile("");
77-
* }
78-
*
79-
* produce the following assembly code:
80-
*
81-
* loop:
82-
* subs r3, #1 // 1 Core cycle
83-
* bne.n loop // 1 Core cycle + 1 if branch is taken
84-
*/
85-
86-
// VARIANT_MCK / 1000000 == cycles needed to delay 1uS
87-
// 3 == cycles used in a loop
88-
uint32_t n = usec * (VARIANT_MCK / 1000000) / 3;
89-
__asm__ __volatile__(
90-
"1: \n"
91-
" sub %0, #1 \n" // substract 1 from %0 (n)
92-
" bne 1b \n" // if result is not 0 jump to 1
93-
: "+r" (n) // '%0' is n variable with RW constraints
94-
: // no input
95-
: // no clobber
96-
);
97-
// https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html
98-
// https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html#Volatile
74+
nrf_delay_us(usec);
9975
}
10076

10177
#ifdef __cplusplus

0 commit comments

Comments
 (0)