FreeCalypso > hg > fc-magnetite
changeset 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 |
files | src/cs/drivers/drv_app/fchg/fchg_env.h src/cs/drivers/drv_app/fchg/fchg_func_i.h src/cs/drivers/drv_app/fchg/fchg_process.c |
diffstat | 3 files changed, 78 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/src/cs/drivers/drv_app/fchg/fchg_env.h Thu Dec 14 18:35:16 2017 +0000 +++ b/src/cs/drivers/drv_app/fchg/fchg_env.h Thu Dec 14 19:54:18 2017 +0000 @@ -9,7 +9,8 @@ #include "fchg/fchg_struct.h" #include "fchg/fchg_pool_size.h" -#define FCHG_MAILBOX_USED RVF_TASK_MBOX_1 +#define FCHG_MAILBOX RVF_TASK_MBOX_0 +#define FCHG_TIMER RVF_TIMER_0 /* memory bank size and watermark */ #define FCHG_MB_PRIM_SIZE FCHG_MB1_SIZE
--- a/src/cs/drivers/drv_app/fchg/fchg_func_i.h Thu Dec 14 18:35:16 2017 +0000 +++ b/src/cs/drivers/drv_app/fchg/fchg_func_i.h Thu Dec 14 19:54:18 2017 +0000 @@ -13,5 +13,8 @@ void pwr_set_default_batt_table(void); void pwr_process_adc(struct pwr_adc_ind_s *msg); +void pwr_handle_timer(void); +void pwr_charger_plug(void); +void pwr_charger_unplug(void); #endif /* include guard */
--- a/src/cs/drivers/drv_app/fchg/fchg_process.c Thu Dec 14 18:35:16 2017 +0000 +++ b/src/cs/drivers/drv_app/fchg/fchg_process.c Thu Dec 14 19:54:18 2017 +0000 @@ -221,3 +221,76 @@ FCHG_USE_ID); } } + +void pwr_handle_timer(void) +{ + if (pwr_ctrl->state != FCHG_STATE_PWR_PLUG_TIMER) + return; + rvf_send_trace("Timer expired, ready to charge", 30, NULL_PARAM, + RV_TRACE_LEVEL_DEBUG_LOW, FCHG_USE_ID); + pwr_ctrl->state = FCHG_STATE_READY_TO_CHARGE; +} + +void pwr_charger_plug(void) +{ + if (pwr_ctrl->state != FCHG_STATE_NO_EXT_PWR) { + rvf_send_trace("Charger plug event in unexpected state", 38, + pwr_ctrl->state, RV_TRACE_LEVEL_ERROR, + FCHG_USE_ID); + return; + } + if (!pwr_ctrl->config_present) { + rvf_send_trace( + "Charger plugged in, but no config: won't charge", 47, + NULL_PARAM, RV_TRACE_LEVEL_ERROR, FCHG_USE_ID); + pwr_ctrl->state = FCHG_STATE_NO_CHARGING; + return; + } + if (pwr_ctrl->config.start_delay) { + rvf_send_trace("Charger plug, starting timer", 28, NULL_PARAM, + RV_TRACE_LEVEL_DEBUG_HIGH, FCHG_USE_ID); + rvf_start_timer(FCHG_TIMER, + RVF_MS_TO_TICKS(pwr_ctrl->config.start_delay), + FALSE); + pwr_ctrl->state = FCHG_STATE_PWR_PLUG_TIMER; + } else { + rvf_send_trace("Charger plug, ready to charge", 29, NULL_PARAM, + RV_TRACE_LEVEL_DEBUG_HIGH, FCHG_USE_ID); + pwr_ctrl->state = FCHG_STATE_READY_TO_CHARGE; + } +} + +void pwr_charger_unplug(void) +{ + switch (pwr_ctrl->state) { + case FCHG_STATE_NO_EXT_PWR: + rvf_send_trace("Charger unplug, already handled", 31, + NULL_PARAM, RV_TRACE_LEVEL_DEBUG_LOW, + FCHG_USE_ID); + /* 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: + case FCHG_STATE_NO_CHARGING: + rvf_send_trace("Charger unplug", 14, NULL_PARAM, + RV_TRACE_LEVEL_DEBUG_LOW, FCHG_USE_ID); + pwr_ctrl->state = FCHG_STATE_NO_EXT_PWR; + 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("Charger unplug, charging stopped", 32, + NULL_PARAM, RV_TRACE_LEVEL_DEBUG_HIGH, + FCHG_USE_ID); + pwr_ctrl->state = FCHG_STATE_NO_EXT_PWR; + pwr_init_discharge(); + return; + default: + rvf_send_trace("Invalid state in pwr_charger_unplug()", 35, + pwr_ctrl->state, RV_TRACE_LEVEL_ERROR, + FCHG_USE_ID); + } +}