summaryrefslogtreecommitdiff
path: root/firmware/common/timefuncs.c
diff options
context:
space:
mode:
authorBrandon Low <lostlogic@rockbox.org>2006-03-05 18:19:46 +0000
committerBrandon Low <lostlogic@rockbox.org>2006-03-05 18:19:46 +0000
commit6668b65ef22c5ad6dd13b4a63de22763ff6f93da (patch)
treeca03aa7e9219baf2aab8e08f3d5ecc2b715017f5 /firmware/common/timefuncs.c
parent63c0d1dd9c22658b12a48dfc2015bfb0bf1239a4 (diff)
downloadrockbox-6668b65ef22c5ad6dd13b4a63de22763ff6f93da.zip
rockbox-6668b65ef22c5ad6dd13b4a63de22763ff6f93da.tar.gz
rockbox-6668b65ef22c5ad6dd13b4a63de22763ff6f93da.tar.bz2
rockbox-6668b65ef22c5ad6dd13b4a63de22763ff6f93da.tar.xz
Move the RTC read throttling to a smarter place
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@8912 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/common/timefuncs.c')
-rw-r--r--firmware/common/timefuncs.c27
1 files changed, 16 insertions, 11 deletions
diff --git a/firmware/common/timefuncs.c b/firmware/common/timefuncs.c
index 81d5c49..19033a5 100644
--- a/firmware/common/timefuncs.c
+++ b/firmware/common/timefuncs.c
@@ -20,6 +20,7 @@
#include <stdio.h> /* get NULL */
#include "config.h"
+#include "kernel.h"
#include "rtc.h"
#include "timefuncs.h"
#include "debug.h"
@@ -42,25 +43,29 @@ bool valid_time(const struct tm *tm)
return true;
}
+static int last_tick = 0;
struct tm *get_time(void)
{
#ifndef SIMULATOR
#ifdef CONFIG_RTC
- char rtcbuf[7];
- rtc_read_datetime(rtcbuf);
+ /* Don't read the RTC more than 4 times per second */
+ if (last_tick + HZ/4 < current_tick) {
+ char rtcbuf[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[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_yday = 0; /* Not implemented for now */
- tm.tm_isdst = -1; /* Not implemented for now */
+ tm.tm_yday = 0; /* Not implemented for now */
+ tm.tm_isdst = -1; /* Not implemented for now */
+ }
#else
tm.tm_sec = 0;
tm.tm_min = 0;