FreeCalypso > hg > fc-tourmaline
annotate src/cs/services/fcbm/fcbm_charging.c @ 248:a5b00817a60f
FCBM reset mode implemented
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Mon, 10 May 2021 01:54:19 +0000 |
parents | 3eccca3ac219 |
children | 00107c0b8570 |
rev | line source |
---|---|
230
baa738eeb842
FCBM code implemented in first pass
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
baa738eeb842
FCBM code implemented in first pass
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * In this module we are going to implement FCBM functions |
baa738eeb842
FCBM code implemented in first pass
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * related specifically to charging mode, as opposed to other |
baa738eeb842
FCBM code implemented in first pass
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 * special boot modes. |
baa738eeb842
FCBM code implemented in first pass
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 */ |
baa738eeb842
FCBM code implemented in first pass
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 |
baa738eeb842
FCBM code implemented in first pass
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include "rv/rv_general.h" |
baa738eeb842
FCBM code implemented in first pass
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include "rvf/rvf_api.h" |
baa738eeb842
FCBM code implemented in first pass
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include "rvm/rvm_use_id_list.h" |
baa738eeb842
FCBM code implemented in first pass
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include "fcbm/fcbm_func_i.h" |
baa738eeb842
FCBM code implemented in first pass
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 #include "fcbm/fcbm_life_cycle.h" |
baa738eeb842
FCBM code implemented in first pass
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 #include "fcbm/fcbm_timer_i.h" |
baa738eeb842
FCBM code implemented in first pass
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 #include "fchg/fchg_api.h" |
243
35474f3a1782
FCBM: beginning of display output
Mychaela Falconia <falcon@freecalypso.org>
parents:
230
diff
changeset
|
14 #include "r2d/r2d.h" |
230
baa738eeb842
FCBM code implemented in first pass
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 #include "r2d/r2d_blrr_api.h" |
baa738eeb842
FCBM code implemented in first pass
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 #include "abb/abb.h" |
245
3eccca3ac219
FCBM: charging state display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
243
diff
changeset
|
17 #include <stdio.h> |
230
baa738eeb842
FCBM code implemented in first pass
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 |
243
35474f3a1782
FCBM: beginning of display output
Mychaela Falconia <falcon@freecalypso.org>
parents:
230
diff
changeset
|
19 #ifdef LSCREEN |
35474f3a1782
FCBM: beginning of display output
Mychaela Falconia <falcon@freecalypso.org>
parents:
230
diff
changeset
|
20 char fcbm_prod_banner_string[] = "FreeCalypso Handset"; |
35474f3a1782
FCBM: beginning of display output
Mychaela Falconia <falcon@freecalypso.org>
parents:
230
diff
changeset
|
21 #else |
35474f3a1782
FCBM: beginning of display output
Mychaela Falconia <falcon@freecalypso.org>
parents:
230
diff
changeset
|
22 char fcbm_prod_banner_string[] = "FreeCalypso Lite"; |
35474f3a1782
FCBM: beginning of display output
Mychaela Falconia <falcon@freecalypso.org>
parents:
230
diff
changeset
|
23 #endif |
35474f3a1782
FCBM: beginning of display output
Mychaela Falconia <falcon@freecalypso.org>
parents:
230
diff
changeset
|
24 |
245
3eccca3ac219
FCBM: charging state display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
243
diff
changeset
|
25 static char *fchg_states[] = { |
3eccca3ac219
FCBM: charging state display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
243
diff
changeset
|
26 "No charge power", |
3eccca3ac219
FCBM: charging state display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
243
diff
changeset
|
27 "CHG start delay", |
3eccca3ac219
FCBM: charging state display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
243
diff
changeset
|
28 "Ready to charge", |
3eccca3ac219
FCBM: charging state display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
243
diff
changeset
|
29 "Charge complete", |
3eccca3ac219
FCBM: charging state display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
243
diff
changeset
|
30 "I2V cal phase 1", |
3eccca3ac219
FCBM: charging state display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
243
diff
changeset
|
31 "I2V cal phase 2", |
3eccca3ac219
FCBM: charging state display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
243
diff
changeset
|
32 "CI charging", |
3eccca3ac219
FCBM: charging state display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
243
diff
changeset
|
33 "CV charging", |
3eccca3ac219
FCBM: charging state display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
243
diff
changeset
|
34 "Time exceeded", |
3eccca3ac219
FCBM: charging state display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
243
diff
changeset
|
35 "No charging" |
3eccca3ac219
FCBM: charging state display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
243
diff
changeset
|
36 }; |
3eccca3ac219
FCBM: charging state display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
243
diff
changeset
|
37 |
230
baa738eeb842
FCBM code implemented in first pass
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 void fcbm_process_msg_chg_mode(void) |
baa738eeb842
FCBM code implemented in first pass
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 { |
baa738eeb842
FCBM code implemented in first pass
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 if (fcbm_life_cycle_state != FCBM_STATE_INACTIVE) { |
baa738eeb842
FCBM code implemented in first pass
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 rvf_send_trace("FCBM got charging mode request in wrong state", |
baa738eeb842
FCBM code implemented in first pass
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 45, fcbm_life_cycle_state, |
baa738eeb842
FCBM code implemented in first pass
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 RV_TRACE_LEVEL_ERROR, FCBM_USE_ID); |
baa738eeb842
FCBM code implemented in first pass
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 return; |
baa738eeb842
FCBM code implemented in first pass
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 } |
baa738eeb842
FCBM code implemented in first pass
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 rvf_send_trace("Entering charging boot mode", 27, NULL_PARAM, |
baa738eeb842
FCBM code implemented in first pass
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 RV_TRACE_LEVEL_DEBUG_HIGH, FCBM_USE_ID); |
baa738eeb842
FCBM code implemented in first pass
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 fcbm_subscribe_kpd(); |
baa738eeb842
FCBM code implemented in first pass
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 fcbm_setup_long_pwon(); |
243
35474f3a1782
FCBM: beginning of display output
Mychaela Falconia <falcon@freecalypso.org>
parents:
230
diff
changeset
|
50 fcbm_display_init(); |
35474f3a1782
FCBM: beginning of display output
Mychaela Falconia <falcon@freecalypso.org>
parents:
230
diff
changeset
|
51 fcbm_display_line(0, fcbm_prod_banner_string); |
35474f3a1782
FCBM: beginning of display output
Mychaela Falconia <falcon@freecalypso.org>
parents:
230
diff
changeset
|
52 fcbm_display_line(1, "Charge boot mode"); |
35474f3a1782
FCBM: beginning of display output
Mychaela Falconia <falcon@freecalypso.org>
parents:
230
diff
changeset
|
53 r2d_flush(); |
230
baa738eeb842
FCBM code implemented in first pass
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 blrr_display_ctrl(BLRR_DISPLAY_CHG_BOOT); |
baa738eeb842
FCBM code implemented in first pass
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 rvf_start_timer(FCBM_TIMER_DSPL_OFF, |
baa738eeb842
FCBM code implemented in first pass
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 RVF_SECS_TO_TICKS(FCBM_DISPLAY_SECS), FALSE); |
baa738eeb842
FCBM code implemented in first pass
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 rvf_start_timer(FCBM_TIMER_CHG_UPD, |
baa738eeb842
FCBM code implemented in first pass
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 RVF_MS_TO_TICKS(FCBM_CHG_UPD_INTERVAL), TRUE); |
baa738eeb842
FCBM code implemented in first pass
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 fcbm_life_cycle_state = FCBM_STATE_ACTIVE; |
baa738eeb842
FCBM code implemented in first pass
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 } |
baa738eeb842
FCBM code implemented in first pass
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 |
baa738eeb842
FCBM code implemented in first pass
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 static void charging_info_update(void) |
baa738eeb842
FCBM code implemented in first pass
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 { |
245
3eccca3ac219
FCBM: charging state display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
243
diff
changeset
|
64 struct fchg_user_state state; |
3eccca3ac219
FCBM: charging state display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
243
diff
changeset
|
65 char str[20]; |
3eccca3ac219
FCBM: charging state display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
243
diff
changeset
|
66 |
3eccca3ac219
FCBM: charging state display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
243
diff
changeset
|
67 fchg_get_current_state(&state); |
3eccca3ac219
FCBM: charging state display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
243
diff
changeset
|
68 fcbm_display_line(3, fchg_states[state.chg_state]); |
3eccca3ac219
FCBM: charging state display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
243
diff
changeset
|
69 sprintf(str, "Vbat=%u mV", state.batt_mv); |
3eccca3ac219
FCBM: charging state display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
243
diff
changeset
|
70 fcbm_display_line(5, str); |
3eccca3ac219
FCBM: charging state display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
243
diff
changeset
|
71 sprintf(str, "Ichg=%u mA", fchg_convert_ichg_to_mA(state.ichg)); |
3eccca3ac219
FCBM: charging state display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
243
diff
changeset
|
72 fcbm_display_line(6, str); |
3eccca3ac219
FCBM: charging state display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
243
diff
changeset
|
73 sprintf(str, "(%u ADC units)", state.ichg); |
3eccca3ac219
FCBM: charging state display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
243
diff
changeset
|
74 fcbm_display_line(7, str); |
3eccca3ac219
FCBM: charging state display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
243
diff
changeset
|
75 r2d_flush(); |
230
baa738eeb842
FCBM code implemented in first pass
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 } |
baa738eeb842
FCBM code implemented in first pass
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 |
baa738eeb842
FCBM code implemented in first pass
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 static void power_off_check(void) |
baa738eeb842
FCBM code implemented in first pass
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 { |
baa738eeb842
FCBM code implemented in first pass
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 SYS_UWORD16 abb_status; |
baa738eeb842
FCBM code implemented in first pass
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 |
baa738eeb842
FCBM code implemented in first pass
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 abb_status = ABB_Read_Status(); |
baa738eeb842
FCBM code implemented in first pass
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
83 if (abb_status & CHGPRES) |
baa738eeb842
FCBM code implemented in first pass
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
84 return; |
baa738eeb842
FCBM code implemented in first pass
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
85 rvf_send_trace("Charger unplug, powering off", 28, NULL_PARAM, |
baa738eeb842
FCBM code implemented in first pass
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
86 RV_TRACE_LEVEL_DEBUG_HIGH, FCBM_USE_ID); |
243
35474f3a1782
FCBM: beginning of display output
Mychaela Falconia <falcon@freecalypso.org>
parents:
230
diff
changeset
|
87 fcbm_display_line(3, "Charger unplug"); |
35474f3a1782
FCBM: beginning of display output
Mychaela Falconia <falcon@freecalypso.org>
parents:
230
diff
changeset
|
88 r2d_flush(); |
230
baa738eeb842
FCBM code implemented in first pass
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
89 blrr_display_ctrl(BLRR_DISPLAY_CHG_BOOT); |
243
35474f3a1782
FCBM: beginning of display output
Mychaela Falconia <falcon@freecalypso.org>
parents:
230
diff
changeset
|
90 rvf_delay(RVF_MS_TO_TICKS(1500)); |
230
baa738eeb842
FCBM code implemented in first pass
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
91 ABB_Power_Off(); |
baa738eeb842
FCBM code implemented in first pass
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
92 } |
baa738eeb842
FCBM code implemented in first pass
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
93 |
baa738eeb842
FCBM code implemented in first pass
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
94 void fcbm_chg_periodic_timer(void) |
baa738eeb842
FCBM code implemented in first pass
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
95 { |
baa738eeb842
FCBM code implemented in first pass
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
96 if (fcbm_life_cycle_state != FCBM_STATE_ACTIVE) { |
baa738eeb842
FCBM code implemented in first pass
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
97 rvf_send_trace("Charging mode periodic timer in wrong state", |
baa738eeb842
FCBM code implemented in first pass
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
98 43, fcbm_life_cycle_state, |
baa738eeb842
FCBM code implemented in first pass
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
99 RV_TRACE_LEVEL_WARNING, FCBM_USE_ID); |
baa738eeb842
FCBM code implemented in first pass
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
100 return; |
baa738eeb842
FCBM code implemented in first pass
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
101 } |
baa738eeb842
FCBM code implemented in first pass
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
102 power_off_check(); |
baa738eeb842
FCBM code implemented in first pass
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
103 charging_info_update(); |
baa738eeb842
FCBM code implemented in first pass
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
104 } |