FreeCalypso > hg > fc-tourmaline
diff src/cs/drivers/drv_app/fchg/fchg_process.c @ 239:305d3bb691a5
FCHG startup: replace fchg_is_running with fchg_first_vbat
and also report the first Vbat reading in a trace
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 02 May 2021 05:30:59 +0000 |
parents | 3c790d29748e |
children | 769cf6273fe4 |
line wrap: on
line diff
--- a/src/cs/drivers/drv_app/fchg/fchg_process.c Sun May 02 04:36:25 2021 +0000 +++ b/src/cs/drivers/drv_app/fchg/fchg_process.c Sun May 02 05:30:59 2021 +0000 @@ -23,12 +23,11 @@ #endif /* - * The following global variable is a system startup synchronization flag: - * it indicates that FCHG is running and has processed at least one - * ADC message, signifying that meaningful information about the state - * of the battery is available. + * The following global variable captures the initial battery voltage + * at the time of system boot - it is intended to be used for various + * system start-up decisions. */ -int fchg_is_running; +UINT16 fchg_first_vbat; void pwr_init_discharge(void) { @@ -62,6 +61,16 @@ pwr_ctrl->event_handler(FCHG_EVENT_DISCHARGE); } +static void capture_first_vbat(void) +{ + char trace[64]; + + fchg_first_vbat = pwr_ctrl->batt_mv; + sprintf(trace, "System boot: Vbat=%u", pwr_ctrl->batt_mv); + rvf_send_trace(trace, strlen(trace), NULL_PARAM, + RV_TRACE_LEVEL_DEBUG_HIGH, FCHG_USE_ID); +} + static void start_i2v_cal(void) { UINT16 bciconf; @@ -271,6 +280,8 @@ void pwr_process_adc(struct pwr_adc_ind_s *msg) { pwr_ctrl->batt_mv = madc_vbat_2_physical(msg->data[0]); + if (!fchg_first_vbat) + capture_first_vbat(); switch (pwr_ctrl->state) { case FCHG_STATE_NO_EXT_PWR: @@ -365,7 +376,6 @@ pwr_ctrl->state, RV_TRACE_LEVEL_ERROR, FCHG_USE_ID); } - fchg_is_running = 1; } void pwr_handle_timer(void)