-
Notifications
You must be signed in to change notification settings - Fork 3k
Add support and tests for extended RTC #5363
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
@c1728p9 Could you review? |
@c1728p9 ping |
The functions functions The problem that needs to be addressed is that different devices calculate leap year differently. For example after year 2100 the LPC1768's counter will be off by a day, since it's hardware has a simpler leap year calculation. The RZ-A1H does not have this problem, as it factors in 100 and 400 year leap years. To account for these two types of behavior there should be two variants of each function, or an extra parameter of each function to choose this behavior at run time. A separate enhancement to the RTC HAL tests also needs to be made (in a separate PR), to test both 4 year leap year calculations and 100 year leap year handling on hardware. For reference here is the RTC behavior of two separate devices: LPC1768 User Manual:
RZ_A1H User Manual:
|
@c1728p9 Thank you for detailed objectives. I will come back to this PR next week.
We can use entire 32-bit range, but then we will not have value which indicate error. Can we modify the |
@c1728p9 Could you please confirm if I correctly understand the problem:
I'm not sure how these invalid dates should be handled. Lets take an example: Expected functions behaviour: b) Questions:
|
@mprse your understanding of this is correct based on the points you made.
Adding a bool to this works for me. @pan- are you ok with this?
A preprocessor directive should only be used as a last resort as it complicates the code (in this case the same function behaves differently) and prevents testing all configurations in the same build. |
@c1728p9 This PR has been updated to meet the requirements. |
platform/mbed_mktime.h
Outdated
*/ | ||
typedef enum { | ||
RTC_FULL_LEAP_YEAR_SUPPORT, | ||
RTC_PARTIAL_LEAP_YEAR_SUPPORT |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To remove some ambiguity it may be good to rename this to something like RTC_4_YEAR_LEAP_YEAR_SUPPORT
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed as suggested.
platform/mbed_mktime.c
Outdated
|
||
/* Macros which will be used to determine if we are within valid range. */ | ||
#define EDGE_TIMESTAMP_FULL_LEAP_YEAR_SUPPORT 3220095 // 7th of February 1970 at 06:28:15 | ||
#define EDGE_TIMESTAMP_PARTIAL_LEAP_YEAR_SUPPORT 3133695 // 6th of February 1970 at 06:28:15 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why was this date chosen? Also, why is it different for partial vs full?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a shortcut to check if calendar date provided to _rtc_mktime() function is within valid range. This is used to check upper limit. Function first only checks if the year range is valid. Then it calculates elapsed time since the beginning of the specified year. At this point we can check if provided date is within the range using these macros. If specified year is 2106 (last valid) and seconds since the beginning of the year are greater than edge timestamp, then we are out of range.
Different values are used for these two types of RTC devices. On devices which support full leap year detection last valid point of time is the 7th of February 2106 at 06:28:15 and on devices which have only 4 year leap year detection last valid date is 6th of February 2106 at 06:28:15 (at this point we are one day off). Both dates correspond to 0xffff_ffff number of seconds since the start of unix epoch.
@mprse ping |
I would also rename the function to discriminate it from |
Changed
All change requests are processed now. |
@mprse can you fix the conflict please. |
Conflict has been resolved. |
@mprse Can you please check travis , the failures are related to this patch |
This PR modifies API of _rtc_is_leap_year(), _rtc_mktime(), _rtc_localtime() functions and renames _rtc_mktime() to _rtc_maketime(). Travis reports errors since Vendor's RTC drivers are not updated. @c1728p9 @0xc0170 @bulislaw |
Changed base of this PR from ARMmbed:master to ARMmbed:feature-hal-spec-rtc. |
Increased timeout for rtc_time_conv test. |
/morph build |
Build : SUCCESSBuild number : 649 Triggering tests/morph test |
Exporter Build : ABORTEDBuild number : 288 |
Test : FAILUREBuild number : 472 |
Increased timeout for rtc_time_conv test again. |
/morph build |
@mprse Please test locally if possible |
Build : SUCCESSBuild number : 652 Triggering tests/morph test |
Exporter Build : SUCCESSBuild number : 292 |
Test : SUCCESSBuild number : 476 |
Although the extened RTC is supported by ARMmbed#5363 commit ("Add support and tests for extended RTC"), it seems that the changes was overlooked in RZ_A1H_api.c. So I added the changes with reference to other rtc_api.c.
Although the extened RTC is supported by #5363 commit ("Add support and tests for extended RTC"), it seems that the changes was overlooked in RZ_A1H_api.c. So I added the changes with reference to other rtc_api.c.
Although the extened RTC is supported by #5363 commit ("Add support and tests for extended RTC"), it seems that the changes was overlooked in RZ_A1H_api.c. So I added the changes with reference to other rtc_api.c.
@mprse We should review this As a result, even though it was tagged for 5.8, this is causing some new target dependencies that we should avoid. I am thinking if this can be made backward compatible (it is internal API but affects targets) - having the functionality as it was, and the new one with suffix |
Description
Add support for extended RTC.
Add tests for extended RTC.
Provide support to use whole 32-bit range (unsigned int) to hold time since UNIX epoch.
The supported time range is now from the 1st of January 1970 at 00:00:00 to the 7th of February 2106 at 06:28:15.
Add support for two types of RTC devices:
Status
READY
Migrations
YES
Modified API of _rtc_is_leap_year(), _rtc_mktime(), _rtc_localtime() functions.
Renamed _rtc_mktime() to _rtc_maketime().
Each function has additional parameter which informs if function is used for RTC which provides full leap year detection or not.