FreeCalypso > hg > fc-selenite
comparison src/cs/drivers/drv_app/fchg/fchg_api.c @ 0:b6a5e36de839
src/cs: initial import from Magnetite
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 15 Jul 2018 04:39:26 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:b6a5e36de839 |
---|---|
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 } |