-
Notifications
You must be signed in to change notification settings - Fork 3k
Modify description of set_time() function. #5100
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
Add note about setting RTC time value to 0.
cc @c1728p9 |
what platforms have this behaviour ? |
For example K64F board have this issue. But it looks like it is valid for the following freescale platforms: Code example:
Note: When I remove code which modify 'time to set' to 1 in case when 0 is given, then RTC time can be successfully set to 0 and RTC counts time (checked on K64F board). Maybe drivers should be modified? |
That makes it more clear now. I had a look at KL27Z reference manual
This is target specific. I've checked other targets, they support writing 0. There are often anomalies in the API like this, not certain if we create notes for each target (we might end up with lot of notes in some cases). One thing I have noticed, lot of our targets use time_base variable that is set in rtc_write()? An example: https://github.com/ARMmbed/mbed-os/blob/master/targets/TARGET_Silicon_Labs/TARGET_EFM32/rtc_api.c#L268 @bulislaw @c1728p9 @deepikabhavnani Suggestions? |
* @note On some platforms time can not be set to 0 since it is invalid value. | ||
* In such case when 0 value is passed to this function, then RTC time | ||
* value is set to 1. | ||
* |
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.
I would consider this a bug with the vendor implementation. If 0 is unsupported by hardware then they should have a software translation.
I would argue code like this should be updated to have an offset instead:
#define RTC_OFFSET 1
time_t rtc_read(void)
{
return (time_t)(RTC->TSR - RTC_OFFSET);
}
void rtc_write(time_t t)
{
RTC_StopTimer(RTC);
RTC->TSR = t + RTC_OFFSET;
RTC_StartTimer(RTC);
}
I have created a PR to allow writing 0 to the TSR register. There is no hardware limitation in writing this value. It is suggested in the manual to avoid this value as 0 when read from the TSR also indicates that a overflow or invalid flag is set. However we do not use this way inside mbed and probe the status register directly for overflow and invalid time information. |
We can close this PR. @mprse Thanks for finding this bug |
Description
Add note about setting RTC time value to 0.
This PR is a result of discussion from PR#5087:
Status
READY
Migrations
NO