annotate src/cs/drivers/drv_app/fchg/fchg_api.c @ 245:3eccca3ac219

FCBM: charging state display implemented
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 05 May 2021 07:02:50 +0000
parents 75067af48bfd
children 769cf6273fe4
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 * The implementation of our external API functions lives here.
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 */
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 #include "fchg/fchg_api.h"
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_messages.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
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 T_RV_RET fchg_get_current_state(struct fchg_user_state *rstruct)
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 {
61
75067af48bfd FCHG updates for Tourmaline UI integration
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
14 UINT16 curr_disch_thresh;
75067af48bfd FCHG updates for Tourmaline UI integration
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
15 INT16 ichg_temp;
75067af48bfd FCHG updates for Tourmaline UI integration
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
16
0
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 if (!pwr_ctrl)
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 return RV_NOT_READY;
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 rstruct->chg_state = pwr_ctrl->state;
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 rstruct->batt_mv = pwr_ctrl->batt_mv;
61
75067af48bfd FCHG updates for Tourmaline UI integration
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
21 curr_disch_thresh = pwr_ctrl->curr_disch_thresh;
0
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 rstruct->batt_percent =
61
75067af48bfd FCHG updates for Tourmaline UI integration
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
23 pwr_ctrl->batt.percent_thresh[curr_disch_thresh].remain_capa;
75067af48bfd FCHG updates for Tourmaline UI integration
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
24 switch (rstruct->chg_state) {
75067af48bfd FCHG updates for Tourmaline UI integration
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
25 case FCHG_STATE_CI_CHARGING:
75067af48bfd FCHG updates for Tourmaline UI integration
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
26 ichg_temp = pwr_ctrl->ci_ichg - pwr_ctrl->i2v_offset;
75067af48bfd FCHG updates for Tourmaline UI integration
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
27 if (ichg_temp < 0)
75067af48bfd FCHG updates for Tourmaline UI integration
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
28 ichg_temp = 0;
75067af48bfd FCHG updates for Tourmaline UI integration
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
29 rstruct->ichg = ichg_temp;
75067af48bfd FCHG updates for Tourmaline UI integration
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
30 rstruct->batt_bars = FCHG_BATT_BARS_CHARGING;
75067af48bfd FCHG updates for Tourmaline UI integration
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
31 break;
75067af48bfd FCHG updates for Tourmaline UI integration
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
32 case FCHG_STATE_CV_CHARGING:
75067af48bfd FCHG updates for Tourmaline UI integration
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
33 ichg_temp = pwr_ctrl->ichg_average - pwr_ctrl->i2v_offset;
75067af48bfd FCHG updates for Tourmaline UI integration
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
34 if (ichg_temp < 0)
75067af48bfd FCHG updates for Tourmaline UI integration
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
35 ichg_temp = 0;
75067af48bfd FCHG updates for Tourmaline UI integration
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
36 rstruct->ichg = ichg_temp;
75067af48bfd FCHG updates for Tourmaline UI integration
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
37 rstruct->batt_bars = FCHG_BATT_BARS_CHARGING;
75067af48bfd FCHG updates for Tourmaline UI integration
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
38 break;
75067af48bfd FCHG updates for Tourmaline UI integration
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
39 default:
75067af48bfd FCHG updates for Tourmaline UI integration
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
40 rstruct->ichg = 0;
75067af48bfd FCHG updates for Tourmaline UI integration
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
41 if (curr_disch_thresh <= pwr_ctrl->batt.bars_thresh[0])
75067af48bfd FCHG updates for Tourmaline UI integration
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
42 rstruct->batt_bars = 4;
75067af48bfd FCHG updates for Tourmaline UI integration
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
43 else if (curr_disch_thresh <= pwr_ctrl->batt.bars_thresh[1])
75067af48bfd FCHG updates for Tourmaline UI integration
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
44 rstruct->batt_bars = 3;
75067af48bfd FCHG updates for Tourmaline UI integration
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
45 else if (curr_disch_thresh <= pwr_ctrl->batt.bars_thresh[2])
75067af48bfd FCHG updates for Tourmaline UI integration
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
46 rstruct->batt_bars = 2;
75067af48bfd FCHG updates for Tourmaline UI integration
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
47 else if (curr_disch_thresh <= pwr_ctrl->batt.bars_thresh[3])
75067af48bfd FCHG updates for Tourmaline UI integration
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
48 rstruct->batt_bars = 1;
75067af48bfd FCHG updates for Tourmaline UI integration
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
49 else
75067af48bfd FCHG updates for Tourmaline UI integration
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
50 rstruct->batt_bars = 0;
75067af48bfd FCHG updates for Tourmaline UI integration
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
51 }
0
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 return RV_OK;
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 }
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 T_RV_RET fchg_user_charge_control(enum fchg_user_charge_ctrl arg)
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 {
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 enum pwr_msg_id msg_id;
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 struct pwr_req_s *msg;
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 if (!pwr_ctrl)
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 return RV_NOT_READY;
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 switch (arg) {
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 case FCHG_CHARGE_START:
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 if (!pwr_ctrl->config_present)
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 return RV_NOT_READY;
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 msg_id = USER_START_CHARGE_REQ;
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 break;
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 case FCHG_CHARGE_STOP:
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 msg_id = USER_STOP_CHARGE_REQ;
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 break;
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 default:
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 return RV_INVALID_PARAMETER;
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 }
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 if (rvf_get_buf(pwr_ctrl->prim_id, sizeof(struct pwr_req_s),
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 (T_RVF_BUFFER **)&msg) == RVF_RED) {
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 rvf_send_trace(
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 "rvf_get_buf() failed in fchg_user_charge_control()",
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 50, 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
79 return RV_MEMORY_ERR;
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 }
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 msg->header.msg_id = msg_id;
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 msg->header.src_addr_id = pwr_ctrl->addr_id;
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 msg->header.dest_addr_id = pwr_ctrl->addr_id;
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 msg->header.callback_func = NULL;
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 if (rvf_send_msg(pwr_ctrl->addr_id, msg) != RV_OK) {
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 rvf_send_trace("fchg_user_charge_control(): Send failed!", 40,
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 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
88 rvf_free_buf(msg);
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 return RV_INTERNAL_ERR;
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 return RV_OK;
4e78acac3d88 src/{condat,cs,gpf,nucleus}: import from Selenite
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92 }
61
75067af48bfd FCHG updates for Tourmaline UI integration
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
93
75067af48bfd FCHG updates for Tourmaline UI integration
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
94 T_RV_RET fchg_register_event_handler(T_FCHG_EVENT_HANDLER handler)
75067af48bfd FCHG updates for Tourmaline UI integration
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
95 {
75067af48bfd FCHG updates for Tourmaline UI integration
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
96 if (!pwr_ctrl)
75067af48bfd FCHG updates for Tourmaline UI integration
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
97 return RV_NOT_READY;
75067af48bfd FCHG updates for Tourmaline UI integration
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
98 pwr_ctrl->event_handler = handler;
75067af48bfd FCHG updates for Tourmaline UI integration
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
99 return RV_OK;
75067af48bfd FCHG updates for Tourmaline UI integration
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
100 }