chrtlib.c

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderator: RoccoMarco

Post Reply
Tabulous
Posts: 518
Joined: Fri May 03, 2013 12:02 pm
Has thanked: 7 times
Been thanked: 18 times

chrtlib.c

Post by Tabulous »

can someone explain why in stm32_rtc_tm2bcd the tm_year is minus 100 years.

And in stm32_rtc_bcd2tm it is plus 100 years ?

i dont get it, the years register only has years tens and years units, of which both are 4bits wide, thus can only hold 99 years max

Is this a bug ?
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: chrtlib.c

Post by Giovanni »

This is a question that barthess could answer, I am not very inside that part of the code.

Giovanni
skute
Posts: 64
Joined: Wed Aug 29, 2012 10:17 pm

Re: chrtlib.c

Post by skute »

I assume this is to be compliant to c standard for the struct tm which stores tm_year as years since 1900 (see http://www.cplusplus.com/reference/ctime/tm/). This would make the RTC time base January 1, 2000.
Tabulous
Posts: 518
Joined: Fri May 03, 2013 12:02 pm
Has thanked: 7 times
Been thanked: 18 times

Re: chrtlib.c

Post by Tabulous »

skute wrote:I assume this is to be compliant to c standard for the struct tm which stores tm_year as years since 1900 (see http://www.cplusplus.com/reference/ctime/tm/). This would make the RTC time base January 1, 2000.


So im setting date with the following input argv[1] = "24/02/14"

t.tm_mon = atoi( (const char *)&argv[1][3] );
t.tm_mday = atoi( (const char *)&argv[1][0] );
t.tm_year = atoi( (const char *)&argv[1][6] );

rtcSetTimeTm( &RTCD1, &t );


thus t.tm_year is equal to 14, i take it this is not correct then ?
What your saying is i should do

t.tm_year = atoi( (const char *)&argv[1][6] ) + 100;

Thus is amount of years from 1900 ?
Post Reply