view src/cs/services/fcbm/fcbm_charging.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 00107c0b8570
children
line wrap: on
line source

/*
 * In this module we are going to implement FCBM functions
 * related specifically to charging mode, as opposed to other
 * special boot modes.
 */

#include "rv/rv_general.h"
#include "rvf/rvf_api.h"
#include "rvm/rvm_use_id_list.h"
#include "fcbm/fcbm_func_i.h"
#include "fcbm/fcbm_life_cycle.h"
#include "fcbm/fcbm_timer_i.h"
#include "fchg/fchg_api.h"
#include "r2d/r2d.h"
#include "r2d/r2d_blrr_api.h"
#include "abb/abb.h"
#include <stdio.h>

#ifdef LSCREEN
char fcbm_prod_banner_string[] = "FreeCalypso Handset";
#else
char fcbm_prod_banner_string[] = "FreeCalypso Lite";
#endif

static char *fchg_states[] = {
	"No charge power",
#ifdef LSCREEN
	"Charger plug debounce",
#else
	"Chg plug debnce",
#endif
	"Ready to charge",
	"Charge complete",
	"I2V cal phase 1",
	"I2V cal phase 2",
	"CI charging",
	"CV charging",
	"Time exceeded",
	"No charging"
};

void fcbm_process_msg_chg_mode(void)
{
	if (fcbm_life_cycle_state != FCBM_STATE_INACTIVE) {
		rvf_send_trace("FCBM got charging mode request in wrong state",
				45, fcbm_life_cycle_state,
				RV_TRACE_LEVEL_ERROR, FCBM_USE_ID);
		return;
	}
	rvf_send_trace("Entering charging boot mode", 27, NULL_PARAM,
			RV_TRACE_LEVEL_DEBUG_HIGH, FCBM_USE_ID);
	fcbm_subscribe_kpd();
	fcbm_setup_long_pwon();
	fcbm_display_init();
	fcbm_display_line(0, fcbm_prod_banner_string);
	fcbm_display_line(1, "Charge boot mode");
	r2d_flush();
	blrr_display_ctrl(BLRR_DISPLAY_CHG_BOOT);
	rvf_start_timer(FCBM_TIMER_DSPL_OFF,
			RVF_SECS_TO_TICKS(FCBM_DISPLAY_SECS), FALSE);
	rvf_start_timer(FCBM_TIMER_CHG_UPD,
			RVF_MS_TO_TICKS(FCBM_CHG_UPD_INTERVAL), TRUE);
	fcbm_life_cycle_state = FCBM_STATE_ACTIVE;
}

static void charging_info_update(void)
{
	struct fchg_user_state state;
	char str[20];

	fchg_get_current_state(&state);
	fcbm_display_line(3, fchg_states[state.chg_state]);
	sprintf(str, "Vbat=%u mV", state.batt_mv);
	fcbm_display_line(5, str);
	sprintf(str, "Ichg=%u mA", fchg_convert_ichg_to_mA(state.ichg));
	fcbm_display_line(6, str);
	sprintf(str, "(%u ADC units)", state.ichg);
	fcbm_display_line(7, str);
	r2d_flush();
}

static void power_off_check(void)
{
	SYS_UWORD16 abb_status;

	abb_status = ABB_Read_Status();
	if (abb_status & CHGPRES)
		return;
	rvf_send_trace("Charger unplug, powering off", 28, NULL_PARAM,
			RV_TRACE_LEVEL_DEBUG_HIGH, FCBM_USE_ID);
	fcbm_display_line(3, "Charger unplug");
	r2d_flush();
	blrr_display_ctrl(BLRR_DISPLAY_CHG_BOOT);
	rvf_delay(RVF_MS_TO_TICKS(1500));
	ABB_Power_Off();
}

void fcbm_chg_periodic_timer(void)
{
	if (fcbm_life_cycle_state != FCBM_STATE_ACTIVE) {
		rvf_send_trace("Charging mode periodic timer in wrong state",
				43, fcbm_life_cycle_state,
				RV_TRACE_LEVEL_WARNING, FCBM_USE_ID);
		return;
	}
	power_off_check();
	charging_info_update();
}