FreeCalypso > hg > fc-tourmaline
comparison 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 |
comparison
equal
deleted
inserted
replaced
238:8f16e0663737 | 239:305d3bb691a5 |
---|---|
21 #else | 21 #else |
22 #define LEDC 0 | 22 #define LEDC 0 |
23 #endif | 23 #endif |
24 | 24 |
25 /* | 25 /* |
26 * The following global variable is a system startup synchronization flag: | 26 * The following global variable captures the initial battery voltage |
27 * it indicates that FCHG is running and has processed at least one | 27 * at the time of system boot - it is intended to be used for various |
28 * ADC message, signifying that meaningful information about the state | 28 * system start-up decisions. |
29 * of the battery is available. | |
30 */ | 29 */ |
31 int fchg_is_running; | 30 UINT16 fchg_first_vbat; |
32 | 31 |
33 void pwr_init_discharge(void) | 32 void pwr_init_discharge(void) |
34 { | 33 { |
35 pwr_ctrl->curr_disch_thresh = 0; | 34 pwr_ctrl->curr_disch_thresh = 0; |
36 } | 35 } |
58 pwr_ctrl->batt.percent_thresh[i-1].remain_capa); | 57 pwr_ctrl->batt.percent_thresh[i-1].remain_capa); |
59 rvf_send_trace(trace, strlen(trace), NULL_PARAM, | 58 rvf_send_trace(trace, strlen(trace), NULL_PARAM, |
60 RV_TRACE_LEVEL_WARNING, FCHG_USE_ID); | 59 RV_TRACE_LEVEL_WARNING, FCHG_USE_ID); |
61 if (pwr_ctrl->event_handler) | 60 if (pwr_ctrl->event_handler) |
62 pwr_ctrl->event_handler(FCHG_EVENT_DISCHARGE); | 61 pwr_ctrl->event_handler(FCHG_EVENT_DISCHARGE); |
62 } | |
63 | |
64 static void capture_first_vbat(void) | |
65 { | |
66 char trace[64]; | |
67 | |
68 fchg_first_vbat = pwr_ctrl->batt_mv; | |
69 sprintf(trace, "System boot: Vbat=%u", pwr_ctrl->batt_mv); | |
70 rvf_send_trace(trace, strlen(trace), NULL_PARAM, | |
71 RV_TRACE_LEVEL_DEBUG_HIGH, FCHG_USE_ID); | |
63 } | 72 } |
64 | 73 |
65 static void start_i2v_cal(void) | 74 static void start_i2v_cal(void) |
66 { | 75 { |
67 UINT16 bciconf; | 76 UINT16 bciconf; |
269 } | 278 } |
270 | 279 |
271 void pwr_process_adc(struct pwr_adc_ind_s *msg) | 280 void pwr_process_adc(struct pwr_adc_ind_s *msg) |
272 { | 281 { |
273 pwr_ctrl->batt_mv = madc_vbat_2_physical(msg->data[0]); | 282 pwr_ctrl->batt_mv = madc_vbat_2_physical(msg->data[0]); |
283 if (!fchg_first_vbat) | |
284 capture_first_vbat(); | |
274 | 285 |
275 switch (pwr_ctrl->state) { | 286 switch (pwr_ctrl->state) { |
276 case FCHG_STATE_NO_EXT_PWR: | 287 case FCHG_STATE_NO_EXT_PWR: |
277 case FCHG_STATE_PWR_PLUG_TIMER: | 288 case FCHG_STATE_PWR_PLUG_TIMER: |
278 case FCHG_STATE_NO_CHARGING: | 289 case FCHG_STATE_NO_CHARGING: |
363 default: | 374 default: |
364 rvf_send_trace("Invalid state in pwr_process_adc()", 32, | 375 rvf_send_trace("Invalid state in pwr_process_adc()", 32, |
365 pwr_ctrl->state, RV_TRACE_LEVEL_ERROR, | 376 pwr_ctrl->state, RV_TRACE_LEVEL_ERROR, |
366 FCHG_USE_ID); | 377 FCHG_USE_ID); |
367 } | 378 } |
368 fchg_is_running = 1; | |
369 } | 379 } |
370 | 380 |
371 void pwr_handle_timer(void) | 381 void pwr_handle_timer(void) |
372 { | 382 { |
373 if (pwr_ctrl->state != FCHG_STATE_PWR_PLUG_TIMER) | 383 if (pwr_ctrl->state != FCHG_STATE_PWR_PLUG_TIMER) |