Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
Arduino Core for SAMD21 CPU
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
josc941e
Arduino Core for SAMD21 CPU
Commits
56c096bd
Commit
56c096bd
authored
10 years ago
by
Cristian Maglie
Committed by
Cristian Maglie
10 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Fixed delayMicrosecond for non-constant case.
parent
2cba1137
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
cores/arduino/delay.h
+29
-29
29 additions, 29 deletions
cores/arduino/delay.h
with
29 additions
and
29 deletions
cores/arduino/delay.h
+
29
−
29
View file @
56c096bd
...
...
@@ -61,40 +61,40 @@ extern void delay( uint32_t dwMs ) ;
* \param dwUs the number of microseconds to pause (uint32_t)
*/
static
__inline__
void
delayMicroseconds
(
uint32_t
)
__attribute__
((
always_inline
,
unused
))
;
static
__inline__
void
delayMicroseconds
(
uint32_t
ul_
usec
)
static
__inline__
void
delayMicroseconds
(
uint32_t
usec
)
{
if
(
ul_
usec
==
0
)
if
(
usec
==
0
)
{
return
;
}
uint32_t
ul
=
ul_usec
*
(
VARIANT_MCK
/
3000000
);
// = ul_usec * 16 with VARIANT_MCK @ 48MHz
/* following 'for' loop will generate this:
*
loop:
*
subs r3, #1 // 1 Core cycle
* bne.n loop // 1 or 2 Core cycles, depends on pipeline break (50/50?)
for ( ; ul != 0 ; ul-- )
{
__asm__ volatile("");
}
*/
/*
* __asm__ [__volatile__] ( AssemblerTemplate : [OutputOperands] [ : [InputOperands] [ : [Clobbers] ] ] )
*
* __asm__ documentation for GCC: https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html
*
__
volatile__ documentation for GCC: https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html#V
olatile
*
*/
__asm__
__volatile__
(
"1:
\n
"
"sub %0, #1
\n
"
/* substract 1 from %0 (ul) */
"bne 1b
\n
"
:
/* no outputs */
:
"r"
(
ul
)
/* 'ul' variable is '%0', '+' means R/W constraint on this variable/register, 'r' means 'register' (versus 'm' for 'memory' */
:
/* no clobber, ie nothing should be damaged by this asm code */
)
;
/*
* 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__
__v
olatile
__
(
"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
}
#ifdef __cplusplus
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment