1
0
Fork 0
forked from len0rd/rockbox

FS#9985: The OF of AMS sansas seems to keep time in seconds since 1970-1-1 instead of 1980-1-1 used in earlier sansas, so apply an adjustment for this difference when reading/writing the RTC. This avoids resetting of date/time by the OF.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@20697 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Bertrik Sikken 2009-04-12 18:00:53 +00:00
parent ab1e97aea8
commit 7d0119fe81

View file

@ -19,11 +19,18 @@
*
****************************************************************************/
#include <stdbool.h>
#include "config.h"
#include "rtc.h"
#include "i2c-pp.h"
#include "as3514.h"
#include "ascodec.h"
/* AMS Sansas start counting from Jan 1st 1970 instead of 1980 */
#if (CONFIG_CPU==AS3525)
#define SECS_ADJUST 315532800 /* seconds between 1970-1-1 and 1980-1-1 */
#else
#define SECS_ADJUST 0
#endif
#define MINUTE_SECONDS 60
#define HOUR_SECONDS 3600
#define DAY_SECONDS 86400
@ -61,6 +68,7 @@ int rtc_read_datetime(unsigned char* buf)
tmp[i] = ascodec_read(AS3514_RTC_0 + i);
}
seconds = tmp[0] + (tmp[1]<<8) + (tmp[2]<<16) + (tmp[3]<<24);
seconds -= SECS_ADJUST;
/* Convert seconds since Jan-1-1980 to format compatible with
* get_time() from firmware/common/timefuncs.c */
@ -160,6 +168,7 @@ int rtc_write_datetime(unsigned char* buf)
+ (buf[4]-1)*DAY_SECONDS
+ month_days*DAY_SECONDS
+ year_days*DAY_SECONDS;
seconds += SECS_ADJUST;
/* Send data to RTC */
for (i=0;i<4;i++){