summaryrefslogtreecommitdiff
path: root/src/arch/msp430fr5969lp
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2018-10-16 07:46:59 +0200
committerDaniel Friesel <derf@finalrewind.org>2018-10-16 07:46:59 +0200
commit1a0aaa326afa8e9b06795755cacea72b464393ad (patch)
tree8167aa61bd098d9326db9660db4b67352657ff23 /src/arch/msp430fr5969lp
parenta1bbc3b6f2707fa808d19ad0baa035c3bac3f641 (diff)
MSP430: Support CPU speed variation in microsecond timer
Diffstat (limited to 'src/arch/msp430fr5969lp')
-rw-r--r--src/arch/msp430fr5969lp/arch.cc22
1 files changed, 17 insertions, 5 deletions
diff --git a/src/arch/msp430fr5969lp/arch.cc b/src/arch/msp430fr5969lp/arch.cc
index b5b23b6..28d01a5 100644
--- a/src/arch/msp430fr5969lp/arch.cc
+++ b/src/arch/msp430fr5969lp/arch.cc
@@ -60,14 +60,26 @@ void Arch::setup(void)
#endif
#ifdef TIMER_US
- // 16MHz/16 -> ~1MHz timer
- TA0CTL = TASSEL__SMCLK | ID__8 | MC__CONTINUOUS;
- TA0EX0 = 1;
+#if F_CPU == 16000000UL
+ TA0CTL = TASSEL__SMCLK | ID__8 | MC__CONTINUOUS; // /8
+ TA0EX0 = 1; // /2 -> /16
+#elif F_CPU == 8000000UL
+ TA0CTL = TASSEL__SMCLK | ID__8 | MC__CONTINUOUS; // /8
+ TA0EX0 = 0; // /1 -> /8
+#elif F_CPU == 4000000UL
+ TA0CTL = TASSEL__SMCLK | ID__4 | MC__CONTINUOUS; // /4
+ TA0EX0 = 0; // /1 -> /8
+#elif F_CPU == 1000000UL
+ TA0CTL = TASSEL__SMCLK | ID__1 | MC__CONTINUOUS; // /1
+ TA0EX0 = 0; // /1 -> /8
+#else
+#error Unsupported F_CPU
+#endif /* F_CPU */
TA0CTL |= TACLR;
-#endif
+#endif /* TIMER_US */
#if defined(WITH_LOOP) || defined(TIMER_S)
- // 1s per wakeup for loop
+ // 1s per wakeup for loop. Independent of SMCLK/F_CPU
TA1CTL = TASSEL__ACLK | ID__8 | MC__UP;
TA1EX0 = 0;
TA1CCR0 = 4096;