Chromatix wrote:
I think it makes most sense to have dedicated RTC hardware tracking the wall-clock date and time, rather than relying on a periodic ISR.
Actually, not.
Internally maintaining the date and time in broken-down format, as much RTC hardware does, is inefficient. For one thing, computing some time in the past or future relative to the RTC's notion of time becomes very non-trivial. Another consideration is that the accuracy of timekeeping is strongly tied to the accuracy and stability of the RTC itself.
As my own experience with POC V1.1 highlighted, that accuracy and stability is not something that can be taken for granted.
Furthermore, if time is maintained in software via a jiffy IRQ generated by an interval timer (as is done on virtually all modern computers), a fetch of the time is a compute-bound operation that can be very fast. If the time has to be fetched from an RTC every time it is needed (and that could be a lot more often than you think) now an I/O-bound operation has to occur on multiple device registers. Much slower, especially if the RTC hardware requires wait-stating.
Quote:
That typically provides the data in a human-accessible format, and handles month lengths and leap years autonomously (except, curiously, for the century rule). If you maintain the hardware at UTC, correcting for timezone offset from there is not hugely complicated.
Many RTCs only devote one (8 bit) register to the year, which means end-of-century leap year rules are not correctly implemented. The Maxim DS1511Y in my POC units is guilty of this.
Another consideration is that many RTCs read out the date and time in binary-code decimal (BCD) format, which is convenient from a display perspective, but not so much when doing arithmetic as quickly as possible. That especially becomes a consideration in accommodating time zone offset with broken-down time. Consider that not all locales are in a time zone that is an exact hour multiple offset relative to UTC. For example, how would you handle, say, Chatham Island, where standard time is UTC+12:45?
Quote:
For time-since-boot, you could increment a 16-bit counter at 32kHz and run an ISR when it overflows, every 2 seconds, to maintain a software extension word - or run a 32-bit counter which overflows at roughly 36-hour intervals. For many purposes, 32kHz is fine enough resolution. Readings from this timer should not ordinarily be converted into dates and times of day, but used for measuring relatively short intervals of time - milliseconds, seconds, minutes, hours.
You're making it too convoluted, in my opinion. A single hardware timer (I use the 28L92 counter/timer in POC for that), generating a jiffy IRQ at 100 Hz will produce centisecond resolution with very succinct code.
Quote:
*Processing* dates consistently, especially dates which may be far in the future or past, in strange and inconsistent calendars, etc - that is known to be a Hard Problem, and should be discussed separately.
For a discussion of calendric and temporal computing
see here. The topic isn't complete, however.