FreeCalypso > hg > fc-magnetite
changeset 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 | d583a1f5bd6a |
children | be011556e71f |
files | src/cs/drivers/drv_app/fchg/fchg_func_i.h src/cs/drivers/drv_app/fchg/fchg_process.c |
diffstat | 2 files changed, 73 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/src/cs/drivers/drv_app/fchg/fchg_func_i.h Thu Dec 14 19:54:18 2017 +0000 +++ b/src/cs/drivers/drv_app/fchg/fchg_func_i.h Thu Dec 14 20:41:18 2017 +0000 @@ -16,5 +16,7 @@ void pwr_handle_timer(void); void pwr_charger_plug(void); void pwr_charger_unplug(void); +void pwr_charge_start_req(void); +void pwr_charge_stop_req(void); #endif /* include guard */
--- a/src/cs/drivers/drv_app/fchg/fchg_process.c Thu Dec 14 19:54:18 2017 +0000 +++ b/src/cs/drivers/drv_app/fchg/fchg_process.c Thu Dec 14 20:41:18 2017 +0000 @@ -294,3 +294,74 @@ FCHG_USE_ID); } } + +void pwr_charge_start_req(void) +{ + switch (pwr_ctrl->state) { + case FCHG_STATE_NO_EXT_PWR: + rvf_send_trace("Cannot charge without a power source", 36, + NULL_PARAM, RV_TRACE_LEVEL_ERROR, FCHG_USE_ID); + return; + case FCHG_STATE_NO_CHARGING: + if (!pwr_ctrl->config_present) { + rvf_send_trace("No config set, cannot charge", 28, + NULL_PARAM, RV_TRACE_LEVEL_ERROR, + FCHG_USE_ID); + return; + } + /* FALL THRU */ + case FCHG_STATE_PWR_PLUG_TIMER: + case FCHG_STATE_READY_TO_CHARGE: + case FCHG_STATE_READY_TO_RECHARGE: + rvf_send_trace("Starting charge on user request", 31, + NULL_PARAM, RV_TRACE_LEVEL_DEBUG_HIGH, + FCHG_USE_ID); + pwr_ctrl->state = FCHG_STATE_I2V_CAL_1; + return; + case FCHG_STATE_I2V_CAL_1: + case FCHG_STATE_I2V_CAL_2: + case FCHG_STATE_CI_CHARGING: + case FCHG_STATE_CV_CHARGING: + rvf_send_trace( + "Charging already in progress, start request ignored", + 51, NULL_PARAM, RV_TRACE_LEVEL_WARNING, FCHG_USE_ID); + return; + default: + rvf_send_trace("Invalid state in pwr_charge_start_req()", 37, + pwr_ctrl->state, RV_TRACE_LEVEL_ERROR, + FCHG_USE_ID); + } +} + +void pwr_charge_stop_req(void) +{ + switch (pwr_ctrl->state) { + case FCHG_STATE_NO_EXT_PWR: + case FCHG_STATE_NO_CHARGING: + /* nothing to do */ + return; + case FCHG_STATE_PWR_PLUG_TIMER: + case FCHG_STATE_READY_TO_CHARGE: + case FCHG_STATE_READY_TO_RECHARGE: + case FCHG_STATE_I2V_CAL_1: + rvf_send_trace("Charging disabled by user request", 33, + NULL_PARAM, RV_TRACE_LEVEL_DEBUG_HIGH, + FCHG_USE_ID); + pwr_ctrl->state = FCHG_STATE_NO_CHARGING; + return; + case FCHG_STATE_I2V_CAL_2: + case FCHG_STATE_CI_CHARGING: + case FCHG_STATE_CV_CHARGING: + ABB_Write_Register_on_page(PAGE0, BCICTL2, 0); + rvf_send_trace("Charging stopped by user request", 32, + NULL_PARAM, RV_TRACE_LEVEL_DEBUG_HIGH, + FCHG_USE_ID); + pwr_ctrl->state = FCHG_STATE_NO_CHARGING; + pwr_init_discharge(); + return; + default: + rvf_send_trace("Invalid state in pwr_charge_stop_req()", 36, + pwr_ctrl->state, RV_TRACE_LEVEL_ERROR, + FCHG_USE_ID); + } +}