MC32 BackupRtc Routine whitepaper

Article ID: 92884153

Question


 
How can the default date, time and time zone can be modified from the value the device is shipped?

Answer


 

When the device is left without a battery for a long period of time the Real Time Clock (RTC) may default to an unwanted value.
RTCBackup will discard an TimeZone change with regkey and or an SNTP thread on coldboot.

The RTC is maintained by a supercap which has a limited backup time.  In addition to the supercap the RTC information is maintained in the file Application\System\BackupRtc\BackupRtc.ini.  The default file can be replaced during a cold boot so a custom default date, time and timezone can be set.

The BackupRtc.ini file uses the following format and can be created or edited using a text editor like ‘notepad.exe’:

[Latest Rtc]
Year=2013
Month=02
Day=02
Hour=02
Minute=02
Second=02

[Latest Time Zone Title]
Israel Standard Time         

[Latest Time Zone Info]
88 ff ff ff 4a 00 65 00 72 00 75 00 73 00 61 00 6c 00 65 00 6d 00 20 00 53
00 74 00 61 00 6e 00 64 00 61 00 72 00 64 00 20 00 54 00 69 00 6d 00 65 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0a 00 00 00 05
00 02 00 00 00 00 00 00 00 00 00 00 00 4a 00 65 00 72 00 75 00 73 00 61 00
6c 00 65 00 6d 00 20 00 44 00 61 00 79 00 6c 00 69 00 67 00 68 00 74 00 20
00 54 00 69 00 6d 00 65 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 03 00 05 00 05 00 02 00 00 00 00 00 00 00 c4 ff ff ff


- The information associated with ‘[Latest Rtc]‘ section should be self explanatory.
 - The value for ‘[Latest Time Zone Title]‘ is the Microsoft name of the time zone.  This can be found in the registry location [HKEY_LOCAL_MACHINE\Time Zones\<time zone name>], which may be different the name displayed in the Date & Time GUI.  For example the time zone name ‘Israel Standard Time’ is found in the registry key:

[HKEY_LOCAL_MACHINE\Time Zones\Israel Standard Time]
"ID"=dword:000005a0
"Display"="(UTC+02:00) Jerusalem"

- The value for ‘[Latest Time Zone Info]’ is found in the registry key [HKEY_LOCAL_MACHINE\Time]"TimeZoneInformation".  For example the time zone information for the same ‘Israel Standard Time’ is:

[HKEY_LOCAL_MACHINE\Time]
"TZID"=dword:000005a0
"TimeZoneInformation"=hex:88 ff ff ff 4a 00 65 00 72 00 75 00 73 00 61 00 6c 00 65 00 6d 00 20 00 53
 00 74 00 61 00 6e 00 64 00 61 00 72 00 64 00 20 00 54 00 69 00 6d 00 65 00
 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0a 00 00 00 05
 00 02 00 00 00 00 00 00 00 00 00 00 00 4a 00 65 00 72 00 75 00 73 00 61 00
 6c 00 65 00 6d 00 20 00 44 00 61 00 79 00 6c 00 69 00 67 00 68 00 74 00 20
 00 54 00 69 00 6d 00 65 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
 00 00 00 00 03 00 05 00 05 00 02 00 00 00 00 00 00 00 c4 ff ff ff


Once the ‘BackupRtc.ini’ has been created copy it to the \Application drive on the device.  In addition to the ‘BackupRtc.ini’ a .cpy file is needed to replace the default ‘BackupRtc.ini’.  Create a text file with the file name ‘BackupRtc.cpy’ with the following information in the file:

\Application\BackupRtc.ini            >         \Application\System\BackupRtc\BackupRtc.ini

This will copy the newly created ‘BackupRtc.ini’ to the location where the device saves the RTC information to file when the device cold boots.

Note
The format of the ‘BackupRtc.ini’ file very important.  It should not contain any extra characters.
The date and time are only restored from file if the RTC has been reset.