FreeCalypso > hg > fc-magnetite
comparison src/cs/drivers/drv_app/power/board/power.c @ 0:945cf7f506b2
src/cs: chipsetsw import from tcs211-fcmodem
binary blobs and LCD demo files have been excluded,
all line endings are LF only
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 25 Sep 2016 22:50:11 +0000 |
parents | |
children | 4b6acb68b851 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:945cf7f506b2 |
---|---|
1 /******************************************************************************* | |
2 * | |
3 * power.c | |
4 * | |
5 * Purpose: This file contains the functions used for power on and off | |
6 * management of the board. | |
7 * In case of RVM_PWR_SWE, this file contains also the | |
8 * functions used for charger plug and unplug management. | |
9 * They are all called after the occurence of the ABB interrupt. | |
10 * | |
11 * Author: Candice Bazanegue (c-brille@ti.com) | |
12 * | |
13 * | |
14 * (C) Texas Instruments 2001 | |
15 * | |
16 ******************************************************************************/ | |
17 | |
18 #ifndef _WINDOWS | |
19 #include "rv.cfg" | |
20 #endif | |
21 | |
22 #include "abb/abb.h" | |
23 #include "rvm/rvm_use_id_list.h" | |
24 #include "spi/spi_env.h" | |
25 #include "power/power.h" | |
26 #include "rv/rv_defined_swe.h" // for RVM_PWR_SWE | |
27 | |
28 #ifndef _WINDOWS | |
29 #include "kpd/kpd_power_api.h" | |
30 #include "ffs/ffs.h" | |
31 #endif // _WINDOWS | |
32 | |
33 #ifdef RVM_PWR_SWE | |
34 #include "spi/spi_task.h" | |
35 #ifndef _WINDOWS | |
36 #include "l1sw.cfg" | |
37 #include "chipset.cfg" | |
38 #endif // _WINDOWS | |
39 #include "pwr/pwr_messages.h" | |
40 #include "pwr/pwr_liion_cha.h" | |
41 #include "pwr/pwr_disch.h" | |
42 #endif /* #ifdef RVM_PWR_SWE */ | |
43 | |
44 | |
45 | |
46 #ifndef _WINDOWS | |
47 /* Declare the variable containing pressed and released callback. */ | |
48 extern T_KPD_KEYPAD Kp; | |
49 | |
50 extern effs_t ffs_exit(void); | |
51 #endif // _WINDOWS | |
52 | |
53 | |
54 /// The ABB status used to know the cause of the Switch ON event. | |
55 static SYS_UWORD16 Power_abb_status = 0; | |
56 | |
57 | |
58 /******************************************************************************* | |
59 ** | |
60 ** Function Power_ON_Button | |
61 ** | |
62 ** Description: Informs the Protocol Stack that the Power ON key has been | |
63 ** pressed, and thus allows it to start. | |
64 ** | |
65 *******************************************************************************/ | |
66 void Power_ON_Button(void) | |
67 { | |
68 #ifndef _WINDOWS | |
69 SPI_GBL_INFO_PTR->is_gsm_on = TRUE; | |
70 | |
71 /* | |
72 When we build for ACI, we have no MMI, so there's no point waiting | |
73 for a keypress. See CR 17958. | |
74 */ | |
75 #if (MMI == 0) | |
76 return; | |
77 #endif | |
78 | |
79 #if (OP_WCP == 0) | |
80 | |
81 /* Wait until the pointers initialization by the SMI */ | |
82 while(!(Kp.pressed && Kp.released)) | |
83 rvf_delay(1); | |
84 | |
85 #if (TEST==0) | |
86 (Kp.pressed)(KPD_PWR); /* tell key is pressed */ | |
87 rvf_delay(5); | |
88 (Kp.released)(); /* allow protocol stack to start */ | |
89 #endif | |
90 | |
91 #endif // OP_WCP == 0 | |
92 | |
93 #else | |
94 rvf_send_trace("Start from button", 17, NULL_PARAM, RV_TRACE_LEVEL_WARNING, LCC_USE_ID); | |
95 SPI_GBL_INFO_PTR->is_gsm_on = TRUE; | |
96 #endif // _WINDOWS | |
97 } | |
98 | |
99 | |
100 | |
101 /******************************************************************************* | |
102 ** | |
103 ** Function Power_OFF_Button | |
104 ** | |
105 ** Description: Informs the Protocol Stack that the Power OFF key has been | |
106 ** pressed, and thus allows it to stop. | |
107 ** | |
108 *******************************************************************************/ | |
109 void Power_OFF_Button(void) | |
110 { | |
111 #ifndef _WINDOWS | |
112 ffs_exit (); | |
113 #endif // _WINDOWS | |
114 rvf_send_trace("Power off button", 16, NULL_PARAM, RV_TRACE_LEVEL_WARNING, LCC_USE_ID); | |
115 SPI_GBL_INFO_PTR->is_gsm_on = FALSE; | |
116 #ifndef _WINDOWS | |
117 #if (OP_WCP == 0) | |
118 (Kp.pressed)(KPD_PWR); /* tell key is pressed */ | |
119 rvf_delay(5); | |
120 (Kp.released)(); /* tell key is released */ | |
121 #endif | |
122 #endif // _WINDOWS | |
123 } | |
124 | |
125 | |
126 /** | |
127 * @brief Sets the cause of the swith ON event. | |
128 * | |
129 * This function get the ABB status register and stores it into the | |
130 * global variable Power_abb_status. | |
131 * | |
132 * @noparam | |
133 * | |
134 * @noreturn | |
135 */ | |
136 void Set_Switch_ON_Cause(void) | |
137 { | |
138 Power_abb_status = ABB_Read_Status(); | |
139 } | |
140 | |
141 | |
142 /******************************************************************************* | |
143 ** | |
144 ** Function Switch_ON | |
145 ** | |
146 ** Description This function is called by the spi task after the board is | |
147 ** switched ON. It calls the appropriate function according | |
148 ** to the ABB status register. | |
149 ** | |
150 ** Warning The Set_Switch_ON_Cause() function has to be called prior. | |
151 ** | |
152 *******************************************************************************/ | |
153 void Switch_ON(void) | |
154 { | |
155 #if ((ANLG_FAM == 1) || (ANLG_FAM == 2)) | |
156 if (Power_abb_status & ONBSTS) | |
157 #elif (ANLG_FAM == 3) | |
158 if (Power_abb_status & PWONBSTS) | |
159 #endif | |
160 { | |
161 /* Switch on Condition on ON BUTTON Push */ | |
162 rvf_send_trace("Push Button from OFF to ON",26, NULL_PARAM, RV_TRACE_LEVEL_DEBUG_LOW, LCC_USE_ID); | |
163 Power_ON_Button(); | |
164 #ifdef RVM_PWR_SWE | |
165 pwr_handle_discharge(); | |
166 #endif | |
167 } | |
168 | |
169 #if ((ANLG_FAM == 1) || (ANLG_FAM == 2)) | |
170 else if (Power_abb_status & ONRSTS) | |
171 #elif (ANLG_FAM == 3) | |
172 else if (Power_abb_status & RPSTS) | |
173 #endif | |
174 { | |
175 /* Switch on Condition on ON REM transition 0->1 */ | |
176 rvf_send_trace("ON Remote",9, NULL_PARAM, RV_TRACE_LEVEL_DEBUG_LOW, LCC_USE_ID); | |
177 Power_ON_Remote(); | |
178 #ifdef RVM_PWR_SWE | |
179 pwr_handle_discharge(); | |
180 #endif | |
181 } | |
182 | |
183 #ifdef RVM_PWR_SWE | |
184 else if (Power_abb_status & CHGSTS) | |
185 { | |
186 /* Switch on Condition on CHARGER IC PLUG */ | |
187 rvf_send_trace("PWR: Charger Plug",17, NULL_PARAM, RV_TRACE_LEVEL_DEBUG_LOW, LCC_USE_ID); | |
188 if (Power_abb_status & CHGPRES) | |
189 { | |
190 /* charger still present */ | |
191 PWR_Charger_Plug(); | |
192 } | |
193 } | |
194 #endif /* #ifdef RVM_PWR_SWE */ | |
195 | |
196 else | |
197 { | |
198 // The reset should run the SW in the same way than a Power ON | |
199 rvf_send_trace("Start from reset",16, NULL_PARAM, RV_TRACE_LEVEL_DEBUG_LOW, LCC_USE_ID); | |
200 Power_ON_Button(); | |
201 #ifdef RVM_PWR_SWE | |
202 pwr_handle_discharge(); | |
203 #endif | |
204 } | |
205 } | |
206 | |
207 | |
208 | |
209 /******************************************************************************* | |
210 ** | |
211 ** Function Power_ON_Remote | |
212 ** | |
213 ** Description | |
214 ** | |
215 ** | |
216 *******************************************************************************/ | |
217 void Power_ON_Remote(void) | |
218 { | |
219 } | |
220 | |
221 | |
222 | |
223 /******************************************************************************* | |
224 ** | |
225 ** Function Power_OFF_Remote | |
226 ** | |
227 ** Description | |
228 ** | |
229 ** | |
230 *******************************************************************************/ | |
231 void Power_OFF_Remote(void) | |
232 { | |
233 } | |
234 | |
235 | |
236 | |
237 /******************************************************************************* | |
238 ** | |
239 ** Function Power_IT_WakeUp | |
240 ** | |
241 ** Description | |
242 ** | |
243 ** | |
244 *******************************************************************************/ | |
245 void Power_IT_WakeUp(void) | |
246 { | |
247 } | |
248 | |
249 | |
250 | |
251 #ifdef RVM_PWR_SWE | |
252 /******************************************************************************* | |
253 ** | |
254 ** Function PWR_Charger_Plug | |
255 ** | |
256 ** Description | |
257 ** | |
258 ** | |
259 *******************************************************************************/ | |
260 void PWR_Charger_Plug(void) | |
261 { | |
262 | |
263 /* Start the fast charging cycle */ | |
264 | |
265 /* Since this function is called from the SPI task | |
266 it can't be interrupt by another task | |
267 so we can directly access the SPI through the low-level driver */ | |
268 | |
269 if (SPI_GBL_INFO_PTR->is_gsm_on == FALSE) /* GSM OFF */ | |
270 { | |
271 rvf_delay(RVF_MS_TO_TICKS(2000)); | |
272 } | |
273 | |
274 rvf_stop_timer(SPI_TIMER3); | |
275 | |
276 /* informs the upper layer that the charger has been plugged */ | |
277 pwr_send_charger_plug_event(); | |
278 | |
279 /* get the type of the battery */ | |
280 pwr_get_battery_type(); | |
281 } | |
282 | |
283 | |
284 | |
285 /******************************************************************************* | |
286 ** | |
287 ** Function PWR_Charger_Unplug | |
288 ** | |
289 ** Description | |
290 ** | |
291 ** | |
292 *******************************************************************************/ | |
293 void PWR_Charger_Unplug(void) | |
294 { | |
295 /* informs the upper layer that the charger has been unplugged */ | |
296 pwr_send_charger_unplug_event(); | |
297 | |
298 rvf_send_trace("Charger unplug", 14, NULL_PARAM, RV_TRACE_LEVEL_DEBUG_LOW, LCC_USE_ID ); | |
299 pwr_stop_charging(); | |
300 if (SPI_GBL_INFO_PTR->is_gsm_on == FALSE) /* GSM OFF */ | |
301 { | |
302 #ifndef _WINDOWS | |
303 #if (ANLG_FAM == 1) | |
304 ABB_Write_Register_on_page(PAGE0, VRPCCTL2, 0x00EE); | |
305 #elif ((ANLG_FAM == 2) || (ANLG_FAM == 3)) | |
306 ABB_Write_Register_on_page(PAGE0, VRPCDEV, 0x0001); | |
307 #endif | |
308 #else | |
309 ABB_Write_Register_on_page(PAGE0, VRPCDEV, 0x00EE); | |
310 #endif // _WINDOWS | |
311 } | |
312 else | |
313 { | |
314 pwr_handle_discharge(); | |
315 } | |
316 } | |
317 #endif /* #ifdef RVM_PWR_SWE */ | |
318 | |
319 | |
320 | |
321 | |
322 |