nvr: add support for UTC time sync

This commit is contained in:
David Hrdlička
2018-08-01 17:52:20 +02:00
parent 3a05287b45
commit a4f6bfde58
6 changed files with 16 additions and 8 deletions

View File

@@ -280,7 +280,7 @@ rtc_start(nvr_t *nvr)
struct tm tm;
/* Initialize the internal and chip times. */
if (enable_sync) {
if (enable_sync & TIME_SYNC_ENABLED) {
/* Use the internal clock's time. */
nvr_time_get(&tm);
rtc_time_set(nvr->regs, &tm);

View File

@@ -258,7 +258,7 @@ tc8521_start(nvr_t *nvr)
struct tm tm;
/* Initialize the internal and chip times. */
if (enable_sync) {
if (enable_sync & TIME_SYNC_ENABLED) {
/* Use the internal clock's time. */
nvr_time_get(&tm);
tc8521_time_set(nvr->regs, &tm);

View File

@@ -181,10 +181,13 @@ nvr_init(nvr_t *nvr)
/* Initialize the internal clock as needed. */
memset(&intclk, 0x00, sizeof(intclk));
if (enable_sync) {
if (enable_sync & TIME_SYNC_ENABLED) {
/* Get the current time of day, and convert to local time. */
(void)time(&now);
tm = localtime(&now);
if(enable_sync & TIME_SYNC_UTC)
tm = gmtime(&now);
else
tm = localtime(&now);
/* Set the internal clock. */
nvr_time_set(tm);

View File

@@ -55,6 +55,11 @@
#define RTC_DCB(x) ((((x) & 0xf0) >> 4) * 10 + ((x) & 0x0f))
#define RTC_BCDINC(x,y) RTC_BCD(RTC_DCB(x) + y)
/* Time sync options */
#define TIME_SYNC_DISABLED 0
#define TIME_SYNC_ENABLED 1
#define TIME_SYNC_UTC 2
/* Define a generic RTC/NVRAM device. */
typedef struct _nvr_ {

View File

@@ -554,7 +554,7 @@ nvr_write(uint16_t addr, uint8_t val, void *priv)
if ((local->addr < RTC_REGA) || ((local->cent != 0xff) && (local->addr == local->cent))) {
if ((local->addr != 1) && (local->addr != 3) && (local->addr != 5)) {
if ((old != val) && !enable_sync) {
if ((old != val) && !(enable_sync & TIME_SYNC_ENABLED)) {
/* Update internal clock. */
time_get(nvr, &tm);
nvr_time_set(&tm);
@@ -630,7 +630,7 @@ nvr_start(nvr_t *nvr)
struct tm tm;
/* Initialize the internal and chip times. */
if (enable_sync) {
if (time_sync & TIME_SYNC_ENABLED) {
/* Use the internal clock's time. */
nvr_time_get(&tm);
time_set(nvr, &tm);

View File

@@ -202,7 +202,7 @@ win_settings_init(void)
temp_dynarec = cpu_use_dynarec;
#endif
temp_fpu = enable_external_fpu;
temp_sync = enable_sync;
temp_sync = enable_sync & TIME_SYNC_ENABLED;
/* Video category */
temp_gfxcard = gfxcard;
@@ -305,7 +305,7 @@ win_settings_changed(void)
i = i || (temp_dynarec != cpu_use_dynarec);
#endif
i = i || (temp_fpu != enable_external_fpu);
i = i || (temp_sync != enable_sync);
i = i || (temp_sync != (enable_sync & TIME_SYNC_ENABLED));
/* Video category */
i = i || (gfxcard != temp_gfxcard);