summaryrefslogtreecommitdiffstats
path: root/firmware
diff options
context:
space:
mode:
authorDave Chapman <dave@dchapman.com>2005-12-11 00:47:40 +0000
committerDave Chapman <dave@dchapman.com>2005-12-11 00:47:40 +0000
commit790b365595ce0e3407777b9ff37494ec7fe7db0f (patch)
tree0af5f8bcbe9c4b5edbdb55f137f02fc0989480d0 /firmware
parent6ddfac0806a15a8771725ec4fdc39247f36949ff (diff)
downloadrockbox-790b365595ce0e3407777b9ff37494ec7fe7db0f.tar.gz
rockbox-790b365595ce0e3407777b9ff37494ec7fe7db0f.zip
Reworking of Archos RTC code to create a (slightly) more abstract RTC api
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@8216 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware')
-rw-r--r--firmware/common/timefuncs.c44
-rw-r--r--firmware/drivers/rtc.c32
-rw-r--r--firmware/export/rtc.h11
3 files changed, 61 insertions, 26 deletions
diff --git a/firmware/common/timefuncs.c b/firmware/common/timefuncs.c
index c40ff2880c..81d5c493ec 100644
--- a/firmware/common/timefuncs.c
+++ b/firmware/common/timefuncs.c
@@ -47,21 +47,18 @@ struct tm *get_time(void)
{
#ifndef SIMULATOR
#ifdef CONFIG_RTC
- char rtcbuf[8];
+ char rtcbuf[7];
- /* We don't need the first byte, but we want the indexes in the
- buffer to match the data sheet */
- rtc_read_multiple(1, &rtcbuf[1], 7);
+ rtc_read_datetime(rtcbuf);
+
+ tm.tm_sec = ((rtcbuf[0] & 0x70) >> 4) * 10 + (rtcbuf[0] & 0x0f);
+ tm.tm_min = ((rtcbuf[1] & 0x70) >> 4) * 10 + (rtcbuf[1] & 0x0f);
+ tm.tm_hour = ((rtcbuf[2] & 0x30) >> 4) * 10 + (rtcbuf[2] & 0x0f);
+ tm.tm_wday = rtcbuf[3] & 0x07;
+ tm.tm_mday = ((rtcbuf[4] & 0x30) >> 4) * 10 + (rtcbuf[4] & 0x0f);
+ tm.tm_mon = ((rtcbuf[5] & 0x10) >> 4) * 10 + (rtcbuf[5] & 0x0f) - 1;
+ tm.tm_year = ((rtcbuf[6] & 0xf0) >> 4) * 10 + (rtcbuf[6] & 0x0f) + 100;
- tm.tm_sec = ((rtcbuf[1] & 0x70) >> 4) * 10 + (rtcbuf[1] & 0x0f);
- tm.tm_min = ((rtcbuf[2] & 0x70) >> 4) * 10 + (rtcbuf[2] & 0x0f);
- tm.tm_hour = ((rtcbuf[3] & 0x30) >> 4) * 10 + (rtcbuf[3] & 0x0f);
- tm.tm_mday = ((rtcbuf[5] & 0x30) >> 4) * 10 + (rtcbuf[5] & 0x0f);
- tm.tm_mon = ((rtcbuf[6] & 0x10) >> 4) * 10 + (rtcbuf[6] & 0x0f) - 1;
- tm.tm_year = ((rtcbuf[7] & 0xf0) >> 4) * 10 + (rtcbuf[7] & 0x0f) + 100;
- tm.tm_wday = rtcbuf[4] & 0x07;
- if(tm.tm_wday == 7)
- tm.tm_wday = 0;
tm.tm_yday = 0; /* Not implemented for now */
tm.tm_isdst = -1; /* Not implemented for now */
#else
@@ -86,22 +83,19 @@ int set_time(const struct tm *tm)
{
#ifdef CONFIG_RTC
int rc;
- int tmp;
+ char rtcbuf[7];
if (valid_time(tm))
{
- rc = rtc_write(1, ((tm->tm_sec/10) << 4) | (tm->tm_sec%10));
- rc |= rtc_write(2, ((tm->tm_min/10) << 4) | (tm->tm_min%10));
- rc |= rtc_write(3, ((tm->tm_hour/10) << 4) | (tm->tm_hour%10));
- tmp = tm->tm_wday;
- if(tmp == 0)
- tmp = 7;
- rc |= rtc_write(4, tmp);
- rc |= rtc_write(5, ((tm->tm_mday/10) << 4) | (tm->tm_mday%10));
- rc |= rtc_write(6, (((tm->tm_mon+1)/10) << 4) | ((tm->tm_mon+1)%10));
- rc |= rtc_write(7, (((tm->tm_year-100)/10) << 4) | ((tm->tm_year-100)%10));
+ rtcbuf[0]=((tm->tm_sec/10) << 4) | (tm->tm_sec%10);
+ rtcbuf[1]=((tm->tm_min/10) << 4) | (tm->tm_min%10);
+ rtcbuf[2]=((tm->tm_hour/10) << 4) | (tm->tm_hour%10);
+ rtcbuf[3]=tm->tm_wday;
+ rtcbuf[4]=((tm->tm_mday/10) << 4) | (tm->tm_mday%10);
+ rtcbuf[5]=(((tm->tm_mon+1)/10) << 4) | ((tm->tm_mon+1)%10);
+ rtcbuf[6]=(((tm->tm_year-100)/10) << 4) | ((tm->tm_year-100)%10);
- rc |= rtc_write(8, 0x80); /* Out=1, calibration = 0 */
+ rc = rtc_write_datetime(rtcbuf);
if(rc)
return -1;
diff --git a/firmware/drivers/rtc.c b/firmware/drivers/rtc.c
index 30bbb6dfcb..b77db8b865 100644
--- a/firmware/drivers/rtc.c
+++ b/firmware/drivers/rtc.c
@@ -249,4 +249,34 @@ int rtc_read_multiple(unsigned char address, unsigned char *buf, int numbytes)
i2c_end();
return ret;
}
-#endif
+
+int rtc_read_datetime(unsigned char* buf) {
+ int rc;
+
+ rc = rtc_read_multiple(1, buf, 7);
+
+ /* Adjust weekday */
+ if(buf[3] == 7)
+ buf[3]=0;
+
+ return rc;
+}
+
+int rtc_write_datetime(unsigned char* buf) {
+ int i;
+ int rc = 0;
+
+ /* Adjust weekday */
+ if(buf[3] == 0)
+ buf[3] = 7;
+
+ for (i = 0; i < 7 ; i++)
+ {
+ rc |= rtc_write(i+1, buf[i]);
+ }
+ rc |= rtc_write(8, 0x80); /* Out=1, calibration = 0 */
+
+ return rc;
+}
+
+#endif /* CONFIG_RTC */
diff --git a/firmware/export/rtc.h b/firmware/export/rtc.h
index 88413c795f..28a4a2636a 100644
--- a/firmware/export/rtc.h
+++ b/firmware/export/rtc.h
@@ -22,7 +22,16 @@
#include <stdbool.h>
#ifdef CONFIG_RTC
+
+/* Common functions for all targets */
void rtc_init(void);
+int rtc_read_datetime(unsigned char* buf);
+int rtc_write_datetime(unsigned char* buf);
+
+#if CONFIG_RTC == RTC_M41ST84W
+
+/* The RTC in the Archos devices is used for much more than just the clock
+ data */
int rtc_read(unsigned char address);
int rtc_read_multiple(unsigned char address, unsigned char *buf, int numbytes);
int rtc_write(unsigned char address, unsigned char value);
@@ -35,6 +44,8 @@ bool rtc_check_alarm_started(bool release_alarm);
bool rtc_check_alarm_flag(void);
#endif /* HAVE_ALARM_MOD */
+#endif /* RTC_M41ST84W */
+
#endif /* CONFIG_RTC */
#endif