summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLinus Nielsen Feltzing <linus@haxx.se>2008-02-14 14:00:59 +0000
committerLinus Nielsen Feltzing <linus@haxx.se>2008-02-14 14:00:59 +0000
commitca3cb1e96596055e7ff3fb83b391ade88984f2e3 (patch)
tree171c4b9b69de8cb0b6eb9967b493f214219dbd7c
parent3fd2e52a0aa08c3d80ff797350f14f8a6dccb4b5 (diff)
downloadrockbox-ca3cb1e96596055e7ff3fb83b391ade88984f2e3.tar.gz
rockbox-ca3cb1e96596055e7ff3fb83b391ade88984f2e3.zip
FS#8273 by Przemyslaw Holubowski - H10 RTC alarm bugfixes
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@16310 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--firmware/drivers/rtc/rtc_e8564.c21
1 files changed, 14 insertions, 7 deletions
diff --git a/firmware/drivers/rtc/rtc_e8564.c b/firmware/drivers/rtc/rtc_e8564.c
index 0e81ee276d..322b04b20b 100644
--- a/firmware/drivers/rtc/rtc_e8564.c
+++ b/firmware/drivers/rtc/rtc_e8564.c
@@ -48,6 +48,8 @@
48/* Timer register flags */ 48/* Timer register flags */
49#define RTC_TE 0x80 49#define RTC_TE 0x80
50 50
51bool rtc_lock_alarm_clear=true;
52
51void rtc_init(void) 53void rtc_init(void)
52{ 54{
53 unsigned char tmp; 55 unsigned char tmp;
@@ -59,8 +61,8 @@ void rtc_init(void)
59 61
60 /* read value of the Control 2 register - we'll need it to preserve alarm and timer interrupt assertion flags */ 62 /* read value of the Control 2 register - we'll need it to preserve alarm and timer interrupt assertion flags */
61 rv = i2c_readbytes(0x51,RTC_CTRL2,1,&tmp); 63 rv = i2c_readbytes(0x51,RTC_CTRL2,1,&tmp);
62 /* clear alarm and timer interrupts */ 64 /* preserve alarm and timer interrupt flags */
63 tmp &= (RTC_TF | RTC_AF); 65 tmp &= (RTC_TF | RTC_AF | RTC_TIE | RTC_AIE);
64 pp_i2c_send(0x51, RTC_CTRL2,tmp); 66 pp_i2c_send(0x51, RTC_CTRL2,tmp);
65} 67}
66 68
@@ -149,19 +151,23 @@ bool rtc_enable_alarm(bool enable)
149{ 151{
150 unsigned char tmp=0; 152 unsigned char tmp=0;
151 int rv=0; 153 int rv=0;
152 154
153 if(enable) 155 if(enable)
154 { 156 {
155 /* enable alarm interrupt */ 157 /* enable alarm interrupt */
156 rv = i2c_readbytes(0x51,RTC_CTRL2,1,&tmp); 158 rv = i2c_readbytes(0x51,RTC_CTRL2,1,&tmp);
157 tmp |= RTC_AIE; 159 tmp |= RTC_AIE;
160 tmp &= ~RTC_AF;
158 pp_i2c_send(0x51, RTC_CTRL2,tmp); 161 pp_i2c_send(0x51, RTC_CTRL2,tmp);
159 } 162 }
160 else 163 else
161 { 164 {
162 /* disable alarm interrupt */ 165 /* disable alarm interrupt */
166 if(rtc_lock_alarm_clear)
167 /* lock disabling alarm before it was checked whether or not the unit was started by RTC alarm */
168 return false;
163 rv = i2c_readbytes(0x51,RTC_CTRL2,1,&tmp); 169 rv = i2c_readbytes(0x51,RTC_CTRL2,1,&tmp);
164 tmp &= ~RTC_AIE; 170 tmp &= ~(RTC_AIE | RTC_AF);
165 pp_i2c_send(0x51, RTC_CTRL2,tmp); 171 pp_i2c_send(0x51, RTC_CTRL2,tmp);
166 } 172 }
167 173
@@ -185,9 +191,9 @@ bool rtc_check_alarm_started(bool release_alarm)
185 /* read Control 2 register which contains alarm flag */ 191 /* read Control 2 register which contains alarm flag */
186 rv = i2c_readbytes(0x51,RTC_CTRL2,1,&tmp); 192 rv = i2c_readbytes(0x51,RTC_CTRL2,1,&tmp);
187 193
188 alarm_state = started = tmp & (RTC_AF | RTC_AIE); 194 alarm_state = started = ( (tmp & RTC_AF) && (tmp & RTC_AIE) );
189 195
190 if(release_alarm) 196 if(release_alarm && started)
191 { 197 {
192 rv = i2c_readbytes(0x51,RTC_CTRL2,1,&tmp); 198 rv = i2c_readbytes(0x51,RTC_CTRL2,1,&tmp);
193 /* clear alarm interrupt enable and alarm flag */ 199 /* clear alarm interrupt enable and alarm flag */
@@ -195,6 +201,7 @@ bool rtc_check_alarm_started(bool release_alarm)
195 pp_i2c_send(0x51, RTC_CTRL2,tmp); 201 pp_i2c_send(0x51, RTC_CTRL2,tmp);
196 } 202 }
197 run_before = true; 203 run_before = true;
204 rtc_lock_alarm_clear = false;
198 } 205 }
199 206
200 return started; 207 return started;