Index: firmware/drivers/rtc/rtc_as3514.c =================================================================== --- firmware/drivers/rtc/rtc_as3514.c (revision 27293) +++ firmware/drivers/rtc/rtc_as3514.c (working copy) @@ -68,8 +68,36 @@ *m = wakeup_m; } +/* Reads the AS3543 wakeup register */ +static void wakeup_read(unsigned char *buf, int len) +{ + int i, oldstatus; + + oldstatus = disable_irq_save(); + ascodec_read(0); + for (i = 0; i < len; i++) { + buf[i] = ascodec_read(AS3543_WAKEUP); + } + restore_irq(oldstatus); +} + +/* Writes the AS3543 wakeup register */ +static void wakeup_write(unsigned char *buf, int len) +{ + int i, oldstatus; + + oldstatus = disable_irq_save(); + ascodec_read(0); + for (i = 0; i < len; i++) { + ascodec_write(AS3543_WAKEUP, buf[i]); + } + restore_irq(oldstatus); +} + void rtc_alarm_poweroff(void) { + unsigned char buf[6]; + if(!alarm_enabled) return; @@ -91,26 +119,19 @@ seconds -= tm.tm_sec; - disable_irq(); + /* write wakeup register */ + buf[0] = seconds & 0xFF; + buf[1] = (seconds >> 8) & 0xFF; + buf[2] = ((seconds >> 16) & 0xFF) | (1 << 7); + buf[3] = 0x80; /* prevents OF database refresh from micro SD */ + buf[4] = wakeup_h; + buf[5] = wakeup_m; + wakeup_write(buf, sizeof(buf)); - ascodec_write(AS3543_WAKEUP, seconds); - seconds >>= 8; - ascodec_write(AS3543_WAKEUP, seconds); - seconds >>= 8; - seconds |= 1<<7; /* enable bit */ - ascodec_write(AS3543_WAKEUP, seconds); - - /* write 0x80 to prevent the OF refreshing its database from the microSD */ - ascodec_write(AS3543_WAKEUP, 0x80); - - /* write our desired time of wake up to detect power-up from RTC */ - ascodec_write(AS3543_WAKEUP, wakeup_h); - ascodec_write(AS3543_WAKEUP, wakeup_m); - - /* enable hearbeat watchdog */ + /* enable heartbeat watchdog */ ascodec_write(AS3514_SYSTEM, (1<<3) | (1<<0)); - /* In_Cntr : disable hearbeat source */ + /* In_Cntr : disable heartbeat source */ ascodec_write_pmu(0x1a, 4, ascodec_read_pmu(0x1a, 4) & ~(3<<2)); while(1); @@ -123,20 +144,22 @@ bool rtc_check_alarm_started(bool release_alarm) { + unsigned char buf[6]; + (void) release_alarm; - /* 3 first reads give the 23 bits counter and enable bit */ - ascodec_read(AS3543_WAKEUP); /* bits 7:0 */ - ascodec_read(AS3543_WAKEUP); /* bits 15:8 */ - if(!(ascodec_read(AS3543_WAKEUP) & (1<<7))) /* enable bit */ + /* read wakeup register and check if alarm was enabled */ + wakeup_read(buf, sizeof(buf)); + if (!(buf[2] & (1 << 7))) { return false; - - /* skip WAKEUP[3] which the OF uses for other purposes */ - ascodec_read(AS3543_WAKEUP); + } + wakeup_h = buf[4]; + wakeup_m = buf[5]; - /* subsequent reads give the 16 bytes static SRAM */ - wakeup_h = ascodec_read(AS3543_WAKEUP); - wakeup_m = ascodec_read(AS3543_WAKEUP); + if (release_alarm) { + buf[2] &= ~(1 << 7); + wakeup_write(buf, 3); + } struct tm tm; rtc_read_datetime(&tm);