FreeCalypso > hg > fc-magnetite
annotate src/cs/drivers/drv_app/pwr/pwr_cust.c @ 335:6c0659acf93e
FCHG: implemented functions for user-initiated charge start and stop
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Thu, 14 Dec 2017 20:41:18 +0000 |
parents | c93a236e0d50 |
children |
rev | line source |
---|---|
145
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /******************************************************************************* |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * pwr_cust.c |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 * |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 * Purpose: This file contains functions for battery management. |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 * These functions can be modified by the customer. |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 * |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 * Author Candice Bazanegue (c-brille@ti.com) |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 * |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 * |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 * (C) Texas Instruments 2001 |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 * |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 ******************************************************************************/ |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 |
151
c93a236e0d50
PWR SWE compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
146
diff
changeset
|
15 #include "rv/rv_defined_swe.h" // for RVM_PWR_SWE |
145
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 #ifdef RVM_PWR_SWE |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 |
151
c93a236e0d50
PWR SWE compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
146
diff
changeset
|
19 #include "abb/abb.h" |
c93a236e0d50
PWR SWE compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
146
diff
changeset
|
20 #include "rvm/rvm_use_id_list.h" |
c93a236e0d50
PWR SWE compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
146
diff
changeset
|
21 #include "pwr/pwr_messages.h" |
c93a236e0d50
PWR SWE compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
146
diff
changeset
|
22 #include "rvf/rvf_api.h" |
c93a236e0d50
PWR SWE compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
146
diff
changeset
|
23 #include "pwr/pwr_cust.h" |
c93a236e0d50
PWR SWE compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
146
diff
changeset
|
24 #include "pwr/pwr_env.h" |
c93a236e0d50
PWR SWE compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
146
diff
changeset
|
25 #include "pwr/pwr_analog_dev.h" |
c93a236e0d50
PWR SWE compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
146
diff
changeset
|
26 #include "spi/spi_env.h" |
c93a236e0d50
PWR SWE compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
146
diff
changeset
|
27 #include "spi/spi_task.h" |
c93a236e0d50
PWR SWE compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
146
diff
changeset
|
28 #include "pwr/pwr_liion_cha.h" |
c93a236e0d50
PWR SWE compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
146
diff
changeset
|
29 #include "pwr/pwr_disch.h" |
145
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 /* Caution: keep ascending order in the temperature arrays !!! */ |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 const INT16 BAT_Celsius_temp_10uA[4]= |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 { |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 -10, -5, 0, 5 |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 }; |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 const UINT16 BAT_MADC_temp_10uA[4]= |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 { |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 0x13F, 0x103, 0xCB, 0x9C |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 }; |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 const INT16 BAT_Celsius_temp_50uA[13]= |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 { |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60 |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 }; |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 const UINT16 BAT_MADC_temp_50uA[13]= |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 { |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 0x351, 0x2AD, 0x22E, 0x1C4, 0x169, 0x128, 0xF9, 0xCB, 0x96, 0x83, 0x68, 0x58, 0x4A |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 }; |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 /* Correpondence between the battery voltage and the remaining capacity in the battery */ |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 /* The voltages have to be expressed in mV units */ |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 /* The capacities are percentages of the total capacity */ |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 /* Caution: keep this order in the array !!!! (in voltage (or capacity) descending order) */ |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 const T_PWR_THRESHOLDS a_pwr_thresholds[NB_THRESHOLDS]= |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 {{4200,100}, {4000,75}, {3970,50}, {3950,25}, {3900,15}, {3870,10}}; |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 /* Global variable */ |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 extern T_SPI_GBL_INFO *SPI_GBL_INFO_PTR; |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 /******************************************************************************* |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 ** Function pwr_adc_to_mvolt |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 ** |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 ** Description Converts the MADC voltage reading into voltage in mVolt |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 ** |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 ** Warning: The offsets are not taken into account !!! |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 ** |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 *******************************************************************************/ |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 UINT16 pwr_adc_to_mvolt(UINT16 voltage_madc) |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 { |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 UINT16 voltage_mvolt; |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 /* Note: /1000 because MADC_VOLTAGE_STEP is expressed in uV */ |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 voltage_mvolt = (voltage_madc * MADC_VOLTAGE_STEP * 4) / 1000; |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 /* return voltage in mVolt */ |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 return (voltage_mvolt); |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
83 } |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
84 |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
85 |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
86 /******************************************************************************* |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
87 ** Function pwr_adc_to_mA |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
88 ** |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
89 ** Description Converts the MADC current reading into current in mA |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
90 ** |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
91 ** Warning: The offsets are not taken into account !!! |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
92 ** |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
93 *******************************************************************************/ |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
94 UINT16 pwr_adc_to_mA(UINT16 current_madc) |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
95 { |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
96 UINT16 current_mA; |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
97 |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
98 /* Note: /1000 because MADC_VOLTAGE_STEP is expressed in uA */ |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
99 current_mA = (current_madc * MADC_CURRENT_STEP) / 1000; |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
100 |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
101 /* return current in mA */ |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
102 return (current_mA); |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
103 } |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
104 |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
105 |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
106 |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
107 |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
108 |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
109 /******************************************************************************* |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
110 ** Function pwr_bat_temp_within_limits |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
111 ** |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
112 ** Description Check if the battery temperature is within limits |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
113 ** |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
114 ** Parameter battery_temperature : battery temperature un Celsius degrees |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
115 ** |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
116 *******************************************************************************/ |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
117 UINT8 pwr_bat_temp_within_limits(INT16 battery_temperature) |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
118 { |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
119 rvf_send_trace("Battery temperature (Celsius degrees) ", 38, battery_temperature, RV_TRACE_LEVEL_DEBUG_LOW, PWR_USE_ID); |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
120 if ((battery_temperature < BAT_TEMPERATURE_MAX) && |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
121 (battery_temperature > BAT_TEMPERATURE_MIN)) |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
122 { |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
123 rvf_send_trace("Battery temperature within limits",33, NULL_PARAM, RV_TRACE_LEVEL_DEBUG_LOW, PWR_USE_ID); |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
124 return (TRUE); |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
125 } |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
126 |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
127 rvf_send_trace("Battery temperature outside limits",34, NULL_PARAM, RV_TRACE_LEVEL_DEBUG_MEDIUM, PWR_USE_ID); |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
128 return (FALSE); |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
129 } |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
130 |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
131 |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
132 |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
133 /******************************************************************************* |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
134 ** Function pwr_madc_to_Celius_conv |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
135 ** |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
136 ** Description Find the temperature in Celsius degrees corresponding |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
137 ** to the value given by the MADC |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
138 ** |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
139 *******************************************************************************/ |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
140 UINT8 pwr_madc_to_Celsius_conv(UINT8 bias_current, UINT16 madc_temp, INT16 *celsius_temp) |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
141 { |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
142 UINT8 last_index, i; |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
143 const UINT16 *MADC_temp_array; |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
144 const INT16 *celsius_temp_array; |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
145 UINT16 madc_diff; |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
146 UINT16 madc_inc; |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
147 UINT16 celsius_inc; |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
148 |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
149 /* choose the table */ |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
150 switch(bias_current) |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
151 { |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
152 case THEN_10uA: |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
153 MADC_temp_array = BAT_MADC_temp_10uA; |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
154 celsius_temp_array = BAT_Celsius_temp_10uA; |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
155 /* get last index of the lookup table array(s) */ |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
156 last_index = sizeof(BAT_MADC_temp_10uA)/sizeof(BAT_MADC_temp_10uA[0]); |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
157 break; |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
158 |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
159 case THEN_50uA: |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
160 MADC_temp_array = BAT_MADC_temp_50uA; |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
161 celsius_temp_array = BAT_Celsius_temp_50uA; |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
162 /* get last index of the lookup table array(s) */ |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
163 last_index = sizeof(BAT_MADC_temp_50uA)/sizeof(BAT_MADC_temp_50uA[0]); |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
164 break; |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
165 |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
166 default: return (FALSE); |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
167 } |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
168 |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
169 /* check the limits */ |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
170 if((madc_temp > MADC_temp_array[0]) || (madc_temp < MADC_temp_array[last_index-1])) |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
171 { |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
172 return (FALSE); |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
173 } |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
174 |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
175 |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
176 /* find the two points between which the given point lies */ |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
177 for(i=0; i<last_index; i++) |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
178 { |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
179 if(madc_temp >= MADC_temp_array[i]) |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
180 { |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
181 if(i==0) |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
182 { |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
183 *celsius_temp = celsius_temp_array[0]; |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
184 return (TRUE); |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
185 } |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
186 |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
187 /* the value is between MADC_temp_array[i] and MADC_temp_array[i-1] */ |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
188 /* interpolate to get a more precise value */ |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
189 |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
190 madc_inc = MADC_temp_array[i-1] - MADC_temp_array[i]; |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
191 celsius_inc = celsius_temp_array[1] - celsius_temp_array[0]; /* positive value */ |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
192 |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
193 /* difference between the given point and the first madc value below this point */ |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
194 madc_diff = madc_temp - MADC_temp_array[i]; |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
195 |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
196 *celsius_temp = celsius_temp_array[i] - (madc_diff*celsius_inc)/madc_inc; |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
197 |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
198 return (TRUE); |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
199 } |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
200 |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
201 /* else, try a smaller value */ |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
202 } |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
203 |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
204 return (FALSE); |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
205 } |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
206 |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
207 |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
208 |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
209 /******************************************************************************* |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
210 ** Function pwr_get_battery_temperature |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
211 ** |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
212 ** Description Start MADC temperature reading |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
213 ** |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
214 ** Note If the used battery does not allow to make a temperature |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
215 ** measurement, the body of this function can be replaced |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
216 ** by just a "return" with a temperature (in Celsius degrees) |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
217 ** between BAT_TEMPERATURE_MIN and BAT_TEMPERATURE_MAX. |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
218 *******************************************************************************/ |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
219 void pwr_get_battery_temperature(void) |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
220 { |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
221 |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
222 /* set the bias current to 50uA */ |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
223 ABB_Write_Register_on_page(PAGE0, BCICTL1, THEN_50uA); |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
224 rvf_delay(RVF_MS_TO_TICKS(5)); |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
225 |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
226 pwr_env_ctrl_blk->timer0_state = BATTERY_50UA_TEMP_TEST; |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
227 |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
228 if (SPI_GBL_INFO_PTR->is_adc_on == FALSE) |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
229 { |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
230 /* start ADIN2REG channel conversion by writing in the result register */ |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
231 ABB_Write_Register_on_page(PAGE0, ADIN2REG, 0x0000); |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
232 rvf_start_timer (SPI_TIMER0, |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
233 RVF_MS_TO_TICKS (SPI_TIMER0_INTERVAL_1), |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
234 FALSE); |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
235 } |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
236 else /* The L1 asks for ADC conversions */ |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
237 { |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
238 /* Let time for the L1 to ask for new AD conversions */ |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
239 rvf_start_timer (SPI_TIMER0, |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
240 RVF_MS_TO_TICKS (SPI_TIMER0_INTERVAL_2), |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
241 FALSE); |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
242 } |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
243 } |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
244 |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
245 |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
246 |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
247 /******************************************************************************* |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
248 ** Function pwr_bat_50uA_temp_test_timer_process |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
249 ** |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
250 ** Description |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
251 ** |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
252 ** |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
253 *******************************************************************************/ |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
254 void pwr_bat_50uA_temp_test_timer_process(void) |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
255 { |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
256 UINT16 bat_madc_temp; |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
257 |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
258 rvf_send_trace("TIMER0: Battery 50uA temp test",30, NULL_PARAM, RV_TRACE_LEVEL_WARNING, PWR_USE_ID); |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
259 |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
260 pwr_env_ctrl_blk->bat_celsius_temp = (INT16)(0xFFFF); |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
261 |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
262 /* Read ADC result */ |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
263 bat_madc_temp = ABB_Read_Register_on_page(PAGE0, ADIN2REG); |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
264 |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
265 /* MADC value to Celsius degrees conversion */ |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
266 if (!pwr_madc_to_Celsius_conv(THEN_50uA, bat_madc_temp, &(pwr_env_ctrl_blk->bat_celsius_temp))) |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
267 { |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
268 /* outside the 50uA temp range */ |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
269 /* set the bias current to 10uA */ |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
270 |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
271 pwr_env_ctrl_blk->timer0_state = BATTERY_10UA_TEMP_TEST; |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
272 |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
273 ABB_Write_Register_on_page(PAGE0, BCICTL1, THEN_10uA); |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
274 rvf_delay(RVF_MS_TO_TICKS(5)); |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
275 |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
276 if (SPI_GBL_INFO_PTR->is_adc_on == FALSE) |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
277 { |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
278 /* start ADIN2REG channel conversion by writing in the result register */ |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
279 ABB_Write_Register_on_page(PAGE0, ADIN2REG, 0x0000); |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
280 rvf_start_timer (SPI_TIMER0, |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
281 RVF_MS_TO_TICKS (SPI_TIMER0_INTERVAL_1), |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
282 FALSE); |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
283 } |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
284 else /* The L1 asks for ADC conversions */ |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
285 { |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
286 /* Let time for the L1 to ask for new AD conversions */ |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
287 rvf_start_timer (SPI_TIMER0, |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
288 RVF_MS_TO_TICKS (SPI_TIMER0_INTERVAL_2), |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
289 FALSE); |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
290 } |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
291 } |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
292 |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
293 else |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
294 { |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
295 /* The battery temp is inside the 50uA temp range */ |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
296 /* Turn OFF the current source */ |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
297 ABB_Write_Register_on_page(PAGE0, BCICTL1, MESBAT); |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
298 |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
299 /* Go ahead */ |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
300 if (pwr_env_ctrl_blk->charging_state == CI_CHARGE_STARTED) |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
301 { |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
302 /* temperature measurement during CI charge */ |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
303 pwr_CI_charge_process(); |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
304 } |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
305 else if (pwr_env_ctrl_blk->charging_state == CV_CHARGE_STARTED) |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
306 { |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
307 /* temperature measurement during CV charge */ |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
308 pwr_CV_charge_process(); |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
309 } |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
310 else if (pwr_env_ctrl_blk->charging_state == TESTING_BATTERY) |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
311 { |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
312 /* temperature measurement before calibration */ |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
313 pwr_calibration_process(); |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
314 } |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
315 else |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
316 { |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
317 /* temperature measurement for battery information */ |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
318 pwr_get_bat_info(); |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
319 } |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
320 } |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
321 } |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
322 |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
323 |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
324 /******************************************************************************* |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
325 ** Function pwr_bat_10uA_temp_test_timer_process |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
326 ** |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
327 ** Description |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
328 ** |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
329 ** |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
330 *******************************************************************************/ |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
331 void pwr_bat_10uA_temp_test_timer_process(void) |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
332 { |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
333 UINT16 bat_madc_temp; |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
334 |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
335 rvf_send_trace("TIMER0: Battery 10uA temp test",30, NULL_PARAM, RV_TRACE_LEVEL_WARNING, PWR_USE_ID); |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
336 |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
337 pwr_env_ctrl_blk->bat_celsius_temp = (INT16)(0xFFFF); |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
338 |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
339 bat_madc_temp = ABB_Read_Register_on_page(PAGE0, ADIN2REG); |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
340 |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
341 /* MADC value to Celsius degrees conversion */ |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
342 if (!pwr_madc_to_Celsius_conv(THEN_10uA, bat_madc_temp, &(pwr_env_ctrl_blk->bat_celsius_temp))) |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
343 { |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
344 /* ERROR: Reading out of limits */ |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
345 rvf_send_trace("Battery temperature reading out of limits", 41, NULL_PARAM, RV_TRACE_LEVEL_WARNING, PWR_USE_ID); |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
346 |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
347 /* turn OFF the current source */ |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
348 ABB_Write_Register_on_page(PAGE0, BCICTL1, MESBAT); |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
349 |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
350 pwr_stop_charging(); |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
351 |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
352 /* informs the upper layer that the battery temperature is not correct */ |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
353 pwr_send_charge_not_possible_event(BAT_TEMP_OUTSIDE_LIMITS); |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
354 |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
355 if (SPI_GBL_INFO_PTR->is_gsm_on == FALSE) /* GSM OFF */ |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
356 { |
146
fb95e3f83dc5
imported PWR source: s/ANALOG/ANLG_FAM/ for TCS211 environment
Mychaela Falconia <falcon@freecalypso.org>
parents:
145
diff
changeset
|
357 #if (ANLG_FAM == 1) |
145
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
358 ABB_Write_Register_on_page(PAGE0, VRPCCTL2, 0x00EE); |
146
fb95e3f83dc5
imported PWR source: s/ANALOG/ANLG_FAM/ for TCS211 environment
Mychaela Falconia <falcon@freecalypso.org>
parents:
145
diff
changeset
|
359 #elif (ANLG_FAM == 2) |
145
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
360 ABB_Write_Register_on_page(PAGE0, VRPCDEV, 0x0001); |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
361 #endif |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
362 } |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
363 else |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
364 { |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
365 pwr_handle_discharge(); |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
366 } |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
367 } |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
368 |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
369 else |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
370 { |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
371 /* The battery temperature is inside the 10uA temp range */ |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
372 /* turn OFF the current source */ |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
373 ABB_Write_Register_on_page(PAGE0, BCICTL1, MESBAT); |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
374 |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
375 /* Go ahead */ |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
376 if (pwr_env_ctrl_blk->charging_state == CI_CHARGE_STARTED) |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
377 { |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
378 /* temperature measurement during CI charge */ |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
379 pwr_CI_charge_process(); |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
380 } |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
381 else if (pwr_env_ctrl_blk->charging_state == CV_CHARGE_STARTED) |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
382 { |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
383 /* temperature measurement during CV charge */ |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
384 pwr_CV_charge_process(); |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
385 } |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
386 else if (pwr_env_ctrl_blk->charging_state == TESTING_BATTERY) |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
387 { |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
388 /* temperature measurement before calibration */ |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
389 pwr_calibration_process(); |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
390 } |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
391 else |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
392 { |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
393 /* temperature measurement for battery information */ |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
394 pwr_get_bat_info(); |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
395 } |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
396 } |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
397 } |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
398 |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
399 |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
400 |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
401 |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
402 /******************************************************************************* |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
403 ** Function pwr_get_battery_type |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
404 ** |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
405 ** Description Return the type of the battery |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
406 ** |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
407 ** Note If the used battery does not allow to make a battery type |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
408 ** SW detection, the body of this function can be replaced |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
409 ** by the last 2 lines |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
410 ** |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
411 *******************************************************************************/ |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
412 void pwr_get_battery_type(void) |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
413 { |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
414 |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
415 /* enable bias current for main battery type reading |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
416 ABB_Write_Register_on_page(PAGE0, BCICTL1, 0x0081); |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
417 rvf_delay(RVF_MS_TO_TICKS(5)); |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
418 |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
419 pwr_env_ctrl_blk->timer0_state = BATTERY_TYPE_TEST; |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
420 |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
421 if (SPI_GBL_INFO_PTR->is_adc_on == FALSE) |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
422 { |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
423 /* start ADIN1REG channel conversion by writing in the result register |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
424 ABB_Write_Register_on_page(PAGE0, ADIN1REG, 0x0000); |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
425 rvf_start_timer (SPI_TIMER0, |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
426 RVF_MS_TO_TICKS (SPI_TIMER0_INTERVAL_1), |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
427 FALSE); |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
428 } |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
429 else /* The L1 asks for ADC conversions |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
430 { |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
431 /* Let time for the L1 to ask for new AD conversions |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
432 rvf_start_timer (SPI_TIMER0, |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
433 RVF_MS_TO_TICKS (SPI_TIMER0_INTERVAL_2), |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
434 FALSE); |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
435 } |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
436 */ |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
437 |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
438 |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
439 |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
440 /****************************************/ |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
441 /* If the battery can not be detected, */ |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
442 /* the code above has to be replaced by */ |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
443 /* those 2 lines (with the type of the */ |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
444 /* used battery). */ |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
445 /****************************************/ |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
446 |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
447 pwr_env_ctrl_blk->bat_type = LI_ION; |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
448 |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
449 /* Check if the battery is OK */ |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
450 pwr_battery_qualification(); |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
451 |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
452 |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
453 } |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
454 |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
455 |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
456 |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
457 /******************************************************************************* |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
458 ** Function pwr_type_test_timer_process |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
459 ** |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
460 ** Description |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
461 ** |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
462 ** |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
463 *******************************************************************************/ |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
464 void pwr_type_test_timer_process(void) |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
465 { |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
466 UINT16 bat_type_voltage; |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
467 |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
468 rvf_send_trace("TIMER0: Battery type test",25, NULL_PARAM, RV_TRACE_LEVEL_WARNING, PWR_USE_ID); |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
469 |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
470 bat_type_voltage = ABB_Read_Register_on_page(PAGE0, ADIN1REG); |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
471 |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
472 /* turn OFF the current source */ |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
473 ABB_Write_Register_on_page(PAGE0, BCICTL1, MESBAT); |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
474 |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
475 if ((bat_type_voltage >= BAT_TYPE_LI_ION_MIN) && |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
476 (bat_type_voltage <= BAT_TYPE_LI_ION_MAX)) /* Li-ion batteries */ |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
477 { |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
478 pwr_env_ctrl_blk->bat_type = LI_ION; |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
479 |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
480 /* Check if the battery is OK */ |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
481 pwr_battery_qualification(); |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
482 |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
483 } |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
484 |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
485 else /* battery type unknown */ |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
486 { |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
487 pwr_env_ctrl_blk->bat_type = UNKNOWN; |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
488 |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
489 /* informs the upper layer that the battery type is unknown */ |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
490 pwr_send_charge_not_possible_event(BAT_TYPE_UNKNOWN); |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
491 if (SPI_GBL_INFO_PTR->is_gsm_on == FALSE) /* GSM OFF */ |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
492 { |
146
fb95e3f83dc5
imported PWR source: s/ANALOG/ANLG_FAM/ for TCS211 environment
Mychaela Falconia <falcon@freecalypso.org>
parents:
145
diff
changeset
|
493 #if (ANLG_FAM == 1) |
145
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
494 ABB_Write_Register_on_page(PAGE0, VRPCCTL2, 0x00EE); |
146
fb95e3f83dc5
imported PWR source: s/ANALOG/ANLG_FAM/ for TCS211 environment
Mychaela Falconia <falcon@freecalypso.org>
parents:
145
diff
changeset
|
495 #elif (ANLG_FAM == 2) |
145
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
496 ABB_Write_Register_on_page(PAGE0, VRPCDEV, 0x0001); |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
497 #endif |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
498 } |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
499 else |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
500 { |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
501 pwr_handle_discharge(); |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
502 } |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
503 } |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
504 } |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
505 |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
506 |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
507 |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
508 /******************************************************************************* |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
509 ** Function pwr_get_capacity_vs_voltage |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
510 ** |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
511 ** Description Compares the battery voltage with the thresholds given in the |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
512 ** a_pwr_thresholds array and returns the remaining capacity |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
513 ** corresponding to the threshold above this voltage. |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
514 ** |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
515 ** Parameters: UINT16 bat_voltage: battery voltage in mV !!! |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
516 ** |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
517 *******************************************************************************/ |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
518 T_PWR_PERCENT pwr_get_capacity_vs_voltage(UINT16 bat_voltage) |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
519 { |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
520 volatile UINT16 i; |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
521 T_PWR_PERCENT remaining_capacity; |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
522 |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
523 for(i=0; i<NB_THRESHOLDS; i++) |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
524 { |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
525 if(bat_voltage > a_pwr_thresholds[i].bat_voltage) |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
526 { |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
527 if(i==0) |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
528 { |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
529 remaining_capacity = a_pwr_thresholds[0].remain_capa; |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
530 } |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
531 else |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
532 { |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
533 remaining_capacity = a_pwr_thresholds[i-1].remain_capa; |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
534 } |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
535 |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
536 return (remaining_capacity); |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
537 } |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
538 /* else, try the next threshold */ |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
539 } |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
540 |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
541 if(i==NB_THRESHOLDS) |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
542 { |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
543 /* battery voltage below the last threshold */ |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
544 remaining_capacity = a_pwr_thresholds[i-1].remain_capa; |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
545 return (remaining_capacity); |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
546 } |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
547 |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
548 return 0; /* dummy return */ |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
549 } |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
550 |
246f4a7dd92b
src/cs/drivers/drv_app/pwr: import from MV100 source
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
551 #endif /* #ifdef RVM_PWR_SWE */ |