📄 charger_mmi.c
字号:
/**
* charger_mmi.c
* This module serves as interface between TI's charging management module(LCC)
* and MI's MMI module.
* LCC module provides the MMI with a callback method named 'return path' to
* utilize its charging and power management service.
* In this interface module, we use the callback path in the 'return path'.
*
* History:
* 2004-05-24 Robert.Chen Init.
*
*/
#include "typedefs.h"
#include "ffs.h"
#include "lcc_api.h"
#include "lcc.h"
#include "gdi.h"
#ifndef NEW_FRAME
#define NEW_FRAME
#endif
#include "pwr.h"
#include "abb.h"
#include "charger_mmi.h"
/* global event store for carrying power infomation to MMI */
T_PWR_MMI_INFO_IND_EVENT g_mmi_pwr_evt;
/* mobile switch on reason indication */
int g_switchon = -1;
/**
* external function prototype
**/
/* get VRPCSTS register value from ABB */
extern SYS_UWORD16 ABB_Read_Status(void);
/* auto power off mobile when low voltage detected */
extern void LowVol_Poweroff(void);
/* show low voltage warning message with alert tone */
extern void LowVol_Warning(void);
#define WARNING_VOLTAGE_THR 3450 /* threshold to begin play low voltage warning */
#define WARNING_VOLTAGE_CNT 20 /* continuous voltage below warning threshold */
#define SWITCHOFF_VOLTAGE_THR 3350 /* threshold to auto switch off mobile */
#define SWITCHOFF_VOLTAGE_CNT 20 /* continuous voltage below switch off threshold */
#define WARNING_TIME_IDLE 150
#define WARNING_TIME_CALLING 60
/***
* default config data
***/
const T_PWR_I2V_CAL_BLOCK i2vCal =
{
6828, /* alfa_num */
1024, /* alfa_demon */
0 /* offset */
};
/* corresponds to /pwr/vbat.cal */
const T_PWR_VBAT_CAL_BLOCK vbatCal =
{
6825, /* alfa_num */
1024, /* alfa_demon */
0 /* offset */
};
/* corresponds to /pwr/common.cfg */
const T_PWR_COMMON_CFG_BLOCK commCfg =
{
10000, /* sampling time [ms] */
20000, /* mod_cycle [ms] */
4, /* pins, only 4 supported */
0, /* chg_dedic */
10, /* alfa1 */
5, /* alfa2 */
10, /* alfa3 */
4 /* rise_thr */
};
/* corresponds to /pwr/bat/bat<N>.cfg */
const T_PWR_BAT_CFG_BLOCK batCfg =
{
1, /* battery type */
0, /* rf_temp */
0, /* battery type low limit */
1023, /* battery type high limit */
700, /* standard battery capacity [mAh] */
50, /* time ratio of charge current, not used */
4000000,/* the total time charging counter */
3600000,/* the CV charging complete timer */
300000, /* re-charge attempt timer counter */
4100, /* CV charging begin battery voltage threshold value */
4200, /* (CI and CV) charge end (stop) battery voltage threshold value */
80, /* minimal charge control value threshold, charging stop criteria [mA] */
90 //uint16 chg_again_thr; /* 2 */ // The charge again capacity threshold (t=20 degrees)
};
/* corresponds to /pwr/bat/bat/temp<N>.cfg */
const T_PWR_BAT_TEMP_CFG_BLOCK tempCfg =
{
-20, /* tbat_min */
60, /* tbat_max */
0, /* capacity temperature compensation a0 (a2*t*t + a1*t +a0) */
0, /* capacity temperature compensation a1 (a2*t*t + a1*t +a0) */
0, /* capacity temperature compensation a2 (a2*t*t + a1*t +a0) */
{
/* Voltage VS Capacity vector */
4200, // 100%,
4050, // 90%,
3950, // 80%,
3850, // 70%,
3750, // 60%,
3650, // 50%,
3550, // 40%,
3500, // 30%,
3400, // 20%,
3350 // 10%
},
10, /* i_meas1 */
50, /* i_meas2 */
{/* voltage to temperature mapper for i_measure */
0x22E,
0x13F,
0xCB,
0xFFFF,
0xFFFF,
0xFFFF,
0xFFFF,
0xFFFF,
0xFFFF
},
{/* the voltage to temperature mapper for i_measure */
// Temperature vector :
0xFFFF, // -20,
0xFFFF, // -10,
0x351, // 0,
0x22E, // 10,
0x169, // 20,
0xF9, // 30,
0x96, // 40,
0x68, // 50,
0x4A // 60
}
};
/* corresponds to /pwr/chg/chg<N>.cfg */
const T_PWR_CHG_CFG_BLOCK chgCfg =
{
1, /* charger type */
800, /* ichg_max */
4600, /* vchg_low */
7000 /* vchg_high */
};
/* corresponds to /mmi/pwr/bsie.cfg */
const T_PWR_MMI_CFG_BLOCK bsieCfg =
{
2000 /* repetition interval for sending MMI info events */
};
/* register mmi MMI callback function to LCC */
void mmi_pwr_register(void)
{
T_RV_RETURN_PATH mmi_pwr_rtp;
//mmi_pwr_initStatus();
mmi_pwr_rtp.addr_id = NULL;
mmi_pwr_rtp.callback_func = mmi_pwr_cb_func;
pwr_register(&mmi_pwr_rtp, &g_mmi_pwr_evt);
mmi_pwr_chkCfg();
//pwr_ttr_init(0xFFFFFFFF);
}
/* MMI power management callback invoked by LCC */
void mmi_pwr_cb_func(void* evt_ptr)
{
T_PWR_MMI_INFO_IND_EVENT *pEvt;
UINT8 bSendVK = 1;
pEvt = (T_PWR_MMI_INFO_IND_EVENT *)evt_ptr;
PWR_MMI_TR(("mmi_pwr_cb():received event, id=%d", pEvt->header.msg_id));
/* dispatch received power event to MMI */
switch(pEvt->header.msg_id)
{
case MMI_CHG_PLUG_IND:
pwr_Status.charger_plugged = 1;
break;
case MMI_CHG_UNPLUG_IND:
pwr_Status.charger_plugged = 0;
break;
case MMI_CHG_START_IND:
pwr_Status.charging_state = 1;
break;
case MMI_CHG_STOP_IND:
pwr_Status.charging_state = 0;
break;
case MMI_CHG_UNKNOWN_IND:
bSendVK = 0;
PWR_MMI_TR(("mmi_pwr_cb():received event, charger UNKNOWN!!!"));
break;
case MMI_BAT_UNKNOWN_IND:
bSendVK = 0;
PWR_MMI_TR(("mmi_pwr_cb():received event, battery UNKNOWN!!!"));
break;
case MMI_CHG_FAILED_IND:
bSendVK = 0;
PWR_MMI_TR(("mmi_pwr_cb():received event, charging FAILED!!!"));
break;
case MMI_BAT_SUPERVISION_INFO_IND:
PWR_MMI_TR(("mmi_pwr_cb():INFO C=%d, V=%d, T=%d", pEvt->Cbat, pEvt->Vbat, pEvt->Tbat));
if(pwr_Status.remain_capacity != pEvt->Cbat)
{
pwr_Status.remain_capacity = (UBYTE)pEvt->Cbat;
}
else
{
bSendVK = 0;
}
mmi_pwr_discharging(pEvt->Cbat, pEvt->Vbat);
break;
default:
PWR_MMI_TR(("mmi_pwr_cb():unexcepted event!!!, id=%d", pEvt->header.msg_id));
break;
}
if(bSendVK)
{
pwr_Status.ChargingVirtualKeyFlag = 1;
SendVirtualKeyToMMI(0,101);
}
}
/* Setting power management information about charging and battery before MMI start */
void mmi_pwr_initStatus(void)
{
SYS_UWORD16 on_status;
PWR_MMI_TR(("mmi_pwr_initStatus()"));
on_status = ABB_Read_Status();
PWR_MMI_TR(("mmi_pwr_initStatus():on_status = %2X", on_status));
#if 1
if(on_status & ONBSTS) /* push power button */
{
g_switchon = 3;
}
else if(on_status & ONRSTS) /* push remote power on button */
{
g_switchon = 1;
}
else if(on_status & CHGSTS) /* charger plug force power on */
{
g_switchon = 2;
}
else /* software or hardware reset */
{
g_switchon = 4;
}
#endif
if(on_status & CHGPRES)
{
pwr_Status.charger_plugged = 1;
}
else
{
pwr_Status.charger_plugged = 0;
}
if(on_status == 0x78 || on_status == 0x70)
{
pwr_Status.swichonstatus = 1;
}
else
{
pwr_Status.swichonstatus = 0;
}
PWR_MMI_TR(("mmi_pwr_initStatus():g_s=%d, ss=%d", g_switchon, pwr_Status.swichonstatus));
pwr_Status.charging_state = 0; /* no charging */
pwr_Status.ChargingVirtualKeyFlag = 1; /* power information is available */
pwr_Status.chargenotpossibleflag = 0; /* charging is allowed */
pwr_Status.lowvoltagewarningflag = 0;
pwr_Status.switchoffflag = 0;
pwr_Status.mobilestatusflag = 0;
pwr_Status.remain_capacity = 1;
}
/* check if a FFS DIR exists, if not, make it */
UINT8 mmi_pwr_chkDir(const char* dir)
{
T_FFS_RET error;
T_FFS_STAT stat;
if((error = ffs_stat(dir, &stat)) != EFFS_OK)
{
PWR_MMI_TR(("mmi_pwr_chkDir(): directory %s not exist!!!", dir));
if((error = ffs_mkdir(dir)) == EFFS_OK)
{
PWR_MMI_TR(("mmi_pwr_chkDir(): create directory %s ok!!!", dir));
}
else
{
PWR_MMI_TR(("mmi_pwr_chkDir(): create directory %s error = %d!!!", dir, error));
return 0;
}
}
return 1;
}
/* check if a FFS file exists, if not, make it */
UINT8 mmi_pwr_chkFile(const char* name, void* data, int size)
{
T_FFS_RET error;
T_FFS_STAT stat;
//if((error = ffs_stat(name, &stat)) != EFFS_OK)
{
PWR_MMI_TR(("mmi_pwr_chkFile(): file %s not exist!!!", name));
/* write a default file */
error = ffs_fwrite(name, data, size);
if(error == EFFS_OK)
{
PWR_MMI_TR(("mmi_pwr_chkFile(): write default %s ok!!!", name));
}
else
{
PWR_MMI_TR(("mmi_pwr_chkFile(): write default %s error = %d!!!", name, error));
return 0;
}
}
return 1;
}
/*
* Check to see if all the LCC required charger and battery config file exist,
* if anyone is not occur, write a default file
*/
void mmi_pwr_chkCfg(void)
{
T_FFS_RET error;
T_FFS_STAT stat;
/* check and create dirs before checking files */
if(!mmi_pwr_chkDir("/pwr")) return;
if(!mmi_pwr_chkDir("/pwr/bat")) return;
if(!mmi_pwr_chkDir("/pwr/chg")) return;
/* /mmi/pwr/bsie.cfg is not necessary, optional */
mmi_pwr_chkDir("/mmi/pwr");
/* check and set default config files */
if(!mmi_pwr_chkFile("/pwr/vbat.cal", (void*)&vbatCal, sizeof(T_PWR_VBAT_CAL_BLOCK))) return;
if(!mmi_pwr_chkFile("/pwr/common.cfg", (void*)&commCfg, sizeof(T_PWR_COMMON_CFG_BLOCK))) return;
if(!mmi_pwr_chkFile("/pwr/bat/bat1.cfg", (void*)&batCfg, sizeof(T_PWR_BAT_CFG_BLOCK))) return;
if(!mmi_pwr_chkFile("/pwr/bat/temp1.cfg", (void*)&tempCfg, sizeof(T_PWR_BAT_TEMP_CFG_BLOCK))) return;
if(!mmi_pwr_chkFile("/pwr/chg/chg1.cfg", (void*)&chgCfg, sizeof(T_PWR_CHG_CFG_BLOCK))) return;
/* /mmi/pwr/bsie.cfg is not necessary, optional */
mmi_pwr_chkFile("/mmi/pwr/bsie.cfg", (void*)&bsieCfg, sizeof(T_PWR_MMI_CFG_BLOCK));
PWR_MMI_TR(("mmi_pwr_chkCfg():check all pwr config ok!!!"));
}
void InitpwrStatus(void)
{
int i ;
//rvf_send_trace("SPI_task:InitpwrStatus ", 30, NULL_PARAM, RV_TRACE_LEVEL_DEBUG_LOW, SPI_USE_ID);
pwr_Status.charging_state = 0; //stop charging
// Jeffrey temparily commented out this to pass linking, 03/08/04
/* TODO Uncomment this */
// Use this, Jeffrey, 03/10/04
i = ABB_Read_Status() ;
if (i & CHGPRES)
{
pwr_Status.charger_plugged = 1;
}
else
{
pwr_Status.charger_plugged = 0;
}
//pwr_Status.remain_capacity = pwr_get_capacity_vs_voltage((UINT16)GetBatteryVoltage(1),0);
pwr_Status.remain_capacity = 1;
pwr_Status.chargenotpossibleflag=0; ///mobile can be charged
pwr_Status.lowvoltagewarningflag=0;
pwr_Status.switchoffflag=0;
pwr_Status.mobilestatusflag=0;
if ((i == 0x78)||(i == 0x70)) ///be attention to this
pwr_Status.swichonstatus = 1;
else
pwr_Status.swichonstatus = 0;
pwr_Status.ChargingVirtualKeyFlag = 1;
}
/*
* check charger status, if charger is still present, reture 1, otherwise return 0
*/
UINT8 ChargerPlugIn(void)
{
UINT16 status;
status = ABB_Read_Status();
if (status & CHGPRES)
{
return 1;
}
return 0;
}
void mmi_pwr_discharging(int Cbat, int Vbat)
{
static UINT8 lowvoltageCnt = 0;
static UINT8 switchoffCnt = 0;
static UINT8 offCnt = 0; /* time elapsed from switch off voltage detection */
static UINT16 infoCnt = 0; /* timer, timeout = info_cnt * mmi_info_repeatiton */
PWR_MMI_TR(("mmi_pwr_disch():lCnt=%d, sCnt=%d, iCnt=%d, oCnt=%d", lowvoltageCnt, switchoffCnt, infoCnt, offCnt));
if(pwr_Status.charging_state != 0) /* charging in process */
{
lowvoltageCnt = 0;
switchoffCnt = 0;
infoCnt = 0;
offCnt = 0;
}
if(Vbat <= WARNING_VOLTAGE_THR)
{
if(lowvoltageCnt < (WARNING_VOLTAGE_CNT + 1))
lowvoltageCnt++;
}
else
{
lowvoltageCnt =0;
}
if(Vbat <= SWITCHOFF_VOLTAGE_THR)
{
if(switchoffCnt < (WARNING_VOLTAGE_CNT + 1))
switchoffCnt++;
}
else
{
switchoffCnt = 0;
}
++infoCnt; /* increase timer by one unit (repeatition interval of LCC-MMI information) */
if(infoCnt % 30) /* about 60 secs */
return;
/****
* timerout for play MMI low voltage alert
*/
if(lowvoltageCnt > WARNING_VOLTAGE_CNT) /* play MMI low voltage alert */
{
/* if should switch off mobile? */
if(switchoffCnt > SWITCHOFF_VOLTAGE_CNT && !pwr_Status.mobilestatusflag && offCnt >= 60)
{
PWR_MMI_TR(("mmi_pwr_disch():switch off!!!"));
LowVol_Poweroff();
return;
}
if(!(infoCnt % WARNING_TIME_IDLE)) /* about 5 mins */
{
PWR_MMI_TR(("mmi_pwr_disch():low voltage warning!!!"));
LowVol_Warning();
}
else if(pwr_Status.mobilestatusflag && !(infoCnt % WARNING_TIME_CALLING))
{
PWR_MMI_TR(("mmi_pwr_disch():low voltage warning in calling!!!"));
LowVol_Warning();
}
if(offCnt <= 60)
offCnt++;
}
else
{
offCnt = 0;
}
if(!(infoCnt % WARNING_TIME_IDLE))
infoCnt = 0; /* start next WARNING_TIME_IDLE period */
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -