[PATCH] Proper RTC emulation and time sync stuff

Discussion of development and patch submission.
Post Reply
Battler
Posts: 793
Joined: Sun 06 Jul, 2014 7:05 pm

[PATCH] Proper RTC emulation and time sync stuff

Post 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.
Attachments
rtc_patch.rar
(8.77 KiB) Downloaded 294 times
Battler
Posts: 793
Joined: Sun 06 Jul, 2014 7:05 pm

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

Post 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.
Attachments
rtc_patch.rar
(8.77 KiB) Downloaded 274 times
Battler
Posts: 793
Joined: Sun 06 Jul, 2014 7:05 pm

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

Post 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.
Attachments
rtc_patch.rar
(8.76 KiB) Downloaded 274 times
Battler
Posts: 793
Joined: Sun 06 Jul, 2014 7:05 pm

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

Post 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.
Attachments
rtc_patch.rar
(9.12 KiB) Downloaded 275 times
Battler
Posts: 793
Joined: Sun 06 Jul, 2014 7:05 pm

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

Post by Battler »

Updated patch attached with onesec update stuff done the way SarahWalker suggested.
Attachments
rtc_patch.rar
(12.77 KiB) Downloaded 272 times
Battler
Posts: 793
Joined: Sun 06 Jul, 2014 7:05 pm

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

Post by Battler »

Another update - forgot to change the new timer's counter to int for the mainline. Updated patch attached.
Attachments
rtc_patch.rar
(12.77 KiB) Downloaded 272 times
User avatar
SarahWalker
Site Admin
Posts: 2054
Joined: Thu 24 Apr, 2014 4:18 pm

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

Post by SarahWalker »

Committed to rev 525.
Post Reply