summaryrefslogtreecommitdiff
path: root/firmware
diff options
context:
space:
mode:
authorRafaël Carré <rafael.carre@gmail.com>2010-05-22 00:28:03 +0000
committerRafaël Carré <rafael.carre@gmail.com>2010-05-22 00:28:03 +0000
commit172fc967b07f59e4928db9ca331f2f7a3a383c04 (patch)
treec87f3d76efae7b84f0061336ed555d1e5a1f38c8 /firmware
parent2e004fd4047a03e0e57bdb02a67a85a729a3caaa (diff)
downloadrockbox-172fc967b07f59e4928db9ca331f2f7a3a383c04.tar.gz
rockbox-172fc967b07f59e4928db9ca331f2f7a3a383c04.zip
as3525v2: RTC alarm
A specific poweroff function needs to be used for wake-up to work Disable RTC in bootloaders for consistency with other Sansas git-svn-id: svn://svn.rockbox.org/rockbox/trunk@26243 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware')
-rw-r--r--firmware/drivers/rtc/rtc_as3514.c107
-rw-r--r--firmware/export/as3514.h4
-rw-r--r--firmware/export/config/sansaclipplus.h5
-rw-r--r--firmware/export/config/sansaclipv2.h5
-rw-r--r--firmware/export/config/sansafuzev2.h6
-rw-r--r--firmware/target/arm/as3525/power-as3525.c8
6 files changed, 131 insertions, 4 deletions
diff --git a/firmware/drivers/rtc/rtc_as3514.c b/firmware/drivers/rtc/rtc_as3514.c
index 8597d138fb..fe2921b433 100644
--- a/firmware/drivers/rtc/rtc_as3514.c
+++ b/firmware/drivers/rtc/rtc_as3514.c
@@ -51,6 +51,112 @@ static inline bool is_leapyear(int year)
51 return false; 51 return false;
52} 52}
53 53
54#ifdef HAVE_RTC_ALARM /* as3543 */
55static int wakeup_h;
56static int wakeup_m;
57static bool alarm_enabled = false;
58
59void rtc_set_alarm(int h, int m)
60{
61 wakeup_h = h;
62 wakeup_m = m;
63}
64
65void rtc_get_alarm(int *h, int *m)
66{
67 *h = wakeup_h;
68 *m = wakeup_m;
69}
70
71void rtc_alarm_poweroff(void)
72{
73 if(!alarm_enabled)
74 return;
75
76 struct tm tm;
77 rtc_read_datetime(&tm);
78 int hours = wakeup_h - tm.tm_hour;
79 int mins = wakeup_m - tm.tm_min;
80 if(mins < 0)
81 {
82 mins += 60;
83 hours -= 1;
84 }
85 if(hours < 0)
86 hours += 24;
87
88 uint32_t seconds = hours*3600 + mins*60;
89 if(seconds == 0)
90 seconds = 24*3600;
91
92 seconds -= tm.tm_sec;
93
94 disable_irq();
95
96 ascodec_write_pmu(0x1a, 4, 0x0); // In_Cntr : disable hearbeat source
97
98 ascodec_write(AS3543_WAKEUP, seconds);
99 seconds >>= 8;
100 ascodec_write(AS3543_WAKEUP, seconds);
101 seconds >>= 8;
102 seconds |= 1<<7; /* enable bit */
103 ascodec_write(AS3543_WAKEUP, seconds);
104
105 /* write our watermark : desired time of wake up */
106 ascodec_write(AS3543_WAKEUP, wakeup_h);
107 ascodec_write(AS3543_WAKEUP, wakeup_m);
108
109 ascodec_write(AS3514_SYSTEM, (1<<3) | (1<<0)); // enable hearbeat watchdog
110
111 while(1);
112}
113
114bool rtc_enable_alarm(bool enable)
115{
116 return alarm_enabled = enable;
117}
118
119bool rtc_check_alarm_started(bool release_alarm)
120{
121 (void) release_alarm;
122
123 /* was it an alarm that triggered power on ? */
124 bool alarm_start = false;
125
126 /* 3 first reads give the 23 bits counter and enable bit */
127 ascodec_read(AS3543_WAKEUP); /* bits 7:0 */
128 ascodec_read(AS3543_WAKEUP); /* bits 15:8 */
129 if(ascodec_read(AS3543_WAKEUP) & (1<<7)) /* enable bit */
130 {
131 alarm_enabled = true;
132
133 /* subsequent reads give the 16 bytes static SRAM */
134 wakeup_h = ascodec_read(AS3543_WAKEUP);
135 wakeup_m = ascodec_read(AS3543_WAKEUP);
136
137 struct tm tm;
138 rtc_read_datetime(&tm);
139
140 /* do we wake up at the programmed time, or for another reason ? */
141 if(wakeup_h == tm.tm_hour && wakeup_m == tm.tm_min)
142 alarm_start = true;
143 }
144
145 /* disable alarm */
146 ascodec_write(AS3543_WAKEUP, 0); /* bits 7:0 */
147 ascodec_write(AS3543_WAKEUP, 0); /* bits 15:8 */
148 ascodec_write(AS3543_WAKEUP, 0); /* bits 22:16 + enable bit */
149
150 return alarm_start;
151}
152
153bool rtc_check_alarm_flag(void)
154{
155 /* We don't need to do anything special if it has already fired */
156 return false;
157}
158#endif /* HAVE_RTC_ALARM */
159
54void rtc_init(void) 160void rtc_init(void)
55{ 161{
56} 162}
@@ -168,4 +274,3 @@ int rtc_write_datetime(const struct tm *tm)
168 } 274 }
169 return 1; 275 return 1;
170} 276}
171
diff --git a/firmware/export/as3514.h b/firmware/export/as3514.h
index e9eda62ee3..31253724a7 100644
--- a/firmware/export/as3514.h
+++ b/firmware/export/as3514.h
@@ -96,6 +96,10 @@ extern void audiohw_set_lineout_vol(int vol_l, int vol_r);
96#define AS3514_SUPERVISOR 0x24 96#define AS3514_SUPERVISOR 0x24
97#endif 97#endif
98 98
99#ifdef HAVE_AS3543
100#define AS3543_WAKEUP 0x22
101#endif
102
99/* AS3543 has 2 IRQ_ENRD registers at 0x23 and 0x24, but we don't use them 103/* AS3543 has 2 IRQ_ENRD registers at 0x23 and 0x24, but we don't use them
100 * We call the real IRQ_ENRD2 register, IRQ_ENRD0, to stay compatible with 104 * We call the real IRQ_ENRD2 register, IRQ_ENRD0, to stay compatible with
101 * as3514, because the bits we use are the same 105 * as3514, because the bits we use are the same
diff --git a/firmware/export/config/sansaclipplus.h b/firmware/export/config/sansaclipplus.h
index ab4408afe5..9382b22cbd 100644
--- a/firmware/export/config/sansaclipplus.h
+++ b/firmware/export/config/sansaclipplus.h
@@ -101,9 +101,12 @@
101#define HAVE_AS3514 101#define HAVE_AS3514
102#define HAVE_AS3543 102#define HAVE_AS3543
103 103
104/* define this if you have a real-time clock */
105#ifndef BOOTLOADER 104#ifndef BOOTLOADER
105/* define this if you have a real-time clock */
106#define CONFIG_RTC RTC_AS3514 106#define CONFIG_RTC RTC_AS3514
107
108/* Define if the device can wake from an RTC alarm */
109#define HAVE_RTC_ALARM
107#endif 110#endif
108 111
109/* Define this if you have a software controlled poweroff */ 112/* Define this if you have a software controlled poweroff */
diff --git a/firmware/export/config/sansaclipv2.h b/firmware/export/config/sansaclipv2.h
index 262ed36167..3ae09b7003 100644
--- a/firmware/export/config/sansaclipv2.h
+++ b/firmware/export/config/sansaclipv2.h
@@ -97,9 +97,12 @@
97#define HAVE_AS3514 97#define HAVE_AS3514
98#define HAVE_AS3543 98#define HAVE_AS3543
99 99
100/* define this if you have a real-time clock */
101#ifndef BOOTLOADER 100#ifndef BOOTLOADER
101/* define this if you have a real-time clock */
102#define CONFIG_RTC RTC_AS3514 102#define CONFIG_RTC RTC_AS3514
103
104/* Define if the device can wake from an RTC alarm */
105#define HAVE_RTC_ALARM
103#endif 106#endif
104 107
105/* Define this if you have a software controlled poweroff */ 108/* Define this if you have a software controlled poweroff */
diff --git a/firmware/export/config/sansafuzev2.h b/firmware/export/config/sansafuzev2.h
index a21eb34f94..8b13217dce 100644
--- a/firmware/export/config/sansafuzev2.h
+++ b/firmware/export/config/sansafuzev2.h
@@ -61,10 +61,14 @@
61/* define this if you can invert the colours on your LCD */ 61/* define this if you can invert the colours on your LCD */
62//#define HAVE_LCD_INVERT 62//#define HAVE_LCD_INVERT
63 63
64 64#ifndef BOOTLOADER
65/* define this if you have a real-time clock */ 65/* define this if you have a real-time clock */
66#define CONFIG_RTC RTC_AS3514 66#define CONFIG_RTC RTC_AS3514
67 67
68/* Define if the device can wake from an RTC alarm */
69#define HAVE_RTC_ALARM
70#endif
71
68/* There is no hardware tone control */ 72/* There is no hardware tone control */
69#define HAVE_SW_TONE_CONTROLS 73#define HAVE_SW_TONE_CONTROLS
70 74
diff --git a/firmware/target/arm/as3525/power-as3525.c b/firmware/target/arm/as3525/power-as3525.c
index 7b93dd1cd1..21ce98bd75 100644
--- a/firmware/target/arm/as3525/power-as3525.c
+++ b/firmware/target/arm/as3525/power-as3525.c
@@ -26,6 +26,14 @@
26 26
27void power_off(void) 27void power_off(void)
28{ 28{
29#ifdef HAVE_RTC_ALARM
30 /* as3543 RTC wake-up needs a specific power down */
31
32 extern void rtc_alarm_poweroff(void); /* in drivers/rtc/rtc_as3514.c */
33
34 rtc_alarm_poweroff(); /* will return if wake-up isn't enabled */
35#endif /* HAVE_RTC_ALARM */
36
29 /* clear bit 0 of system register */ 37 /* clear bit 0 of system register */
30 ascodec_write(AS3514_SYSTEM, ascodec_read(AS3514_SYSTEM) & ~1); 38 ascodec_write(AS3514_SYSTEM, ascodec_read(AS3514_SYSTEM) & ~1);
31 39