summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2017-12-11 10:28:25 +0100
committerDaniel Friesel <derf@finalrewind.org>2017-12-11 10:28:25 +0100
commit2253c912c86b5196e17657ee067abfc7afa4d652 (patch)
treec10d2722e0c44355bded196209bfba6d5827d06c
parent540974f8f109aa8874f032eddf59819c76eb018e (diff)
Add basic uptime getter, improve loop support
-rw-r--r--Makefile2
-rw-r--r--include/esp8266/driver/uptime.h17
-rw-r--r--include/msp430fr5969lp/driver/uptime.h17
-rw-r--r--include/posix/driver/uptime.h17
-rw-r--r--src/arch/esp8266/Makefile.inc2
-rw-r--r--src/arch/esp8266/driver/uptime.cc12
-rw-r--r--src/arch/msp430fr5969lp/Makefile.inc2
-rw-r--r--src/arch/msp430fr5969lp/arch.cc35
-rw-r--r--src/arch/msp430fr5969lp/driver/uptime.cc9
-rw-r--r--src/arch/posix/Makefile.inc2
-rw-r--r--src/arch/posix/driver/uptime.cc11
-rw-r--r--src/os/main.cc6
12 files changed, 128 insertions, 4 deletions
diff --git a/Makefile b/Makefile
index 849411d..6440a1b 100644
--- a/Makefile
+++ b/Makefile
@@ -7,7 +7,7 @@ CXXFLAGS = -std=c++14
TARGETS = src/os/main.cc src/os/object/cpp_helpers.cc src/os/object/outputstream.cc
-ifeq (${arduino}, 1)
+ifeq (${loop}, 1)
COMMON_FLAGS += -DWITH_LOOP
endif
diff --git a/include/esp8266/driver/uptime.h b/include/esp8266/driver/uptime.h
new file mode 100644
index 0000000..7da10cb
--- /dev/null
+++ b/include/esp8266/driver/uptime.h
@@ -0,0 +1,17 @@
+#ifndef UPTIME_H
+#define UPTIME_H
+
+#include "c_types.h"
+
+class Uptime {
+ private:
+ Uptime(const Uptime &copy);
+
+ public:
+ Uptime () {}
+ uint32_t get();
+};
+
+extern Uptime uptime;
+
+#endif
diff --git a/include/msp430fr5969lp/driver/uptime.h b/include/msp430fr5969lp/driver/uptime.h
new file mode 100644
index 0000000..f18a7fe
--- /dev/null
+++ b/include/msp430fr5969lp/driver/uptime.h
@@ -0,0 +1,17 @@
+#ifndef UPTIME_H
+#define UPTIME_H
+
+#include <stdint.h>
+
+class Uptime {
+ private:
+ Uptime(const Uptime &copy);
+
+ public:
+ Uptime () {}
+ uint32_t get();
+};
+
+extern Uptime uptime;
+
+#endif
diff --git a/include/posix/driver/uptime.h b/include/posix/driver/uptime.h
new file mode 100644
index 0000000..c92ccf1
--- /dev/null
+++ b/include/posix/driver/uptime.h
@@ -0,0 +1,17 @@
+#ifndef UPTIME_H
+#define UPTIME_H
+
+#include <stdint.h>
+
+class Uptime {
+ private:
+ Uptime(const Uptime &copy);
+
+ public:
+ Uptime () {}
+ uint64_t get();
+};
+
+extern Uptime uptime;
+
+#endif
diff --git a/src/arch/esp8266/Makefile.inc b/src/arch/esp8266/Makefile.inc
index 9a08678..3b1c8cb 100644
--- a/src/arch/esp8266/Makefile.inc
+++ b/src/arch/esp8266/Makefile.inc
@@ -17,7 +17,7 @@ CXXFLAGS = -std=c++11
LDFLAGS += -nostdlib -Wl,--no-check-sections -u call_user_start -Wl,-static
TARGETS += src/arch/esp8266/arch.cc src/arch/esp8266/driver/gpio.cc
-TARGETS += src/arch/esp8266/driver/stdout.cc
+TARGETS += src/arch/esp8266/driver/stdout.cc src/arch/esp8266/driver/uptime.cc
OBJECTS = ${TARGETS:.cc=.o}
diff --git a/src/arch/esp8266/driver/uptime.cc b/src/arch/esp8266/driver/uptime.cc
new file mode 100644
index 0000000..51cc617
--- /dev/null
+++ b/src/arch/esp8266/driver/uptime.cc
@@ -0,0 +1,12 @@
+#include "driver/uptime.h"
+extern "C" {
+#include "osapi.h"
+#include "user_interface.h"
+}
+
+uint32_t Uptime::get()
+{
+ return system_get_time();
+}
+
+Uptime uptime;
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 <msp430.h>
+
+uint32_t Uptime::get()
+{
+ return TA0R;
+}
+
+Uptime uptime;
diff --git a/src/arch/posix/Makefile.inc b/src/arch/posix/Makefile.inc
index 9dd723d..7553fd4 100644
--- a/src/arch/posix/Makefile.inc
+++ b/src/arch/posix/Makefile.inc
@@ -5,7 +5,7 @@ CXX = g++
INCLUDES += -Iinclude/posix
TARGETS += src/arch/posix/arch.cc src/arch/posix/driver/gpio.cc
-TARGETS += src/arch/posix/driver/stdout.cc
+TARGETS += src/arch/posix/driver/stdout.cc src/arch/posix/driver/uptime.cc
OBJECTS = ${TARGETS:.cc=.o}
diff --git a/src/arch/posix/driver/uptime.cc b/src/arch/posix/driver/uptime.cc
new file mode 100644
index 0000000..040b51c
--- /dev/null
+++ b/src/arch/posix/driver/uptime.cc
@@ -0,0 +1,11 @@
+#include "driver/uptime.h"
+#include <time.h>
+
+uint64_t Uptime::get()
+{
+ struct timespec ts;
+ clock_gettime(CLOCK_REALTIME, &ts);
+ return (uint64_t)ts.tv_nsec + (1000000ULL * ((uint64_t)ts.tv_sec % 256));
+}
+
+Uptime uptime;
diff --git a/src/os/main.cc b/src/os/main.cc
index 4509301..740309b 100644
--- a/src/os/main.cc
+++ b/src/os/main.cc
@@ -1,6 +1,7 @@
#include "arch.h"
#include "driver/gpio.h"
#include "driver/stdout.h"
+#include "driver/uptime.h"
/*
void check_command(unsigned char argc, char** argv)
@@ -88,6 +89,7 @@ void check_command(unsigned char argc, char** argv)
void loop(void)
{
gpio.led_toggle(1);
+ kout << dec << uptime.get() << endl;
}
int main(void)
@@ -99,6 +101,10 @@ int main(void)
gpio.led_on(0);
kout << "Hello, World!" << endl;
kout << "Test, World!" << endl;
+ kout << dec << uptime.get() << endl;
+ kout << dec << uptime.get() << endl;
+ kout << dec << uptime.get() << endl;
+ kout << dec << uptime.get() << endl;
arch.idle_loop();