comparison src/cs/drivers/drv_app/fchg/fchg_task.c @ 0:92470e5d0b9e

src: partial import from FC Selenite
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 15 May 2020 01:28:16 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:92470e5d0b9e
1 /*
2 * The FCHG task's core function lives here.
3 */
4
5 #include "fchg/fchg_env.h"
6 #include "fchg/fchg_func_i.h"
7 #include "rv/rv_general.h"
8 #include "rvf/rvf_api.h"
9 #include "rvm/rvm_use_id_list.h"
10 #include "abb/abb.h"
11
12 static void set_initial_state(void)
13 {
14 SYS_UWORD16 abb_status;
15
16 abb_status = ABB_Read_Status();
17 if (abb_status & CHGPRES) {
18 if (pwr_ctrl->config_present)
19 pwr_ctrl->state = FCHG_STATE_READY_TO_CHARGE;
20 else
21 pwr_ctrl->state = FCHG_STATE_NO_CHARGING;
22 } else
23 pwr_ctrl->state = FCHG_STATE_NO_EXT_PWR;
24 }
25
26 T_RV_RET fchg_core(void)
27 {
28 BOOLEAN error_occured = FALSE;
29 T_RV_HDR *msg_ptr;
30
31 rvf_send_trace("FCHG task: Initialization", 25, NULL_PARAM,
32 RV_TRACE_LEVEL_DEBUG_LOW, FCHG_USE_ID);
33 pwr_load_ffs_batt_table();
34 pwr_load_ffs_charging_config();
35 set_initial_state();
36 pwr_init_discharge();
37
38 /* loop to process messages */
39 while (error_occured == FALSE)
40 {
41 /* Wait for the necessary events (infinite wait for a msg in the mailbox 0). */
42 UINT16 received_event = rvf_wait (0xffff, 0);
43
44 /* If an event related to mailbox 0 is received, then */
45 if (received_event & RVF_TASK_MBOX_0_EVT_MASK)
46 {
47 /* Read the message in the driver mailbox and delegate action..*/
48 msg_ptr = (T_RV_HDR *) rvf_read_mbox(FCHG_MAILBOX);
49 if (msg_ptr) {
50 pwr_process_message(msg_ptr);
51 rvf_free_buf ((void *) msg_ptr);
52 }
53 }
54
55 /* Timers */
56 if (received_event & RVF_TIMER_0_EVT_MASK)
57 pwr_handle_timer();
58
59 } // end of while
60 return RV_OK;
61 }