From cd7ee540291f7412153ee9fa1e785cc859c589fe Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Fri, 8 Mar 2019 11:53:33 +0100 Subject: msp430fr5969 counter: Track overflows --- include/arch/msp430fr5969lp/driver/counter.h | 10 +++++++--- src/arch/msp430fr5969lp/driver/counter.cc | 11 +++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/include/arch/msp430fr5969lp/driver/counter.h b/include/arch/msp430fr5969lp/driver/counter.h index b95aba1..0d7e140 100644 --- a/include/arch/msp430fr5969lp/driver/counter.h +++ b/include/arch/msp430fr5969lp/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; + __dint(); value = TA2R; + TA2CTL = 0; } }; diff --git a/src/arch/msp430fr5969lp/driver/counter.cc b/src/arch/msp430fr5969lp/driver/counter.cc index 62ac778..cd10b5c 100644 --- a/src/arch/msp430fr5969lp/driver/counter.cc +++ b/src/arch/msp430fr5969lp/driver/counter.cc @@ -1,7 +1,18 @@ +#include "arch.h" #include "driver/counter.h" +#include "driver/gpio.h" #if defined(TIMER_CYCLES) #warn "timer_cycles and counter are mutually exclusive. Expect odd behaviour." #endif Counter counter; + +__attribute__((interrupt(TIMER2_A1_VECTOR))) void handle_timer2_overflow() +{ + if (TA2IV == 0x0e) { + if (counter.overflow < 255) { + counter.overflow++; + } + } +} -- cgit v1.2.3