Пример #1
0
void mxs_log_charge_update(int mode) /* 0 : event, 1 : auto */
{
	static unsigned long count;
	char log[100];
	struct timespec ts;
	struct rtc_time tm;
	int16_t i16Low;
	int16_t i16High;
	uint16_t u16Reading;

	if (!_timeout || mxs_log_open(_FILE_NAME) < 0)
		return;

	getnstimeofday(&ts);

	if (_state == -1) {
		_time = ts.tv_sec;
		_gi_time = ts.tv_sec;
		rtc_time_to_tm(ts.tv_sec, &tm);
		sprintf(log, "%d-%02d-%02d %02d:%02d:%02d,,,,,,\n%s\n",
				tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
				tm.tm_hour, tm.tm_min, tm.tm_sec,
				_LOG_TITLE);
		mxs_log_write(_FILE_NAME, log);
	}

	if (!mode && _state == ddi_bc_GetState())
		return;

	count++;
	_state = ddi_bc_GetState();

	if (ts.tv_sec - _gi_time < _timeout)
		return;

	ddi_bc_hwGetDieTemp(&i16Low, &i16High);
	ddi_bc_hwGetBatteryTemp(&u16Reading);

	sprintf(log, "%ld,%d,%d,%d.%03d,%d,%d,%d,%d,%d\n",
			(ts.tv_sec - _time),
			mode,
			count,
			(ddi_power_GetBattery()/1000),
			(ddi_power_GetBattery()%1000),
			_state,
			mxs_bat_get_ui_status(),
			ddi_bc_GetBrokenReason(),
			(i16High - 5), /* remove margin */
			u16Reading);

	mxs_log_write(_FILE_NAME, log);
	_gi_time = ts.tv_sec;
	count = 0;
}
Пример #2
0
void ddi_bc_RampUpdateAlarms()
{

	/* Set to true if something changed and we need to step the ramp right away. */

	int iStepTheRamp = 0;

	/* -------------------------------------------------------------------------- */
	/* Are we monitoring die temperature? */
	/* -------------------------------------------------------------------------- */

	if (g_ddi_bc_Configuration.monitorDieTemp) {

		/* ---------------------------------------------------------------------- */
		/* Get the die temperature range. */
		/* ---------------------------------------------------------------------- */

		int16_t i16Low;
		int16_t i16High;

		ddi_bc_hwGetDieTemp(&i16Low, &i16High);

		/* ---------------------------------------------------------------------- */
		/* Now we need to decide if it's time to raise or lower the alarm. The */
		/* first question to ask is: Were we already under an alarm? */
		/* ---------------------------------------------------------------------- */

		if (g_RampControl.dieTempAlarm) {

			/* ------------------------------------------------------------------ */
			/* If control arrives here, we were already under an alarm. We'll */
			/* change that if the high end of the temperature range drops below */
			/* the low temperature mark. */
			/* ------------------------------------------------------------------ */

			if (i16High < g_ddi_bc_Configuration.u8DieTempLow) {

				/* -------------------------------------------------------------- */
				/* If control arrives here, we're safe now. Drop the alarm. */
				/* -------------------------------------------------------------- */

				g_RampControl.dieTempAlarm = 0;

				iStepTheRamp = !0;

#ifdef CONFIG_POWER_SUPPLY_DEBUG
				printk("Battery charger: releasing "
				       "die temp alarm: [%d, %d] < %d\r\n",
				       (int32_t) i16Low, (int32_t) i16High,
				       (int32_t) g_ddi_bc_Configuration.
				       u8DieTempLow);
#endif

			}

		} else {

			/* ------------------------------------------------------------------ */
			/* If control arrives here, we were not under an alarm. We'll change */
			/* that if the high end of the temperature range rises above the */
			/* high temperature mark. */
			/* ------------------------------------------------------------------ */

			if (i16High >= g_ddi_bc_Configuration.u8DieTempHigh) {

				/* -------------------------------------------------------------- */
				/* If control arrives here, we're running too hot. Raise the */
				/* alarm. */
				/* -------------------------------------------------------------- */

				g_RampControl.dieTempAlarm = 1;

				iStepTheRamp = !0;

#ifdef CONFIG_POWER_SUPPLY_DEBUG
				printk("Battery charger: declaring "
				       "die temp alarm: [%d, %d] >= %d\r\n",
				       (int32_t) i16Low, (int32_t) i16High,
				       (int32_t) g_ddi_bc_Configuration.
				       u8DieTempLow);
#endif
			}

		}

	}
	/* -------------------------------------------------------------------------- */
	/* Are we monitoring battery temperature? */
	/* -------------------------------------------------------------------------- */

	if (g_ddi_bc_Configuration.monitorBatteryTemp) {

		ddi_bc_Status_t status;

		/* ---------------------------------------------------------------------- */
		/* Get the battery temperature reading. */
		/* ---------------------------------------------------------------------- */

		uint16_t u16Reading;

		status = ddi_bc_hwGetBatteryTemp(&u16Reading);

		/* ---------------------------------------------------------------------- */
		/* If there was a problem, then we ignore the reading. Otherwise, let's */
		/* have a look. */
		/* ---------------------------------------------------------------------- */

		if (status == DDI_BC_STATUS_SUCCESS) {

			/* ------------------------------------------------------------------ */
			/* Now we need to decide if it's time to raise or lower the alarm. */
			/* The first question to ask is: Were we already under an alarm? */
			/* ------------------------------------------------------------------ */

			if (g_RampControl.batteryTempAlarm) {

				/* -------------------------------------------------------------- */
				/* If control arrives here, we were already under an alarm. */
				/* We'll change that if the reading drops below the low mark. */
				/* -------------------------------------------------------------- */

				if (u16Reading <
				    g_ddi_bc_Configuration.u16BatteryTempLow) {

					/* ---------------------------------------------------------- */
					/* If control arrives here, we're safe now. Drop the alarm. */
					/* ---------------------------------------------------------- */

					g_RampControl.batteryTempAlarm = 0;

					iStepTheRamp = !0;

				}

			} else {

				/* -------------------------------------------------------------- */
				/* If control arrives here, we were not under an alarm. We'll */
				/* change that if the reading rises above the high mark. */
				/* -------------------------------------------------------------- */

				if (u16Reading >=
				    g_ddi_bc_Configuration.u16BatteryTempHigh) {

					/* ---------------------------------------------------------- */
					/* If control arrives here, we're running too hot. Raise the */
					/* alarm. */
					/* ---------------------------------------------------------- */

					g_RampControl.batteryTempAlarm = 1;

					iStepTheRamp = !0;

				}

			}

		}

	}
	/* -------------------------------------------------------------------------- */
	/* Do we need to step the ramp? */
	/* -------------------------------------------------------------------------- */

	if (iStepTheRamp)
		ddi_bc_RampStep(0);

}