Page 1 of 1

chrtlib.c

Posted: Fri Feb 21, 2014 5:57 pm
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 ?

Re: chrtlib.c

Posted: Fri Feb 21, 2014 8:25 pm
by Giovanni
This is a question that barthess could answer, I am not very inside that part of the code.

Giovanni

Re: chrtlib.c

Posted: Sat Feb 22, 2014 3:42 am
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.

Re: chrtlib.c

Posted: Mon Feb 24, 2014 11:46 am
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 ?