view src/cs/drivers/drv_app/fchg/fchg_task.c @ 303:f76436d19a7a default tip

!GPRS config: fix long-standing AT+COPS chance hanging bug There has been a long-standing bug in FreeCalypso going back years: sometimes in the AT command bring-up sequence of an ACI-only MS, the AT+COPS command would produce only a power scan followed by cessation of protocol stack activity (only L1 ADC traces), instead of the expected network search sequence. This behaviour was seen in different FC firmware versions going back to Citrine, and seemed to follow some law of chance, not reliably repeatable. This bug has been tracked down and found to be specific to !GPRS configuration, stemming from our TCS2/TCS3 hybrid and reconstruction of !GPRS support that was bitrotten in TCS3.2/LoCosto version. ACI module psa_mms.c, needed only for !GPRS, was missing in the TCS3 version and had to be pulled from TCS2 - but as it turns out, there is a new field in the MMR_REG_REQ primitive that needs to be set correctly, and that psa_mms.c module is the place where this initialization needed to be added.
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 08 Jun 2023 08:23:37 +0000
parents aec644728174
children
line wrap: on
line source

/*
 * The FCHG task's core function lives here.
 */

#include "fchg/fchg_env.h"
#include "fchg/fchg_func_i.h"
#include "fchg/bsim_func_i.h"
#include "rv/rv_general.h"
#include "rvf/rvf_api.h"
#include "rvm/rvm_use_id_list.h"
#include "abb/abb.h"
#include "etm/etm.h"
#include "etm/etm_api.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->bsim_mode)
			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_check_ffs_bsim();
	if (!pwr_ctrl->bsim_mode)
		pwr_load_ffs_charging_config();
	set_initial_state();
	/* just for safety, clear any previous BCI hardware state */
	ABB_Write_Register_on_page(PAGE0, BCICTL2, 0);
	if (pwr_ctrl->bsim_mode) {
		bsim_init_percent();
		etm_register("BSIM", ETM_BSIM, 0, pwr_ctrl->addr_id, 0);
	} else
		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);
			if (msg_ptr) {
				pwr_process_message(msg_ptr);
				rvf_free_buf ((void *) msg_ptr);
			}
		}

		/* Timers */
		if (received_event & RVF_TIMER_0_EVT_MASK)
			pwr_handle_timer();

	}	 // end of while
	return RV_OK;	
}