FreeCalypso > hg > ffs-editor
comparison src/cs/drivers/drv_app/pwr/pwr_liion_cha.c @ 0:92470e5d0b9e
src: partial import from FC Selenite
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Fri, 15 May 2020 01:28:16 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:92470e5d0b9e |
---|---|
1 /******************************************************************************* | |
2 * | |
3 * pwr_liion_cha.c | |
4 * | |
5 * Purpose: This file contains functions for managing the Li-ion batteries | |
6 * charging process. | |
7 * | |
8 * Author Candice Bazanegue (c-brille@ti.com) | |
9 * | |
10 * | |
11 * (C) Texas Instruments 2001 | |
12 * | |
13 ******************************************************************************/ | |
14 | |
15 #include "rv/rv_defined_swe.h" // for RVM_PWR_SWE | |
16 | |
17 #ifdef RVM_PWR_SWE | |
18 | |
19 #include "rvm/rvm_use_id_list.h" | |
20 #include "spi/spi_task.h" | |
21 #include "spi/spi_api.h" | |
22 #include "pwr/pwr_cust.h" | |
23 #include "pwr/pwr_liion_cha.h" | |
24 #include "pwr/pwr_disch.h" | |
25 #include "spi/spi_env.h" | |
26 #include "rvf/rvf_api.h" | |
27 #include "pwr/pwr_analog_dev.h" | |
28 #include "pwr/pwr_messages.h" | |
29 | |
30 /* Global variable */ | |
31 extern T_SPI_GBL_INFO *SPI_GBL_INFO_PTR; | |
32 | |
33 | |
34 /******************************************************************************* | |
35 ** Function pwr_start_CI_charging | |
36 ** | |
37 ** Description This function is used to start the constant current | |
38 ** battery charging. | |
39 ** | |
40 *******************************************************************************/ | |
41 void pwr_start_CI_charging(unsigned short charging_current) | |
42 { | |
43 volatile unsigned short dac_current_code; | |
44 | |
45 | |
46 rvf_send_trace("Start CI charging",17, NULL_PARAM, RV_TRACE_LEVEL_DEBUG_LOW, PWR_USE_ID); | |
47 dac_current_code = (unsigned int)((1000 * charging_current)/DAC_CURRENT_STEP); | |
48 | |
49 /* Select constant current charging. The charger is disabled */ | |
50 ABB_Write_Register_on_page(PAGE0, BCICTL2, 0x0002); | |
51 | |
52 /* Program the DAC with the constant current value */ | |
53 ABB_Write_Register_on_page(PAGE0, CHGREG, dac_current_code); | |
54 | |
55 /* Enable the charger */ | |
56 ABB_Write_Register_on_page(PAGE0, BCICTL2, 0x0003); | |
57 | |
58 pwr_env_ctrl_blk->charging_state = CI_CHARGE_STARTED; | |
59 | |
60 } | |
61 | |
62 | |
63 | |
64 /******************************************************************************* | |
65 ** Function pwr_start_CV_charging | |
66 ** | |
67 ** Description This function is used to start the constant voltage | |
68 ** battery charging. | |
69 ** | |
70 *******************************************************************************/ | |
71 void pwr_start_CV_charging(unsigned short charging_voltage) | |
72 { | |
73 volatile unsigned short dac_voltage_code; | |
74 unsigned short dac_voltage; | |
75 | |
76 rvf_send_trace("Start CV charging",17, NULL_PARAM, RV_TRACE_LEVEL_DEBUG_LOW, PWR_USE_ID); | |
77 dac_voltage = charging_voltage + VOLTAGE_LOOP_OFFSET; | |
78 | |
79 dac_voltage_code = (unsigned int)((1000 * ((dac_voltage /4) - DAC_THRESHOLD))/DAC_VOLTAGE_STEP); | |
80 | |
81 rvf_send_trace("Voltage (DAC code) ", 19, dac_voltage_code, RV_TRACE_LEVEL_DEBUG_LOW, PWR_USE_ID); | |
82 | |
83 /* Select constant voltage charging. The charger is disabled */ | |
84 ABB_Write_Register_on_page(PAGE0, BCICTL2, 0); | |
85 | |
86 /* Program the DAC with the constant voltage value */ | |
87 ABB_Write_Register_on_page(PAGE0, CHGREG, dac_voltage_code); | |
88 | |
89 /* Enable the charger */ | |
90 ABB_Write_Register_on_page(PAGE0, BCICTL2, 0x0001); | |
91 | |
92 pwr_env_ctrl_blk->charging_state = CV_CHARGE_STARTED; | |
93 | |
94 } | |
95 | |
96 | |
97 | |
98 /******************************************************************************* | |
99 ** Function pwr_stop_charging | |
100 ** | |
101 ** Description This function is used to stop the battery charging process. | |
102 ** | |
103 *******************************************************************************/ | |
104 void pwr_stop_charging(void) | |
105 { | |
106 | |
107 rvf_send_trace("Stop charging process",21, NULL_PARAM, RV_TRACE_LEVEL_DEBUG_LOW, PWR_USE_ID); | |
108 ABB_Write_Register_on_page(PAGE0, BCICTL2, 0); | |
109 pwr_env_ctrl_blk->charging_state = CHARGE_STOPPED; | |
110 } | |
111 | |
112 | |
113 | |
114 | |
115 /******************************************************************************* | |
116 ** Function pwr_current_loop_cal | |
117 ** | |
118 ** Description This function is used to evaluate the offset introduced | |
119 ** by the current to voltage converter in the current loop. | |
120 ** | |
121 ** | |
122 *******************************************************************************/ | |
123 void pwr_current_loop_cal(void) | |
124 { | |
125 rvf_send_trace("Current loop calibration",24, NULL_PARAM, RV_TRACE_LEVEL_DEBUG_LOW, PWR_USE_ID); | |
126 | |
127 /* Set the CHDISPA bit */ | |
128 /* And start the zero calibration routine of the I to V converter */ | |
129 ABB_Write_Register_on_page(PAGE0, BCICTL2, 0x0010); | |
130 ABB_Write_Register_on_page(PAGE0, BCICTL2, 0x0019); | |
131 | |
132 if (SPI_GBL_INFO_PTR->is_adc_on == FALSE) | |
133 { | |
134 /* start ICHG channel conversion by writing in the result register */ | |
135 ABB_Write_Register_on_page(PAGE0, ICHGREG, 0x0000); | |
136 | |
137 rvf_start_timer (SPI_TIMER0, | |
138 RVF_MS_TO_TICKS (SPI_TIMER0_INTERVAL_3), | |
139 FALSE); | |
140 } | |
141 else /* The L1 asks for ADC conversions */ | |
142 { | |
143 rvf_start_timer (SPI_TIMER0, | |
144 RVF_MS_TO_TICKS (SPI_TIMER0_INTERVAL_4), | |
145 FALSE); | |
146 } | |
147 | |
148 } | |
149 | |
150 | |
151 | |
152 /******************************************************************************* | |
153 ** Function pwr_calibration_process | |
154 ** | |
155 ** Description | |
156 ** | |
157 *******************************************************************************/ | |
158 void pwr_calibration_process(void) | |
159 { | |
160 if (pwr_bat_temp_within_limits(pwr_env_ctrl_blk->bat_celsius_temp)) | |
161 { | |
162 pwr_env_ctrl_blk->timer0_state = BATTERY_CALIBRATION; | |
163 pwr_current_loop_cal(); | |
164 } | |
165 else | |
166 { | |
167 /* informs the upper layer that the battery temperature is not correct */ | |
168 pwr_send_charge_not_possible_event(BAT_TEMP_OUTSIDE_LIMITS); | |
169 if (SPI_GBL_INFO_PTR->is_gsm_on == FALSE) /* GSM OFF */ | |
170 { | |
171 #if (ANLG_FAM == 1) | |
172 ABB_Write_Register_on_page(PAGE0, VRPCCTL2, 0x00EE); | |
173 #elif (ANLG_FAM == 2) | |
174 ABB_Write_Register_on_page(PAGE0, VRPCDEV, 0x0001); | |
175 #endif | |
176 } | |
177 else | |
178 { | |
179 pwr_handle_discharge(); | |
180 } | |
181 } | |
182 } | |
183 | |
184 | |
185 | |
186 | |
187 /******************************************************************************* | |
188 ** Function pwr_battery_qualification | |
189 ** | |
190 ** Description Battery open and short tests | |
191 ** | |
192 *******************************************************************************/ | |
193 void pwr_battery_qualification(void) | |
194 { | |
195 rvf_send_trace("Battery qualification",21, NULL_PARAM, RV_TRACE_LEVEL_DEBUG_LOW, PWR_USE_ID); | |
196 | |
197 pwr_env_ctrl_blk->timer0_state = BATTERY_SHORT_TEST; | |
198 | |
199 /* Short test */ | |
200 pwr_start_CI_charging(CONSTANT_CURRENT_VALUE); | |
201 if (SPI_GBL_INFO_PTR->is_adc_on == FALSE) | |
202 { | |
203 /* Start VBAT channel conversion by writing in the result register */ | |
204 ABB_Write_Register_on_page(PAGE0, VBATREG, 0x0000); | |
205 rvf_start_timer (SPI_TIMER0, | |
206 RVF_MS_TO_TICKS (SPI_TIMER0_INTERVAL_1), | |
207 FALSE); | |
208 } | |
209 else | |
210 { | |
211 /* Let time for the L1 to ask for new AD conversions */ | |
212 rvf_start_timer (SPI_TIMER0, | |
213 RVF_MS_TO_TICKS (SPI_TIMER0_INTERVAL_2), | |
214 FALSE); | |
215 } | |
216 | |
217 } | |
218 | |
219 | |
220 | |
221 /********************************************************************************/ | |
222 /* */ | |
223 /* Function Name: pwr_start_fast_charge */ | |
224 /* */ | |
225 /* Purpose: Starts the fast charging process for Li-ion batteries */ | |
226 /* */ | |
227 /* */ | |
228 /********************************************************************************/ | |
229 void pwr_start_fast_charge(void) | |
230 { | |
231 UINT16 i2v_dac_offset_mA; | |
232 | |
233 /* Informs the upper layer that the charging process has started */ | |
234 pwr_send_CI_charge_start_event(); | |
235 | |
236 /* Connect resistive bridge to main battery */ | |
237 ABB_Write_Register_on_page(PAGE0, BCICTL1, MESBAT); | |
238 | |
239 /* Start the constant current charging */ | |
240 i2v_dac_offset_mA = (UINT16)((MADC_CURRENT_STEP*pwr_env_ctrl_blk->i2v_madc_offset)/1000); | |
241 | |
242 pwr_start_CI_charging((unsigned short)(CONSTANT_CURRENT_VALUE + i2v_dac_offset_mA)); | |
243 | |
244 rvf_start_timer (SPI_TIMER1, | |
245 RVF_MS_TO_TICKS (SPI_TIMER1_INTERVAL), | |
246 FALSE); | |
247 } | |
248 | |
249 | |
250 | |
251 /********************************************************************************/ | |
252 /* */ | |
253 /* Function Name: pwr_short_test_timer_process */ | |
254 /* */ | |
255 /* Purpose: */ | |
256 /* */ | |
257 /* */ | |
258 /********************************************************************************/ | |
259 void pwr_short_test_timer_process(void) | |
260 { | |
261 UINT16 Vbat_test; | |
262 | |
263 rvf_send_trace("TIMER0: Battery short test",26, NULL_PARAM, RV_TRACE_LEVEL_WARNING, PWR_USE_ID); | |
264 | |
265 /* Read ADC result */ | |
266 Vbat_test = ABB_Read_Register_on_page(PAGE0, VBATREG); | |
267 rvf_send_trace("Vbat (MADC code) ",17, Vbat_test, RV_TRACE_LEVEL_WARNING, PWR_USE_ID); | |
268 | |
269 pwr_stop_charging(); | |
270 | |
271 if (Vbat_test > 0) | |
272 { | |
273 pwr_env_ctrl_blk->timer0_state = BATTERY_OPEN_TEST; | |
274 | |
275 /* Start open test */ | |
276 pwr_start_CV_charging(CONSTANT_VOLTAGE_VALUE); | |
277 rvf_delay(RVF_MS_TO_TICKS(5)); | |
278 | |
279 if (SPI_GBL_INFO_PTR->is_adc_on == FALSE) | |
280 { | |
281 /* start ICHG channel conversion by writing in the result register */ | |
282 ABB_Write_Register_on_page(PAGE0, ICHGREG, 0x0000); | |
283 rvf_start_timer (SPI_TIMER0, | |
284 RVF_MS_TO_TICKS (SPI_TIMER0_INTERVAL_1), | |
285 FALSE); | |
286 } | |
287 else | |
288 { | |
289 /* Let time for the L1 to ask for new AD conversions */ | |
290 rvf_start_timer (SPI_TIMER0, | |
291 RVF_MS_TO_TICKS (SPI_TIMER0_INTERVAL_2), | |
292 FALSE); | |
293 } | |
294 } | |
295 else | |
296 { | |
297 rvf_send_trace("Short battery",13, NULL_PARAM, RV_TRACE_LEVEL_WARNING, PWR_USE_ID); | |
298 | |
299 /* informs the upper layer that the short test has failed */ | |
300 pwr_send_charge_not_possible_event(BAT_SHORT_TEST_FAILED); | |
301 if (SPI_GBL_INFO_PTR->is_gsm_on == FALSE) /* GSM OFF */ | |
302 { | |
303 #if (ANLG_FAM == 1) | |
304 ABB_Write_Register_on_page(PAGE0, VRPCCTL2, 0x00EE); | |
305 #elif (ANLG_FAM == 2) | |
306 ABB_Write_Register_on_page(PAGE0, VRPCDEV, 0x0001); | |
307 #endif | |
308 } | |
309 else | |
310 { | |
311 pwr_handle_discharge(); | |
312 } | |
313 } | |
314 } | |
315 | |
316 | |
317 | |
318 /********************************************************************************/ | |
319 /* */ | |
320 /* Function Name: pwr_open_test_timer_process */ | |
321 /* */ | |
322 /* Purpose: */ | |
323 /* */ | |
324 /* */ | |
325 /********************************************************************************/ | |
326 void pwr_open_test_timer_process(void) | |
327 { | |
328 UINT16 Ichg_test; | |
329 | |
330 rvf_send_trace("TIMER0: Battery open test",25, NULL_PARAM, RV_TRACE_LEVEL_WARNING, PWR_USE_ID); | |
331 | |
332 /* Read ADC result */ | |
333 Ichg_test = ABB_Read_Register_on_page(PAGE0, ICHGREG); | |
334 rvf_send_trace("Charge current (MADC code) ",27, Ichg_test, RV_TRACE_LEVEL_DEBUG_LOW, PWR_USE_ID); | |
335 | |
336 pwr_stop_charging(); | |
337 | |
338 if (Ichg_test > 0) /* Battery OK */ | |
339 { | |
340 rvf_send_trace("Battery OK",10, NULL_PARAM, RV_TRACE_LEVEL_DEBUG_LOW, PWR_USE_ID); | |
341 | |
342 /* Check if the initial battery temperature is correct */ | |
343 pwr_env_ctrl_blk->charging_state = TESTING_BATTERY; | |
344 pwr_get_battery_temperature(); | |
345 } | |
346 | |
347 else /* Open battery */ | |
348 { | |
349 rvf_send_trace("Open battery",12, NULL_PARAM, RV_TRACE_LEVEL_WARNING, PWR_USE_ID); | |
350 | |
351 /* informs the upper layer that the open test has failed */ | |
352 pwr_send_charge_not_possible_event(BAT_OPEN_TEST_FAILED); | |
353 if (SPI_GBL_INFO_PTR->is_gsm_on == FALSE) /* GSM OFF */ | |
354 { | |
355 #if (ANLG_FAM == 1) | |
356 ABB_Write_Register_on_page(PAGE0, VRPCCTL2, 0x00EE); | |
357 #elif (ANLG_FAM == 2) | |
358 ABB_Write_Register_on_page(PAGE0, VRPCDEV, 0x0001); | |
359 #endif | |
360 } | |
361 else | |
362 { | |
363 pwr_handle_discharge(); | |
364 } | |
365 } | |
366 } | |
367 | |
368 | |
369 | |
370 /********************************************************************************/ | |
371 /* */ | |
372 /* Function Name: pwr_cal_timer_process */ | |
373 /* */ | |
374 /* Purpose: */ | |
375 /* */ | |
376 /* */ | |
377 /********************************************************************************/ | |
378 void pwr_cal_timer_process(void) | |
379 { | |
380 rvf_send_trace("TIMER0: Battery calibration",27, NULL_PARAM, RV_TRACE_LEVEL_WARNING, PWR_USE_ID); | |
381 | |
382 pwr_env_ctrl_blk->i2v_madc_offset = ABB_Read_Register_on_page(PAGE0, ICHGREG); | |
383 | |
384 rvf_send_trace("i2v offset (MADC code) ", 23, pwr_env_ctrl_blk->i2v_madc_offset, RV_TRACE_LEVEL_DEBUG_LOW, PWR_USE_ID); | |
385 pwr_stop_charging(); | |
386 | |
387 #if (ANLG_FAM == 2) | |
388 if (pwr_env_ctrl_blk->i2v_madc_offset == 0) | |
389 { | |
390 /* IOTA: the offset can be made positive and minimized programming */ | |
391 /* the OFFEN and OFFSN bits in the BCICONF register */ | |
392 ABB_Write_Register_on_page(PAGE1, BCICONF, 0x001F); | |
393 pwr_current_loop_cal(); | |
394 } | |
395 else | |
396 { | |
397 /* the i2v calibration must be done before this initialization */ | |
398 pwr_env_ctrl_blk->madc_eoc_current_code = (UINT16)(1000 * END_OF_CHARGE_I / MADC_CURRENT_STEP) + pwr_env_ctrl_blk->i2v_madc_offset; | |
399 | |
400 rvf_send_trace("End of charge current (MADC code) ", 34, pwr_env_ctrl_blk->madc_eoc_current_code, RV_TRACE_LEVEL_DEBUG_LOW, PWR_USE_ID); | |
401 | |
402 /* Start the fast charging cycle */ | |
403 pwr_start_fast_charge(); | |
404 } | |
405 | |
406 #elif (ANLG_FAM == 1) | |
407 /* the i2v calibration must be done before this initialization */ | |
408 pwr_env_ctrl_blk->madc_eoc_current_code = (UINT16)(1000 * END_OF_CHARGE_I / MADC_CURRENT_STEP) + pwr_env_ctrl_blk->i2v_madc_offset; | |
409 | |
410 rvf_send_trace("End of charge current (MADC code) ", 34, pwr_env_ctrl_blk->madc_eoc_current_code, RV_TRACE_LEVEL_DEBUG_LOW, PWR_USE_ID); | |
411 | |
412 /* Start the fast charging cycle */ | |
413 pwr_start_fast_charge(); | |
414 | |
415 #endif /* #if (ANLG_FAM == 2) */ | |
416 } | |
417 | |
418 | |
419 | |
420 | |
421 /********************************************************************************/ | |
422 /* */ | |
423 /* Function Name: pwr_CI_charge_process */ | |
424 /* */ | |
425 /* Purpose: */ | |
426 /* */ | |
427 /* */ | |
428 /********************************************************************************/ | |
429 void pwr_CI_charge_process(void) | |
430 { | |
431 UINT16 vbat; | |
432 UINT16 ichg; | |
433 | |
434 /* Check if the battery temperature is still correct */ | |
435 if (pwr_bat_temp_within_limits(pwr_env_ctrl_blk->bat_celsius_temp)) | |
436 { | |
437 if (SPI_GBL_INFO_PTR->is_adc_on == FALSE) | |
438 { | |
439 /* start VBAT channel conversion by writing in the result register */ | |
440 ABB_Write_Register_on_page(PAGE0, VBATREG, 0x0000); | |
441 rvf_delay(RVF_MS_TO_TICKS(5)); | |
442 vbat = ABB_Read_Register_on_page(PAGE0, VBATREG); | |
443 } | |
444 else | |
445 { | |
446 /* Use the ADC conversions results from the L1 */ | |
447 vbat = SPI_GBL_INFO_PTR->adc_result[0]; | |
448 } | |
449 | |
450 rvf_send_trace("TIMER1", 6, NULL_PARAM, RV_TRACE_LEVEL_WARNING, PWR_USE_ID); | |
451 rvf_send_trace("Vbat (MADC code) ", 17, vbat, RV_TRACE_LEVEL_DEBUG_LOW, PWR_USE_ID); | |
452 | |
453 if (vbat < pwr_env_ctrl_blk->max_voltage_code) | |
454 { | |
455 rvf_start_timer (SPI_TIMER1, RVF_MS_TO_TICKS (SPI_TIMER1_INTERVAL), FALSE); | |
456 } | |
457 else | |
458 { | |
459 pwr_stop_charging(); | |
460 pwr_send_CV_charge_start_event(); | |
461 pwr_start_CV_charging(CONSTANT_VOLTAGE_VALUE); | |
462 rvf_start_timer (SPI_TIMER2, RVF_MS_TO_TICKS (SPI_TIMER2_INTERVAL), FALSE); | |
463 } | |
464 | |
465 if (SPI_GBL_INFO_PTR->is_adc_on == FALSE) | |
466 { | |
467 /* start ICHG channel conversion by writing in the result register */ | |
468 ABB_Write_Register_on_page(PAGE0, ICHGREG, 0x0000); | |
469 rvf_delay(RVF_MS_TO_TICKS(5)); | |
470 ichg = ABB_Read_Register_on_page(PAGE0, ICHGREG); | |
471 } | |
472 else | |
473 { | |
474 ichg = SPI_GBL_INFO_PTR->adc_result[2]; | |
475 } | |
476 | |
477 rvf_send_trace("Ichg (MADC code) ", 17, ichg, RV_TRACE_LEVEL_DEBUG_LOW, PWR_USE_ID); | |
478 } | |
479 | |
480 else /* battery temperature not correct !!! */ | |
481 { | |
482 pwr_stop_charging(); | |
483 rvf_send_trace("Battery temperature not correct! ",33, NULL_PARAM, RV_TRACE_LEVEL_WARNING, PWR_USE_ID); | |
484 | |
485 /* informs the upper layer that the battery temperature is not correct */ | |
486 pwr_send_charge_not_possible_event(BAT_TEMP_OUTSIDE_LIMITS); | |
487 | |
488 if (SPI_GBL_INFO_PTR->is_gsm_on == FALSE) /* GSM OFF */ | |
489 { | |
490 #if (ANLG_FAM == 1) | |
491 ABB_Write_Register_on_page(PAGE0, VRPCCTL2, 0x00EE); | |
492 #elif (ANLG_FAM == 2) | |
493 ABB_Write_Register_on_page(PAGE0, VRPCDEV, 0x0001); | |
494 #endif | |
495 } | |
496 else | |
497 { | |
498 pwr_handle_discharge(); | |
499 } | |
500 } | |
501 } | |
502 | |
503 | |
504 | |
505 | |
506 /********************************************************************************/ | |
507 /* */ | |
508 /* Function Name: pwr_CI_charge_timer_process */ | |
509 /* */ | |
510 /* Purpose: */ | |
511 /* */ | |
512 /* */ | |
513 /********************************************************************************/ | |
514 void pwr_CI_charge_timer_process(void) | |
515 { | |
516 UINT16 status_value; | |
517 | |
518 status_value = ABB_Read_Status(); | |
519 if (status_value & CHGPRES) /* if the charger is still plugged */ | |
520 { | |
521 pwr_get_battery_temperature(); | |
522 } | |
523 else | |
524 { | |
525 /* informs the upper layer that the charging process has stopped */ | |
526 pwr_send_charge_stop_event(); | |
527 } | |
528 } | |
529 | |
530 | |
531 | |
532 | |
533 /********************************************************************************/ | |
534 /* */ | |
535 /* Function Name: pwr_CV_charge_process */ | |
536 /* */ | |
537 /* Purpose: */ | |
538 /* */ | |
539 /* */ | |
540 /********************************************************************************/ | |
541 void pwr_CV_charge_process(void) | |
542 { | |
543 UINT16 vbat; | |
544 UINT16 ichg; | |
545 | |
546 /* Check if the battery temperature is still correct */ | |
547 if (pwr_bat_temp_within_limits(pwr_env_ctrl_blk->bat_celsius_temp)) | |
548 { | |
549 if (SPI_GBL_INFO_PTR->is_adc_on == FALSE) | |
550 { | |
551 /* start ICHG channel conversion by writing in the result register */ | |
552 ABB_Write_Register_on_page(PAGE0, ICHGREG, 0x0000); | |
553 rvf_delay(RVF_MS_TO_TICKS(5)); | |
554 ichg = ABB_Read_Register_on_page(PAGE0, ICHGREG); | |
555 } | |
556 else | |
557 { | |
558 ichg = SPI_GBL_INFO_PTR->adc_result[2]; | |
559 } | |
560 | |
561 rvf_send_trace("TIMER2",6, NULL_PARAM, RV_TRACE_LEVEL_WARNING, PWR_USE_ID); | |
562 rvf_send_trace("Ichg (MADC code) ", 17, ichg, RV_TRACE_LEVEL_DEBUG_LOW, PWR_USE_ID); | |
563 | |
564 if (SPI_GBL_INFO_PTR->is_adc_on == FALSE) | |
565 { | |
566 /* start VBAT channel conversion by writing in the result register */ | |
567 ABB_Write_Register_on_page(PAGE0, VBATREG, 0x0000); | |
568 rvf_delay(RVF_MS_TO_TICKS(5)); | |
569 vbat = ABB_Read_Register_on_page(PAGE0, VBATREG); | |
570 } | |
571 else | |
572 { | |
573 /* Use the ADC results asked for by the layer 1 */ | |
574 vbat = SPI_GBL_INFO_PTR->adc_result[0]; | |
575 } | |
576 | |
577 rvf_send_trace("Vbat (MADC code) ", 17, vbat, RV_TRACE_LEVEL_DEBUG_LOW, PWR_USE_ID); | |
578 if (ichg > pwr_env_ctrl_blk->madc_eoc_current_code) | |
579 { | |
580 rvf_start_timer (SPI_TIMER2, RVF_MS_TO_TICKS (SPI_TIMER2_INTERVAL), FALSE); | |
581 } | |
582 else | |
583 { | |
584 pwr_stop_charging(); | |
585 /* informs the upper layer that the charging process has stopped */ | |
586 pwr_send_charge_stop_event(); | |
587 rvf_send_trace("Fast charge termination criterion",33, NULL_PARAM, | |
588 RV_TRACE_LEVEL_DEBUG_LOW, PWR_USE_ID); | |
589 | |
590 if (SPI_GBL_INFO_PTR->is_gsm_on == FALSE) /* GSM OFF */ | |
591 { | |
592 #if (ANLG_FAM == 1) | |
593 ABB_Write_Register_on_page(PAGE0, VRPCCTL2, 0x00EE); | |
594 #elif (ANLG_FAM == 2) | |
595 ABB_Write_Register_on_page(PAGE0, VRPCDEV, 0x0001); | |
596 #endif | |
597 } | |
598 else | |
599 { | |
600 pwr_handle_discharge(); | |
601 } | |
602 } | |
603 } | |
604 | |
605 else /* Battery temperature not correct !!! */ | |
606 { | |
607 pwr_stop_charging(); | |
608 rvf_send_trace("Battery temperature not correct! ",33, NULL_PARAM, RV_TRACE_LEVEL_WARNING, PWR_USE_ID); | |
609 | |
610 /* informs the upper layer that the battery temperature is not correct */ | |
611 pwr_send_charge_not_possible_event(BAT_TEMP_OUTSIDE_LIMITS); | |
612 | |
613 if (SPI_GBL_INFO_PTR->is_gsm_on == FALSE) /* GSM OFF */ | |
614 { | |
615 #if (ANLG_FAM == 1) | |
616 ABB_Write_Register_on_page(PAGE0, VRPCCTL2, 0x00EE); | |
617 #elif (ANLG_FAM == 2) | |
618 ABB_Write_Register_on_page(PAGE0, VRPCDEV, 0x0001); | |
619 #endif | |
620 } | |
621 else | |
622 { | |
623 pwr_handle_discharge(); | |
624 } | |
625 } | |
626 } | |
627 | |
628 | |
629 | |
630 | |
631 /********************************************************************************/ | |
632 /* */ | |
633 /* Function Name: pwr_CV_charge_timer_process */ | |
634 /* */ | |
635 /* Purpose: */ | |
636 /* */ | |
637 /* */ | |
638 /********************************************************************************/ | |
639 void pwr_CV_charge_timer_process(void) | |
640 { | |
641 UINT16 status_value; | |
642 | |
643 status_value = ABB_Read_Status(); | |
644 if (status_value & CHGPRES) /* if the charger is still plugged */ | |
645 { | |
646 /* Control the battery temperature */ | |
647 pwr_get_battery_temperature(); | |
648 } | |
649 else | |
650 { | |
651 /* informs the upper layer that the charging process has stopped */ | |
652 pwr_send_charge_stop_event(); | |
653 } | |
654 } | |
655 | |
656 | |
657 | |
658 | |
659 /********************************************************************************/ | |
660 /* */ | |
661 /* Function Name: pwr_bat_test_timer_process */ | |
662 /* */ | |
663 /* Purpose: */ | |
664 /* */ | |
665 /* */ | |
666 /********************************************************************************/ | |
667 void pwr_bat_test_timer_process(void) | |
668 { | |
669 if (pwr_env_ctrl_blk->timer0_state == BATTERY_TYPE_TEST) | |
670 { | |
671 pwr_type_test_timer_process(); | |
672 } | |
673 else if (pwr_env_ctrl_blk->timer0_state == BATTERY_SHORT_TEST) | |
674 { | |
675 pwr_short_test_timer_process(); | |
676 } | |
677 else if (pwr_env_ctrl_blk->timer0_state == BATTERY_OPEN_TEST) | |
678 { | |
679 pwr_open_test_timer_process(); | |
680 } | |
681 else if (pwr_env_ctrl_blk->timer0_state == BATTERY_50UA_TEMP_TEST) | |
682 { | |
683 pwr_bat_50uA_temp_test_timer_process(); | |
684 } | |
685 else if (pwr_env_ctrl_blk->timer0_state == BATTERY_10UA_TEMP_TEST) | |
686 { | |
687 pwr_bat_10uA_temp_test_timer_process(); | |
688 } | |
689 else if (pwr_env_ctrl_blk->timer0_state == BATTERY_CALIBRATION) | |
690 { | |
691 /* end of current loop calibration */ | |
692 pwr_cal_timer_process(); | |
693 } | |
694 } | |
695 | |
696 #endif /* #ifdef RVM_PWR_SWE */ | |
697 | |
698 |