From 273bb36d589d283b7bd1098fe699c92f97322cdf Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Mon, 25 Oct 2021 08:21:33 -0500 Subject: [PATCH] build for arduino this, or something very close to it, did actually set the time once but since then it stopped even synching to the wwvb pps. --- Makefile | 31 ++++++++++++++++ wwvbdecode.cc | 99 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 130 insertions(+) diff --git a/Makefile b/Makefile index d76f3e7..be97e69 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,36 @@ CXX := g++ CFLAGS := -Os -g -Wall +MCU := atmega328 +AMCU := m328p +AVRDUDE := avrdude -p${AMCU} -c arduino -P /dev/ttyUSB0 -b57600 + +default: wwvbdecode wwvb.elf + +ifeq ($(shell [ -e /dev/ttyUSB0 ] && echo 1),1) +default: program-stamp +endif + +program-stamp: program + touch program-stamp + +program: wwvb.hex + ${AVRDUDE} -q -q -D -U flash:w:$<:i + ${AVRDUDE} -q -q -D -U eeprom:w:0x75,0x6e,0x73,0x65,0x74,0xd,0xa,0x0:m + + wwvbdecode: wwvbdecode.cc $(CXX) $(CFLAGS) -o $@ $< + +AVR-CC := avr-gcc +AVR-CFLAGS := -ffreestanding -funit-at-a-time -finline-functions-called-once \ + -fno-exceptions -fno-rtti -mmcu=${MCU} -O3 -g + +wwvb.elf: wwvbdecode.cc + $(AVR-CC) $(AVR-CFLAGS) -o $@ $< + avr-size $@ + +%.hex: %.elf + avr-objcopy -O ihex -R eeprom $< $@ + +# vim:noet:ts=8:sts=8:sw=8 diff --git a/wwvbdecode.cc b/wwvbdecode.cc index eff27c1..19332f6 100644 --- a/wwvbdecode.cc +++ b/wwvbdecode.cc @@ -384,5 +384,104 @@ int main() { wwvb_receive_loop(c == '1'); } printf("failed to set time\n"); +} +#else +#include +#include +#include +#include + +#define LED (5) +#define WWVB (0) + +#define CYCLES_HIGH 16000 + +int uptime; + +char buf[80]; +void set_time(const wwvb_t &t) { + snprintf(buf, sizeof(buf), + "set time %d/%03d %d:%02d:%02d ly=%d ls=%d dst=%d uptime=%d pol=%d\n", + t.year + 2000, t.yday, t.hour, t.minute, t.second, t.ls, t.ly, t.dst, + uptime, wwvb_polarity); + eeprom_write_block(buf, 0, strlen(buf)+1); + + // set LED on solid + PORTB |= (1< + UBRR0H = UBRRH_VALUE; + UBRR0L = UBRRL_VALUE; + #if USE_2X + UCSR0A |= (1 << U2X0); + #else + UCSR0A &= ~(1 << U2X0); + #endif + DDRD = (1<<1); // enable TXD as output + + // Set up the LED as output + DDRB = (1<