Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
multipass
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
derf
multipass
Commits
60cb80bd
Commit
60cb80bd
authored
6 years ago
by
Birte Kristina Friesel
Browse files
Options
Downloads
Patches
Plain Diff
add timertest app, improve msp430 timer driver
parent
2727c03a
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
include/arch/msp430fr5969lp/driver/timer.h
+42
-7
42 additions, 7 deletions
include/arch/msp430fr5969lp/driver/timer.h
src/app/timertest/Makefile.inc
+3
-0
3 additions, 0 deletions
src/app/timertest/Makefile.inc
src/app/timertest/main.cc
+43
-0
43 additions, 0 deletions
src/app/timertest/main.cc
with
88 additions
and
7 deletions
include/arch/msp430fr5969lp/driver/timer.h
+
42
−
7
View file @
60cb80bd
#include
<msp430.h>
#include
<stdint.h>
#define ON_TIMER_INTERRUPT_head __attribute__((interrupt(TIMER0_A1_VECTOR))) __attribute__((wakeup)) void handle_timer0_overflow() { if (TA0IV == 0x0e) {
#define ON_TIMER_INTERRUPT_tail } }
#if F_CPU == 16000000UL
#define _TA0_MAIN_DIV ID__8
#elif F_CPU == 8000000UL
#define _TA0_MAIN_DIV ID__4
#elif F_CPU == 4000000UL
#define _TA0_MAIN_DIV ID__2
#elif F_CPU == 1000000UL
#define _TA0_MAIN_DIV ID__1
#else
#error Unsupported F_CPU
#endif
class
Timer
{
private:
Timer
(
const
Timer
&
copy
);
...
...
@@ -10,19 +23,41 @@ class Timer {
public:
Timer
()
{}
#if F_CPU == 1000000UL
inline
void
setup_khz
(
uint16_t
const
frequency
)
{
TA0CTL
=
TASSEL__SMCLK
|
ID__1
|
MC__UP
;
// -> 1 MHz base
TA0EX0
=
0
;
TA0CCR0
=
1000UL
/
frequency
;
TA0CTL
|=
TACLR
;
}
inline
void
setup_hz
(
uint16_t
const
frequency
)
{
// 1 MHz base
if
(
frequency
<
20
)
{
TA0CTL
=
TASSEL__SMCLK
|
ID__8
|
MC__UP
;
// /8
TA0EX0
=
1
;
// /2 -> /16 -> 62500 Hz
TA0CCR0
=
62500UL
/
frequency
;
}
else
{
TA0CTL
=
TASSEL__SMCLK
|
ID__1
|
MC__UP
;
TA0EX0
=
0
;
TA0CCR0
=
1000000UL
/
frequency
;
}
TA0CTL
|=
TACLR
;
}
#else
inline
void
setup_khz
(
uint16_t
const
frequency
)
{
TA0CTL
=
TASSEL__SMCLK
|
ID__8
|
MC__UP
;
TA0EX0
=
1
;
TA0CCR0
=
1
000
/
frequency
;
TA0CTL
=
TASSEL__SMCLK
|
_TA0_MAIN_DIV
|
MC__UP
;
// -> 2 MHz base
TA0EX0
=
0
;
TA0CCR0
=
2
000
UL
/
frequency
;
TA0CTL
|=
TACLR
;
}
inline
void
setup_hz
(
uint16_t
const
frequency
)
{
TA0CTL
=
TASSEL__SMCLK
|
ID__8
|
MC__UP
;
TA0EX0
=
1
;
TA0CCR0
=
1
000000
/
frequency
;
inline
void
setup_hz
(
uint16_t
const
frequency
)
{
// 2 MHz base
TA0CTL
=
TASSEL__SMCLK
|
_TA0_MAIN_DIV
|
MC__UP
;
TA0EX0
=
0
;
TA0CCR0
=
2
000000
UL
/
frequency
;
TA0CTL
|=
TACLR
;
}
#endif
inline
void
start
(
unsigned
char
const
interrupt
)
{
if
(
interrupt
)
{
...
...
This diff is collapsed.
Click to expand it.
src/app/timertest/Makefile.inc
0 → 100644
+
3
−
0
View file @
60cb80bd
loop
?=
1
timer_s
?=
1
arch_drivers
+=
,timer
This diff is collapsed.
Click to expand it.
src/app/timertest/main.cc
0 → 100644
+
43
−
0
View file @
60cb80bd
#include
"arch.h"
#include
"driver/gpio.h"
#include
"driver/stdout.h"
#include
"driver/timer.h"
#include
"driver/uptime.h"
#ifndef F_TIMER
#define F_TIMER 100000
#endif
volatile
unsigned
long
int
timer_val
=
0
;
void
loop
(
void
)
{
gpio
.
led_toggle
(
1
);
kout
<<
"Actual frequency: approx. "
<<
timer_val
<<
" Hz"
<<
endl
;
timer_val
=
0
;
}
int
main
(
void
)
{
arch
.
setup
();
gpio
.
setup
();
kout
.
setup
();
#if F_TIMER > 999
timer
.
setup_khz
(
F_TIMER
/
1000
);
#else
timer
.
setup_hz
(
F_TIMER
);
#endif
timer
.
start
(
1
);
gpio
.
led_on
(
0
);
kout
<<
"Timer running at "
<<
dec
<<
F_TIMER
<<
" Hz"
<<
endl
;
arch
.
idle_loop
();
return
0
;
}
ON_TIMER_INTERRUPT_head
gpio
.
led_toggle
(
0
);
timer_val
++
;
ON_TIMER_INTERRUPT_tail
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