summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Franke <nobody@nowhere.ws>2012-04-10 23:56:27 +0200
committerChristian Franke <nobody@nowhere.ws>2012-04-10 23:56:27 +0200
commitf714cacefc9a04fbae7249cc4b707a27cedabc36 (patch)
tree4ca878c493b94205eea8bd298501b862b58b7816
parent313db8238b0014df203cb3c36102928087a32af8 (diff)
Decode and display flags
-rw-r--r--clock.c32
-rw-r--r--clock.h8
-rw-r--r--dcf77.c18
-rw-r--r--main.c18
-rw-r--r--timebase.c2
5 files changed, 51 insertions, 27 deletions
diff --git a/clock.c b/clock.c
index 3068816..270edff 100644
--- a/clock.c
+++ b/clock.c
@@ -15,31 +15,42 @@
struct time data time;
-u8 code MDAYS[] = {
+const u8 code MDAYS[] = {
29, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
+u8 is_cet(void)
+{
+ return ((time.flags & FLAG_CET) && !(time.flags & FLAG_CEST));
+}
+
+u8 is_cest(void)
+{
+ return ((time.flags & FLAG_CEST) && !(time.flags & FLAG_CET));
+}
void clock(void)
{
u8 i;
time.second++;
- if( time.second == 60 ){
+ if( time.second >= 60 ){
+ if (time.flags & FLAG_LEAP_SECOND && time.second == 60) {
+ return;
+ }
time.second = 0;
timeflags = 1<<ONE_MINUTE; // to correct deviation per minute
time.minute++;
if( time.minute == 60 ){
time.minute = 0;
time.hour++;
- switch( time.hour ){
- case 24:
+ if (time.hour == 24) {
time.hour = 0;
time.day++;
time.wday++;
if( time.wday == 8 )
time.wday = 1;
i = time.month;
- if( i == 2 && (time.year & 3) == 0 ) // leap year
+ if( i == 2 && !(time.year % 4) ) // leap year
i = 0;
if( LPM(MDAYS+i) < time.day ){
time.day = 1;
@@ -51,9 +62,14 @@ void clock(void)
time.year = 0; // next century
}
}
- break;
-// case 2:
-// case 3: summertime(); break;
+ }
+ if (time.flags & FLAG_SUMMERTIME_PENDING) {
+ if (is_cet() && time.hour == 2) {
+ time.hour = 3;
+ }
+ if (is_cest() && time.hour == 3) {
+ time.hour = 2;
+ }
}
}
}
diff --git a/clock.h b/clock.h
index 51a7a59..9c7e196 100644
--- a/clock.h
+++ b/clock.h
@@ -1,6 +1,11 @@
#ifndef _CLOCK_H
#define _CLOCK_H
+#define FLAG_SUMMERTIME_PENDING 1
+#define FLAG_CEST 2
+#define FLAG_CET 4
+#define FLAG_LEAP_SECOND 8
+
struct time {
u8 second;
u8 minute;
@@ -9,6 +14,7 @@ struct time {
u8 wday;
u8 month;
u8 year;
+ u8 flags;
};
extern struct time time;
@@ -16,5 +22,7 @@ extern struct time time;
void display_date(void);
void display_time(void);
void clock( void );
+u8 is_cet(void);
+u8 is_cest(void);
#endif /* _CLOCK_H */
diff --git a/dcf77.c b/dcf77.c
index 91ae618..8cc385e 100644
--- a/dcf77.c
+++ b/dcf77.c
@@ -14,7 +14,8 @@
#include "dcf77.h"
- u8 code BITNO[] = {
+const u8 code BITNO[] = {
+ 0x60, 0x61, 0x62, 0x63, 0x68, // flags
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, // minute
0xFF, // parity
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, // hour
@@ -24,7 +25,7 @@
0x40, 0x41, 0x42, 0x43, 0x44, // month
0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, // year
0xFF }; // parity
- u8 code BMASK[] = { 1, 2, 4, 8, 10, 20, 40, 80 };
+const u8 code BMASK[] = { 1, 2, 4, 8, 10, 20, 40, 80, 0 };
struct time newtime;
@@ -39,13 +40,13 @@ void decode_dcf77( u8 pulse )
u8 i;
u8 *d;
- i = newtime.second - 21;
+ i = newtime.second - 16;
if( i >= sizeof( BITNO )) // only bit 21 ... 58
return;
parity ^= pulse; // calculate parity
i = LPM(&BITNO[i]);
- if( i == 0xFF ){ // test parity
- if( parity )
+ if( i & 0x08 ){ // test parity
+ if( (i & 0x80) && parity )
dcf77error = 1;
parity = 0;
return;
@@ -81,13 +82,8 @@ void scan_dcf77( void )
if( dcf77error == 0 && newtime.second == 59 ){
synchronize = 0xFF;
sync_sec();
+ time = newtime;
time.second = 0;
- time.minute = newtime.minute;
- time.hour = newtime.hour;
- time.wday = newtime.wday;
- time.day = newtime.day;
- time.month = newtime.month;
- time.year = newtime.year;
}
newtime.second = 0;
dcf77error = 0;
diff --git a/main.c b/main.c
index cd9666a..c5e4bd2 100644
--- a/main.c
+++ b/main.c
@@ -37,7 +37,8 @@ enum stepstate {
} stepstate = STEP_INACTIVE;
const char PROGMEM disp[2] = {'_', '+'};
-const char PROGMEM status[24] = "normalsync adj + adj - ";
+const char PROGMEM status[8] = "oksya+a-";
+const char PROGMEM zone[4] = "?12?";
const char PROGMEM cksumfail[] = "cksum fail";
static void puttwo(uint8_t arg)
@@ -63,15 +64,18 @@ static void puttime(void)
puttwo(time.second);
lcd_line2();
+ lcd_put(time.flags & FLAG_SUMMERTIME_PENDING ? '!' : ' ');
+ lcd_put(zone[is_cet() + (is_cest() << 1)]);
+ lcd_put(time.flags & FLAG_LEAP_SECOND ? '!' : ' ');
+
msg = &status[0];
if (time.year <= 10)
- msg = &status[6];
+ msg = &status[2];
if (~PINB & (1 << B_SW_FRWD))
- msg = &status[12];
+ msg = &status[4];
if (~PINB & (1 << B_SW_BACK))
- msg = &status[18];
-
- lcd_puts(msg, 6);
+ msg = &status[6];
+ lcd_puts(msg, 2);
lcd_put(__LPM(&disp[stepstate]));
puttwo(ext_hour);
puttwo(ext_minute);
@@ -182,7 +186,7 @@ static void perform(void)
extern void __vectors(void) __attribute__((noreturn));
__attribute__ ((noreturn))
-SIGNAL (SIG_ANA_COMP)
+SIGNAL (ANA_COMP_vect)
{
PORTA = 0xff;
diff --git a/timebase.c b/timebase.c
index ee58bf1..ea8f8b9 100644
--- a/timebase.c
+++ b/timebase.c
@@ -26,7 +26,7 @@ void timebase_init( void )
extern uint8_t waitctr;
-SIGNAL (SIG_OVERFLOW0)
+SIGNAL (TIMER0_OVF0_vect)
{
static u8 dcf77_time, old_dcf77;
// DCF77 receive