-
-
Notifications
You must be signed in to change notification settings - Fork 8.4k
alif: implement machine.RTC.datetime
, enable remaining time functions, and implement littlefs, FAT and mbedTLS time
#17900
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
Conversation
e1edabd
to
31ed09c
Compare
@dpgeorge - Do you need us to check or approve anything? |
I you have any review comments, please make them. Note that this changes the prescaler on the LPRTC to 32768, so it clocks at 1Hz. The comments in the code explain the reasoning. |
I don't have any comments, just for you to keep your eye on adding RTC Memory too at some point for the AE3 and N6 to access the battery backup RAM. @iabdalkader may have some. |
If I understand correctly, the tradeoff is between date range and resolution? I'd say finer resolution is more important, and more likely to be needed than a 100+ years range. However at the same time 30us is good enough for any application, I think. So either way is fine with me, your call. |
Sort of. It's really a resolution of the LPRTC alarm more than anything.
Note that you can never get better (or worse) than 30us for the combined counter+prescaler resolution. That's just 1/32kHz, the resolution of the LPRTC clock. The question is where you draw the line between counter and prescaler: the counter+prescaler are a 48-bit counter counting at 32kHz and you can chose what the prescaler counts to before clocking the counter by 1.
In all the above cases the prescaler is used to get extra resolution, so that counter+prescaler always has 30us resolution. See |
Still seems good enough for the RTC. |
The LPRTC peripheral is a 32-bit counter with a 16-bit prescaler. It's configured here to count at 1Hz (to get maximum date range) and then the prescaler value is used to get 30 microsecond resolution. That's essentially a 32+15=47-bit counter. Signed-off-by: Damien George <damien@micropython.org>
Signed-off-by: Damien George <damien@micropython.org>
Signed-off-by: Damien George <damien@micropython.org>
Signed-off-by: Damien George <damien@micropython.org>
Adds: `time.time()`, `time.time_ns()`, `time.localtime()`, `time.mktime()` and `time.gmtime()`. Signed-off-by: Damien George <damien@micropython.org>
31ed09c
to
f146244
Compare
Summary
This PR finishes the time implementation on the alif port:
machine.RTC.datetime
to get/set the RTCtime.time()
,time.time_ns()
,time.localtime()
,time.mktime()
,time.gmtime()
The Epoch is 1970 and the time range is the year 1970 to 2106. Resolution is 30 microseconds (achievable via
time.time_ns()
).Testing
Tested on OPENMV_AE3, running the entire test suite:
Trade-offs and Alternatives
The LPRTC peripheral is a 32-bit counter with a 16-bit prescaler. I configured the counter to count at 1Hz (to get maximum date range) and then used the prescaler value to get 30 microsecond resolution. That's essentially a 32+15=47-bit counter. That's the best scheme I could come up with.