summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <daniel.friesel@uos.de>2019-07-26 10:50:59 +0200
committerDaniel Friesel <daniel.friesel@uos.de>2019-07-26 10:50:59 +0200
commite41dd62ff0415b254d8846280fe6070f834d0907 (patch)
tree1a5b963306b4f418b1d150fd406d1ab373d3358e
parentd6cb4dbc366194c1dd9d4752fb7b0a74da6e26f0 (diff)
MSP430FR5994 counter: Track overflows.
-rw-r--r--include/arch/msp430fr5994lp/driver/counter.h8
-rw-r--r--src/arch/msp430fr5994lp/driver/counter.cc11
2 files changed, 17 insertions, 2 deletions
diff --git a/include/arch/msp430fr5994lp/driver/counter.h b/include/arch/msp430fr5994lp/driver/counter.h
index b95aba1..1d7800a 100644
--- a/include/arch/msp430fr5994lp/driver/counter.h
+++ b/include/arch/msp430fr5994lp/driver/counter.h
@@ -13,7 +13,7 @@ class Counter {
public:
uint16_t value;
- uint8_t overflow;
+ volatile uint8_t overflow;
Counter() : overflow(0) {}
@@ -21,12 +21,16 @@ class Counter {
overflow = 0;
TA2CTL = TASSEL__SMCLK | ID__1 | MC__CONTINUOUS;
TA2EX0 = 0;
- TA2CTL |= TACLR;
+ TA2CTL |= TACLR | TAIE;
+ asm volatile("nop");
+ __eint();
+ asm volatile("nop");
}
inline void stop() {
TA2CTL = 0;
value = TA2R;
+ __dint();
}
};
diff --git a/src/arch/msp430fr5994lp/driver/counter.cc b/src/arch/msp430fr5994lp/driver/counter.cc
index 62ac778..98a2c4f 100644
--- a/src/arch/msp430fr5994lp/driver/counter.cc
+++ b/src/arch/msp430fr5994lp/driver/counter.cc
@@ -5,3 +5,14 @@
#endif
Counter counter;
+
+#ifndef __acweaving
+__attribute__((interrupt(TIMER2_A1_VECTOR))) void handle_timer2_overflow()
+{
+ if (TA2IV == 0x0e) {
+ if (counter.overflow < 255) {
+ counter.overflow++;
+ }
+ }
+}
+#endif