2007年3月8日 星期四

BattDrv_661

1. 有可能會因為wm9712忙碌的關係導致抓取不到電壓值。
抓取6次wm9712電壓取平均,若其中有n次miss則取n次平均。
//BspBattPdd.c
static USHORT
SYSCheckBattVoltage(BOOL bSet)
{

...
for(iCount=0;iCount<6;icount++)
{
if (usWm9712ADD == 0)
usMiss++;
else
{
usVolTmp[iCount] = usWm9712ADD;
usTemp+=usWm9712ADD;
}
Sleep(10);
}

if(ADC_COUNT>usMiss)
usWm9712ADD=usTemp/(ADC_COUNT-usMiss); //internal voltage
else
usWm9712ADD=usTemp;
avgVol = ((usWm9712ADD*806)/1000)*3;
....
}

2.ADC output levels are calculated by [internal voltage/805.86uV]



3.每次resume重讀registry會影響resume的時間,hold住一段時間會造成device開啟不了,因此將 registry移到BatteryPDDInitialize讀取。
//battif.c
BOOL WINAPI
BatteryPDDInitialize(LPCTSTR pszRegistryContext)
{

BspGetSettingFromRegistry(BAT_REG_LEVEL1, &g_BatRegValue[0]);
BspGetSettingFromRegistry(BAT_REG_LEVEL2, &g_BatRegValue[1]);
BspGetSettingFromRegistry(BAT_REG_LEVEL3, &g_BatRegValue[2]);
BspGetSettingFromRegistry(BAT_REG_LEVEL4, &g_BatRegValue[3]);
BspGetSettingFromRegistry(BAT_REG_LEVEL5, &g_BatRegValue[4]);
BspGetSettingFromRegistry(BAT_REG_LEVEL6, &g_BatRegValue[5]);
BspGetSettingFromRegistry(BAT_REG_LEVEL7, &g_BatRegValue[6]);
BspGetSettingFromRegistry(BAT_REG_LEVEL8, &g_BatRegValue[7]);
BspGetSettingFromRegistry(BAT_REG_LEVEL9, &g_BatRegValue[8]);
BspGetSettingFromRegistry(BAT_REG_LEVEL10, &g_BatRegValue[9]);

BspGetSettingFromRegistry(BAT_REG_LEVEL0, &g_BatChargingRegValue);

}

4.因為計算出來的
avgVol會有些上下跳動的情形而導致show出來的percentage也有變化,所以加了一些修改,感覺有點小作弊。
//BspBattPdd.c
static USHORT
SYSCheckBattVoltage(BOOL bSet)
{
...

if(bSet)

{

if(iMax

{

iMax=avgVol;

iMin=5000;

}

usBatChargingPer= (USHORT)BattChargingGetLevel(iMax);

return usBatChargingPer;

}

if(iMin>avgVol)

{

iMin=avgVol;

iMax=0;

}


usBatteryPer = (USHORT)BattGetLevel(iMin);

return (usBatteryPer);

}

4.因為registry定義,加上判斷suspend時間點的關系,導致低電量時device自行進入suspend後做charging再按resume會有bug產生,device會show出剩餘10%電量後再show出charging,照道理是一按resume後會show charging才是。
以下對code再加判斷解決。

//BspBattPdd.c
DWORD BattGetLevel(DWORD dwVoltage)
{
...
if(g_icount<5) g_icount="0;" g_icount="0;" style="color: rgb(255, 0, 0);">if(BspGetBatteryFlag()==PDD_BATTERY_CHARGING)

{
return BATTERY_PERCENTAGE_UNKNOWN;
}
else
{
return 10;
}
}
...
}

//battif.c
BatteryPDDGetStatus(
PSYSTEM_POWER_STATUS_EX2 pstatus, PBOOL pfBatteriesChangedSinceLastCall)
{
...
if (PDD_BATTERY_CHARGING == battery_status )
{
RETAILMSG(ZONE_REG_PRINT, (TEXT("+Battery status PDD_BATTERY_CHARGING... \r\n")));

ucBatChargingPer=BspFuelGaugeResetBatStatusInPercent();
BspNotifyLed(FALSE);
if(ucBatChargingPer==100)
{
sps.BatteryFlag = BATTERY_FLAG_HIGH;
sps.BatteryLifePercent = 100;
BspNotifyLed(FALSE);
IOW_REG_OR(ULONG, &(v_pGpioRegs->gpio[5].paden), GPIO23);
PIO_OUTPUT_ZERO (GPIO, GPIO_GROUP(5), GPIO_INDEX(23));
PIO_OUTPUT_ENABLE ( GPIO, GPIO_GROUP (5), GPIO_INDEX (23) );
}else
{
sps.BatteryFlag = BATTERY_FLAG_CHARGING;
sps.BatteryLifePercent = BATTERY_PERCENTAGE_UNKNOWN;
BspNotifyLed(FALSE);
IOW_REG_OR(ULONG, &(v_pGpioRegs->gpio[5].paden), GPIO23);
PIO_OUTPUT_ONE (GPIO, GPIO_GROUP(5), GPIO_INDEX(23));
PIO_OUTPUT_ENABLE ( GPIO, GPIO_GROUP (5), GPIO_INDEX (23) );
}
}
else
{
ucBatteryPer = BspFuelGaugeGetBatStatusInPercent();

if(ucBatteryPer == dwTenPercentage)
SetEvent(hBattLowEvent);
if(ucBatteryPer==BATTERY_PERCENTAGE_UNKNOWN)
{
sps.BatteryFlag = BATTERY_FLAG_CHARGING;
sps.BatteryLifePercent = BATTERY_PERCENTAGE_UNKNOWN;
}
else if(ucBatteryPer >= dwHighBattPercentage)
{
sps.BatteryFlag = BATTERY_FLAG_HIGH;
BspNotifyLed(FALSE);
sps.BatteryLifePercent = ucBatteryPer;
}
else if (( ucBatteryPer =dwLowBattPercentage))
{
sps.BatteryFlag = BATTERY_FLAG_LOW;
BspNotifyLed(TRUE);
sps.BatteryLifePercent = ucBatteryPer;
}
else if(ucBatteryPer<=dwLowBattPercentage)
{
sps.BatteryFlag = BATTERY_FLAG_CRITICAL;
BspNotifyLed(TRUE);
sps.BatteryLifePercent = ucBatteryPer;
}

}
...
}