annotate src/cs/drivers/drv_app/fchg/fchg_process.c @ 304:58c7961bd0b0 default tip

TCH tap: extend DL sniffing feature to support CSD modes Our debug feature for TCH DL sniffing reads the content of the DSP's a_dd_0 buffer (or a_dd_1 for TCH/H subchannel 1) at appropriate times and forwards captured bits to the host. This feature was originally implemented for TCH/FS, TCH/EFS and TCH/HS - now extend it to cover TCH/F data modes too.
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 25 Nov 2024 23:33:27 +0000
parents 7420959e02ec
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * In this module we are going to implement the main process functions
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * for FCHG.
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 */
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include "fchg/fchg_env.h"
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include "fchg/fchg_func_i.h"
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include "rv/rv_general.h"
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include "rvf/rvf_api.h"
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include "rvm/rvm_use_id_list.h"
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include "abb/abb.h"
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 #include "fc-target.h"
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 #include <string.h>
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 #include <stdio.h>
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 extern UINT16 madc_vbat_2_physical(UINT16 adc_val);
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 extern UINT16 madc_vbat_inverse(UINT16 mv);
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 #if defined(CONFIG_TARGET_C155) || defined(CONFIG_TARGET_J100)
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 #define LEDC 0x20
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 #else
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 #define LEDC 0
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 #endif
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24
262
7420959e02ec FCHG rework for charger plug/unplug debouncing
Mychaela Falconia <falcon@freecalypso.org>
parents: 255
diff changeset
25 #define CHARGER_PLUG_DEBOUNCE_MS 200
7420959e02ec FCHG rework for charger plug/unplug debouncing
Mychaela Falconia <falcon@freecalypso.org>
parents: 255
diff changeset
26
236
3c790d29748e fchg_is_running startup sync flag change:
Mychaela Falconia <falcon@freecalypso.org>
parents: 61
diff changeset
27 /*
239
305d3bb691a5 FCHG startup: replace fchg_is_running with fchg_first_vbat
Mychaela Falconia <falcon@freecalypso.org>
parents: 236
diff changeset
28 * The following global variable captures the initial battery voltage
305d3bb691a5 FCHG startup: replace fchg_is_running with fchg_first_vbat
Mychaela Falconia <falcon@freecalypso.org>
parents: 236
diff changeset
29 * at the time of system boot - it is intended to be used for various
305d3bb691a5 FCHG startup: replace fchg_is_running with fchg_first_vbat
Mychaela Falconia <falcon@freecalypso.org>
parents: 236
diff changeset
30 * system start-up decisions.
236
3c790d29748e fchg_is_running startup sync flag change:
Mychaela Falconia <falcon@freecalypso.org>
parents: 61
diff changeset
31 */
239
305d3bb691a5 FCHG startup: replace fchg_is_running with fchg_first_vbat
Mychaela Falconia <falcon@freecalypso.org>
parents: 236
diff changeset
32 UINT16 fchg_first_vbat;
236
3c790d29748e fchg_is_running startup sync flag change:
Mychaela Falconia <falcon@freecalypso.org>
parents: 61
diff changeset
33
0
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 void pwr_init_discharge(void)
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 {
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 pwr_ctrl->curr_disch_thresh = 0;
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 }
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 static void handle_discharge(void)
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 {
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 UINT16 i;
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 char trace[64];
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 /* first we need to find the current threshold we are at */
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 i = pwr_ctrl->curr_disch_thresh;
61
75067af48bfd FCHG updates for Tourmaline UI integration
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
46 /* are we at the bottom? */
75067af48bfd FCHG updates for Tourmaline UI integration
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
47 if ((i + 1) == pwr_ctrl->nb_percent_thresh)
0
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 return;
61
75067af48bfd FCHG updates for Tourmaline UI integration
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
49 /* are we crossing our current threshold? */
75067af48bfd FCHG updates for Tourmaline UI integration
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
50 if (pwr_ctrl->batt_mv >= pwr_ctrl->batt.percent_thresh[i].bat_voltage)
0
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 return;
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 /* yes, we crossed it - see if we fell even further down */
61
75067af48bfd FCHG updates for Tourmaline UI integration
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
53 while (i < pwr_ctrl->nb_percent_thresh-1 &&
75067af48bfd FCHG updates for Tourmaline UI integration
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
54 pwr_ctrl->batt_mv < pwr_ctrl->batt.percent_thresh[i].bat_voltage)
0
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 i++;
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 /* the last one was it */
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 pwr_ctrl->curr_disch_thresh = i;
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 sprintf(trace, "Battery fell through %u%% mark",
61
75067af48bfd FCHG updates for Tourmaline UI integration
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
59 pwr_ctrl->batt.percent_thresh[i-1].remain_capa);
0
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 rvf_send_trace(trace, strlen(trace), NULL_PARAM,
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 RV_TRACE_LEVEL_WARNING, FCHG_USE_ID);
61
75067af48bfd FCHG updates for Tourmaline UI integration
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
62 if (pwr_ctrl->event_handler)
75067af48bfd FCHG updates for Tourmaline UI integration
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
63 pwr_ctrl->event_handler(FCHG_EVENT_DISCHARGE);
0
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 }
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65
239
305d3bb691a5 FCHG startup: replace fchg_is_running with fchg_first_vbat
Mychaela Falconia <falcon@freecalypso.org>
parents: 236
diff changeset
66 static void capture_first_vbat(void)
305d3bb691a5 FCHG startup: replace fchg_is_running with fchg_first_vbat
Mychaela Falconia <falcon@freecalypso.org>
parents: 236
diff changeset
67 {
305d3bb691a5 FCHG startup: replace fchg_is_running with fchg_first_vbat
Mychaela Falconia <falcon@freecalypso.org>
parents: 236
diff changeset
68 char trace[64];
305d3bb691a5 FCHG startup: replace fchg_is_running with fchg_first_vbat
Mychaela Falconia <falcon@freecalypso.org>
parents: 236
diff changeset
69
305d3bb691a5 FCHG startup: replace fchg_is_running with fchg_first_vbat
Mychaela Falconia <falcon@freecalypso.org>
parents: 236
diff changeset
70 fchg_first_vbat = pwr_ctrl->batt_mv;
305d3bb691a5 FCHG startup: replace fchg_is_running with fchg_first_vbat
Mychaela Falconia <falcon@freecalypso.org>
parents: 236
diff changeset
71 sprintf(trace, "System boot: Vbat=%u", pwr_ctrl->batt_mv);
305d3bb691a5 FCHG startup: replace fchg_is_running with fchg_first_vbat
Mychaela Falconia <falcon@freecalypso.org>
parents: 236
diff changeset
72 rvf_send_trace(trace, strlen(trace), NULL_PARAM,
305d3bb691a5 FCHG startup: replace fchg_is_running with fchg_first_vbat
Mychaela Falconia <falcon@freecalypso.org>
parents: 236
diff changeset
73 RV_TRACE_LEVEL_DEBUG_HIGH, FCHG_USE_ID);
305d3bb691a5 FCHG startup: replace fchg_is_running with fchg_first_vbat
Mychaela Falconia <falcon@freecalypso.org>
parents: 236
diff changeset
74 }
305d3bb691a5 FCHG startup: replace fchg_is_running with fchg_first_vbat
Mychaela Falconia <falcon@freecalypso.org>
parents: 236
diff changeset
75
0
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 static void start_i2v_cal(void)
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 {
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 UINT16 bciconf;
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 rvf_send_trace("Calibrating i2v offset", 22, NULL_PARAM,
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 RV_TRACE_LEVEL_DEBUG_HIGH, FCHG_USE_ID);
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 pwr_ctrl->state = FCHG_STATE_I2V_CAL_2;
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 bciconf = ABB_Read_Register_on_page(PAGE1, BCICONF);
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 bciconf &= 0x3E0;
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 bciconf |= pwr_ctrl->config.bciconf;
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 ABB_Write_Register_on_page(PAGE1, BCICONF, bciconf);
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 /*
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 * Set the CHDISPA bit and start the zero calibration routine
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 * of the I to V converter
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 */
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 ABB_Write_Register_on_page(PAGE0, BCICTL2, 0x0010);
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92 ABB_Write_Register_on_page(PAGE0, BCICTL2, 0x0019 | LEDC);
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93 }
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95 static void start_ci_charging(void)
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96 {
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97 rvf_send_trace("Start CI charging", 17, NULL_PARAM,
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
98 RV_TRACE_LEVEL_DEBUG_HIGH, FCHG_USE_ID);
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
99 pwr_ctrl->state = FCHG_STATE_CI_CHARGING;
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
100 /* Select constant current charging. The charger is disabled */
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
101 ABB_Write_Register_on_page(PAGE0, BCICTL2, 0x0002);
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
102 /* Program the DAC with the constant current value */
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
103 ABB_Write_Register_on_page(PAGE0, CHGREG,
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
104 pwr_ctrl->config.ci_current + pwr_ctrl->i2v_offset);
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
105 /* Enable the charger */
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
106 ABB_Write_Register_on_page(PAGE0, BCICTL2, 0x0003 | LEDC);
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
107 /* The total charging time starts now */
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
108 pwr_ctrl->start_time = rvf_get_tick_count();
61
75067af48bfd FCHG updates for Tourmaline UI integration
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
109 if (pwr_ctrl->event_handler)
75067af48bfd FCHG updates for Tourmaline UI integration
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
110 pwr_ctrl->event_handler(FCHG_EVENT_CHARGING_START);
0
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
111 }
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
112
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
113 static void start_cv_charging(void)
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
114 {
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
115 UINT16 code;
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
116
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
117 rvf_send_trace("Start CV charging", 17, NULL_PARAM,
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
118 RV_TRACE_LEVEL_DEBUG_HIGH, FCHG_USE_ID);
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
119 pwr_ctrl->state = FCHG_STATE_CV_CHARGING;
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
120 /* Select constant voltage charging. The charger is disabled */
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
121 ABB_Write_Register_on_page(PAGE0, BCICTL2, 0);
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
122 /* figure out the DAC code */
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
123 code = madc_vbat_inverse(pwr_ctrl->config.cv_init_set);
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
124 rvf_send_trace("Voltage (DAC code) ", 19, code,
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
125 RV_TRACE_LEVEL_DEBUG_LOW, FCHG_USE_ID);
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
126 /* Program the DAC with the constant voltage value */
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
127 ABB_Write_Register_on_page(PAGE0, CHGREG, code);
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
128 /* Enable the charger */
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
129 ABB_Write_Register_on_page(PAGE0, BCICTL2, 0x0001 | LEDC);
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
130 /* CV control loop state init */
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
131 pwr_ctrl->cv_dac_init = code;
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
132 pwr_ctrl->cv_dac_curr = code;
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
133 pwr_ctrl->cv_high_vbat_count = 0;
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
134 pwr_ctrl->cv_low_vbat_count = 0;
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
135 /* Ichg averaging state init */
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
136 pwr_ctrl->ichg_fill_level = 0;
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
137 pwr_ctrl->ichg_ring_ptr = 0;
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
138 pwr_ctrl->ichg_low_count = 0;
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
139 }
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
140
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
141 static void start_charge_condition_met(void)
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
142 {
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
143 rvf_send_trace("Charge start condition met", 26, NULL_PARAM,
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
144 RV_TRACE_LEVEL_DEBUG_HIGH, FCHG_USE_ID);
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
145 if (pwr_ctrl->config.bciconf)
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
146 start_i2v_cal();
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
147 else {
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
148 pwr_ctrl->i2v_offset = 0;
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
149 start_ci_charging();
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
150 }
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
151 }
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
152
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
153 static void ci_progress_trace(UINT16 ichg)
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
154 {
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
155 char trace[64];
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
156
61
75067af48bfd FCHG updates for Tourmaline UI integration
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
157 pwr_ctrl->ci_ichg = ichg;
0
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
158 sprintf(trace, "CI charging: Vbat=%u Ichg=%u i2v=%u",
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
159 pwr_ctrl->batt_mv, ichg, pwr_ctrl->i2v_offset);
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
160 rvf_send_trace(trace, strlen(trace), NULL_PARAM,
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
161 RV_TRACE_LEVEL_DEBUG_LOW, FCHG_USE_ID);
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
162 }
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
163
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
164 static int cv_ichg_process(UINT16 ichg_new)
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
165 {
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
166 UINT16 ichg_clip, ichg_entry;
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
167 UINT32 ichg_accum;
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
168 UINT16 i;
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
169 char trace[64];
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
170
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
171 if (pwr_ctrl->ichg_fill_level < ICHG_AVG_WINDOW)
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
172 pwr_ctrl->ichg_avg_buf[pwr_ctrl->ichg_fill_level++] = ichg_new;
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
173 else {
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
174 ichg_clip = pwr_ctrl->ichg_average +
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
175 pwr_ctrl->config.ichg_max_spike;
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
176 if (ichg_new > ichg_clip)
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
177 ichg_entry = ichg_clip;
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
178 else
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
179 ichg_entry = ichg_new;
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
180 pwr_ctrl->ichg_avg_buf[pwr_ctrl->ichg_ring_ptr++] = ichg_entry;
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
181 if (pwr_ctrl->ichg_ring_ptr >= ICHG_AVG_WINDOW)
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
182 pwr_ctrl->ichg_ring_ptr = 0;
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
183 }
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
184 ichg_accum = 0;
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
185 for (i = 0; i < pwr_ctrl->ichg_fill_level; i++)
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
186 ichg_accum += pwr_ctrl->ichg_avg_buf[i];
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
187 pwr_ctrl->ichg_average = ichg_accum / pwr_ctrl->ichg_fill_level;
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
188 sprintf(trace, "CV charging: Vbat=%u Ichg=%u Ichg_avg=%u i2v=%u",
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
189 pwr_ctrl->batt_mv, ichg_new, pwr_ctrl->ichg_average,
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
190 pwr_ctrl->i2v_offset);
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
191 rvf_send_trace(trace, strlen(trace), NULL_PARAM,
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
192 RV_TRACE_LEVEL_DEBUG_LOW, FCHG_USE_ID);
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
193 if (pwr_ctrl->ichg_average >
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
194 (pwr_ctrl->config.end_current + pwr_ctrl->i2v_offset)) {
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
195 pwr_ctrl->ichg_low_count = 0;
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
196 return 0;
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
197 }
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
198 pwr_ctrl->ichg_low_count++;
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
199 if (pwr_ctrl->ichg_low_count < pwr_ctrl->config.ichg_samples_needed)
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
200 return 0;
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
201 rvf_send_trace("Stopping charge by low current condition", 40,
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
202 NULL_PARAM, RV_TRACE_LEVEL_DEBUG_HIGH, FCHG_USE_ID);
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
203 ABB_Write_Register_on_page(PAGE0, BCICTL2, 0);
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
204 pwr_init_discharge();
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
205 pwr_ctrl->state = FCHG_STATE_READY_TO_RECHARGE;
61
75067af48bfd FCHG updates for Tourmaline UI integration
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
206 if (pwr_ctrl->event_handler)
75067af48bfd FCHG updates for Tourmaline UI integration
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
207 pwr_ctrl->event_handler(FCHG_EVENT_CHARGING_COMPLETE);
0
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
208 return 1;
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
209 }
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
210
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
211 static int overvoltage_end_charge_check(void)
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
212 {
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
213 if (pwr_ctrl->batt_mv < pwr_ctrl->config.overvoltage)
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
214 return 0;
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
215 if (pwr_ctrl->cv_dac_curr !=
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
216 (pwr_ctrl->cv_dac_init - pwr_ctrl->config.cv_dac_max_decr))
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
217 return 0;
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
218 rvf_send_trace("Stopping charge by overvoltage condition", 40,
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
219 NULL_PARAM, RV_TRACE_LEVEL_WARNING, FCHG_USE_ID);
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
220 ABB_Write_Register_on_page(PAGE0, BCICTL2, 0);
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
221 pwr_init_discharge();
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
222 pwr_ctrl->state = FCHG_STATE_READY_TO_RECHARGE;
61
75067af48bfd FCHG updates for Tourmaline UI integration
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
223 if (pwr_ctrl->event_handler)
75067af48bfd FCHG updates for Tourmaline UI integration
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
224 pwr_ctrl->event_handler(FCHG_EVENT_CHARGING_COMPLETE);
0
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
225 return 1;
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
226 }
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
227
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
228 static void cv_ctrl_loop_high_check(void)
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
229 {
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
230 if (pwr_ctrl->batt_mv < pwr_ctrl->config.cv_ctrl_loop_high) {
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
231 pwr_ctrl->cv_high_vbat_count = 0;
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
232 return;
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
233 }
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
234 pwr_ctrl->cv_high_vbat_count++;
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
235 if (pwr_ctrl->cv_high_vbat_count < pwr_ctrl->config.cv_samples_needed)
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
236 return;
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
237 if (pwr_ctrl->cv_dac_curr ==
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
238 (pwr_ctrl->cv_dac_init - pwr_ctrl->config.cv_dac_max_decr))
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
239 return;
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
240 pwr_ctrl->cv_dac_curr--;
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
241 ABB_Write_Register_on_page(PAGE0, CHGREG, pwr_ctrl->cv_dac_curr);
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
242 rvf_send_trace("Sub CV DAC", 10, pwr_ctrl->cv_dac_curr,
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
243 RV_TRACE_LEVEL_DEBUG_MEDIUM, FCHG_USE_ID);
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
244 pwr_ctrl->cv_high_vbat_count = 0;
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
245 }
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
246
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
247 static void cv_ctrl_loop_low_check(void)
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
248 {
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
249 if (pwr_ctrl->batt_mv >= pwr_ctrl->config.cv_ctrl_loop_low) {
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
250 pwr_ctrl->cv_low_vbat_count = 0;
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
251 return;
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
252 }
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
253 pwr_ctrl->cv_low_vbat_count++;
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
254 if (pwr_ctrl->cv_low_vbat_count < pwr_ctrl->config.cv_samples_needed)
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
255 return;
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
256 if (pwr_ctrl->cv_dac_curr ==
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
257 (pwr_ctrl->cv_dac_init + pwr_ctrl->config.cv_dac_max_incr))
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
258 return;
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
259 pwr_ctrl->cv_dac_curr++;
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
260 ABB_Write_Register_on_page(PAGE0, CHGREG, pwr_ctrl->cv_dac_curr);
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
261 rvf_send_trace("Add CV DAC", 10, pwr_ctrl->cv_dac_curr,
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
262 RV_TRACE_LEVEL_DEBUG_MEDIUM, FCHG_USE_ID);
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
263 pwr_ctrl->cv_low_vbat_count = 0;
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
264 }
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
265
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
266 static int charging_time_limit_check(void)
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
267 {
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
268 if ((rvf_get_tick_count() - pwr_ctrl->start_time) <
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
269 RVF_SECS_TO_TICKS(pwr_ctrl->config.charge_time_limit))
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
270 return 0;
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
271 rvf_send_trace("Stopping charge by time exceeded condition", 42,
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
272 NULL_PARAM, RV_TRACE_LEVEL_WARNING, FCHG_USE_ID);
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
273 ABB_Write_Register_on_page(PAGE0, BCICTL2, 0);
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
274 pwr_init_discharge();
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
275 pwr_ctrl->state = FCHG_STATE_RECHARGE_TIMER;
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
276 pwr_ctrl->start_time = rvf_get_tick_count();
61
75067af48bfd FCHG updates for Tourmaline UI integration
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
277 if (pwr_ctrl->event_handler)
75067af48bfd FCHG updates for Tourmaline UI integration
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
278 pwr_ctrl->event_handler(FCHG_EVENT_CHARGING_TIMEOUT);
0
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
279 return 1;
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
280 }
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
281
253
769cf6273fe4 FCHG: beginning of battery simulation mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 239
diff changeset
282 static void process_adc_regular(struct pwr_adc_ind_s *msg)
0
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
283 {
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
284 switch (pwr_ctrl->state) {
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
285 case FCHG_STATE_NO_EXT_PWR:
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
286 case FCHG_STATE_PWR_PLUG_TIMER:
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
287 case FCHG_STATE_NO_CHARGING:
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
288 handle_discharge();
253
769cf6273fe4 FCHG: beginning of battery simulation mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 239
diff changeset
289 return;
0
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
290 case FCHG_STATE_READY_TO_CHARGE:
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
291 handle_discharge();
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
292 if (!(msg->data[9] & CHGPRES)) {
262
7420959e02ec FCHG rework for charger plug/unplug debouncing
Mychaela Falconia <falcon@freecalypso.org>
parents: 255
diff changeset
293 pwr_ctrl->state = FCHG_STATE_NO_CHARGING;
253
769cf6273fe4 FCHG: beginning of battery simulation mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 239
diff changeset
294 return;
0
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
295 }
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
296 if (pwr_ctrl->batt_mv < pwr_ctrl->config.start_thresh)
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
297 start_charge_condition_met();
253
769cf6273fe4 FCHG: beginning of battery simulation mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 239
diff changeset
298 return;
0
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
299 case FCHG_STATE_READY_TO_RECHARGE:
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
300 handle_discharge();
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
301 if (!(msg->data[9] & CHGPRES)) {
262
7420959e02ec FCHG rework for charger plug/unplug debouncing
Mychaela Falconia <falcon@freecalypso.org>
parents: 255
diff changeset
302 pwr_ctrl->state = FCHG_STATE_NO_CHARGING;
253
769cf6273fe4 FCHG: beginning of battery simulation mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 239
diff changeset
303 return;
0
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
304 }
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
305 if (pwr_ctrl->batt_mv < pwr_ctrl->config.restart_thresh)
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
306 start_charge_condition_met();
253
769cf6273fe4 FCHG: beginning of battery simulation mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 239
diff changeset
307 return;
0
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
308 case FCHG_STATE_I2V_CAL_1:
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
309 if (!(msg->data[9] & CHGPRES)) {
262
7420959e02ec FCHG rework for charger plug/unplug debouncing
Mychaela Falconia <falcon@freecalypso.org>
parents: 255
diff changeset
310 pwr_ctrl->state = FCHG_STATE_NO_CHARGING;
253
769cf6273fe4 FCHG: beginning of battery simulation mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 239
diff changeset
311 return;
0
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
312 }
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
313 if (pwr_ctrl->config.bciconf)
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
314 start_i2v_cal();
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
315 else {
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
316 pwr_ctrl->i2v_offset = 0;
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
317 start_ci_charging();
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
318 }
253
769cf6273fe4 FCHG: beginning of battery simulation mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 239
diff changeset
319 return;
0
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
320 case FCHG_STATE_I2V_CAL_2:
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
321 pwr_ctrl->i2v_offset = msg->data[2];
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
322 ABB_Write_Register_on_page(PAGE0, BCICTL2, 0);
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
323 rvf_send_trace("i2v offset (MADC code) ", 23,
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
324 pwr_ctrl->i2v_offset,
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
325 RV_TRACE_LEVEL_DEBUG_LOW, FCHG_USE_ID);
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
326 if (!(msg->data[9] & CHGPRES)) {
262
7420959e02ec FCHG rework for charger plug/unplug debouncing
Mychaela Falconia <falcon@freecalypso.org>
parents: 255
diff changeset
327 pwr_ctrl->state = FCHG_STATE_NO_CHARGING;
0
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
328 pwr_init_discharge();
253
769cf6273fe4 FCHG: beginning of battery simulation mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 239
diff changeset
329 return;
0
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
330 }
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
331 start_ci_charging();
253
769cf6273fe4 FCHG: beginning of battery simulation mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 239
diff changeset
332 return;
0
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
333 case FCHG_STATE_CI_CHARGING:
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
334 ci_progress_trace(msg->data[2]);
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
335 if (!(msg->data[9] & CHGPRES)) {
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
336 ABB_Write_Register_on_page(PAGE0, BCICTL2, 0);
262
7420959e02ec FCHG rework for charger plug/unplug debouncing
Mychaela Falconia <falcon@freecalypso.org>
parents: 255
diff changeset
337 pwr_ctrl->state = FCHG_STATE_NO_CHARGING;
0
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
338 pwr_init_discharge();
253
769cf6273fe4 FCHG: beginning of battery simulation mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 239
diff changeset
339 return;
0
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
340 }
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
341 if (charging_time_limit_check())
253
769cf6273fe4 FCHG: beginning of battery simulation mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 239
diff changeset
342 return;
0
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
343 if (pwr_ctrl->batt_mv >= pwr_ctrl->config.ci2cv_thresh)
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
344 start_cv_charging();
253
769cf6273fe4 FCHG: beginning of battery simulation mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 239
diff changeset
345 return;
0
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
346 case FCHG_STATE_CV_CHARGING:
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
347 if (!(msg->data[9] & CHGPRES)) {
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
348 ABB_Write_Register_on_page(PAGE0, BCICTL2, 0);
262
7420959e02ec FCHG rework for charger plug/unplug debouncing
Mychaela Falconia <falcon@freecalypso.org>
parents: 255
diff changeset
349 pwr_ctrl->state = FCHG_STATE_NO_CHARGING;
0
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
350 pwr_init_discharge();
253
769cf6273fe4 FCHG: beginning of battery simulation mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 239
diff changeset
351 return;
0
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
352 }
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
353 if (cv_ichg_process(msg->data[2]))
253
769cf6273fe4 FCHG: beginning of battery simulation mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 239
diff changeset
354 return;
0
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
355 if (overvoltage_end_charge_check())
253
769cf6273fe4 FCHG: beginning of battery simulation mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 239
diff changeset
356 return;
0
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
357 if (charging_time_limit_check())
253
769cf6273fe4 FCHG: beginning of battery simulation mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 239
diff changeset
358 return;
0
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
359 cv_ctrl_loop_high_check();
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
360 cv_ctrl_loop_low_check();
253
769cf6273fe4 FCHG: beginning of battery simulation mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 239
diff changeset
361 return;
0
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
362 case FCHG_STATE_RECHARGE_TIMER:
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
363 handle_discharge();
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
364 if ((rvf_get_tick_count() - pwr_ctrl->start_time) <
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
365 RVF_SECS_TO_TICKS(pwr_ctrl->config.recharge_delay))
253
769cf6273fe4 FCHG: beginning of battery simulation mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 239
diff changeset
366 return;
0
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
367 rvf_send_trace("Restart time met, allowing new charging", 39,
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
368 NULL_PARAM, RV_TRACE_LEVEL_DEBUG_HIGH,
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
369 FCHG_USE_ID);
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
370 pwr_ctrl->state = FCHG_STATE_READY_TO_RECHARGE;
253
769cf6273fe4 FCHG: beginning of battery simulation mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 239
diff changeset
371 return;
0
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
372 default:
253
769cf6273fe4 FCHG: beginning of battery simulation mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 239
diff changeset
373 rvf_send_trace("Invalid state in pwr_process_adc()", 34,
0
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
374 pwr_ctrl->state, RV_TRACE_LEVEL_ERROR,
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
375 FCHG_USE_ID);
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
376 }
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
377 }
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
378
253
769cf6273fe4 FCHG: beginning of battery simulation mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 239
diff changeset
379 static void process_adc_bsim(struct pwr_adc_ind_s *msg)
769cf6273fe4 FCHG: beginning of battery simulation mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 239
diff changeset
380 {
769cf6273fe4 FCHG: beginning of battery simulation mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 239
diff changeset
381 switch (pwr_ctrl->state) {
769cf6273fe4 FCHG: beginning of battery simulation mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 239
diff changeset
382 case FCHG_STATE_READY_TO_CHARGE:
769cf6273fe4 FCHG: beginning of battery simulation mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 239
diff changeset
383 if (!pwr_ctrl->bsim.start_enable)
769cf6273fe4 FCHG: beginning of battery simulation mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 239
diff changeset
384 return;
769cf6273fe4 FCHG: beginning of battery simulation mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 239
diff changeset
385 rvf_send_trace("BSIM: simulated charging auto-start", 35,
769cf6273fe4 FCHG: beginning of battery simulation mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 239
diff changeset
386 NULL_PARAM, RV_TRACE_LEVEL_DEBUG_MEDIUM,
769cf6273fe4 FCHG: beginning of battery simulation mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 239
diff changeset
387 FCHG_USE_ID);
769cf6273fe4 FCHG: beginning of battery simulation mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 239
diff changeset
388 pwr_ctrl->state = FCHG_STATE_I2V_CAL_1;
769cf6273fe4 FCHG: beginning of battery simulation mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 239
diff changeset
389 return;
769cf6273fe4 FCHG: beginning of battery simulation mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 239
diff changeset
390 case FCHG_STATE_I2V_CAL_1:
769cf6273fe4 FCHG: beginning of battery simulation mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 239
diff changeset
391 rvf_send_trace("BSIM: advancing from I2V_CAL_1 to I2V_CAL_2",
769cf6273fe4 FCHG: beginning of battery simulation mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 239
diff changeset
392 43, NULL_PARAM, RV_TRACE_LEVEL_DEBUG_LOW,
769cf6273fe4 FCHG: beginning of battery simulation mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 239
diff changeset
393 FCHG_USE_ID);
769cf6273fe4 FCHG: beginning of battery simulation mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 239
diff changeset
394 pwr_ctrl->state = FCHG_STATE_I2V_CAL_2;
769cf6273fe4 FCHG: beginning of battery simulation mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 239
diff changeset
395 return;
769cf6273fe4 FCHG: beginning of battery simulation mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 239
diff changeset
396 case FCHG_STATE_I2V_CAL_2:
769cf6273fe4 FCHG: beginning of battery simulation mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 239
diff changeset
397 rvf_send_trace("BSIM: advancing from I2V_CAL_2 to CI charging",
769cf6273fe4 FCHG: beginning of battery simulation mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 239
diff changeset
398 45, NULL_PARAM, RV_TRACE_LEVEL_DEBUG_LOW,
769cf6273fe4 FCHG: beginning of battery simulation mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 239
diff changeset
399 FCHG_USE_ID);
769cf6273fe4 FCHG: beginning of battery simulation mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 239
diff changeset
400 pwr_ctrl->state = FCHG_STATE_CI_CHARGING;
255
1a4413c4eb7e FCHG: missed charging start event in BSIM mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 253
diff changeset
401 if (pwr_ctrl->event_handler)
1a4413c4eb7e FCHG: missed charging start event in BSIM mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 253
diff changeset
402 pwr_ctrl->event_handler(FCHG_EVENT_CHARGING_START);
253
769cf6273fe4 FCHG: beginning of battery simulation mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 239
diff changeset
403 return;
769cf6273fe4 FCHG: beginning of battery simulation mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 239
diff changeset
404 default:
769cf6273fe4 FCHG: beginning of battery simulation mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 239
diff changeset
405 /* remaining states require no action in BSIM */
769cf6273fe4 FCHG: beginning of battery simulation mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 239
diff changeset
406 return;
769cf6273fe4 FCHG: beginning of battery simulation mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 239
diff changeset
407 }
769cf6273fe4 FCHG: beginning of battery simulation mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 239
diff changeset
408 }
769cf6273fe4 FCHG: beginning of battery simulation mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 239
diff changeset
409
769cf6273fe4 FCHG: beginning of battery simulation mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 239
diff changeset
410 void pwr_process_adc(struct pwr_adc_ind_s *msg)
769cf6273fe4 FCHG: beginning of battery simulation mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 239
diff changeset
411 {
769cf6273fe4 FCHG: beginning of battery simulation mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 239
diff changeset
412 pwr_ctrl->batt_mv = madc_vbat_2_physical(msg->data[0]);
769cf6273fe4 FCHG: beginning of battery simulation mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 239
diff changeset
413 if (!fchg_first_vbat)
769cf6273fe4 FCHG: beginning of battery simulation mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 239
diff changeset
414 capture_first_vbat();
769cf6273fe4 FCHG: beginning of battery simulation mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 239
diff changeset
415 if (pwr_ctrl->bsim_mode)
769cf6273fe4 FCHG: beginning of battery simulation mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 239
diff changeset
416 process_adc_bsim(msg);
769cf6273fe4 FCHG: beginning of battery simulation mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 239
diff changeset
417 else
769cf6273fe4 FCHG: beginning of battery simulation mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 239
diff changeset
418 process_adc_regular(msg);
769cf6273fe4 FCHG: beginning of battery simulation mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 239
diff changeset
419 }
769cf6273fe4 FCHG: beginning of battery simulation mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 239
diff changeset
420
262
7420959e02ec FCHG rework for charger plug/unplug debouncing
Mychaela Falconia <falcon@freecalypso.org>
parents: 255
diff changeset
421 void pwr_charger_plug_unplug_ind(void)
0
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
422 {
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
423 switch (pwr_ctrl->state) {
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
424 case FCHG_STATE_NO_EXT_PWR:
262
7420959e02ec FCHG rework for charger plug/unplug debouncing
Mychaela Falconia <falcon@freecalypso.org>
parents: 255
diff changeset
425 rvf_send_trace("Charger plug interrupt, beginning debounce",
7420959e02ec FCHG rework for charger plug/unplug debouncing
Mychaela Falconia <falcon@freecalypso.org>
parents: 255
diff changeset
426 42, NULL_PARAM, RV_TRACE_LEVEL_DEBUG_LOW,
0
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
427 FCHG_USE_ID);
262
7420959e02ec FCHG rework for charger plug/unplug debouncing
Mychaela Falconia <falcon@freecalypso.org>
parents: 255
diff changeset
428 pwr_ctrl->state = FCHG_STATE_PWR_PLUG_TIMER;
61
75067af48bfd FCHG updates for Tourmaline UI integration
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
429 break;
0
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
430 case FCHG_STATE_PWR_PLUG_TIMER:
262
7420959e02ec FCHG rework for charger plug/unplug debouncing
Mychaela Falconia <falcon@freecalypso.org>
parents: 255
diff changeset
431 /* debouncing in action - nothing to do here */
7420959e02ec FCHG rework for charger plug/unplug debouncing
Mychaela Falconia <falcon@freecalypso.org>
parents: 255
diff changeset
432 break;
0
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
433 case FCHG_STATE_READY_TO_CHARGE:
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
434 case FCHG_STATE_READY_TO_RECHARGE:
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
435 case FCHG_STATE_I2V_CAL_1:
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
436 case FCHG_STATE_RECHARGE_TIMER:
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
437 case FCHG_STATE_NO_CHARGING:
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
438 rvf_send_trace("Charger unplug", 14, NULL_PARAM,
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
439 RV_TRACE_LEVEL_DEBUG_LOW, FCHG_USE_ID);
262
7420959e02ec FCHG rework for charger plug/unplug debouncing
Mychaela Falconia <falcon@freecalypso.org>
parents: 255
diff changeset
440 pwr_ctrl->state = FCHG_STATE_PWR_PLUG_TIMER;
7420959e02ec FCHG rework for charger plug/unplug debouncing
Mychaela Falconia <falcon@freecalypso.org>
parents: 255
diff changeset
441 if (pwr_ctrl->event_handler)
7420959e02ec FCHG rework for charger plug/unplug debouncing
Mychaela Falconia <falcon@freecalypso.org>
parents: 255
diff changeset
442 pwr_ctrl->event_handler(FCHG_EVENT_CHARGER_UNPLUG);
61
75067af48bfd FCHG updates for Tourmaline UI integration
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
443 break;
0
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
444 case FCHG_STATE_I2V_CAL_2:
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
445 case FCHG_STATE_CI_CHARGING:
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
446 case FCHG_STATE_CV_CHARGING:
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
447 ABB_Write_Register_on_page(PAGE0, BCICTL2, 0);
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
448 rvf_send_trace("Charger unplug, charging stopped", 32,
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
449 NULL_PARAM, RV_TRACE_LEVEL_DEBUG_HIGH,
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
450 FCHG_USE_ID);
262
7420959e02ec FCHG rework for charger plug/unplug debouncing
Mychaela Falconia <falcon@freecalypso.org>
parents: 255
diff changeset
451 pwr_ctrl->state = FCHG_STATE_PWR_PLUG_TIMER;
0
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
452 pwr_init_discharge();
262
7420959e02ec FCHG rework for charger plug/unplug debouncing
Mychaela Falconia <falcon@freecalypso.org>
parents: 255
diff changeset
453 if (pwr_ctrl->event_handler)
7420959e02ec FCHG rework for charger plug/unplug debouncing
Mychaela Falconia <falcon@freecalypso.org>
parents: 255
diff changeset
454 pwr_ctrl->event_handler(FCHG_EVENT_CHARGER_UNPLUG);
61
75067af48bfd FCHG updates for Tourmaline UI integration
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
455 break;
0
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
456 default:
262
7420959e02ec FCHG rework for charger plug/unplug debouncing
Mychaela Falconia <falcon@freecalypso.org>
parents: 255
diff changeset
457 rvf_send_trace("Invalid state in pwr_charger_plug_unplug_ind()",
7420959e02ec FCHG rework for charger plug/unplug debouncing
Mychaela Falconia <falcon@freecalypso.org>
parents: 255
diff changeset
458 46, pwr_ctrl->state, RV_TRACE_LEVEL_ERROR,
0
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
459 FCHG_USE_ID);
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
460 }
262
7420959e02ec FCHG rework for charger plug/unplug debouncing
Mychaela Falconia <falcon@freecalypso.org>
parents: 255
diff changeset
461 rvf_start_timer(FCHG_TIMER, RVF_MS_TO_TICKS(CHARGER_PLUG_DEBOUNCE_MS),
7420959e02ec FCHG rework for charger plug/unplug debouncing
Mychaela Falconia <falcon@freecalypso.org>
parents: 255
diff changeset
462 FALSE);
7420959e02ec FCHG rework for charger plug/unplug debouncing
Mychaela Falconia <falcon@freecalypso.org>
parents: 255
diff changeset
463 /* unmask further charger interrupts */
7420959e02ec FCHG rework for charger plug/unplug debouncing
Mychaela Falconia <falcon@freecalypso.org>
parents: 255
diff changeset
464 ABB_Write_Register_on_page(PAGE0, ITMASK, 0);
7420959e02ec FCHG rework for charger plug/unplug debouncing
Mychaela Falconia <falcon@freecalypso.org>
parents: 255
diff changeset
465 }
7420959e02ec FCHG rework for charger plug/unplug debouncing
Mychaela Falconia <falcon@freecalypso.org>
parents: 255
diff changeset
466
7420959e02ec FCHG rework for charger plug/unplug debouncing
Mychaela Falconia <falcon@freecalypso.org>
parents: 255
diff changeset
467 void pwr_handle_timer(void)
7420959e02ec FCHG rework for charger plug/unplug debouncing
Mychaela Falconia <falcon@freecalypso.org>
parents: 255
diff changeset
468 {
7420959e02ec FCHG rework for charger plug/unplug debouncing
Mychaela Falconia <falcon@freecalypso.org>
parents: 255
diff changeset
469 SYS_UWORD16 abb_status;
7420959e02ec FCHG rework for charger plug/unplug debouncing
Mychaela Falconia <falcon@freecalypso.org>
parents: 255
diff changeset
470
7420959e02ec FCHG rework for charger plug/unplug debouncing
Mychaela Falconia <falcon@freecalypso.org>
parents: 255
diff changeset
471 if (pwr_ctrl->state != FCHG_STATE_PWR_PLUG_TIMER) {
7420959e02ec FCHG rework for charger plug/unplug debouncing
Mychaela Falconia <falcon@freecalypso.org>
parents: 255
diff changeset
472 rvf_send_trace(
7420959e02ec FCHG rework for charger plug/unplug debouncing
Mychaela Falconia <falcon@freecalypso.org>
parents: 255
diff changeset
473 "Charger debounce timer expired in unexpected state",
7420959e02ec FCHG rework for charger plug/unplug debouncing
Mychaela Falconia <falcon@freecalypso.org>
parents: 255
diff changeset
474 50, pwr_ctrl->state, RV_TRACE_LEVEL_ERROR,
7420959e02ec FCHG rework for charger plug/unplug debouncing
Mychaela Falconia <falcon@freecalypso.org>
parents: 255
diff changeset
475 FCHG_USE_ID);
7420959e02ec FCHG rework for charger plug/unplug debouncing
Mychaela Falconia <falcon@freecalypso.org>
parents: 255
diff changeset
476 return;
7420959e02ec FCHG rework for charger plug/unplug debouncing
Mychaela Falconia <falcon@freecalypso.org>
parents: 255
diff changeset
477 }
7420959e02ec FCHG rework for charger plug/unplug debouncing
Mychaela Falconia <falcon@freecalypso.org>
parents: 255
diff changeset
478 /* so was it a plug or an unplug after all? */
7420959e02ec FCHG rework for charger plug/unplug debouncing
Mychaela Falconia <falcon@freecalypso.org>
parents: 255
diff changeset
479 abb_status = ABB_Read_Status();
7420959e02ec FCHG rework for charger plug/unplug debouncing
Mychaela Falconia <falcon@freecalypso.org>
parents: 255
diff changeset
480 if (abb_status & CHGPRES) {
7420959e02ec FCHG rework for charger plug/unplug debouncing
Mychaela Falconia <falcon@freecalypso.org>
parents: 255
diff changeset
481 /* charger plug */
7420959e02ec FCHG rework for charger plug/unplug debouncing
Mychaela Falconia <falcon@freecalypso.org>
parents: 255
diff changeset
482 if (pwr_ctrl->config_present || pwr_ctrl->bsim_mode) {
7420959e02ec FCHG rework for charger plug/unplug debouncing
Mychaela Falconia <falcon@freecalypso.org>
parents: 255
diff changeset
483 rvf_send_trace("Charger plug, ready to charge", 29,
7420959e02ec FCHG rework for charger plug/unplug debouncing
Mychaela Falconia <falcon@freecalypso.org>
parents: 255
diff changeset
484 NULL_PARAM, RV_TRACE_LEVEL_DEBUG_HIGH,
7420959e02ec FCHG rework for charger plug/unplug debouncing
Mychaela Falconia <falcon@freecalypso.org>
parents: 255
diff changeset
485 FCHG_USE_ID);
7420959e02ec FCHG rework for charger plug/unplug debouncing
Mychaela Falconia <falcon@freecalypso.org>
parents: 255
diff changeset
486 pwr_ctrl->state = FCHG_STATE_READY_TO_CHARGE;
7420959e02ec FCHG rework for charger plug/unplug debouncing
Mychaela Falconia <falcon@freecalypso.org>
parents: 255
diff changeset
487 if (pwr_ctrl->event_handler)
7420959e02ec FCHG rework for charger plug/unplug debouncing
Mychaela Falconia <falcon@freecalypso.org>
parents: 255
diff changeset
488 pwr_ctrl->event_handler(FCHG_EVENT_CHARGER_PLUG);
7420959e02ec FCHG rework for charger plug/unplug debouncing
Mychaela Falconia <falcon@freecalypso.org>
parents: 255
diff changeset
489 } else {
7420959e02ec FCHG rework for charger plug/unplug debouncing
Mychaela Falconia <falcon@freecalypso.org>
parents: 255
diff changeset
490 rvf_send_trace(
7420959e02ec FCHG rework for charger plug/unplug debouncing
Mychaela Falconia <falcon@freecalypso.org>
parents: 255
diff changeset
491 "Charger plugged in, but no config: won't charge", 47,
7420959e02ec FCHG rework for charger plug/unplug debouncing
Mychaela Falconia <falcon@freecalypso.org>
parents: 255
diff changeset
492 NULL_PARAM, RV_TRACE_LEVEL_ERROR, FCHG_USE_ID);
7420959e02ec FCHG rework for charger plug/unplug debouncing
Mychaela Falconia <falcon@freecalypso.org>
parents: 255
diff changeset
493 pwr_ctrl->state = FCHG_STATE_NO_CHARGING;
7420959e02ec FCHG rework for charger plug/unplug debouncing
Mychaela Falconia <falcon@freecalypso.org>
parents: 255
diff changeset
494 }
7420959e02ec FCHG rework for charger plug/unplug debouncing
Mychaela Falconia <falcon@freecalypso.org>
parents: 255
diff changeset
495 } else {
7420959e02ec FCHG rework for charger plug/unplug debouncing
Mychaela Falconia <falcon@freecalypso.org>
parents: 255
diff changeset
496 /* charger unplug, already handled */
7420959e02ec FCHG rework for charger plug/unplug debouncing
Mychaela Falconia <falcon@freecalypso.org>
parents: 255
diff changeset
497 pwr_ctrl->state = FCHG_STATE_NO_EXT_PWR;
7420959e02ec FCHG rework for charger plug/unplug debouncing
Mychaela Falconia <falcon@freecalypso.org>
parents: 255
diff changeset
498 }
0
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
499 }
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
500
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
501 void pwr_charge_start_req(void)
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
502 {
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
503 switch (pwr_ctrl->state) {
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
504 case FCHG_STATE_NO_EXT_PWR:
262
7420959e02ec FCHG rework for charger plug/unplug debouncing
Mychaela Falconia <falcon@freecalypso.org>
parents: 255
diff changeset
505 case FCHG_STATE_PWR_PLUG_TIMER:
0
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
506 rvf_send_trace("Cannot charge without a power source", 36,
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
507 NULL_PARAM, RV_TRACE_LEVEL_ERROR, FCHG_USE_ID);
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
508 return;
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
509 case FCHG_STATE_NO_CHARGING:
253
769cf6273fe4 FCHG: beginning of battery simulation mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 239
diff changeset
510 if (!pwr_ctrl->config_present && !pwr_ctrl->bsim_mode) {
0
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
511 rvf_send_trace("No config set, cannot charge", 28,
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
512 NULL_PARAM, RV_TRACE_LEVEL_ERROR,
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
513 FCHG_USE_ID);
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
514 return;
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
515 }
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
516 /* FALL THRU */
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
517 case FCHG_STATE_READY_TO_CHARGE:
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
518 case FCHG_STATE_READY_TO_RECHARGE:
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
519 case FCHG_STATE_RECHARGE_TIMER:
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
520 rvf_send_trace("Starting charge on user request", 31,
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
521 NULL_PARAM, RV_TRACE_LEVEL_DEBUG_HIGH,
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
522 FCHG_USE_ID);
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
523 pwr_ctrl->state = FCHG_STATE_I2V_CAL_1;
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
524 return;
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
525 case FCHG_STATE_I2V_CAL_1:
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
526 case FCHG_STATE_I2V_CAL_2:
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
527 case FCHG_STATE_CI_CHARGING:
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
528 case FCHG_STATE_CV_CHARGING:
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
529 rvf_send_trace(
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
530 "Charging already in progress, start request ignored",
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
531 51, NULL_PARAM, RV_TRACE_LEVEL_WARNING, FCHG_USE_ID);
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
532 return;
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
533 default:
253
769cf6273fe4 FCHG: beginning of battery simulation mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 239
diff changeset
534 rvf_send_trace("Invalid state in pwr_charge_start_req()", 39,
0
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
535 pwr_ctrl->state, RV_TRACE_LEVEL_ERROR,
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
536 FCHG_USE_ID);
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
537 }
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
538 }
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
539
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
540 void pwr_charge_stop_req(void)
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
541 {
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
542 switch (pwr_ctrl->state) {
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
543 case FCHG_STATE_NO_EXT_PWR:
262
7420959e02ec FCHG rework for charger plug/unplug debouncing
Mychaela Falconia <falcon@freecalypso.org>
parents: 255
diff changeset
544 case FCHG_STATE_PWR_PLUG_TIMER:
0
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
545 case FCHG_STATE_NO_CHARGING:
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
546 /* nothing to do */
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
547 return;
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
548 case FCHG_STATE_READY_TO_CHARGE:
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
549 case FCHG_STATE_READY_TO_RECHARGE:
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
550 case FCHG_STATE_I2V_CAL_1:
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
551 case FCHG_STATE_RECHARGE_TIMER:
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
552 rvf_send_trace("Charging disabled by user request", 33,
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
553 NULL_PARAM, RV_TRACE_LEVEL_DEBUG_HIGH,
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
554 FCHG_USE_ID);
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
555 pwr_ctrl->state = FCHG_STATE_NO_CHARGING;
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
556 return;
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
557 case FCHG_STATE_I2V_CAL_2:
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
558 case FCHG_STATE_CI_CHARGING:
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
559 case FCHG_STATE_CV_CHARGING:
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
560 ABB_Write_Register_on_page(PAGE0, BCICTL2, 0);
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
561 rvf_send_trace("Charging stopped by user request", 32,
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
562 NULL_PARAM, RV_TRACE_LEVEL_DEBUG_HIGH,
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
563 FCHG_USE_ID);
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
564 pwr_ctrl->state = FCHG_STATE_NO_CHARGING;
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
565 pwr_init_discharge();
61
75067af48bfd FCHG updates for Tourmaline UI integration
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
566 if (pwr_ctrl->event_handler)
75067af48bfd FCHG updates for Tourmaline UI integration
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
567 pwr_ctrl->event_handler(FCHG_EVENT_CHARGING_STOPPED);
0
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
568 return;
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
569 default:
253
769cf6273fe4 FCHG: beginning of battery simulation mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 239
diff changeset
570 rvf_send_trace("Invalid state in pwr_charge_stop_req()", 38,
0
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
571 pwr_ctrl->state, RV_TRACE_LEVEL_ERROR,
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
572 FCHG_USE_ID);
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
573 }
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
574 }