changeset 337:0df0668f8bea

FCHG: task core function implemented
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 14 Dec 2017 21:47:40 +0000
parents be011556e71f
children 1c711302732a
files components/fchg src/cs/drivers/drv_app/fchg/fchg_func_i.h src/cs/drivers/drv_app/fchg/fchg_task.c
diffstat 3 files changed, 60 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/components/fchg	Thu Dec 14 21:01:59 2017 +0000
+++ b/components/fchg	Thu Dec 14 21:47:40 2017 +0000
@@ -40,3 +40,4 @@
 cfile_plain $SRCDIR/fchg_env.c
 cfile_plain $SRCDIR/fchg_ffs_init.c
 cfile_plain $SRCDIR/fchg_process.c
+cfile_plain $SRCDIR/fchg_task.c
--- a/src/cs/drivers/drv_app/fchg/fchg_func_i.h	Thu Dec 14 21:01:59 2017 +0000
+++ b/src/cs/drivers/drv_app/fchg/fchg_func_i.h	Thu Dec 14 21:47:40 2017 +0000
@@ -12,6 +12,7 @@
 void pwr_load_ffs_charging_config(void);
 void pwr_set_default_batt_table(void);
 
+void pwr_process_message(T_RV_HDR *msg_ptr);
 void pwr_process_adc(struct pwr_adc_ind_s *msg);
 void pwr_handle_timer(void);
 void pwr_charger_plug(void);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/cs/drivers/drv_app/fchg/fchg_task.c	Thu Dec 14 21:47:40 2017 +0000
@@ -0,0 +1,58 @@
+/*
+ * The FCHG task's core function lives here.
+ */
+
+#include "fchg/fchg_env.h"
+#include "fchg/fchg_func_i.h"
+#include "rv/rv_general.h"
+#include "rvf/rvf_api.h"
+#include "rvm/rvm_use_id_list.h"
+#include "abb/abb.h"
+
+static void set_initial_state(void)
+{
+	SYS_UWORD16 abb_status;
+
+	abb_status = ABB_Read_Status();
+	if (abb_status & CHGPRES) {
+		if (pwr_ctrl->config_present)
+			pwr_ctrl->state = FCHG_STATE_READY_TO_CHARGE;
+		else
+			pwr_ctrl->state = FCHG_STATE_NO_CHARGING;
+	} else
+		pwr_ctrl->state = FCHG_STATE_NO_EXT_PWR;
+}
+
+T_RV_RET fchg_core(void)
+{	
+	BOOLEAN error_occured = FALSE;
+	T_RV_HDR *msg_ptr;
+
+	rvf_send_trace("FCHG task: Initialization", 25, NULL_PARAM,
+			RV_TRACE_LEVEL_DEBUG_LOW, FCHG_USE_ID);
+	pwr_load_ffs_batt_table();
+	pwr_load_ffs_charging_config();
+	set_initial_state();
+	pwr_init_discharge();
+
+	/* loop to process messages */
+	while (error_occured == FALSE)
+	{
+		/* Wait for the necessary events (infinite wait for a msg in the mailbox 0). */
+		UINT16 received_event = rvf_wait (0xffff, 0);
+					
+		/* If an event related to mailbox 0 is received, then */
+		if (received_event & RVF_TASK_MBOX_0_EVT_MASK) 
+		{
+			/* Read the message in the driver mailbox and delegate action..*/
+			msg_ptr = (T_RV_HDR *) rvf_read_mbox(FCHG_MAILBOX);
+			pwr_process_message(msg_ptr);
+		}
+
+		/* Timers */
+		if (received_event & RVF_TIMER_0_EVT_MASK)
+			pwr_handle_timer();
+
+	}	 // end of while
+	return RV_OK;	
+}