comparison src/cs/drivers/drv_app/power/board/power.c @ 213:0947a816580c

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