Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Sami Nurmenniemi
u-boot-stm32
Commits
16560282
Commit
16560282
authored
Oct 05, 2011
by
Sergei Poselenov
Browse files
RT #72064. Added timer support to the stm3220g-eval port.
parent
c48e269c
Changes
1
Hide whitespace changes
Inline
Side-by-side
cpu/arm_cortexm3/stm32f2/timer.c
View file @
16560282
...
...
@@ -21,14 +21,26 @@
#include <common.h>
/* HCLK/8 */
#define SYSTICK_FREQ (clock_get(CLOCK_HCLK)/8)
/* Internal tick units */
static
unsigned
long
long
timestamp
;
/* Monotonic incrementing timer */
static
ulong
lastdec
;
/* Last decrementer snapshot */
/*
* Init timer.
*/
int
timer_init
(
void
)
{
/*
* TBD
*/
volatile
struct
cm3_systick
*
systick
=
(
volatile
struct
cm3_systick
*
)
CM3_SYSTICK_BASE
;
systick
->
load
=
CM3_SYSTICK_LOAD_RELOAD_MSK
-
1
;
systick
->
val
=
0
;
/* Use external clock, no ints */
systick
->
ctrl
=
CM3_SYSTICK_CTRL_EN
;
timestamp
=
0
;
return
0
;
}
...
...
@@ -38,11 +50,18 @@ int timer_init(void)
*/
unsigned
long
get_timer
(
unsigned
long
base
)
{
/*
* TBD
*/
volatile
struct
cm3_systick
*
systick
=
(
volatile
struct
cm3_systick
*
)
CM3_SYSTICK_BASE
;
ulong
now
=
systick
->
val
;
return
0
;
if
(
lastdec
>=
now
)
timestamp
+=
lastdec
-
now
;
else
timestamp
+=
lastdec
+
CM3_SYSTICK_LOAD_RELOAD_MSK
-
1
-
now
;
lastdec
=
now
;
return
timestamp
/
(
SYSTICK_FREQ
/
1000
)
-
base
;
}
/*
...
...
@@ -50,9 +69,10 @@ unsigned long get_timer(unsigned long base)
*/
void
reset_timer
(
void
)
{
/*
* TBD
*/
volatile
struct
cm3_systick
*
systick
=
(
volatile
struct
cm3_systick
*
)(
CM3_SYSTICK_BASE
);
lastdec
=
systick
->
val
;
timestamp
=
0
;
}
/*
...
...
@@ -60,9 +80,24 @@ void reset_timer(void)
*/
void
__udelay
(
unsigned
long
usec
)
{
/*
* TBD
*/
ulong
clc
,
tmp
;
volatile
struct
cm3_systick
*
systick
=
(
volatile
struct
cm3_systick
*
)(
CM3_SYSTICK_BASE
);
clc
=
usec
*
(
SYSTICK_FREQ
/
1000000
);
/* get current timestamp */
tmp
=
systick
->
val
;
if
(
tmp
<
clc
)
{
/* loop till event */
while
(
systick
->
val
<
tmp
||
systick
->
val
>
(
CM3_SYSTICK_LOAD_RELOAD_MSK
-
1
-
clc
+
tmp
))
;
/* nop */
}
else
{
while
(
systick
->
val
>
(
tmp
-
clc
))
;
}
}
/*
...
...
@@ -71,9 +106,5 @@ void __udelay(unsigned long usec)
*/
unsigned
long
get_tbclk
(
void
)
{
/*
* TBD
*/
return
0
;
return
SYSTICK_FREQ
;
}
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