From f4c42213062170ddfcc706b3c5ed19f47517c253 Mon Sep 17 00:00:00 2001 From: Michael Sevakis Date: Thu, 26 Jan 2017 21:08:55 -0500 Subject: 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 --- firmware/drivers/rtc/rtc_mc13783.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'firmware/drivers/rtc/rtc_mc13783.c') diff --git a/firmware/drivers/rtc/rtc_mc13783.c b/firmware/drivers/rtc/rtc_mc13783.c index a1f78f738d..aedf5f6fa5 100644 --- a/firmware/drivers/rtc/rtc_mc13783.c +++ b/firmware/drivers/rtc/rtc_mc13783.c @@ -69,6 +69,7 @@ static const unsigned char rtc_registers[RTC_NUM_REGS_RD] = /* was it an alarm that triggered power on ? */ static bool alarm_start = false; +static unsigned long rtc_is_dirty = 1; /* force a read right away */ static const unsigned short month_table[13] = { @@ -96,6 +97,16 @@ static bool read_time_and_day(uint32_t regs[RTC_NUM_REGS_RD]) return true; } +void MC13783_EVENT_CB_1HZ(void) +{ + rtc_is_dirty = 1; +} + +bool rtc_mc13783_dirty(void) +{ + return bitclr32(&rtc_is_dirty, 1); +} + /** Public APIs **/ void rtc_init(void) { @@ -105,6 +116,8 @@ void rtc_init(void) alarm_start = true; mc13783_write(MC13783_INTERRUPT_STATUS1, MC13783_TODAI); } + + mc13783_enable_event(MC13783_INT_ID_1HZ, true); } int rtc_read_datetime(struct tm *tm) -- cgit v1.2.3