diff options
Diffstat (limited to 'firmware/drivers')
-rw-r--r-- | firmware/drivers/rtc.c | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/firmware/drivers/rtc.c b/firmware/drivers/rtc.c index d5b6c2fda6..5f60c23bdd 100644 --- a/firmware/drivers/rtc.c +++ b/firmware/drivers/rtc.c | |||
@@ -28,7 +28,13 @@ | |||
28 | 28 | ||
29 | void rtc_init(void) | 29 | void rtc_init(void) |
30 | { | 30 | { |
31 | unsigned char data; | 31 | unsigned char data; |
32 | |||
33 | #ifdef HAVE_ALARM_MOD | ||
34 | /* Check + save alarm bit first, since something in rtc_init resets AF */ | ||
35 | rtc_check_alarm_started(false); | ||
36 | #endif | ||
37 | |||
32 | rtc_write(0x13, 0x10); /* 32 kHz square wave */ | 38 | rtc_write(0x13, 0x10); /* 32 kHz square wave */ |
33 | 39 | ||
34 | /* Clear the Stop bit if it is set */ | 40 | /* Clear the Stop bit if it is set */ |
@@ -67,6 +73,25 @@ void rtc_init(void) | |||
67 | 73 | ||
68 | #ifdef HAVE_ALARM_MOD | 74 | #ifdef HAVE_ALARM_MOD |
69 | 75 | ||
76 | /* check whether the unit has been started by the RTC alarm function */ | ||
77 | /* (check for AF, which => started using wakeup alarm) */ | ||
78 | bool rtc_check_alarm_started(bool release_alarm) | ||
79 | { | ||
80 | static bool alarm_state, run_before; | ||
81 | bool rc; | ||
82 | |||
83 | if (run_before) { | ||
84 | rc = alarm_state; | ||
85 | alarm_state &= ~release_alarm; | ||
86 | } else { | ||
87 | /* This call resets AF, so we store the state for later recall */ | ||
88 | rc = alarm_state = ((rtc_read(0x0f) & 0x40) != 0); | ||
89 | run_before = true; | ||
90 | } | ||
91 | |||
92 | return rc; | ||
93 | } | ||
94 | |||
70 | /* set alarm time registers to the given time (repeat once per day) */ | 95 | /* set alarm time registers to the given time (repeat once per day) */ |
71 | void rtc_set_alarm(int h, int m) | 96 | void rtc_set_alarm(int h, int m) |
72 | { | 97 | { |
@@ -114,7 +139,7 @@ bool rtc_enable_alarm(bool enable) | |||
114 | data &= 0x5f; /* turn bit d7=AFE and d5=ABE off */ | 139 | data &= 0x5f; /* turn bit d7=AFE and d5=ABE off */ |
115 | rtc_write(0x0a, data); | 140 | rtc_write(0x0a, data); |
116 | 141 | ||
117 | /* check if alarm flag AF is off (as it sould be) */ | 142 | /* check if alarm flag AF is off (as it should be) */ |
118 | if ((rtc_read(0x0f) & 0x40) != 0) /* on */ | 143 | if ((rtc_read(0x0f) & 0x40) != 0) /* on */ |
119 | { | 144 | { |
120 | data &= 0x5f; /* turn bit d7=AFE and d5=ABE off */ | 145 | data &= 0x5f; /* turn bit d7=AFE and d5=ABE off */ |