From fd1aabd0417bef53e7ff54df52eba80be5494d56 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Fri, 12 Oct 2018 10:44:11 +0200 Subject: half-baked timer implementation for MSP430 and Arduino --- include/arch/msp430fr5969lp/driver/timer.h | 40 ++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 include/arch/msp430fr5969lp/driver/timer.h (limited to 'include/arch/msp430fr5969lp') diff --git a/include/arch/msp430fr5969lp/driver/timer.h b/include/arch/msp430fr5969lp/driver/timer.h new file mode 100644 index 0000000..34feb12 --- /dev/null +++ b/include/arch/msp430fr5969lp/driver/timer.h @@ -0,0 +1,40 @@ +#include + +#define ON_TIMER_INTERRUPT_head __attribute__((interrupt(TIMER0_A1_VECTOR))) __attribute__((wakeup)) void handle_timer0_overflow() { if (TA0IV == 0x0e) { +#define ON_TIMER_INTERRUPT_tail } } + +class Timer { + private: + Timer(const Timer ©); + + public: + Timer() {} + + inline void setup_khz(uint16_t const frequency) { + TA0CTL = TASSEL__SMCLK | ID__8 | MC__UP; + TA0EX0 = 1; + TA0CCR0 = 1000 / frequency; + TA0CTL |= TACLR; + } + + inline void setup_hz(uint16_t const frequency) { + TA0CTL = TASSEL__SMCLK | ID__8 | MC__UP; + TA0EX0 = 1; + TA0CCR0 = 1000000 / frequency; + TA0CTL |= TACLR; + } + + inline void start(unsigned char const interrupt) { + if (interrupt) { + TA0CTL |= TACLR | TAIE; + } else { + TA0CTL |= TACLR; + } + } + + inline void stop() { + TA0CTL = 0; + } +}; + +extern Timer timer; -- cgit v1.2.3