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
b3398c81
Commit
b3398c81
authored
10 years ago
by
Thibaut VIARD
Browse files
Options
Downloads
Patches
Plain Diff
First draft for Wiring.c
parent
336de714
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/wiring.c
+38
-68
38 additions, 68 deletions
cores/arduino/wiring.c
cores/arduino/wiring.h
+3
-47
3 additions, 47 deletions
cores/arduino/wiring.h
with
41 additions
and
115 deletions
cores/arduino/wiring.c
+
38
−
68
View file @
b3398c81
...
...
@@ -22,81 +22,51 @@
extern
"C"
{
#endif
uint32_t
millis
(
void
)
{
// todo: ensure no interrupts
return
GetTickCount
()
;
}
// Interrupt-compatible version of micros
// Theory: repeatedly take readings of SysTick counter, millis counter and SysTick interrupt pending flag.
// When it appears that millis counter and pending is stable and SysTick hasn't rolled over, use these
// values to calculate micros. If there is a pending SysTick, add one to the millis counter in the calculation.
uint32_t
micros
(
void
)
{
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
=
GetTickCount
();
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
));
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
}
/*
* System Core Clock is at 1MHz at Reset.
* It is switched to 48MHz in the Reset Handler (startup.c)
*/
extern
uint32_t
SystemCoreClock
=
1000000ul
;
// original function:
// uint32_t micros( void )
// {
// uint32_t ticks ;
// uint32_t count ;
//
// SysTick->CTRL;
// do {
// ticks = SysTick->VAL;
// count = GetTickCount();
// } while (SysTick->CTRL & SysTick_CTRL_COUNTFLAG_Msk);
//
// return count * 1000 + (SysTick->LOAD + 1 - ticks) / (SystemCoreClock/1000000) ;
// }
void
delay
(
uint32_t
ms
)
{
if
(
ms
==
0
)
return
;
uint32_t
start
=
GetTickCount
();
do
{
yield
();
}
while
(
GetTickCount
()
-
start
<
ms
);
}
void
__libc_init_array
(
void
);
#if defined ( __ICCARM__ )
/* IAR Ewarm 5.41+ */
extern
signed
int
putchar
(
signed
int
c
)
;
/**
* \brief
*
* \param c Character to output.
/*
* Arduino Zero board initialization
*
* \return The character that was output.
* Good to know:
* - Watchdog is disabled by default, unless someone plays with NVM User page
* -
*/
extern
WEAK
signed
int
putchar
(
signed
int
c
)
void
init
(
void
)
{
return
c
;
// Set Systick to 1ms interval, common to all SAM3 variants
if
(
SysTick_Config
(
SystemCoreClock
/
1000
))
{
// Capture error
while
(
true
);
}
// Initialize C library
// __libc_init_array();
// Disable pull-up on every pin
for
(
int
i
=
0
;
i
<
PINS_COUNT
;
i
++
)
{
digitalWrite
(
i
,
LOW
)
;
}
// Initialize Serial port U(S)ART pins
// Todo
// Initialize USB pins
// Todo
// Initialize Analog Controller
// Todo
}
#endif
/* __ICCARM__ */
#ifdef __cplusplus
}
#endif
This diff is collapsed.
Click to expand it.
cores/arduino/wiring.h
+
3
−
47
View file @
b3398c81
...
...
@@ -8,7 +8,7 @@
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
...
...
@@ -23,56 +23,12 @@
extern
"C"
{
#endif
/**
*
*/
extern
void
init
(
void
)
;
/**
* \brief Returns the number of milliseconds since the Arduino board began running the current program.
*
* This number will overflow (go back to zero), after approximately 50 days.
*
* \return Number of milliseconds since the program started (uint32_t)
*/
extern
uint32_t
millis
(
void
)
;
/**
* \brief Returns the number of microseconds since the Arduino board began running the current program.
*
* This number will overflow (go back to zero), after approximately 70 minutes. On 16 MHz Arduino boards
* (e.g. Duemilanove and Nano), this function has a resolution of four microseconds (i.e. the value returned is
* always a multiple of four). On 8 MHz Arduino boards (e.g. the LilyPad), this function has a resolution
* of eight microseconds.
*
* \note There are 1,000 microseconds in a millisecond and 1,000,000 microseconds in a second.
*/
extern
uint32_t
micros
(
void
)
;
/**
* \brief Pauses the program for the amount of time (in miliseconds) specified as parameter.
* (There are 1000 milliseconds in a second.)
*
* \param dwMs the number of milliseconds to pause (uint32_t)
*/
extern
void
delay
(
uint32_t
dwMs
)
;
extern
uint32_t
SystemCoreClock
;
/**
* \brief Pauses the program for the amount of time (in microseconds) specified as parameter.
*
* \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
usec
){
if
(
usec
==
0
)
return
;
uint32_t
n
=
usec
*
(
VARIANT_MCK
/
3000000
);
asm
volatile
(
"L_%=_delayMicroseconds:"
"
\n\t
"
"subs %0, #1"
"
\n\t
"
"bne L_%=_delayMicroseconds"
"
\n
"
:
"+r"
(
n
)
:
);
}
extern
void
init
(
void
)
;
#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