Page 1 of 1

[PATCH] Proper RTC emulation and time sync stuff

Posted: Fri 08 Jul, 2016 11:56 pm
by Battler
Based on this PCem pull request by Mahod, that has these changes:
- Replaces linux-time and win-time with rtc, making future changes simpler;
- Adds RTC binary and 12-hour modes;
- Adds RTC century register;
- Improves readability of nvr.c by replacing literals with enums.

My patch takes his work and improves on it further, with these changes:
- Changes the NVR one second ticker to work at 32768 Hz per the datasheet instead of 100 Hz and set the update ended flag at update end (73 ticks / 244+1984 µs after the one second hit);
- Changes the register A bit 7 hack to proper setting of the bit at second hit and clearing at update end;
- Adds alarm support;
- Adds ability to disable time synchronization with host (enabled by default) and use the internal clock instead that is updated when the date and time NVR registers are written to;
- Makes the date and time NVR registers initialized to sane values (1980-01-01 00:00:00) if the NVR is being initialized from scratch and time synchronization is disabled.

The patch is attached. A huge thanks goes to Mahod for both his original patch and bearing with me as I was researching the RTC stuff, as well as for making me think in order to make my internal clock state stuff less complex.

Re: [PATCH] Proper RTC emulation and time sync stuff

Posted: Mon 11 Jul, 2016 12:34 am
by Battler
An updated patch is attached, with the following changes:
- Fixed the condition at which the internal clock state is updated from the registers;
- Removed spurious second instance of register value setting that was preventing the clock registers from being updated;
- Moved getnvrtime() to occur at update end, before the flag is cleared.

Re: [PATCH] Proper RTC emulation and time sync stuff

Posted: Mon 11 Jul, 2016 4:34 am
by Battler
I think there was a risk of time structure related resource leak with the previous patch so attached is a patch that mitigates that.

Re: [PATCH] Proper RTC emulation and time sync stuff

Posted: Mon 11 Jul, 2016 4:45 am
by Battler
Another update. Saves NVR on exit, fatal, and before any kind of menu or configuration change triggered reset, rather than every second. Should improve performance and reduce disk writes compared to the previous patch.

Re: [PATCH] Proper RTC emulation and time sync stuff

Posted: Mon 18 Jul, 2016 9:22 pm
by Battler
Updated patch attached with onesec update stuff done the way SarahWalker suggested.

Re: [PATCH] Proper RTC emulation and time sync stuff

Posted: Mon 18 Jul, 2016 10:04 pm
by Battler
Another update - forgot to change the new timer's counter to int for the mainline. Updated patch attached.

Re: [PATCH] Proper RTC emulation and time sync stuff

Posted: Tue 19 Jul, 2016 7:39 pm
by SarahWalker
Committed to rev 525.