comparison src/cs/drivers/drv_app/fchg/fchg_process.c @ 334:d583a1f5bd6a

FCHG: charger plug and unplug functions implemented
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 14 Dec 2017 19:54:18 +0000
parents 8a90038c0173
children 6c0659acf93e
comparison
equal deleted inserted replaced
333:8a90038c0173 334:d583a1f5bd6a
219 rvf_send_trace("Invalid state in pwr_process_adc()", 32, 219 rvf_send_trace("Invalid state in pwr_process_adc()", 32,
220 pwr_ctrl->state, RV_TRACE_LEVEL_ERROR, 220 pwr_ctrl->state, RV_TRACE_LEVEL_ERROR,
221 FCHG_USE_ID); 221 FCHG_USE_ID);
222 } 222 }
223 } 223 }
224
225 void pwr_handle_timer(void)
226 {
227 if (pwr_ctrl->state != FCHG_STATE_PWR_PLUG_TIMER)
228 return;
229 rvf_send_trace("Timer expired, ready to charge", 30, NULL_PARAM,
230 RV_TRACE_LEVEL_DEBUG_LOW, FCHG_USE_ID);
231 pwr_ctrl->state = FCHG_STATE_READY_TO_CHARGE;
232 }
233
234 void pwr_charger_plug(void)
235 {
236 if (pwr_ctrl->state != FCHG_STATE_NO_EXT_PWR) {
237 rvf_send_trace("Charger plug event in unexpected state", 38,
238 pwr_ctrl->state, RV_TRACE_LEVEL_ERROR,
239 FCHG_USE_ID);
240 return;
241 }
242 if (!pwr_ctrl->config_present) {
243 rvf_send_trace(
244 "Charger plugged in, but no config: won't charge", 47,
245 NULL_PARAM, RV_TRACE_LEVEL_ERROR, FCHG_USE_ID);
246 pwr_ctrl->state = FCHG_STATE_NO_CHARGING;
247 return;
248 }
249 if (pwr_ctrl->config.start_delay) {
250 rvf_send_trace("Charger plug, starting timer", 28, NULL_PARAM,
251 RV_TRACE_LEVEL_DEBUG_HIGH, FCHG_USE_ID);
252 rvf_start_timer(FCHG_TIMER,
253 RVF_MS_TO_TICKS(pwr_ctrl->config.start_delay),
254 FALSE);
255 pwr_ctrl->state = FCHG_STATE_PWR_PLUG_TIMER;
256 } else {
257 rvf_send_trace("Charger plug, ready to charge", 29, NULL_PARAM,
258 RV_TRACE_LEVEL_DEBUG_HIGH, FCHG_USE_ID);
259 pwr_ctrl->state = FCHG_STATE_READY_TO_CHARGE;
260 }
261 }
262
263 void pwr_charger_unplug(void)
264 {
265 switch (pwr_ctrl->state) {
266 case FCHG_STATE_NO_EXT_PWR:
267 rvf_send_trace("Charger unplug, already handled", 31,
268 NULL_PARAM, RV_TRACE_LEVEL_DEBUG_LOW,
269 FCHG_USE_ID);
270 /* nothing to do */
271 return;
272 case FCHG_STATE_PWR_PLUG_TIMER:
273 case FCHG_STATE_READY_TO_CHARGE:
274 case FCHG_STATE_READY_TO_RECHARGE:
275 case FCHG_STATE_I2V_CAL_1:
276 case FCHG_STATE_NO_CHARGING:
277 rvf_send_trace("Charger unplug", 14, NULL_PARAM,
278 RV_TRACE_LEVEL_DEBUG_LOW, FCHG_USE_ID);
279 pwr_ctrl->state = FCHG_STATE_NO_EXT_PWR;
280 return;
281 case FCHG_STATE_I2V_CAL_2:
282 case FCHG_STATE_CI_CHARGING:
283 case FCHG_STATE_CV_CHARGING:
284 ABB_Write_Register_on_page(PAGE0, BCICTL2, 0);
285 rvf_send_trace("Charger unplug, charging stopped", 32,
286 NULL_PARAM, RV_TRACE_LEVEL_DEBUG_HIGH,
287 FCHG_USE_ID);
288 pwr_ctrl->state = FCHG_STATE_NO_EXT_PWR;
289 pwr_init_discharge();
290 return;
291 default:
292 rvf_send_trace("Invalid state in pwr_charger_unplug()", 35,
293 pwr_ctrl->state, RV_TRACE_LEVEL_ERROR,
294 FCHG_USE_ID);
295 }
296 }