Hi!
libcpu\arm\s3c2440\rtc.c
The functions rt_hw_rtc_get and rt_hw_rtc_set assign the RTC values directly to/from the struct tm structure however the values used in the tm struct are not compatible with the S3C2440 RTC. tm_wday uses values 0 - 6 but the RTC uses 1-7 and tm_mon uses values 0-11 where the RTC uses 1-12. Also, depending on the C library used, the tm struct can have an epoch of 1900, 1970 ... but the RTC uses 2000 (the value 00 represents the year 2000).
The RTC uses the month value to determine the number of days in each month, and the year value to determine leap years.
My solution:
#define EPOCH 1900 /* Epoch used by CodeSourcery newLib C Library */
void rt_hw_rtc_get(struct tm *ti)
{
...
ti->tm_mon = BCD2BIN(mon & 0x1F) - 1;
ti->tm_year = BCD2BIN(year) + 2000 - EPOCH;
ti->tm_wday = BCD2BIN(wday & 0x07) - 1;
...
}
void rt_hw_rtc_set(struct tm *ti)
{
...
year = BIN2BCD(ti->tm_year + EPOCH - 2000);
mon = BIN2BCD(ti->tm_mon + 1);
wday = BIN2BCD(ti->tm_wday + 1);
...
}
Regards,
Rob