annotate src/cs/services/fcbm/fcbm_charging.c @ 264:00107c0b8570

FCBM display: new charger plug debounce state
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 14 May 2021 06:01:34 +0000
parents 3eccca3ac219
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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",
264
00107c0b8570 FCBM display: new charger plug debounce state
Mychaela Falconia <falcon@freecalypso.org>
parents: 245
diff changeset
27 #ifdef LSCREEN
00107c0b8570 FCBM display: new charger plug debounce state
Mychaela Falconia <falcon@freecalypso.org>
parents: 245
diff changeset
28 "Charger plug debounce",
00107c0b8570 FCBM display: new charger plug debounce state
Mychaela Falconia <falcon@freecalypso.org>
parents: 245
diff changeset
29 #else
00107c0b8570 FCBM display: new charger plug debounce state
Mychaela Falconia <falcon@freecalypso.org>
parents: 245
diff changeset
30 "Chg plug debnce",
00107c0b8570 FCBM display: new charger plug debounce state
Mychaela Falconia <falcon@freecalypso.org>
parents: 245
diff changeset
31 #endif
245
3eccca3ac219 FCBM: charging state display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 243
diff changeset
32 "Ready to charge",
3eccca3ac219 FCBM: charging state display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 243
diff changeset
33 "Charge complete",
3eccca3ac219 FCBM: charging state display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 243
diff changeset
34 "I2V cal phase 1",
3eccca3ac219 FCBM: charging state display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 243
diff changeset
35 "I2V cal phase 2",
3eccca3ac219 FCBM: charging state display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 243
diff changeset
36 "CI charging",
3eccca3ac219 FCBM: charging state display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 243
diff changeset
37 "CV charging",
3eccca3ac219 FCBM: charging state display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 243
diff changeset
38 "Time exceeded",
3eccca3ac219 FCBM: charging state display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 243
diff changeset
39 "No charging"
3eccca3ac219 FCBM: charging state display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 243
diff changeset
40 };
3eccca3ac219 FCBM: charging state display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 243
diff changeset
41
230
baa738eeb842 FCBM code implemented in first pass
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 void fcbm_process_msg_chg_mode(void)
baa738eeb842 FCBM code implemented in first pass
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 {
baa738eeb842 FCBM code implemented in first pass
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 if (fcbm_life_cycle_state != FCBM_STATE_INACTIVE) {
baa738eeb842 FCBM code implemented in first pass
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 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
46 45, fcbm_life_cycle_state,
baa738eeb842 FCBM code implemented in first pass
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 RV_TRACE_LEVEL_ERROR, FCBM_USE_ID);
baa738eeb842 FCBM code implemented in first pass
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 return;
baa738eeb842 FCBM code implemented in first pass
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 }
baa738eeb842 FCBM code implemented in first pass
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 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
51 RV_TRACE_LEVEL_DEBUG_HIGH, FCBM_USE_ID);
baa738eeb842 FCBM code implemented in first pass
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 fcbm_subscribe_kpd();
baa738eeb842 FCBM code implemented in first pass
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 fcbm_setup_long_pwon();
243
35474f3a1782 FCBM: beginning of display output
Mychaela Falconia <falcon@freecalypso.org>
parents: 230
diff changeset
54 fcbm_display_init();
35474f3a1782 FCBM: beginning of display output
Mychaela Falconia <falcon@freecalypso.org>
parents: 230
diff changeset
55 fcbm_display_line(0, fcbm_prod_banner_string);
35474f3a1782 FCBM: beginning of display output
Mychaela Falconia <falcon@freecalypso.org>
parents: 230
diff changeset
56 fcbm_display_line(1, "Charge boot mode");
35474f3a1782 FCBM: beginning of display output
Mychaela Falconia <falcon@freecalypso.org>
parents: 230
diff changeset
57 r2d_flush();
230
baa738eeb842 FCBM code implemented in first pass
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 blrr_display_ctrl(BLRR_DISPLAY_CHG_BOOT);
baa738eeb842 FCBM code implemented in first pass
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 rvf_start_timer(FCBM_TIMER_DSPL_OFF,
baa738eeb842 FCBM code implemented in first pass
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 RVF_SECS_TO_TICKS(FCBM_DISPLAY_SECS), FALSE);
baa738eeb842 FCBM code implemented in first pass
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 rvf_start_timer(FCBM_TIMER_CHG_UPD,
baa738eeb842 FCBM code implemented in first pass
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 RVF_MS_TO_TICKS(FCBM_CHG_UPD_INTERVAL), TRUE);
baa738eeb842 FCBM code implemented in first pass
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 fcbm_life_cycle_state = FCBM_STATE_ACTIVE;
baa738eeb842 FCBM code implemented in first pass
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 }
baa738eeb842 FCBM code implemented in first pass
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65
baa738eeb842 FCBM code implemented in first pass
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 static void charging_info_update(void)
baa738eeb842 FCBM code implemented in first pass
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 {
245
3eccca3ac219 FCBM: charging state display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 243
diff changeset
68 struct fchg_user_state state;
3eccca3ac219 FCBM: charging state display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 243
diff changeset
69 char str[20];
3eccca3ac219 FCBM: charging state display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 243
diff changeset
70
3eccca3ac219 FCBM: charging state display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 243
diff changeset
71 fchg_get_current_state(&state);
3eccca3ac219 FCBM: charging state display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 243
diff changeset
72 fcbm_display_line(3, fchg_states[state.chg_state]);
3eccca3ac219 FCBM: charging state display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 243
diff changeset
73 sprintf(str, "Vbat=%u mV", state.batt_mv);
3eccca3ac219 FCBM: charging state display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 243
diff changeset
74 fcbm_display_line(5, str);
3eccca3ac219 FCBM: charging state display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 243
diff changeset
75 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
76 fcbm_display_line(6, str);
3eccca3ac219 FCBM: charging state display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 243
diff changeset
77 sprintf(str, "(%u ADC units)", state.ichg);
3eccca3ac219 FCBM: charging state display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 243
diff changeset
78 fcbm_display_line(7, str);
3eccca3ac219 FCBM: charging state display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 243
diff changeset
79 r2d_flush();
230
baa738eeb842 FCBM code implemented in first pass
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 }
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 static void power_off_check(void)
baa738eeb842 FCBM code implemented in first pass
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 {
baa738eeb842 FCBM code implemented in first pass
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 SYS_UWORD16 abb_status;
baa738eeb842 FCBM code implemented in first pass
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85
baa738eeb842 FCBM code implemented in first pass
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 abb_status = ABB_Read_Status();
baa738eeb842 FCBM code implemented in first pass
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 if (abb_status & CHGPRES)
baa738eeb842 FCBM code implemented in first pass
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 return;
baa738eeb842 FCBM code implemented in first pass
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 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
90 RV_TRACE_LEVEL_DEBUG_HIGH, FCBM_USE_ID);
243
35474f3a1782 FCBM: beginning of display output
Mychaela Falconia <falcon@freecalypso.org>
parents: 230
diff changeset
91 fcbm_display_line(3, "Charger unplug");
35474f3a1782 FCBM: beginning of display output
Mychaela Falconia <falcon@freecalypso.org>
parents: 230
diff changeset
92 r2d_flush();
230
baa738eeb842 FCBM code implemented in first pass
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93 blrr_display_ctrl(BLRR_DISPLAY_CHG_BOOT);
243
35474f3a1782 FCBM: beginning of display output
Mychaela Falconia <falcon@freecalypso.org>
parents: 230
diff changeset
94 rvf_delay(RVF_MS_TO_TICKS(1500));
230
baa738eeb842 FCBM code implemented in first pass
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95 ABB_Power_Off();
baa738eeb842 FCBM code implemented in first pass
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96 }
baa738eeb842 FCBM code implemented in first pass
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97
baa738eeb842 FCBM code implemented in first pass
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
98 void fcbm_chg_periodic_timer(void)
baa738eeb842 FCBM code implemented in first pass
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
99 {
baa738eeb842 FCBM code implemented in first pass
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
100 if (fcbm_life_cycle_state != FCBM_STATE_ACTIVE) {
baa738eeb842 FCBM code implemented in first pass
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
101 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
102 43, fcbm_life_cycle_state,
baa738eeb842 FCBM code implemented in first pass
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
103 RV_TRACE_LEVEL_WARNING, FCBM_USE_ID);
baa738eeb842 FCBM code implemented in first pass
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
104 return;
baa738eeb842 FCBM code implemented in first pass
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
105 }
baa738eeb842 FCBM code implemented in first pass
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
106 power_off_check();
baa738eeb842 FCBM code implemented in first pass
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
107 charging_info_update();
baa738eeb842 FCBM code implemented in first pass
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
108 }