Kernal clock_get_date_time() timezone?

If you have feature requests, this is the place to post them. Please note your idea may already be something we have already discussed and decided against, or something we are working on privately, and we cannot be held responsible for any similarities in such instance. Whilst we cannot respond to every suggestion, your idea will be read and responded to where possible. Thank you for your input!
Post Reply
neutrino
Posts: 182
Joined: Wed Oct 19, 2022 5:26 pm

Kernal clock_get_date_time() timezone?

Post by neutrino »


In the Kernal documentation there's calls to set and get the system real time clock:

https://github.com/commanderx16/x16-docs/blob/master/X16 Reference - 04 - KERNAL.md

$FF4D: clock_set_date_time - set date and time

$FF50: clock_get_date_time - get date and time

But I can't find anything about the behavior in regards to time zones and winter/summer time changes.

(also 1 day isn't exactly 86400 seconds, ie leap seconds)

The following call isn't documented:

$FFEA: UDTIM – advance clock

It might be useful with a function to be able to get/set the raw clock ie the epoch time in number of seconds since 1970-01-01.

 

TomXP411
Posts: 1803
Joined: Tue May 19, 2020 8:49 pm

Kernal clock_get_date_time() timezone?

Post by TomXP411 »


Time zones? We don't need no stinking time zones.

Seriously: as far as I know, there is no time zone logic in the clock. You set the time and read the time. That's it.

 

Wavicle
Posts: 288
Joined: Sun Feb 21, 2021 2:40 am

Kernal clock_get_date_time() timezone?

Post by Wavicle »


The kernel code is available here: commanderx16/x16-rom (github.com) I don't know of anybody working on time zone support; it only needs someone to work on it and submit a pull request.

neutrino
Posts: 182
Joined: Wed Oct 19, 2022 5:26 pm

Kernal clock_get_date_time() timezone?

Post by neutrino »


clock_get_date_time is defined as "rtc_get_date_time"

https://github.com/commanderx16/x16-rom/blob/master/kernal/drivers/x16/clock.s

Specified as "MCP7940N RTC Driver"

rtc_get_date_time will read the time directly from the RTC chip over the I2C bus in the second-minute-hour-day-month-year order. And will read the number of seconds again after the all the other data is fetched. If it differs from the first read, it will repeated indefinitely (no timeout).

https://github.com/commanderx16/x16-rom/blob/master/kernal/drivers/x16/rtc.s

The RTC chip is a "The MCP7940N series of low-power Real-Time Clocks (RTC) uses digital timing compensation for an accurate clock/calendar, "

https://www.microchip.com/en-us/product/MCP7940N

The datasheet makes no mention of any normal vs summer time adjustment which is present on some other chips. So winter/summer time adjustment will have to be done by computer software or the user. No mention of any time zones or leap seconds. So it will plainly assume 86400 seconds/day, all other time aspects have to be handled elsewhere.

https://ww1.microchip.com/downloads/aemDocuments/documents/MPD/ProductDocuments/DataSheets/MCP7940N-Battery-Backed-I2C-RTCC-with-SRAM-20005010J.pdf

It's a quite nice chip given that it supports setting trim bits to adjust the clock signal for even better precision time. It supports 2x alarm which could be used with the ATX connected MCU at the VIA chip to wake up the X16 at any desired time. It also keeps track of power failures. Contains 64 bytes of SRAM which is battery backed up which could be used for persistent configuration.

 

 

The 24-bit 60 Hz timer is a plain IRQ software update:

clock_get_timer = softclock_timer_get

https://github.com/commanderx16/x16-rom/blob/master/kernal/drivers/x16/clock.s

softclock_timer_get

https://github.com/commanderx16/x16-rom/blob/master/kernal/drivers/generic/softclock_timer.s

 

 

td;lr The RTC clock doesn't apply any winter/summer time, time zones or leap seconds.

 

Edmond D
Posts: 500
Joined: Thu Aug 19, 2021 1:42 am

Kernal clock_get_date_time() timezone?

Post by Edmond D »



On 10/21/2022 at 9:53 PM, neutrino said:




The datasheet makes no mention of any normal vs summer time adjustment which is present on some other chips



Given the changes in North America over my lifetime I'd hate to have daylight saving time in silicon, as it might break at some point. Especially given the move to eliminate it completely.



In Canada there are many time zones - https://www.thecanadianencyclopedia.ca/en/article/time-zones-and-legal-time Note that a Canadian came up with zones only 140+ years ago, before that civilization managed without them. ?

One time zone doesn't use daylight savings, well, because the cows would get confused on what time they would be milked. 

In most industrial and scientific systems the clock is set to UTC so there is no confusion of when the data is recorded - no gaps or overlaps or having to figure out offsets based on where one is on the planet. This means less math for computers and humans to deal with (and get wrong.)



Perhaps the X16 has a limitation in your view; to me it is a simple solid system that works for its purpose. 



 

neutrino
Posts: 182
Joined: Wed Oct 19, 2022 5:26 pm

Kernal clock_get_date_time() timezone?

Post by neutrino »


 .

neutrino
Posts: 182
Joined: Wed Oct 19, 2022 5:26 pm

Kernal clock_get_date_time() timezone?

Post by neutrino »


.

neutrino
Posts: 182
Joined: Wed Oct 19, 2022 5:26 pm

Kernal clock_get_date_time() timezone?

Post by neutrino »



On 10/23/2022 at 6:42 PM, Edmond D said:




Given the changes in North America over my lifetime I'd hate to have daylight saving time in silicon, as it might break at some point. Especially given the move to eliminate it completely.



Daylight saving in silicon sucks. I found a x86-PC motherboard with an RTC chip I thought could be interesting to desolder and run standalone. So I thought it maybe had a daylight savings function.. but then for which country?;-)  So I read the datasheet and found that it had a builtin automatic daylight savings function.. for a daylight savings that is obsolete. Luckily there's an option to use UTC.

(and running it separately is useful for being able to control the environment of the crystal so it can be made to provide very accurate time keeping)

 


On 10/23/2022 at 6:42 PM, Edmond D said:




In most industrial and scientific systems the clock is set to UTC so there is no confusion



That's the way to setup systems. The RTC chips usually adhere to rules that are outdated and irrelevant. But manufacturers stick with it. In fact it would be better if the RTC clock was a simple binary counter. That way all "smart" algorithms are moved into the operating system that can be updated with reasonable effort. Because even with a UTC mode setting. The operating system still usually have to re-calculate the date into a number of seconds since epoch, and then apply the local date rules anyway. And those re-calculations can make mistaken assumptions.

And even getting time zones and daylight savings right will not take account for leap seconds introduced in 1972 by ITU-R (or IERS?). And to make matters worse the daytime moves back-and-forth with a few ms over the decades.


On 10/23/2022 at 6:42 PM, Edmond D said:




Perhaps the X16 has a limitation in your view;



I doubt the X16 needs time zones or daylight savings. And anyway it can be implemented later in the kernal. In particular daylight savings might produce surprises.

But what is important is to know which behavior the system have so users know what they are dealing with and can expect. An X16 polyphonic alarm clock right now will fail on daylight savings dates unless accounted for in the code..

And the 60 Hz timer (jiffy?) will fail if the interrupt mechanism is not working properly. When a long NMI or IRQ disable occurs.

 

Edmond D
Posts: 500
Joined: Thu Aug 19, 2021 1:42 am

Kernal clock_get_date_time() timezone?

Post by Edmond D »



On 10/24/2022 at 4:35 AM, neutrino said:




I doubt the X16 needs time zones or daylight savings. And anyway it can be implemented later in the kernal. In particular daylight savings might produce surprises.



I question even the need for timing on the X16. I believe it's there if needed at the right level of functionality for most users.

Post Reply