summaryrefslogtreecommitdiff
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
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
-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)
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;
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)
249 i2c_end(); 249 i2c_end();
250 return ret; 250 return ret;
251} 251}
252#endif 252
253int rtc_read_datetime(unsigned char* buf) {
254 int rc;
255
256 rc = rtc_read_multiple(1, buf, 7);
257
258 /* Adjust weekday */
259 if(buf[3] == 7)
260 buf[3]=0;
261
262 return rc;
263}
264
265int rtc_write_datetime(unsigned char* buf) {
266 int i;
267 int rc = 0;
268
269 /* Adjust weekday */
270 if(buf[3] == 0)
271 buf[3] = 7;
272
273 for (i = 0; i < 7 ; i++)
274 {
275 rc |= rtc_write(i+1, buf[i]);
276 }
277 rc |= rtc_write(8, 0x80); /* Out=1, calibration = 0 */
278
279 return rc;
280}
281
282#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 @@
22#include <stdbool.h> 22#include <stdbool.h>
23 23
24#ifdef CONFIG_RTC 24#ifdef CONFIG_RTC
25
26/* Common functions for all targets */
25void rtc_init(void); 27void rtc_init(void);
28int rtc_read_datetime(unsigned char* buf);
29int rtc_write_datetime(unsigned char* buf);
30
31#if CONFIG_RTC == RTC_M41ST84W
32
33/* The RTC in the Archos devices is used for much more than just the clock
34 data */
26int rtc_read(unsigned char address); 35int rtc_read(unsigned char address);
27int rtc_read_multiple(unsigned char address, unsigned char *buf, int numbytes); 36int rtc_read_multiple(unsigned char address, unsigned char *buf, int numbytes);
28int rtc_write(unsigned char address, unsigned char value); 37int rtc_write(unsigned char address, unsigned char value);
@@ -35,6 +44,8 @@ bool rtc_check_alarm_started(bool release_alarm);
35bool rtc_check_alarm_flag(void); 44bool rtc_check_alarm_flag(void);
36#endif /* HAVE_ALARM_MOD */ 45#endif /* HAVE_ALARM_MOD */
37 46
47#endif /* RTC_M41ST84W */
48
38#endif /* CONFIG_RTC */ 49#endif /* CONFIG_RTC */
39 50
40#endif 51#endif