Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
arduino-nRF5
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
arduino-nRF5
Commits
ac708f9f
Commit
ac708f9f
authored
May 09, 2016
by
Sandeep Mistry
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use nrf_delay_us in delayMicroseconds
parent
9e64438f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
3 additions
and
27 deletions
+3
-27
cores/nRF5/delay.h
cores/nRF5/delay.h
+3
-27
No files found.
cores/nRF5/delay.h
View file @
ac708f9f
...
...
@@ -25,6 +25,8 @@ extern "C" {
#include <stdint.h>
#include "nrf_delay.h"
#include "variant.h"
/**
...
...
@@ -69,33 +71,7 @@ static __inline__ void delayMicroseconds( uint32_t usec )
return
;
}
/*
* The following loop:
*
* for (; ul; ul--) {
* __asm__ volatile("");
* }
*
* produce the following assembly code:
*
* loop:
* subs r3, #1 // 1 Core cycle
* bne.n loop // 1 Core cycle + 1 if branch is taken
*/
// VARIANT_MCK / 1000000 == cycles needed to delay 1uS
// 3 == cycles used in a loop
uint32_t
n
=
usec
*
(
VARIANT_MCK
/
1000000
)
/
3
;
__asm__
__volatile__
(
"1:
\n
"
" sub %0, #1
\n
"
// substract 1 from %0 (n)
" bne 1b
\n
"
// if result is not 0 jump to 1
:
"+r"
(
n
)
// '%0' is n variable with RW constraints
:
// no input
:
// no clobber
);
// https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html
// https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html#Volatile
nrf_delay_us
(
usec
);
}
#ifdef __cplusplus
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment