4 years, 7 months ago.

setTime and time exported with __weak for processors without RTC.

Hi,

First time posting a question here.

I am currently creating a library for a Realtime clock chip (DS3231M).

In common/rtc_time.c in the mbed-src, if setTime and time was exported with weak[1] when DEVICE_RTC is not set we could redefine setTime and time in our library and use those standard functions in our program to talk to the external clock chip.

Is it a good idea? Any downsides? Should I create a pull request for mbed-src to implementing this change?

Cheers, Karl

[1] http://www.keil.com/support/man/docs/armccref/armccref_CHDHHIGB.htm

Question relating to:

mbed library sources mbed
Comment on this question

1 Answer

4 years, 7 months ago.

Suddenly remembered I still wanted to respond on this one :).

In general I think it is a good idea if this can be created. I don't know if WEAK is the best option, but also don't know if there are other options. It would be nice if it could also be overridden for devices which have RTC, sometimes using an external RTC makes sense. Ideally I would say it would be nice if you could simply call a function where you set the RTC function to be used, where by default it sets the internal RTC.

At the same time if you make a library, I would make it such that you do not need to do this. I have one RTC library, and saw someone else do the same thing: Just add a .time() function, so you call rtc.time() instead of time(), then it is still very easy to use.

If you make a pull request you need to do it to the mbed github, doing it to mbed-src directly gets ignored.

Not ignored, just redirected :-)

What other options are there? We can create a new library, RTC interface, it would unify the external RTC modules and the RTC in the mbed. As currently there is set of C functions in the mbed.

posted by Martin Kojtal 21 Feb 2015

You have the rtc_read, rtc_init and rtc_write functions there. You could just instead use generic function pointers instead, which can be set using some extra functions. If RTC is available by default these will be set to the internal RTC. If no RTC is available they will be by default NULL pointers which will print out an error.

posted by Erik Olieman 21 Feb 2015

Sorry for the late reply.

Oh, sweet! Thank you for making the pull request. I didn't expect that, much appreciated.

I do agree that having the possibility to set the RTC function is probably a better choice than making the original functions weakly referenced.

posted by Karl Backström 24 Feb 2015