summaryrefslogtreecommitdiffstats
path: root/firmware/common
diff options
context:
space:
mode:
authorMichael Sevakis <jethead71@rockbox.org>2017-01-26 21:08:55 -0500
committerMichael Sevakis <jethead71@rockbox.org>2017-11-21 07:52:02 -0500
commitf4c42213062170ddfcc706b3c5ed19f47517c253 (patch)
tree65f8058970e97d939660cf1e39f844a06df66f84 /firmware/common
parent12bc24adbf919dc945928b2dcda74d51d33708f7 (diff)
downloadrockbox-f4c42213062170ddfcc706b3c5ed19f47517c253.tar.gz
rockbox-f4c42213062170ddfcc706b3c5ed19f47517c253.tar.bz2
rockbox-f4c42213062170ddfcc706b3c5ed19f47517c253.zip
Convert i.MX31 and AMS target to use RTC interrupt
Instead of checking ticks, set a sticky dirty flag that indicates that the RTC needs to be read. This gives a timely update and more accurate readout without actually reading the RTC until it changes. The implementation should atomically read the flag and clear it. Setting the flag would typically happen in an RTC tick ISR. Change-Id: I6fd325f22845029a485c502c884812d3676026ea
Diffstat (limited to 'firmware/common')
-rw-r--r--firmware/common/timefuncs.c45
1 files changed, 33 insertions, 12 deletions
diff --git a/firmware/common/timefuncs.c b/firmware/common/timefuncs.c
index c8819ea76e..50addad27a 100644
--- a/firmware/common/timefuncs.c
+++ b/firmware/common/timefuncs.c
@@ -24,13 +24,21 @@
#include "kernel.h"
#include "rtc.h"
+#ifdef HAVE_RTC_IRQ
+#include "rtc-target.h"
+#endif
#include "timefuncs.h"
#include "debug.h"
static struct tm tm;
#if !CONFIG_RTC
-static void fill_default_tm(struct tm *tm)
+static inline bool rtc_dirty(void)
+{
+ return true;
+}
+
+static inline int rtc_read_datetime(struct tm *tm)
{
tm->tm_sec = 0;
tm->tm_min = 0;
@@ -38,9 +46,9 @@ static void fill_default_tm(struct tm *tm)
tm->tm_mday = 1;
tm->tm_mon = 0;
tm->tm_year = 70;
- tm->tm_wday = 1;
- tm->tm_yday = 0; /* Not implemented for now */
- tm->tm_isdst = -1; /* Not implemented for now */
+ tm->tm_wday = 4;
+ tm->tm_yday = 0;
+ return 1;
}
#endif /* !CONFIG_RTC */
@@ -58,24 +66,37 @@ bool valid_time(const struct tm *tm)
else
return true;
}
-#endif /* CONFIG_RTC */
-struct tm *get_time(void)
+/* Don't read the RTC more than once per second
+ * returns true if the rtc needs to be read
+ * targets may override with their own implementation
+ */
+#ifndef HAVE_RTC_IRQ
+static inline bool rtc_dirty(void)
{
-#if CONFIG_RTC
static long timeout = 0;
/* Don't read the RTC more than once per second */
if (TIME_AFTER(current_tick, timeout))
{
- /* Once per second, 1/10th of a second off */
- timeout = HZ * (current_tick / HZ + 1) + HZ / 5;
+ /* Once per second, 1/5th of a second off */
+ timeout = current_tick / HZ * HZ + 6*HZ / 5;
+ return true;
+ }
+
+ return false;
+}
+#endif /* HAVE_RTC_IRQ */
+#endif /* CONFIG_RTC */
+
+struct tm *get_time(void)
+{
+ if (rtc_dirty())
+ {
rtc_read_datetime(&tm);
tm.tm_isdst = -1; /* Not implemented for now */
}
-#else /* No RTC */
- fill_default_tm(&tm);
-#endif /* RTC */
+
return &tm;
}