FreeCalypso > hg > fc-selenite
comparison src/cs/drivers/drv_app/power/board/power.c @ 0:b6a5e36de839
src/cs: initial import from Magnetite
| author | Mychaela Falconia <falcon@freecalypso.org> |
|---|---|
| date | Sun, 15 Jul 2018 04:39:26 +0000 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:b6a5e36de839 |
|---|---|
| 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 | |
| 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 | |
| 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 } | |
| 95 | |
| 96 | |
| 97 | |
| 98 /******************************************************************************* | |
| 99 ** | |
| 100 ** Function Power_OFF_Button | |
| 101 ** | |
| 102 ** Description: Informs the Protocol Stack that the Power OFF key has been | |
| 103 ** pressed, and thus allows it to stop. | |
| 104 ** | |
| 105 *******************************************************************************/ | |
| 106 void Power_OFF_Button(void) | |
| 107 { | |
| 108 #ifndef _WINDOWS | |
| 109 ffs_exit (); | |
| 110 #endif // _WINDOWS | |
| 111 rvf_send_trace("Power off button", 16, NULL_PARAM, RV_TRACE_LEVEL_WARNING, LCC_USE_ID); | |
| 112 SPI_GBL_INFO_PTR->is_gsm_on = FALSE; | |
| 113 #ifndef _WINDOWS | |
| 114 #if (OP_WCP == 0) && (MMI != 0) | |
| 115 (Kp.pressed)(KPD_PWR); /* tell key is pressed */ | |
| 116 rvf_delay(5); | |
| 117 (Kp.released)(); /* tell key is released */ | |
| 118 #else | |
| 119 ABB_Power_Off(); | |
| 120 #endif | |
| 121 #endif // _WINDOWS | |
| 122 } | |
| 123 | |
| 124 | |
| 125 /** | |
| 126 * @brief Sets the cause of the swith ON event. | |
| 127 * | |
| 128 * This function get the ABB status register and stores it into the | |
| 129 * global variable Power_abb_status. | |
| 130 * | |
| 131 * @noparam | |
| 132 * | |
| 133 * @noreturn | |
| 134 */ | |
| 135 void Set_Switch_ON_Cause(void) | |
| 136 { | |
| 137 Power_abb_status = ABB_Read_Status(); | |
| 138 } | |
| 139 | |
| 140 | |
| 141 /******************************************************************************* | |
| 142 ** | |
| 143 ** Function Switch_ON | |
| 144 ** | |
| 145 ** Description This function is called by the spi task after the board is | |
| 146 ** switched ON. It calls the appropriate function according | |
| 147 ** to the ABB status register. | |
| 148 ** | |
| 149 ** Warning The Set_Switch_ON_Cause() function has to be called prior. | |
| 150 ** | |
| 151 *******************************************************************************/ | |
| 152 void Switch_ON(void) | |
| 153 { | |
| 154 #if ((ANLG_FAM == 1) || (ANLG_FAM == 2)) | |
| 155 if (Power_abb_status & ONBSTS) | |
| 156 #elif (ANLG_FAM == 3) | |
| 157 if (Power_abb_status & PWONBSTS) | |
| 158 #endif | |
| 159 { | |
| 160 /* 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); | |
| 162 Power_ON_Button(); | |
| 163 #ifdef RVM_PWR_SWE | |
| 164 pwr_handle_discharge(); | |
| 165 #endif | |
| 166 } | |
| 167 | |
| 168 #if ((ANLG_FAM == 1) || (ANLG_FAM == 2)) | |
| 169 else if (Power_abb_status & ONRSTS) | |
| 170 #elif (ANLG_FAM == 3) | |
| 171 else if (Power_abb_status & RPSTS) | |
| 172 #endif | |
| 173 { | |
| 174 /* 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); | |
| 176 Power_ON_Remote(); | |
| 177 #ifdef RVM_PWR_SWE | |
| 178 pwr_handle_discharge(); | |
| 179 #endif | |
| 180 } | |
| 181 | |
| 182 #ifdef RVM_PWR_SWE | |
| 183 else if (Power_abb_status & CHGSTS) | |
| 184 { | |
| 185 /* 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); | |
| 187 if (Power_abb_status & CHGPRES) | |
| 188 { | |
| 189 /* charger still present */ | |
| 190 PWR_Charger_Plug(); | |
| 191 } | |
| 192 } | |
| 193 #endif /* #ifdef RVM_PWR_SWE */ | |
| 194 | |
| 195 else | |
| 196 { | |
| 197 // The reset should run the SW in the same way than a Power ON | |
| 198 rvf_send_trace("Start from reset",16, NULL_PARAM, RV_TRACE_LEVEL_DEBUG_LOW, LCC_USE_ID); | |
| 199 Power_ON_Button(); | |
| 200 #ifdef RVM_PWR_SWE | |
| 201 pwr_handle_discharge(); | |
| 202 #endif | |
| 203 } | |
| 204 } | |
| 205 | |
| 206 | |
| 207 | |
| 208 /******************************************************************************* | |
| 209 ** | |
| 210 ** Function Power_ON_Remote | |
| 211 ** | |
| 212 ** Description | |
| 213 ** | |
| 214 ** | |
| 215 *******************************************************************************/ | |
| 216 void Power_ON_Remote(void) | |
| 217 { | |
| 218 } | |
| 219 | |
| 220 | |
| 221 | |
| 222 /******************************************************************************* | |
| 223 ** | |
| 224 ** Function Power_OFF_Remote | |
| 225 ** | |
| 226 ** Description | |
| 227 ** | |
| 228 ** | |
| 229 *******************************************************************************/ | |
| 230 void Power_OFF_Remote(void) | |
| 231 { | |
| 232 } | |
| 233 | |
| 234 | |
| 235 | |
| 236 /******************************************************************************* | |
| 237 ** | |
| 238 ** Function Power_IT_WakeUp | |
| 239 ** | |
| 240 ** Description | |
| 241 ** | |
| 242 ** | |
| 243 *******************************************************************************/ | |
| 244 void Power_IT_WakeUp(void) | |
| 245 { | |
| 246 } | |
| 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 |
