FreeCalypso > hg > fc-magnetite
comparison src/cs/drivers/drv_app/fchg/fchg_process.c @ 333:8a90038c0173
FCHG: store discharge state as threshold index rather than percentage
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Thu, 14 Dec 2017 18:35:16 +0000 |
parents | 8166b0afcf8c |
children | d583a1f5bd6a |
comparison
equal
deleted
inserted
replaced
332:70e3acc5d4c8 | 333:8a90038c0173 |
---|---|
14 | 14 |
15 extern UINT16 madc_vbat_2_physical(UINT16 adc_val); | 15 extern UINT16 madc_vbat_2_physical(UINT16 adc_val); |
16 | 16 |
17 void pwr_init_discharge(void) | 17 void pwr_init_discharge(void) |
18 { | 18 { |
19 pwr_ctrl->curr_percent = pwr_ctrl->batt_thresholds[0].remain_capa; | 19 pwr_ctrl->curr_disch_thresh = 0; |
20 } | 20 } |
21 | 21 |
22 static void handle_discharge(void) | 22 static void handle_discharge(void) |
23 { | 23 { |
24 UINT16 i; | 24 UINT16 i; |
25 char trace[64]; | 25 char trace[64]; |
26 | 26 |
27 /* first we need to find the current threshold we are at */ | 27 /* first we need to find the current threshold we are at */ |
28 for (i = 0; i < pwr_ctrl->nb_thresholds; i++) | 28 i = pwr_ctrl->curr_disch_thresh; |
29 if (pwr_ctrl->batt_thresholds[i].remain_capa == | |
30 pwr_ctrl->curr_percent) | |
31 break; | |
32 /* is there one below? */ | 29 /* is there one below? */ |
33 if (++i == pwr_ctrl->nb_thresholds) | 30 if (++i == pwr_ctrl->nb_thresholds) |
34 return; | 31 return; |
35 /* are we crossing it? */ | 32 /* are we crossing it? */ |
36 if (pwr_ctrl->batt_mv >= pwr_ctrl->batt_thresholds[i].bat_voltage) | 33 if (pwr_ctrl->batt_mv >= pwr_ctrl->batt_thresholds[i].bat_voltage) |
39 while (i < pwr_ctrl->nb_thresholds && | 36 while (i < pwr_ctrl->nb_thresholds && |
40 pwr_ctrl->batt_mv < pwr_ctrl->batt_thresholds[i].bat_voltage) | 37 pwr_ctrl->batt_mv < pwr_ctrl->batt_thresholds[i].bat_voltage) |
41 i++; | 38 i++; |
42 /* the last one was it */ | 39 /* the last one was it */ |
43 i--; | 40 i--; |
44 pwr_ctrl->curr_percent = pwr_ctrl->batt_thresholds[i].remain_capa; | 41 pwr_ctrl->curr_disch_thresh = i; |
45 sprintf(trace, "Battery fell through %u%% mark", | 42 sprintf(trace, "Battery fell through %u%% mark", |
46 pwr_ctrl->curr_percent); | 43 pwr_ctrl->batt_thresholds[i].remain_capa); |
47 rvf_send_trace(trace, strlen(trace), NULL_PARAM, | 44 rvf_send_trace(trace, strlen(trace), NULL_PARAM, |
48 RV_TRACE_LEVEL_WARNING, FCHG_USE_ID); | 45 RV_TRACE_LEVEL_WARNING, FCHG_USE_ID); |
49 } | 46 } |
50 | 47 |
51 static void charge_progress_trace(char *mode, UINT16 ichg) | 48 static void charge_progress_trace(char *mode, UINT16 ichg) |