MBusLightSensor/src/time.cpp

74 lines
981 B
C++
Raw Normal View History

/*
* time.c
*
* Created on: 20.05.2014
* Author: wn
*/
#include <msp430g2553.h>
#include <isr_compat.h>
#include <stdint.h>
2014-10-03 17:27:42 +02:00
#include "time.h"
volatile unsigned long timestamp;
2014-10-03 17:27:42 +02:00
Uptime uptime;
ISR(TIMER0_A0, TA0_ISR) {
static uint8_t state = 0;
timestamp++;
switch (state) {
case 0:
P1OUT = BIT0;
state = 1;
break;
case 1:
P1OUT = BIT6;
state = 0;
break;
default:
state = 0;
}
}
void timeInit() {
timestamp = 0;
P1DIR |= BIT6 | BIT0;
P1OUT = 0;
2014-10-03 16:52:48 +02:00
TACCR0 = 1024;
TACCTL0 = CCIE;
2014-10-03 16:52:48 +02:00
TACTL = MC_1 | ID_3 | TASSEL_1 | TACLR;
}
unsigned long millis() {
return timestamp;
}
2014-10-03 17:27:42 +02:00
Uptime::Uptime() : m_seconds(0), m_minutes(0), m_hours(0), m_days(0) {
}
void Uptime::incOneSecond() {
m_seconds++;
if (m_seconds >= 60) {
m_seconds -= 60;
m_minutes++;
if (m_minutes >= 60) {
m_minutes -= 60;
m_hours++;
if (m_hours >= 24) {
m_hours -= 24;
m_days++;
}
}
}
}