Skip to content
Snippets Groups Projects
Commit 2253c912 authored by Birte Kristina Friesel's avatar Birte Kristina Friesel
Browse files

Add basic uptime getter, improve loop support

parent 540974f8
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
#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
#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
#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
......@@ -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}
......
#include "driver/uptime.h"
extern "C" {
#include "osapi.h"
#include "user_interface.h"
}
uint32_t Uptime::get()
{
return system_get_time();
}
Uptime uptime;
......@@ -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}
......
......@@ -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)
{
......
#include "driver/uptime.h"
#include <msp430.h>
uint32_t Uptime::get()
{
return TA0R;
}
Uptime uptime;
......@@ -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}
......
#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;
#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();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment