Skip to content

[API] Added option to modify RTC source #926

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

Merged
merged 2 commits into from
Mar 9, 2015
Merged

[API] Added option to modify RTC source #926

merged 2 commits into from
Mar 9, 2015

Conversation

Sissors
Copy link
Contributor

@Sissors Sissors commented Feb 22, 2015

Initially from Karls question here:
http://developer.mbed.org/questions/6337/setTime-and-time-exported-with-__weak-fo/#answer6545?compage=1#c15936.
Currently the C time functions only work with internal RTC. Sometimes
you either want to use an external one, or your target does not even
have an internal RTC. I added function attach_rtc(...) where the default
functions can be overridden at runtime.

Verified it to work properly with LPC1768/LPC11u24, both with and without DS1307 RTC connected and used as source for time. I don't think the init and isenabled functions are really important to have, but you can just set them as NULL (did so myself when testing).

Initially from Karls question here:
http://developer.mbed.org/questions/6337/setTime-and-time-exported-with-__weak-fo/#answer6545?compage=1#c15936.
Currently the C time functions only work with internal RTC. Sometimes
you either want to use an external one, or your target does not even
have an internal RTC. I added function attach_rtc(...) where the default
functions can be overridden at runtime.
@0xc0170
Copy link
Contributor

0xc0170 commented Feb 22, 2015

Your branch name: lookmartinImadeanewbranch 😆

if (_rtc_read != NULL) {
t = _rtc_read();
} else {
t = 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can leave uninitialized variable behind:

time_t t = 0;
if (_rtc_read != NULL) {
    t = _rtc_read();
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess bit cleaner code, and tiny, tiny, bit slower. If that is preferred I will change it.

@Sissors
Copy link
Contributor Author

Sissors commented Feb 28, 2015

Did some changes.

0xc0170 added a commit that referenced this pull request Mar 9, 2015
Add option to modify RTC source for time functions (using func pointers)
@0xc0170 0xc0170 merged commit 0531ad4 into ARMmbed:master Mar 9, 2015
@Sissors Sissors deleted the lookmartinImadeanewbranch branch March 22, 2015 14:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants