summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--avr/Tupfile12
-rw-r--r--avr/main.c13
-rw-r--r--avr/timer.c13
3 files changed, 36 insertions, 2 deletions
diff --git a/avr/Tupfile b/avr/Tupfile
index 6c40649..9fc0739 100644
--- a/avr/Tupfile
+++ b/avr/Tupfile
@@ -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}
diff --git a/avr/main.c b/avr/main.c
index 7e832bf..8acf265 100644
--- a/avr/main.c
+++ b/avr/main.c
@@ -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"));
diff --git a/avr/timer.c b/avr/timer.c
index 7907bba..e222e68 100644
--- a/avr/timer.c
+++ b/avr/timer.c
@@ -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;
}