The RTC driver topic

This forum is dedicated to feedback, discussions about ongoing or future developments, ideas and suggestions regarding the ChibiOS projects are welcome. This forum is NOT for support.
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: The RTC driver topic

Post by Giovanni »

I agree, there would be one implementation for each driver, but luckily most RTCs are of the calendar type, the STM32F1 is an exception apparently.

Giovanni
User avatar
barthess
Posts: 861
Joined: Wed Dec 08, 2010 7:55 pm
Been thanked: 7 times

Re: The RTC driver topic

Post by barthess »

I propose to realize own code for "smart" MCUs and keep as is for F1x. Do you agree?
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: The RTC driver topic

Post by Giovanni »

Let's address the F1 last, how would you modify the driver model?

The minimal functionality required is to support the FS, everything else can stay outside the driver.

Giovanni
User avatar
barthess
Posts: 861
Joined: Wed Dec 08, 2010 7:55 pm
Been thanked: 7 times

Re: The RTC driver topic

Post by barthess »

Why driver model? Just add #ifdef STM32_RTC_IS_CALENDAR in rtcGetTimeFat() function.
User avatar
barthess
Posts: 861
Joined: Wed Dec 08, 2010 7:55 pm
Been thanked: 7 times

Re: The RTC driver topic

Post by barthess »

Can we add compiler specific code in #ifdefs? For example,

Code: Select all

localtime_r()
for gcc and

Code: Select all

chSysLock(); localtime(); chSysUnlock();
for other compilers?
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: The RTC driver topic

Post by Giovanni »

The problem is that some compilers don't support localtime() at all. This is why I wrote to support FAT time directly in the driver without dependencies, all conversions done inside directly from RTCTime to fattime.

rtcGetTimeFat() would be part of the driver interface, I don't really care about the other time formats like struct tm and Unix, that stuff brings in a lot of libraries including 64 bits integers.

Giovanni
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: The RTC driver topic

Post by Giovanni »

Probably it is better to move rtcGetTimeTm(), rtcSetTimeTm() back into the driver and make them available only if the compiler supports time.h using a switch defined in the low level driver: RTC_SUPPORTS_TM.
rtcGetTimeFat() also moved in the driver and would always be available regardless the time.h support.

Unix time format is not required, it can stay external, it can be converted from the tm structure anyway so there is no reason to support it in the core OS.

Giovanni
saraben
Posts: 40
Joined: Thu Sep 20, 2012 12:37 am

Re: The RTC driver topic

Post by saraben »

Giovanni, Barthess,
For the STM32F1..., Martin Thomas has some compact time functions including fattime converrsion. Some of them are derived from other sources as noted in his comments. For the F2 where the RTC stores datetime in calander format fat time conversion is trival.
http://www.siwawi.arubi.uni-kl.de/avr_projects/arm_projects/arm_memcards/index.html#chanfat_stm32
Note the following though. In rtc.c, counter_to_struct() has a configurable epoc FIRSTYEAR for converting the F1.. counter to datetime format but struct_to_counter() has a hard coded offset. It is set to the year 2000 in the example

Code: Select all

result -= 730485UL;

Can be changed to UNIX time

Code: Select all

result -= 719528UL;

This really needs converting into a macro if it is to be compile time configurable.
I don't think any other time.h functionality should really be required.

saraben
User avatar
barthess
Posts: 861
Joined: Wed Dec 08, 2010 7:55 pm
Been thanked: 7 times

Re: The RTC driver topic

Post by barthess »

rtcGetTimeFat() for hardware calendar moved inside driver and tested on F4x board (rev 4701).

saraben,
thanks for link, I will look close this evening.
User avatar
barthess
Posts: 861
Joined: Wed Dec 08, 2010 7:55 pm
Been thanked: 7 times

Re: The RTC driver topic

Post by barthess »

Giovanni,
is licensing scheme allow to use this code in chibios?
http://code.google.com/p/sistemasembebi ... /rtc.c?r=9
Post Reply