-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for RTC in M2M: Hardware #29
Comments
Here is the datasheet for the RTC in R4/R5: https://www.microcrystal.com/fileadmin/Media/Products/RTC/App.Manual/RV-3032-C7_App-Manual.pdf . Notes from the datasheet:
For more details, see Chapter 6 pages 121-126 |
The interface to the core is via the C64 cassette port. |
Question: Should we poll the RTC regularly, or should we just read it once after power-on? Surely the crystal oscillator on the MEGA65 is accurate enough for time keeping while the MEGA65 is turned on. |
The following is a description of what I intend to implement. In other words, this describes the interface to the QNICE CPU (firmware). This is all part of the QNICE device number 0x0006 (
|
@MJoergen Sounds good. So the intend is to use this timer as the actual data source for all possible cores, independent of the actual RTC? Like this timer being a "cache" for us not needing to talk via I2C all the time? And then from time to time use command bit 1 to sync for example every 1 second or so? And maybe even offer a menu item in the OSM where the user can adjust the RTC via command bit 2 (without the need of using the MEGA65's setup menu?) And in the C64's case then the MiSTer F83 RTC implementation (MJoergen#103) always uses this timer instead of directly accessing the RTC? |
Exactly! This internal timer is meant as an abstraction. Basically, hide all the various board specific variants, and instead provide a generic interface. |
No need to periodically sync from external RTC to internal RTC. The accuracy is good enough to be less than 1 second within 24 h. I suggest a menu item where the user can manually choose a "sync from external RTC" if he/she so chooses. |
Note: The description in #29 (comment) has been updated. This can now been tested in hardware as follows:
Power cycle machine.
|
This is verified in the C64 repo in commit 111feea. |
Self assigned to test on my R3 machine:
|
@MJoergen Not sure if I am doing everything correctly. The date / time that I have set on my MEGA65 is: 6th of January 2023 (sic!) When doing this here:
I am receiving:
If I decode correctly, then the DATE is correct: 6th of January 2023 I am stopping here. We can do this test together during our next Skype chat. |
For R3 RTC 0x96 is BCD 16 and highest bit 7 set == 24h mode (MIL as in military time). The MEGA65 currently converts this in mega65-libc, the VHDL just transfers the data over I2C to the RTC. Perhaps it is a good idea to let the M2M framework handle this and only expose 24h time to the cores via the framework? Note: in 12h mode 0x31 would be 11am! |
Please retest |
@MJoergen ❌ Test failed:
![]() |
I believe the problem is that the RTC chip is accessed immediately after power-on, and that it sometimes won't respond. I can't find any information in the datasheet on when the RTC is ready after power-on, so now I'm trying with a 200 ms delay after power-on. |
Well, that didn't help. I still sometimes get a "NACK" on the I2C transaction to the RTC chip. |
✅ SUCCESS Here is what I did:
I did only test this cycle here once. Olivier's RTC is not working so we cannot ask him to do this test. I tend to believe that your "retry" fix works and therefore I am closing this and will merge the fix into the C64, so that I can start testing this in GEOS. |
@MJoergen Please decide if you want to do this in 5.1 (then the existing label "R4/R5 Surge" is correct - or not, then delete that label).
Adding support for RTC in M2M makes sense because:
Multiple cores can make use of an RTC: C64 core (GEOS), ZX Uno (currently outputs an error due to missing RTC when booting), the PC 486 core from MiSTer...
The firmware can make use of the RTC and make sure that files on the SD card (FAT32) that are written to/changed (for example disk images) are showing the updated date/time: Add support for RTC in M2M: Firmware #30 (The firmware part is not a long hanging fruit for the R4/R5 surge, but maybe the hardware part is.)
We need to abstract away the details of the different RTCs in R3/R3A vs. R4/R5 and even the fixed RTC for R3/R3A which uses a PMOD connector. So there are three RTCs as of now that we need to support.
The text was updated successfully, but these errors were encountered: