summaryrefslogtreecommitdiff
path: root/firmware/drivers/rtc/rtc_e8564.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/drivers/rtc/rtc_e8564.c')
-rw-r--r--firmware/drivers/rtc/rtc_e8564.c27
1 files changed, 15 insertions, 12 deletions
diff --git a/firmware/drivers/rtc/rtc_e8564.c b/firmware/drivers/rtc/rtc_e8564.c
index 7837bbaa83..ee2449ffb8 100644
--- a/firmware/drivers/rtc/rtc_e8564.c
+++ b/firmware/drivers/rtc/rtc_e8564.c
@@ -7,7 +7,7 @@
7 * \/ \/ \/ \/ \/ 7 * \/ \/ \/ \/ \/
8 * $Id$ 8 * $Id$
9 * 9 *
10 * Copyright (C) 2002 by Linus Nielsen Feltzing, Uwe Freese, Laurent Baum, 10 * Copyright (C) 2002 by Linus Nielsen Feltzing, Uwe Freese, Laurent Baum,
11 * Przemyslaw Holubowski 11 * Przemyslaw Holubowski
12 * 12 *
13 * This program is free software; you can redistribute it and/or 13 * This program is free software; you can redistribute it and/or
@@ -59,13 +59,14 @@ void rtc_init(void)
59{ 59{
60 unsigned char tmp; 60 unsigned char tmp;
61 int rv; 61 int rv;
62 62
63 /* initialize Control 1 register */ 63 /* initialize Control 1 register */
64 tmp = 0; 64 tmp = 0;
65 pp_i2c_send(RTC_ADDR, RTC_CTRL1, tmp); 65 pp_i2c_send(RTC_ADDR, RTC_CTRL1, tmp);
66 66
67 /* read value of the Control 2 register - we'll need it to preserve alarm and timer interrupt assertion flags */ 67 /* read value of the Control 2 register - we'll need it to preserve alarm and timer interrupt assertion flags */
68 rv = i2c_readbytes(RTC_ADDR, RTC_CTRL2, 1, &tmp); 68 rv = i2c_readbytes(RTC_ADDR, RTC_CTRL2, 1, &tmp);
69 (void)rv;
69 /* preserve alarm and timer interrupt flags */ 70 /* preserve alarm and timer interrupt flags */
70 tmp &= (RTC_TF | RTC_AF | RTC_TIE | RTC_AIE); 71 tmp &= (RTC_TF | RTC_AF | RTC_TIE | RTC_AIE);
71 pp_i2c_send(RTC_ADDR, RTC_CTRL2, tmp); 72 pp_i2c_send(RTC_ADDR, RTC_CTRL2, tmp);
@@ -119,6 +120,7 @@ void rtc_set_alarm(int h, int m)
119 120
120 /* clear alarm interrupt */ 121 /* clear alarm interrupt */
121 rv = i2c_readbytes(RTC_ADDR, RTC_CTRL2, 1, buf); 122 rv = i2c_readbytes(RTC_ADDR, RTC_CTRL2, 1, buf);
123 (void)rv;
122 buf[0] &= RTC_AF; 124 buf[0] &= RTC_AF;
123 pp_i2c_send(RTC_ADDR, RTC_CTRL2, buf[0]); 125 pp_i2c_send(RTC_ADDR, RTC_CTRL2, buf[0]);
124 126
@@ -128,7 +130,7 @@ void rtc_set_alarm(int h, int m)
128 else 130 else
129 /* ignore minutes comparison query */ 131 /* ignore minutes comparison query */
130 buf[0] = RTC_AE; 132 buf[0] = RTC_AE;
131 133
132 if( h >= 0 ) 134 if( h >= 0 )
133 buf[1] = DEC2BCD(h); 135 buf[1] = DEC2BCD(h);
134 else 136 else
@@ -172,7 +174,7 @@ void rtc_enable_alarm(bool enable)
172 } 174 }
173 else 175 else
174 { 176 {
175 /* disable alarm interrupt */ 177 /* disable alarm interrupt */
176 if(rtc_lock_alarm_clear) 178 if(rtc_lock_alarm_clear)
177 /* lock disabling alarm before it was checked whether or not the unit was started by RTC alarm */ 179 /* lock disabling alarm before it was checked whether or not the unit was started by RTC alarm */
178 return; 180 return;
@@ -180,6 +182,7 @@ void rtc_enable_alarm(bool enable)
180 tmp &= ~(RTC_AIE | RTC_AF); 182 tmp &= ~(RTC_AIE | RTC_AF);
181 pp_i2c_send(RTC_ADDR, RTC_CTRL2, tmp); 183 pp_i2c_send(RTC_ADDR, RTC_CTRL2, tmp);
182 } 184 }
185 (void)rv;
183} 186}
184 187
185bool rtc_check_alarm_started(bool release_alarm) 188bool rtc_check_alarm_started(bool release_alarm)
@@ -193,14 +196,14 @@ bool rtc_check_alarm_started(bool release_alarm)
193 { 196 {
194 started = alarm_state; 197 started = alarm_state;
195 alarm_state &= ~release_alarm; 198 alarm_state &= ~release_alarm;
196 } 199 }
197 else 200 else
198 { 201 {
199 /* read Control 2 register which contains alarm flag */ 202 /* read Control 2 register which contains alarm flag */
200 rv = i2c_readbytes(RTC_ADDR, RTC_CTRL2, 1, &tmp); 203 rv = i2c_readbytes(RTC_ADDR, RTC_CTRL2, 1, &tmp);
201 204
202 alarm_state = started = ( (tmp & RTC_AF) && (tmp & RTC_AIE) ); 205 alarm_state = started = ( (tmp & RTC_AF) && (tmp & RTC_AIE) );
203 206
204 if(release_alarm && started) 207 if(release_alarm && started)
205 { 208 {
206 rv = i2c_readbytes(RTC_ADDR, RTC_CTRL2, 1, &tmp); 209 rv = i2c_readbytes(RTC_ADDR, RTC_CTRL2, 1, &tmp);
@@ -211,7 +214,8 @@ bool rtc_check_alarm_started(bool release_alarm)
211 run_before = true; 214 run_before = true;
212 rtc_lock_alarm_clear = false; 215 rtc_lock_alarm_clear = false;
213 } 216 }
214 217 (void)rv;
218
215 return started; 219 return started;
216} 220}
217 221
@@ -219,11 +223,10 @@ bool rtc_check_alarm_flag(void)
219{ 223{
220 unsigned char tmp=0; 224 unsigned char tmp=0;
221 int rv=0; 225 int rv=0;
222 226
223 /* read Control 2 register which contains alarm flag */ 227 /* read Control 2 register which contains alarm flag */
224 rv = i2c_readbytes(RTC_ADDR, RTC_CTRL2, 1, &tmp); 228 rv = i2c_readbytes(RTC_ADDR, RTC_CTRL2, 1, &tmp);
225 229
226 return (tmp & RTC_AF); 230 return (tmp & RTC_AF);
227} 231}
228#endif /* HAVE_RTC_ALARM */ 232#endif /* HAVE_RTC_ALARM */
229