From 2253c912c86b5196e17657ee067abfc7afa4d652 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Mon, 11 Dec 2017 10:28:25 +0100 Subject: Add basic uptime getter, improve loop support --- src/arch/msp430fr5969lp/Makefile.inc | 2 +- src/arch/msp430fr5969lp/arch.cc | 35 ++++++++++++++++++++++++++++++++ src/arch/msp430fr5969lp/driver/uptime.cc | 9 ++++++++ 3 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 src/arch/msp430fr5969lp/driver/uptime.cc (limited to 'src/arch/msp430fr5969lp') diff --git a/src/arch/msp430fr5969lp/Makefile.inc b/src/arch/msp430fr5969lp/Makefile.inc index f4b96fe..81c8fdf 100644 --- a/src/arch/msp430fr5969lp/Makefile.inc +++ b/src/arch/msp430fr5969lp/Makefile.inc @@ -11,7 +11,7 @@ CXX = /opt/msp430/ti/gcc/bin/msp430-elf-g++ OBJCOPY = /opt/msp430/ti/gcc/bin/msp430-elf-objcopy TARGETS += src/arch/msp430fr5969lp/arch.cc src/arch/msp430fr5969lp/driver/gpio.cc -TARGETS += src/arch/msp430fr5969lp/driver/stdout.cc +TARGETS += src/arch/msp430fr5969lp/driver/stdout.cc src/arch/msp430fr5969lp/driver/uptime.cc OBJECTS = ${TARGETS:.cc=.o} diff --git a/src/arch/msp430fr5969lp/arch.cc b/src/arch/msp430fr5969lp/arch.cc index 19416e1..be821a6 100644 --- a/src/arch/msp430fr5969lp/arch.cc +++ b/src/arch/msp430fr5969lp/arch.cc @@ -16,10 +16,16 @@ void Arch::setup(void) // 16MHz DCO CSCTL0_H = CSKEY >> 8; CSCTL1 = DCORSEL | DCOFSEL_4; +#ifdef WITH_LOOP + CSCTL2 = SELA__LFXTCLK | SELS__DCOCLK | SELM__DCOCLK; +#else CSCTL2 = SELA__VLOCLK | SELS__DCOCLK | SELM__DCOCLK; +#endif CSCTL3 = DIVA__1 | DIVS__1 | DIVM__1; CSCTL0_H = 0; + +#ifdef WITH_LOOP // enable LXFT for RTC CSCTL0_H = CSKEY >> 8; CSCTL4 &= ~LFXTOFF; @@ -30,17 +36,46 @@ void Arch::setup(void) CSCTL0_H = 0; __delay_cycles(1000000); +#endif + + // 16MHz/16 -> ~1MHz timer + TA0CTL = TASSEL__SMCLK | ID__8 | MC__CONTINUOUS; + TA0EX0 = 1; + TA0CTL |= TACLR; + +#ifdef WITH_LOOP + + // 1s per wakeup for loop + TA1CTL = TASSEL__ACLK | ID__8 | MC__UP; + TA1EX0 = 0; + TA1CCR0 = 4096; + TA1CTL |= TACLR | TAIE; +#endif + //P1OUT = 0; //P4OUT = 0; } void Arch::idle_loop(void) { + __eint(); while (1); } Arch arch; +#ifdef WITH_LOOP + +extern void loop(); + +__attribute__((interrupt(TIMER1_A1_VECTOR))) __attribute__((wakeup)) void handle_timer0_overflow() +{ + if (TA1IV == 0x0e) { + loop(); + } +} + +#endif /* void uart_setup(void) { diff --git a/src/arch/msp430fr5969lp/driver/uptime.cc b/src/arch/msp430fr5969lp/driver/uptime.cc new file mode 100644 index 0000000..6d16441 --- /dev/null +++ b/src/arch/msp430fr5969lp/driver/uptime.cc @@ -0,0 +1,9 @@ +#include "driver/uptime.h" +#include + +uint32_t Uptime::get() +{ + return TA0R; +} + +Uptime uptime; -- cgit v1.2.3