view src/cs/drivers/drv_app/fchg/fchg_api.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 769cf6273fe4
children
line wrap: on
line source

/*
 * The implementation of our external API functions lives here.
 */

#include "fchg/fchg_api.h"
#include "fchg/fchg_env.h"
#include "fchg/fchg_messages.h"
#include "rv/rv_general.h"
#include "rvf/rvf_api.h"
#include "rvm/rvm_use_id_list.h"

T_RV_RET fchg_get_current_state(struct fchg_user_state *rstruct)
{
	UINT16 curr_disch_thresh;
	INT16 ichg_temp;

	if (!pwr_ctrl)
		return RV_NOT_READY;
	rstruct->chg_state = pwr_ctrl->state;
	rstruct->batt_mv = pwr_ctrl->batt_mv;
	curr_disch_thresh = pwr_ctrl->curr_disch_thresh;
	rstruct->batt_percent =
	    pwr_ctrl->batt.percent_thresh[curr_disch_thresh].remain_capa;
	switch (rstruct->chg_state) {
	case FCHG_STATE_CI_CHARGING:
		ichg_temp = pwr_ctrl->ci_ichg - pwr_ctrl->i2v_offset;
		if (ichg_temp < 0)
			ichg_temp = 0;
		rstruct->ichg = ichg_temp;
		rstruct->batt_bars = FCHG_BATT_BARS_CHARGING;
		break;
	case FCHG_STATE_CV_CHARGING:
		ichg_temp = pwr_ctrl->ichg_average - pwr_ctrl->i2v_offset;
		if (ichg_temp < 0)
			ichg_temp = 0;
		rstruct->ichg = ichg_temp;
		rstruct->batt_bars = FCHG_BATT_BARS_CHARGING;
		break;
	default:
		rstruct->ichg = 0;
		if (curr_disch_thresh <= pwr_ctrl->batt.bars_thresh[0])
			rstruct->batt_bars = 4;
		else if (curr_disch_thresh <= pwr_ctrl->batt.bars_thresh[1])
			rstruct->batt_bars = 3;
		else if (curr_disch_thresh <= pwr_ctrl->batt.bars_thresh[2])
			rstruct->batt_bars = 2;
		else if (curr_disch_thresh <= pwr_ctrl->batt.bars_thresh[3])
			rstruct->batt_bars = 1;
		else
			rstruct->batt_bars = 0;
	}
	return RV_OK;
}

T_RV_RET fchg_user_charge_control(enum fchg_user_charge_ctrl arg)
{
	enum pwr_msg_id msg_id;
	struct pwr_req_s *msg;

	if (!pwr_ctrl)
		return RV_NOT_READY;
	switch (arg) {
	case FCHG_CHARGE_START:
		if (!pwr_ctrl->config_present && !pwr_ctrl->bsim_mode)
			return RV_NOT_READY;
		msg_id = USER_START_CHARGE_REQ;
		break;
	case FCHG_CHARGE_STOP:
		msg_id = USER_STOP_CHARGE_REQ;
		break;
	default:
		return RV_INVALID_PARAMETER;
	}
	if (rvf_get_buf(pwr_ctrl->prim_id, sizeof(struct pwr_req_s),
			(T_RVF_BUFFER **)&msg) == RVF_RED) {
		rvf_send_trace(
			"rvf_get_buf() failed in fchg_user_charge_control()",
			50, NULL_PARAM, RV_TRACE_LEVEL_ERROR, FCHG_USE_ID);
		return RV_MEMORY_ERR;
	}
	msg->header.msg_id        = msg_id;
	msg->header.src_addr_id   = pwr_ctrl->addr_id;
	msg->header.dest_addr_id  = pwr_ctrl->addr_id;
	msg->header.callback_func = NULL;
	if (rvf_send_msg(pwr_ctrl->addr_id, msg) != RV_OK) {
		rvf_send_trace("fchg_user_charge_control(): Send failed!", 40,
				NULL_PARAM, RV_TRACE_LEVEL_ERROR, FCHG_USE_ID);
		rvf_free_buf(msg);
		return RV_INTERNAL_ERR;
	}
	return RV_OK;
}

T_RV_RET fchg_register_event_handler(T_FCHG_EVENT_HANDLER handler)
{
	if (!pwr_ctrl)
		return RV_NOT_READY;
	pwr_ctrl->event_handler = handler;
	return RV_OK;
}