FreeCalypso > hg > fc-tourmaline
comparison src/cs/drivers/drv_app/fchg/fchg_api.c @ 0:4e78acac3d88
src/{condat,cs,gpf,nucleus}: import from Selenite
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Fri, 16 Oct 2020 06:23:26 +0000 |
parents | |
children | 75067af48bfd |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4e78acac3d88 |
---|---|
1 /* | |
2 * The implementation of our external API functions lives here. | |
3 */ | |
4 | |
5 #include "fchg/fchg_api.h" | |
6 #include "fchg/fchg_env.h" | |
7 #include "fchg/fchg_messages.h" | |
8 #include "rv/rv_general.h" | |
9 #include "rvf/rvf_api.h" | |
10 #include "rvm/rvm_use_id_list.h" | |
11 | |
12 T_RV_RET fchg_get_current_state(struct fchg_user_state *rstruct) | |
13 { | |
14 if (!pwr_ctrl) | |
15 return RV_NOT_READY; | |
16 rstruct->chg_state = pwr_ctrl->state; | |
17 rstruct->batt_mv = pwr_ctrl->batt_mv; | |
18 rstruct->batt_percent = | |
19 pwr_ctrl->batt_thresholds[pwr_ctrl->curr_disch_thresh].remain_capa; | |
20 return RV_OK; | |
21 } | |
22 | |
23 T_RV_RET fchg_user_charge_control(enum fchg_user_charge_ctrl arg) | |
24 { | |
25 enum pwr_msg_id msg_id; | |
26 struct pwr_req_s *msg; | |
27 | |
28 if (!pwr_ctrl) | |
29 return RV_NOT_READY; | |
30 switch (arg) { | |
31 case FCHG_CHARGE_START: | |
32 if (!pwr_ctrl->config_present) | |
33 return RV_NOT_READY; | |
34 msg_id = USER_START_CHARGE_REQ; | |
35 break; | |
36 case FCHG_CHARGE_STOP: | |
37 msg_id = USER_STOP_CHARGE_REQ; | |
38 break; | |
39 default: | |
40 return RV_INVALID_PARAMETER; | |
41 } | |
42 if (rvf_get_buf(pwr_ctrl->prim_id, sizeof(struct pwr_req_s), | |
43 (T_RVF_BUFFER **)&msg) == RVF_RED) { | |
44 rvf_send_trace( | |
45 "rvf_get_buf() failed in fchg_user_charge_control()", | |
46 50, NULL_PARAM, RV_TRACE_LEVEL_ERROR, FCHG_USE_ID); | |
47 return RV_MEMORY_ERR; | |
48 } | |
49 msg->header.msg_id = msg_id; | |
50 msg->header.src_addr_id = pwr_ctrl->addr_id; | |
51 msg->header.dest_addr_id = pwr_ctrl->addr_id; | |
52 msg->header.callback_func = NULL; | |
53 if (rvf_send_msg(pwr_ctrl->addr_id, msg) != RV_OK) { | |
54 rvf_send_trace("fchg_user_charge_control(): Send failed!", 40, | |
55 NULL_PARAM, RV_TRACE_LEVEL_ERROR, FCHG_USE_ID); | |
56 rvf_free_buf(msg); | |
57 return RV_INTERNAL_ERR; | |
58 } | |
59 return RV_OK; | |
60 } |