summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBertrik Sikken <bertrik@sikken.nl>2009-04-12 18:00:53 +0000
committerBertrik Sikken <bertrik@sikken.nl>2009-04-12 18:00:53 +0000
commit7d0119fe811a08d408019912fadb6850d2caeb6a (patch)
tree7c0c74596113ea11559872b1a82d0325c83dce68
parentab1e97aea8eb4e7c3c3250d9ab90f84814cb5912 (diff)
downloadrockbox-7d0119fe811a08d408019912fadb6850d2caeb6a.tar.gz
rockbox-7d0119fe811a08d408019912fadb6850d2caeb6a.tar.bz2
rockbox-7d0119fe811a08d408019912fadb6850d2caeb6a.zip
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
-rw-r--r--firmware/drivers/rtc/rtc_as3514.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/firmware/drivers/rtc/rtc_as3514.c b/firmware/drivers/rtc/rtc_as3514.c
index 878f204a4e..d20e021ffb 100644
--- a/firmware/drivers/rtc/rtc_as3514.c
+++ b/firmware/drivers/rtc/rtc_as3514.c
@@ -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++){