]> cloudbase.mooo.com Git - z180-stamp.git/commitdiff
System time: Init from rtc on startup, update in timer inerrupt.
authorLeo C <erbl259-lmu@yahoo.de>
Tue, 2 Dec 2014 10:45:40 +0000 (11:45 +0100)
committerLeo C <erbl259-lmu@yahoo.de>
Tue, 2 Dec 2014 10:45:40 +0000 (11:45 +0100)
avr/Tupfile
avr/main.c
avr/timer.c

index 6c406493579f87cc659329f45da62a199fd87f41..9fc073984f627f106b14835a9f7338d15e043d7b 100644 (file)
@@ -16,6 +16,9 @@ SRC           += $(FATFS) $(TOP)/fatfs/src/option/unicode.c
 #TODO: time lib
 SRC            += ../time/asctime_r.c ../time/gmtime_r.c ../time/mk_gmtime.c
 SRC            += ../time/print_lz.c ../time/isLeap.c
+SRC            += ../time/system_time.c ../time/set_system_time.c
+
+ASRC   += ../time/system_tick.S
 
 SRC_Z          = ../z180/hdrom.c
 
@@ -74,17 +77,26 @@ CFLAGS      += $(INCLUDES)
 
 CPPFLAGS += $(DEFS)
 
+#ASFLAGS += -Wa,-adhlns=$(<:.S=.lst),-gstabs
+ASFLAGS += -mmcu=$(MCU_TARGET) -x assembler-with-cpp $(ASFLAGS)
+
 # Linker flags
 LDFLAGS        += -Wl,--gc-sections
 LDFLAGS        += -Wl,--cref
 
+# Assemble: create object files from assembler source files.
+#.S.o:
+#      $(CC) -c $(ALL_ASFLAGS) $< -o $@
+
 
+!as = |> ^ AS %f^ $(CC) $(ASFLAGS) -c %f -o %o |> %B.o
 !cc = |> ^ CC %f^ $(CC) $(CFLAGS) $(CPPFLAGS) $(CFLAGS_%f) -c %f -o %o |> %B.o
 !LINK = |> ^ LINK %o^ $(LD) $(CFLAGS) $(LDFLAGS) -Wl,-Map=%O.map %f $(LDLIBS) -o %o |> | %O.map
 !OBJCOPY= |> ^ OBJCOPY %o^ $(OBJCOPY) -Oihex %f %o |>
 !OBJDUMP= |> ^ OBJDUMP %o^ $(OBJDUMP) -h -S %f > %o |> %O.lss
 !SIZE = |> ^ SIZE^ $(SIZE) %f |>
 
+: foreach $(ASRC) |> !as |>  {objs}
 : foreach $(SRC) | ../z180/hdrom.h |> !cc |>  {objs}
 : $(SRC_Z) |> !cc -D'const=const __flash' |> {objs}
 
index 7e832bf493a216e4392267e99c93336e2c90972d..8acf265b5b430f319780724655899aacb9ba2b64 100644 (file)
@@ -20,6 +20,8 @@
 #include "z180-serv.h"
 #include "spi.h"
 #include "gpio.h"
+#include "time.h"
+#include "rtc.h"
 
 static uint8_t mcusr;
 
@@ -132,6 +134,16 @@ int reset_reason_is_power_on(void)
        return (mcusr & _BV(PORF)) != 0;
 }
 
+static
+void setup_system_time(void)
+{
+       struct tm rtc_time;
+
+       rtc_get(&rtc_time);
+       rtc_time.tm_isdst = 0;
+       set_system_time(mk_gmtime(&rtc_time) );
+}
+
 /*--------------------------------------------------------------------------*/
 
 /* Stored value of bootdelay, used by autoboot_command() */
@@ -252,6 +264,7 @@ int main(void)
 #else
        i2c_init(CONFIG_SYS_I2C_CLOCK);
 #endif
+       setup_system_time();
 
        printf_P(PSTR("\nATMEGA1281+Z8S180 Stamp Monitor\n\n"));
 
index 7907bbad2811598048a1bed29833f18f5b9219de..e222e68792fa8d89527c9942b91cb638cbeae81f 100644 (file)
@@ -4,6 +4,7 @@
 #include "common.h"
 #include <avr/interrupt.h>
 #include <util/atomic.h>
+#include "time.h"
 #include "timer.h"
 
 /* timer interrupt/overflow counter */
@@ -18,7 +19,8 @@ uint32_t timestamp;
 ISR(TIMER3_COMPA_vect)
 {
        static int_fast8_t tick_10ms;
-       int_fast8_t i;
+       static int_fast8_t tick_1s;
+       int_fast8_t i, j;
 
        extern void disk_timerproc(void);
 
@@ -26,11 +28,18 @@ ISR(TIMER3_COMPA_vect)
 
        i = tick_10ms + 1;
        if (i == 10) {
-               i = 0;
                Stat |= S_10MS_TO;
 
                /* Drive timer procedure of low level disk I/O module */
                disk_timerproc();
+
+               j = tick_1s - 1;
+               if (j == 0) {
+                       system_tick();
+                       j = 100;
+               }
+               tick_1s = j;
+               i = 0;
        }
        tick_10ms = i;
 }