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
919bd675
Commit
919bd675
authored
10 years ago
by
Thibaut VIARD
Browse files
Options
Downloads
Patches
Plain Diff
Adding Delay API
parent
15bae0de
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
cores/arduino/delay.c
+33
-30
33 additions, 30 deletions
cores/arduino/delay.c
cores/arduino/delay.h
+18
-3
18 additions, 3 deletions
cores/arduino/delay.h
with
51 additions
and
33 deletions
cores/arduino/delay.c
+
33
−
30
View file @
919bd675
...
...
@@ -5,12 +5,13 @@
extern
"C"
{
#endif
/** Tick Counter united by ms */
static
volatile
uint32_t
_ulTickCount
=
0
;
uint32_t
millis
(
void
)
{
/* TODO
// todo: ensure no interrupts
return GetTickCount() ;
*/
return
0ul
;
return
_ulTickCount
;
}
// Interrupt-compatible version of micros
...
...
@@ -19,28 +20,27 @@ uint32_t millis( void )
// values to calculate micros. If there is a pending SysTick, add one to the millis counter in the calculation.
uint32_t
micros
(
void
)
{
/* TODO
uint32_t ticks, ticks2;
uint32_t pend, pend2;
uint32_t count, count2;
uint32_t
ticks
,
ticks2
;
uint32_t
pend
,
pend2
;
uint32_t
count
,
count2
;
ticks2 = SysTick->VAL;
pend2 = !!(
(
SCB->ICSR & SCB_ICSR_PENDSTSET_Msk)
||((SCB->SHCSR & SCB_SHCSR_SYSTICKACT_Msk)))
;
count2 =
Get
TickCount
()
;
ticks2
=
SysTick
->
VAL
;
pend2
=
!!
(
SCB
->
ICSR
&
SCB_ICSR_PENDSTSET_Msk
)
;
count2
=
_ul
TickCount
;
do {
ticks=ticks2;
pend=pend2;
count=count2;
ticks2 = SysTick->VAL;
pend2 = !!((SCB->ICSR & SCB_ICSR_PENDSTSET_Msk)||((SCB->SHCSR & SCB_SHCSR_SYSTICKACT_Msk))) ;
count2 = GetTickCount();
} while ((pend != pend2) || (count != count2) || (ticks < ticks2));
do
{
ticks
=
ticks2
;
pend
=
pend2
;
count
=
count2
;
ticks2
=
SysTick
->
VAL
;
pend2
=
!!
(
SCB
->
ICSR
&
SCB_ICSR_PENDSTSET_Msk
)
;
count2
=
_ulTickCount
;
}
while
((
pend
!=
pend2
)
||
(
count
!=
count2
)
||
(
ticks
<
ticks2
));
return ((count+pend) * 1000) + (((SysTick->LOAD - ticks)*(1048576/(F_CPU/1000000)))>>20) ;
// this is an optimization to turn a runtime division into two compile-time divisions and
// a runtime multiplication and shift, saving a few cycles
*/
return
0ul
;
return
((
count
+
pend
)
*
1000
)
+
(((
SysTick
->
LOAD
-
ticks
)
*
(
1048576
/
(
VARIANT_MCK
/
1000000
)))
>>
20
)
;
// this is an optimization to turn a runtime division into two compile-time divisions and
// a runtime multiplication and shift, saving a few cycles
}
// original function:
...
...
@@ -61,14 +61,17 @@ uint32_t micros( void )
void
delay
(
uint32_t
ms
)
{
/* TODO
if (ms == 0)
return;
uint32_t start = GetTickCount();
do {
yield();
} while (GetTickCount() - start < ms);
*/
if
(
ms
==
0
)
{
return
;
}
uint32_t
start
=
_ulTickCount
;
do
{
yield
()
;
}
while
(
_ulTickCount
-
start
<
ms
)
;
}
#ifdef __cplusplus
...
...
This diff is collapsed.
Click to expand it.
cores/arduino/delay.h
+
18
−
3
View file @
919bd675
...
...
@@ -64,16 +64,31 @@ static inline void delayMicroseconds(uint32_t) __attribute__((always_inline, unu
static
inline
void
delayMicroseconds
(
uint32_t
usec
){
if
(
usec
==
0
)
return
;
uint32_t
n
=
usec
*
(
VARIANT_MCK
/
3000000
);
/*
asm volatile(
__
asm
__
volatile
(
"L_%=_delayMicroseconds:"
"
\n\t
"
"subs %0, #1"
"
\n\t
"
"bne L_%=_delayMicroseconds"
"
\n
"
:
"+r"
(
n
)
:
);
*/
}
/*
__attribute__((naked)) static void delay_loop(unsigned n)
{
__asm volatile ("1: subs r0, r0, #1");
__asm volatile (" bne 1b");
__asm volatile (" bx lr");
}
void delay_microseconds(unsigned n)
{
// Bogus assumption:
// Assume 8 cycles/iteration and running at 80MHz
delay_loop(n * 10);
}
*/
#ifdef __cplusplus
}
#endif
...
...
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