Browse Source

time: don't sync as often, but always sync after NTP event

Only synchronize the RTC every 511 seconds; every 17 is crazy and
probably just risks causing problems.

However, always sync the RTC immediately after an NTP synchronization
is complete.
H. Peter Anvin 2 years ago
parent
commit
aec0a99499

+ 2 - 0
esp32/max80/fpga.h

@@ -11,6 +11,8 @@ extern_c int fpga_reset(void);
 extern_c esp_err_t fpga_service_init(void);
 extern_c void fpga_service_enable(bool);
 
+extern_c void fpga_timesync_trigger(void);
+
 #define FPGA_CMD_IRQ(x)	((x) << 0)
 #define FPGA_CMD_ACK(x)	((x) << 2)
 #define FPGA_CMD_WR	(0 << 4)

+ 5 - 4
esp32/max80/fpgasvc.c

@@ -19,6 +19,8 @@
 #define FPGA_PRIORITY	10
 #define FPGA_SVC_STACK	4096
 
+#define RTC_TIMESYNC_PERIOD (511*configTICK_RATE_HZ)
+
 static spi_bus_config_t spi_bus_config = {
     .data0_io_num    = PIN_FPGA_IO0,
     .data1_io_num    = PIN_FPGA_IO1,
@@ -108,9 +110,8 @@ static void ARDUINO_ISR_ATTR fpga_interrupt(void)
     fpga_notify_from_isr(NOTIFY_FPGA);
 }
 
-static void fpga_timesync_trigger(TimerHandle_t t)
+void fpga_timesync_trigger(void)
 {
-    (void)t;
     fpga_notify_from_task(NOTIFY_TIMESYNC);
 }
 
@@ -155,8 +156,8 @@ esp_err_t fpga_service_init(void)
 	return ESP_FAIL;
 
     fpga_timesync_timer =
-      null_check(xTimerCreate("rtc_sync", 17*configTICK_RATE_HZ,
-			      pdTRUE, NULL, fpga_timesync_trigger));
+      null_check(xTimerCreate("rtc_sync", RTC_TIMESYNC_PERIOD, pdTRUE, NULL,
+			      (TimerCallbackFunction_t)fpga_timesync_trigger));
 
     esplink_init();
 

+ 4 - 0
esp32/max80/time.c

@@ -1,5 +1,6 @@
 #include "common.h"
 #include "config.h"
+#include "fpga.h"
 
 void print_time(const char *msg, const struct timeval *tv)
 {
@@ -27,4 +28,7 @@ void time_net_sync(const struct timeval *tv)
 	    print_time("[SNTP] Time synchronized: ", tv);
 	}
     }
+
+    if (synced)
+      fpga_timesync_trigger();	/* Push time downstream to FPGA/RTC */
 }

BIN
esp32/output/max80.ino.bin


+ 2 - 2
fpga/max80.qpf

@@ -19,12 +19,12 @@
 #
 # Quartus Prime
 # Version 21.1.0 Build 842 10/21/2021 SJ Lite Edition
-# Date created = 00:20:57  May 17, 2022
+# Date created = 22:34:16  May 17, 2022
 #
 # -------------------------------------------------------------------------- #
 
 QUARTUS_VERSION = "21.1"
-DATE = "00:20:57  May 17, 2022"
+DATE = "22:34:16  May 17, 2022"
 
 # Revisions
 

BIN
fpga/output/bypass.rbf.gz


BIN
fpga/output/bypass.rpd.gz


BIN
fpga/output/bypass.svf.gz


BIN
fpga/output/bypass.xsvf.gz


BIN
fpga/output/v1.fw


BIN
fpga/output/v1.jic


BIN
fpga/output/v1.rbf.gz


BIN
fpga/output/v1.rpd.gz


BIN
fpga/output/v1.sof


BIN
fpga/output/v1.svf.gz


BIN
fpga/output/v1.xsvf.gz


BIN
fpga/output/v2.fw


BIN
fpga/output/v2.jic


BIN
fpga/output/v2.rbf.gz


BIN
fpga/output/v2.rpd.gz


BIN
fpga/output/v2.sof


BIN
fpga/output/v2.svf.gz


BIN
fpga/output/v2.xsvf.gz