return nextState;
}
+#define USE_SW_NTC 0//simware add , use adc to check ntc
+#if USE_SW_NTC
+static UINT32 bat_temp_mv_arry[131] = {
+ 106,109,112,115,119,122,126,130,134,138,//100 ~ 91
+ 142,146,150,154,159,164,169,174,179,185,//90 ~ 81
+ 190,196,202,208,215,221,228,235,242,249,//80 ~ 71
+ 257,265,273,281,290,299,308,317,327,337,//70 ~ 61
+ 347,358,368,380,391,403,415,427,440,453,//60 ~ 51
+ 466,480,494,508,523,538,553,569,585,601,//50 ~ 41
+ 618,635,652,670,688,706,724,743,762,781,//40 ~ 31
+ 800,820,840,860,880,900,920,941,961,982,//30 ~ 21
+ 1003,1023,1044,1065,1085,1106,1126,1146,1166,1186,//20 ~ 11
+ 1206,1226,1245,1264,1283,1302,1320,1338,1355,1372,//10 ~ 01
+ 1389,1406,1422,1438,1453,1468,1482,1496,1510,1523,//00 ~ -9
+ 1536,1549,1561,1572,1583,1594,1605,1615,1624,1633,//-10 ~ -19
+ 1642,1651,1659,1666,1674,1681,1688,1694,1700,1706,//-20 ~ -29
+ 1712,//-30
+};
+extern INT16 GetPm803VrtpAdc(void);
+#endif /*USE_SW_NTC*/
+
int Get_Battery_temp(void)
{
int bat_temp = 100;
UINT32 i;
UINT32 bat_impedance;
+#if USE_SW_NTC
+ bat_impedance = GetPm803VrtpAdc();
+ PMIC_TRACE("bat_temp_mv %d\n", bat_impedance);
+ if(bat_impedance == 0)
+ {
+ return 0xdeaddead;
+ }
+ for(i = 0;i < 131;i++)
+ {
+ if(bat_impedance <= bat_temp_mv_arry[i])
+ {
+ bat_temp = bat_temp - i;
+ PMIC_TRACE("bat_temp %d\n", bat_temp);
+ return bat_temp; //get over temp and near.
+ }
+ }
+ if(i == 131)
+ {
+ PMIC_TRACE("!!!!The bat_temp over range\n");
+ }
+#else
bat_impedance = Pmic_get_battemp_kohm() * 1000;
for(i = 0;i < 29;i++)
{
PMIC_TRACE("!!!!The battery no temp pin,or temp over range\n");
return 0xdeaddead;
}
+#endif
return 0xdeaddead;
}
PMU_CHR_STATUS_T status;
PMIC_CHARGER_STATUS_T nextState = g_pmicChargerState.status;
int batt_temp;
+#if USE_SW_NTC//simware add
+ static UINT8 hot_cnt = 0;
+ static UINT8 cold_cnt = 0;
+ static UINT8 temp_recover_cnt = 0;
+#define HOT_THRESHOLD 45
+#define COLD_THRESHOLD 2
+#endif
switch(charger_event)
{
case PMIC_CHARGE_DC_OFF:
}
g_pmicChargingStage = PMIC_CHARGING_STAGE_ON;
ForceChargerFinished(FALSE);
+#if USE_SW_NTC
+ temp_recover_cnt = 0;
+#endif
charger_event = PMIC_CHARGE_TIMER;
if(Pmic_is_pm813s() || Pmic_is_pm813_a3())
g_pmicChargerHighTemperatureCheckFlag = TRUE;
}
//add battery temp check
+#if USE_SW_NTC
+ batt_temp = Get_Battery_temp();
+ if(batt_temp != 0xdeaddead)
+ {
+ if(batt_temp >= HOT_THRESHOLD)
+ hot_cnt++;
+ else
+ hot_cnt = 0;
+
+ if(batt_temp <= COLD_THRESHOLD)
+ cold_cnt++;
+ else
+ cold_cnt = 0;
+
+ PMIC_TRACE("Battery temperature:%d! hot_cnt:%d cold_cnt:%d\n",batt_temp, hot_cnt, cold_cnt);
+ if(batt_temp <= COLD_THRESHOLD && (cold_cnt >= 2))
+ {
+ ForceChargerFinished(TRUE);
+ temp_recover_cnt = 1;
+ PMIC_TRACE("Battery too cool,pmd charger off!\n");
+ }
+ else if((batt_temp >= HOT_THRESHOLD) && (hot_cnt >= 2))
+ {
+ ForceChargerFinished(TRUE);
+ temp_recover_cnt = 1;
+ PMIC_TRACE("Battery too hot,pmd charger off!\n");
+ }
+ else if(batt_temp < HOT_THRESHOLD && batt_temp > COLD_THRESHOLD && temp_recover_cnt > 60)
+ {
+ temp_recover_cnt = 0;
+ ForceChargerFinished(FALSE);
+ PMIC_TRACE("Battery is not hot or cold!, recover\n");
+ }
+ if(temp_recover_cnt >= 1) {
+ temp_recover_cnt++;
+ }
+ }
+#else
if(g_pmicConfig->Has_battery_temp)
{
//only pm813 & pm813s support to get battery temp
PMIC_TRACE("Battery temperature:%d!\n",batt_temp);
}
}
+#endif
}
extern void ChargerStsEvb1601_Pm802PinmuxCfg(void);