comparison src/cs/drivers/drv_app/pwr/pwr_api.c @ 145:246f4a7dd92b

src/cs/drivers/drv_app/pwr: import from MV100 source
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 09 Oct 2016 05:59:14 +0000
parents
children c93a236e0d50
comparison
equal deleted inserted replaced
144:fd8227e3047d 145:246f4a7dd92b
1 /*******************************************************************************
2 *
3 * pwr_api.c
4 *
5 * Purpose: This file contains functions that can be accessed by any SWE
6 * to use power management services.
7 *
8 * Author Candice Bazanegue (c-brille@ti.com)
9 *
10 *
11 * (C) Texas Instruments 2001
12 *
13 ******************************************************************************/
14
15 #include "rv_defined_swe.h" // for RVM_PWR_SWE
16
17 #ifdef RVM_PWR_SWE
18
19 #include "rvm_use_id_list.h"
20 #include "spi_api.h"
21 #include "spi_env.h"
22 #include "pwr_env.h"
23 #include "pwr_cust.h"
24 #include "pwr_messages.h"
25 #include "pwr_messages_i.h"
26
27 /* Define a pointer to the PWR Environment control block. */
28 extern T_PWR_ENV_CTRL_BLK *pwr_env_ctrl_blk;
29
30
31 /*******************************************************************************
32 **
33 ** Function power_info_register
34 **
35 ** Description Function called by the MMI to enable (or disable) the receipt
36 ** of several events related to the charging process or the
37 ** discharge levels.
38 **
39 **
40 *******************************************************************************/
41 T_POWER_RET power_info_register(BOOLEAN info_enable, T_RV_RETURN return_path)
42 {
43 if (((pwr_env_ctrl_blk->power_info.return_path.callback_func)!= NULL) ||
44 (pwr_env_ctrl_blk->power_info.return_path.addr_id != RVF_INVALID_ADDR_ID))
45 {
46 rvf_send_trace("power_info_register : info already registered, performs another registration",
47 76,
48 NULL_PARAM,
49 RV_TRACE_LEVEL_DEBUG_HIGH,
50 PWR_USE_ID);
51 }
52 pwr_env_ctrl_blk->power_info.info_enable = info_enable;
53 pwr_env_ctrl_blk->power_info.return_path.addr_id = return_path.addr_id;
54 pwr_env_ctrl_blk->power_info.return_path.callback_func = return_path.callback_func;
55
56 return (POWER_OK);
57
58 }
59
60
61
62 /*******************************************************************************
63 **
64 ** Function power_alert_register
65 **
66 ** Description Function called by the MMI to configure the threshold of
67 ** remaining energy in the battery, under which the MMI will
68 ** receive low battery alerts.
69 **
70 **
71 *******************************************************************************/
72 T_POWER_RET power_alert_register(T_PWR_PERCENT remain_capa_threshold,
73 T_RV_RETURN return_path)
74 {
75
76 if (((pwr_env_ctrl_blk->power_alert.return_path.callback_func)!= NULL) ||
77 (pwr_env_ctrl_blk->power_alert.return_path.addr_id != RVF_INVALID_ADDR_ID))
78 {
79 rvf_send_trace("power_alert_register : info already registered, performs another registration",
80 77,
81 NULL_PARAM,
82 RV_TRACE_LEVEL_DEBUG_HIGH,
83 PWR_USE_ID);
84 }
85 pwr_env_ctrl_blk->power_alert.remain_capa_threshold = remain_capa_threshold;
86 pwr_env_ctrl_blk->power_alert.return_path.addr_id = return_path.addr_id;
87 pwr_env_ctrl_blk->power_alert.return_path.callback_func = return_path.callback_func;
88
89 return (POWER_OK);
90
91 }
92
93
94 /*******************************************************************************
95 **
96 ** Function power_emergency_register
97 **
98 ** Description Function called by the MMI to define the call-back function
99 ** which will be called in case of emergency switch OFF.
100 **
101 **
102 *******************************************************************************/
103 T_POWER_RET power_emergency_register(T_RV_RETURN return_path)
104 {
105
106 if (((pwr_env_ctrl_blk->power_emergency.callback_func)!= NULL) ||
107 (pwr_env_ctrl_blk->power_emergency.addr_id != RVF_INVALID_ADDR_ID))
108 {
109 rvf_send_trace("power_emergency_register : info already registered, performs another registration",
110 80,
111 NULL_PARAM,
112 RV_TRACE_LEVEL_DEBUG_HIGH,
113 PWR_USE_ID);
114 }
115 pwr_env_ctrl_blk->power_emergency.addr_id = return_path.addr_id;
116 pwr_env_ctrl_blk->power_emergency.callback_func = return_path.callback_func;
117
118 return (POWER_OK);
119
120 }
121
122
123
124 /*******************************************************************************
125 **
126 ** Function pwr_callback_func
127 **
128 ** Description
129 **
130 **
131 **
132 *******************************************************************************/
133 void pwr_callback_func(void *ptr)
134 {
135 T_PWR_CHARGING_STATE charge_started;
136
137
138 /* Charge started? */
139 charge_started = pwr_env_ctrl_blk->charging_state;
140
141 if (charge_started == CHARGE_STOPPED)
142 {
143 /* Ask for battery temperature measurement */
144 pwr_get_battery_temperature();
145 }
146
147 else if ((charge_started == CI_CHARGE_STARTED) ||
148 (charge_started == CV_CHARGE_STARTED))
149 {
150 /* The battery temperature has been measured during the charge */
151 pwr_get_bat_info();
152 }
153
154 }
155
156
157
158
159 /*******************************************************************************
160 **
161 ** Function pwr_get_bat_info
162 **
163 ** Description
164 **
165 **
166 *******************************************************************************/
167 void pwr_get_bat_info(void)
168 {
169 UINT16 bat_voltage, bat_madc_voltage;
170 UINT16 charger_current, bat_madc_current;
171 UINT16 status;
172 BOOLEAN charger_plugged;
173 T_PWR_CHARGING_STATE charge_started;
174 T_PWR_PERCENT remain_capacity;
175 INT16 bat_temperature;
176
177
178 /* Voltage and current */
179 /* Read the conversion results in the analog device registers */
180 bat_madc_voltage = ABB_Read_Register_on_page(PAGE0, VBATREG);
181 bat_madc_current = ABB_Read_Register_on_page(PAGE0, ICHGREG);
182
183 bat_voltage = pwr_adc_to_mvolt(bat_madc_voltage);
184 charger_current = pwr_adc_to_mA(bat_madc_current);
185
186 /* Remaining capacity in the battery */
187 remain_capacity = pwr_get_capacity_vs_voltage(bat_voltage);
188
189 /* Charger plugged? */
190 status = ABB_Read_Status();
191 if (status & CHGPRES)
192 {
193 charger_plugged = TRUE;
194 }
195 else
196 {
197 charger_plugged = FALSE;
198 }
199
200 /* Charge started? */
201 charge_started = pwr_env_ctrl_blk->charging_state;
202
203 /* The battery temperature is already measured during the charge */
204 /* Use the last result */
205 bat_temperature = pwr_env_ctrl_blk->bat_celsius_temp;
206
207 /* Send the results to the upper layer */
208 pwr_send_battery_info(bat_voltage, bat_temperature, charger_current,
209 charger_plugged, charge_started,
210 remain_capacity);
211 }
212
213
214
215
216 /*******************************************************************************
217 **
218 ** Function power_battery_information
219 **
220 ** Description Function called by the MMI to get information concerning
221 ** the battery.
222 **
223 **
224 *******************************************************************************/
225 T_POWER_RET power_battery_information(void)
226 {
227 T_RV_RET spi_return;
228
229 spi_return = pwr_spi_battery_info(pwr_callback_func);
230 if (spi_return != RV_OK)
231 {
232 return (POWER_ERROR);
233 }
234
235 return (POWER_OK);
236 }
237
238 #endif /* #ifdef RVM_PWR_SWE */
239
240