diff options
author | Brandon Low <lostlogic@rockbox.org> | 2006-03-05 18:19:46 +0000 |
---|---|---|
committer | Brandon Low <lostlogic@rockbox.org> | 2006-03-05 18:19:46 +0000 |
commit | 6668b65ef22c5ad6dd13b4a63de22763ff6f93da (patch) | |
tree | ca03aa7e9219baf2aab8e08f3d5ecc2b715017f5 | |
parent | 63c0d1dd9c22658b12a48dfc2015bfb0bf1239a4 (diff) | |
download | rockbox-6668b65ef22c5ad6dd13b4a63de22763ff6f93da.tar.gz rockbox-6668b65ef22c5ad6dd13b4a63de22763ff6f93da.zip |
Move the RTC read throttling to a smarter place
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@8912 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r-- | firmware/common/timefuncs.c | 27 | ||||
-rw-r--r-- | firmware/drivers/rtc.c | 17 |
2 files changed, 21 insertions, 23 deletions
diff --git a/firmware/common/timefuncs.c b/firmware/common/timefuncs.c index 81d5c493ec..19033a504e 100644 --- a/firmware/common/timefuncs.c +++ b/firmware/common/timefuncs.c | |||
@@ -20,6 +20,7 @@ | |||
20 | #include <stdio.h> /* get NULL */ | 20 | #include <stdio.h> /* get NULL */ |
21 | #include "config.h" | 21 | #include "config.h" |
22 | 22 | ||
23 | #include "kernel.h" | ||
23 | #include "rtc.h" | 24 | #include "rtc.h" |
24 | #include "timefuncs.h" | 25 | #include "timefuncs.h" |
25 | #include "debug.h" | 26 | #include "debug.h" |
@@ -42,25 +43,29 @@ bool valid_time(const struct tm *tm) | |||
42 | return true; | 43 | return true; |
43 | } | 44 | } |
44 | 45 | ||
46 | static int last_tick = 0; | ||
45 | 47 | ||
46 | struct tm *get_time(void) | 48 | struct tm *get_time(void) |
47 | { | 49 | { |
48 | #ifndef SIMULATOR | 50 | #ifndef SIMULATOR |
49 | #ifdef CONFIG_RTC | 51 | #ifdef CONFIG_RTC |
50 | char rtcbuf[7]; | ||
51 | 52 | ||
52 | rtc_read_datetime(rtcbuf); | 53 | /* Don't read the RTC more than 4 times per second */ |
54 | if (last_tick + HZ/4 < current_tick) { | ||
55 | char rtcbuf[7]; | ||
56 | rtc_read_datetime(rtcbuf); | ||
53 | 57 | ||
54 | tm.tm_sec = ((rtcbuf[0] & 0x70) >> 4) * 10 + (rtcbuf[0] & 0x0f); | 58 | tm.tm_sec = ((rtcbuf[0] & 0x70) >> 4) * 10 + (rtcbuf[0] & 0x0f); |
55 | tm.tm_min = ((rtcbuf[1] & 0x70) >> 4) * 10 + (rtcbuf[1] & 0x0f); | 59 | tm.tm_min = ((rtcbuf[1] & 0x70) >> 4) * 10 + (rtcbuf[1] & 0x0f); |
56 | tm.tm_hour = ((rtcbuf[2] & 0x30) >> 4) * 10 + (rtcbuf[2] & 0x0f); | 60 | tm.tm_hour = ((rtcbuf[2] & 0x30) >> 4) * 10 + (rtcbuf[2] & 0x0f); |
57 | tm.tm_wday = rtcbuf[3] & 0x07; | 61 | tm.tm_wday = rtcbuf[3] & 0x07; |
58 | tm.tm_mday = ((rtcbuf[4] & 0x30) >> 4) * 10 + (rtcbuf[4] & 0x0f); | 62 | tm.tm_mday = ((rtcbuf[4] & 0x30) >> 4) * 10 + (rtcbuf[4] & 0x0f); |
59 | tm.tm_mon = ((rtcbuf[5] & 0x10) >> 4) * 10 + (rtcbuf[5] & 0x0f) - 1; | 63 | 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; | 64 | tm.tm_year = ((rtcbuf[6] & 0xf0) >> 4) * 10 + (rtcbuf[6] & 0x0f) + 100; |
61 | 65 | ||
62 | tm.tm_yday = 0; /* Not implemented for now */ | 66 | tm.tm_yday = 0; /* Not implemented for now */ |
63 | tm.tm_isdst = -1; /* Not implemented for now */ | 67 | tm.tm_isdst = -1; /* Not implemented for now */ |
68 | } | ||
64 | #else | 69 | #else |
65 | tm.tm_sec = 0; | 70 | tm.tm_sec = 0; |
66 | tm.tm_min = 0; | 71 | tm.tm_min = 0; |
diff --git a/firmware/drivers/rtc.c b/firmware/drivers/rtc.c index 6458092348..ecfd2ac6ba 100644 --- a/firmware/drivers/rtc.c +++ b/firmware/drivers/rtc.c | |||
@@ -61,24 +61,17 @@ int rtc_write_datetime(unsigned char* buf) | |||
61 | return 1; | 61 | return 1; |
62 | } | 62 | } |
63 | #elif CONFIG_RTC == RTC_PCF50606 | 63 | #elif CONFIG_RTC == RTC_PCF50606 |
64 | static int last_tick; | ||
65 | static char rtc_buf[7]; | ||
66 | void rtc_init(void) | 64 | void rtc_init(void) |
67 | { | 65 | { |
68 | last_tick = 0; | ||
69 | } | 66 | } |
70 | 67 | ||
71 | int rtc_read_datetime(unsigned char* buf) { | 68 | int rtc_read_datetime(unsigned char* buf) { |
72 | int rc; | 69 | int rc; |
73 | if (last_tick + HZ/2 < current_tick) { | 70 | int oldlevel = set_irq_level(HIGHEST_IRQ_LEVEL); |
74 | int oldlevel = set_irq_level(HIGHEST_IRQ_LEVEL); | 71 | |
75 | last_tick = current_tick; | 72 | rc = pcf50606_read_multiple(0x0a, buf, 7); |
76 | rc = pcf50606_read_multiple(0x0a, rtc_buf, 7); | 73 | |
77 | set_irq_level(oldlevel); | 74 | set_irq_level(oldlevel); |
78 | } else { | ||
79 | rc = 7; | ||
80 | } | ||
81 | memcpy(buf, rtc_buf, 7); | ||
82 | return rc; | 75 | return rc; |
83 | } | 76 | } |
84 | 77 | ||