summaryrefslogtreecommitdiff
path: root/firmware/common/timefuncs.c
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/common/timefuncs.c
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/common/timefuncs.c')
-rw-r--r--firmware/common/timefuncs.c44
1 files changed, 19 insertions, 25 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)
47{ 47{
48#ifndef SIMULATOR 48#ifndef SIMULATOR
49#ifdef CONFIG_RTC 49#ifdef CONFIG_RTC
50 char rtcbuf[8]; 50 char rtcbuf[7];
51 51
52 /* We don't need the first byte, but we want the indexes in the 52 rtc_read_datetime(rtcbuf);
53 buffer to match the data sheet */ 53
54 rtc_read_multiple(1, &rtcbuf[1], 7); 54 tm.tm_sec = ((rtcbuf[0] & 0x70) >> 4) * 10 + (rtcbuf[0] & 0x0f);
55 tm.tm_min = ((rtcbuf[1] & 0x70) >> 4) * 10 + (rtcbuf[1] & 0x0f);
56 tm.tm_hour = ((rtcbuf[2] & 0x30) >> 4) * 10 + (rtcbuf[2] & 0x0f);
57 tm.tm_wday = rtcbuf[3] & 0x07;
58 tm.tm_mday = ((rtcbuf[4] & 0x30) >> 4) * 10 + (rtcbuf[4] & 0x0f);
59 tm.tm_mon = ((rtcbuf[5] & 0x10) >> 4) * 10 + (rtcbuf[5] & 0x0f) - 1;
60 tm.tm_year = ((rtcbuf[6] & 0xf0) >> 4) * 10 + (rtcbuf[6] & 0x0f) + 100;
55 61
56 tm.tm_sec = ((rtcbuf[1] & 0x70) >> 4) * 10 + (rtcbuf[1] & 0x0f);
57 tm.tm_min = ((rtcbuf[2] & 0x70) >> 4) * 10 + (rtcbuf[2] & 0x0f);
58 tm.tm_hour = ((rtcbuf[3] & 0x30) >> 4) * 10 + (rtcbuf[3] & 0x0f);
59 tm.tm_mday = ((rtcbuf[5] & 0x30) >> 4) * 10 + (rtcbuf[5] & 0x0f);
60 tm.tm_mon = ((rtcbuf[6] & 0x10) >> 4) * 10 + (rtcbuf[6] & 0x0f) - 1;
61 tm.tm_year = ((rtcbuf[7] & 0xf0) >> 4) * 10 + (rtcbuf[7] & 0x0f) + 100;
62 tm.tm_wday = rtcbuf[4] & 0x07;
63 if(tm.tm_wday == 7)
64 tm.tm_wday = 0;
65 tm.tm_yday = 0; /* Not implemented for now */ 62 tm.tm_yday = 0; /* Not implemented for now */
66 tm.tm_isdst = -1; /* Not implemented for now */ 63 tm.tm_isdst = -1; /* Not implemented for now */
67#else 64#else
@@ -86,22 +83,19 @@ int set_time(const struct tm *tm)
86{ 83{
87#ifdef CONFIG_RTC 84#ifdef CONFIG_RTC
88 int rc; 85 int rc;
89 int tmp; 86 char rtcbuf[7];
90 87
91 if (valid_time(tm)) 88 if (valid_time(tm))
92 { 89 {
93 rc = rtc_write(1, ((tm->tm_sec/10) << 4) | (tm->tm_sec%10)); 90 rtcbuf[0]=((tm->tm_sec/10) << 4) | (tm->tm_sec%10);
94 rc |= rtc_write(2, ((tm->tm_min/10) << 4) | (tm->tm_min%10)); 91 rtcbuf[1]=((tm->tm_min/10) << 4) | (tm->tm_min%10);
95 rc |= rtc_write(3, ((tm->tm_hour/10) << 4) | (tm->tm_hour%10)); 92 rtcbuf[2]=((tm->tm_hour/10) << 4) | (tm->tm_hour%10);
96 tmp = tm->tm_wday; 93 rtcbuf[3]=tm->tm_wday;
97 if(tmp == 0) 94 rtcbuf[4]=((tm->tm_mday/10) << 4) | (tm->tm_mday%10);
98 tmp = 7; 95 rtcbuf[5]=(((tm->tm_mon+1)/10) << 4) | ((tm->tm_mon+1)%10);
99 rc |= rtc_write(4, tmp); 96 rtcbuf[6]=(((tm->tm_year-100)/10) << 4) | ((tm->tm_year-100)%10);
100 rc |= rtc_write(5, ((tm->tm_mday/10) << 4) | (tm->tm_mday%10));
101 rc |= rtc_write(6, (((tm->tm_mon+1)/10) << 4) | ((tm->tm_mon+1)%10));
102 rc |= rtc_write(7, (((tm->tm_year-100)/10) << 4) | ((tm->tm_year-100)%10));
103 97
104 rc |= rtc_write(8, 0x80); /* Out=1, calibration = 0 */ 98 rc = rtc_write_datetime(rtcbuf);
105 99
106 if(rc) 100 if(rc)
107 return -1; 101 return -1;