📄 ist.c
字号:
pPCF50606->pcfRegisterCache+OOCC1,
1);
if (!KernelIoControl(IOCTL_HAL_DISABLE_WAKE, &wakeSrcKeyPad, sizeof(wakeSrcKeyPad), NULL, 0, NULL))
{
RETAILMSG(ZONE_ERROR, (TEXT("PCF50606: Error setting wake src.\r\n")));
}
dwErr = SetSystemPowerState(NULL, POWER_STATE_OFF, POWER_FORCE);
if (ERROR_SUCCESS != dwErr)
{
RETAILMSG(ZONE_ERROR, (TEXT("PCF50606: Error initiating clean shutdown.\r\n")));
}
else
{
// We should not get here
RETAILMSG(ZONE_ERROR, (TEXT("PCF50606: SetSystemPowerState returned ERROR_SUCCESS but the system did not power off.\r\n")));
}
DEBUGCHK(0);
}
//////////////////////////////////////////////////////////////////////////////////
// BEGIN: Battery and Charger maintenance
//////////////////////////////////////////////////////////////////////////////////
GetBatteryVoltage(pPCF50606);
#ifdef _DEBUG
PrintBatteryTemp(pPCF50606);
PrintMBCState(pPCF50606);
#endif
// Compare sample to average
if (pPcfBattery->dwAverageBatteryVolatge)
{
DWORD BattVoltageDelta;
// Get delta between current reading and average.
if (pPcfBattery->dwAverageBatteryVolatge > pPcfBattery->dwCurrentBatteryVoltage)
{
BattVoltageDelta = pPcfBattery->dwAverageBatteryVolatge - pPcfBattery->dwCurrentBatteryVoltage;
}
else
{
BattVoltageDelta = pPcfBattery->dwCurrentBatteryVoltage - pPcfBattery->dwAverageBatteryVolatge;
}
// Check for outlier.
if (BattVoltageDelta >= BATTERY_VOLTAGE_MAX_DELTA)
{
pPcfBattery->dwBattVoltageDeltaPersist++;
DEBUGMSG(ZONE_VERBOSE, (
TEXT("Ignoring battery voltage sample. Avg: %d, Prev: %d, Cur: %d, Persist: %d\r\n"),
pPcfBattery->dwAverageBatteryVolatge,
pPcfBattery->dwBatteryVolatge,
pPcfBattery->dwCurrentBatteryVoltage,
pPcfBattery->dwBattVoltageDeltaPersist));
// Allow for steps in the voltage level
if (pPcfBattery->dwBattVoltageDeltaPersist <= BATTERY_VOLTAGE_NUM_SAMPLES)
{
pPcfBattery->dwCurrentBatteryVoltage = pPcfBattery->dwAverageBatteryVolatge;
}
}
else
{
pPcfBattery->dwBattVoltageDeltaPersist = 0;
}
}
// Compute battery voltage average
pPcfBattery->dwAverageBatteryVolatge = ComputeVoltageAverage(pPcfBattery);
pPcfBattery->dwBatteryVolatge = pPcfBattery->dwAverageBatteryVolatge;
DEBUGMSG(ZONE_VERBOSE, (TEXT("PCF50606: Average Battery Voltage: %dmV\r\n"), pPcfBattery->dwAverageBatteryVolatge));
dwPCFMessage |= PCF_MSG_BATTERY_VOLTAGE;
//
// Read Main battery charger mode and status from PCF50606
//
bytesReturned = PDD_I2CRead(&pPCF50606->csI2CAccess,
pPCF50606->v_pI2CRegs,
pPCF50606->v_pOstRegs,
MBCC1,
pPCF50606->pcfRegisterCache+MBCC1,
1);
DEBUGMSG(ZONE_VERBOSE, (TEXT("PCF50606: Read Charger mode: %x\r\n"),
pPCF50606->pcfRegisterCache[MBCC1]));
bytesReturned = PDD_I2CRead(&pPCF50606->csI2CAccess,
pPCF50606->v_pI2CRegs,
pPCF50606->v_pOstRegs,
MBCS1,
pPCF50606->pcfRegisterCache+MBCS1,
1);
DEBUGMSG(ZONE_VERBOSE, (TEXT("PCF50606: Read Charger status: %x\r\n"),
pPCF50606->pcfRegisterCache[MBCS1]));
// Check for charging voltage and battery voltage
if((pPCF50606->pcfRegisterCache[MBCS1] & MBCS1_CHGVIN_STAT_M(WITHIN_LIMITS)))
{
dwPCFMessage |= PCF_MSG_AC_CONNECTED;
gfACOnline = TRUE;
}
else
{
dwPCFMessage |= PCF_MSG_AC_DISCONNECTED;
gfACOnline = FALSE;
}
//////////////////////////////////////////////////////////////////////////////////
// END: Battery and Charger maintenance
//////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////
// Has the RTC alarm time been reached
///////////////////////////////////////////////
if(pPCF50606->pcfRegisterCache[INT1] & INT1_ALARM)
{
DEBUGMSG(ZONE_VERBOSE,(TEXT("PCF50606: RTC alarm time been reached.\r\n")));
}
// Query INT register #2
///////////////////////////////////////////////
// Has the charger with valid voltage been inserted
///////////////////////////////////////////////
if(pPCF50606->pcfRegisterCache[INT2] & INT2_CHGINS)
{
DEBUGMSG(ZONE_STATECHANGE,(TEXT("PCF50606: Charger insert detected.\r\n")));
// Set thread variable for AC status
gfACOnline = TRUE;
dwPCFMessage |= PCF_MSG_AC_CONNECTED;
SendPowerChangeMessage(pPCF50606->msgQueuePMPOLICY);
StartCharger(pPCF50606);
}
///////////////////////////////////////////////
// Has the charger been disconnected
///////////////////////////////////////////////
if(pPCF50606->pcfRegisterCache[INT2] & INT2_CHGRM)
{
DEBUGMSG(ZONE_STATECHANGE,(TEXT("PCF50606: Charger removal detected.\r\n")));
// Set thread variable for AC status
gfACOnline = FALSE;
dwPCFMessage |= PCF_MSG_AC_DISCONNECTED;
SendPowerChangeMessage(pPCF50606->msgQueuePMPOLICY);
RemoveCharger(pPCF50606);
}
///////////////////////////////////////////////
// Has a charger protection error occured?
///////////////////////////////////////////////
if(pPCF50606->pcfRegisterCache[INT2] & INT2_CHGPROT)
{
RETAILMSG(ZONE_STATECHANGE,(TEXT("PCF50606: Charger protection error occured. Very low battery voltage or Batt temp outside limits.\r\n")));
}
///////////////////////////////////////////////
// Ready for fast charge?
///////////////////////////////////////////////
if(pPCF50606->pcfRegisterCache[INT2] & INT2_CHGFOK)
{
DEBUGMSG(ZONE_STATECHANGE,(TEXT("PCF50606: Charger system ready for fast charge.\r\n")));
}
///////////////////////////////////////////////
// Has the fast charge phase completed
///////////////////////////////////////////////
if(pPCF50606->pcfRegisterCache[INT2] & INT2_CHGFRDY)
{
dwPCFMessage |= PCF_MSG_BATTERY_FULL;
DEBUGMSG(ZONE_STATECHANGE,(TEXT("PCF50606: Fast charge completed.\r\n")));
// Process battery full condition
BatteryFull(pPCF50606);
}
///////////////////////////////////////////////
// Will the charger watchdog expire in 10 sec
///////////////////////////////////////////////
if (pPCF50606->pcfRegisterCache[INT2] & INT2_CHGWD10S)
{
dwPCFMessage |= PCF_MSG_CHARGER_WD10S;
DEBUGMSG(ZONE_STATECHANGE, (TEXT("PCF50606: 10 seconds to watchdog timer expiry. \r\n")));
if (gfACOnline)
{
RestartCharger(pPCF50606);
}
else
{
DEBUGMSG(ZONE_STATECHANGE, (TEXT("PCF50606: BATT: WDT 10S, AC not connected!!!\r\n")));
RemoveCharger(pPCF50606);
}
}
// Query INT register #3
///////////////////////////////////////////////
// Has low battery voltage been detected
///////////////////////////////////////////////
if(pPCF50606->pcfRegisterCache[INT3] & INT3_LOWBAT)
{
RETAILMSG(ZONE_STATECHANGE,(TEXT("PCF50606: Low Battery\r\n")));
dwPCFMessage |= PCF_MSG_BATTERY_LOW;
BatteryEmpty(pPCF50606);
}
//////////////////////
// Send PCF message
//////////////////////
if (dwPCFMessage)
{
SendQueueMessage(pPCF50606->msgQueuePCFWrite,
(LPVOID)&dwPCFMessage,
sizeof(dwPCFMessage));
}
////////////////////////////////////////////////////////
// Synchronize the PCF50606 RTC with the System RTC (if needed)
////////////////////////////////////////////////////////
if (!gfRTCSyncThreadRunning) // No need to do it if thread is already running
{
bytesReturned = PDD_I2CRead(&pPCF50606->csI2CAccess,
pPCF50606->v_pI2CRegs,
pPCF50606->v_pOstRegs,
RTCSC,
pPCF50606->pcfRegisterCache+RTCSC,
7);
GetLocalTime(&sysRTCTime);
// Check to see if the times match
// (within a minute resolution to avoid complexity).
if ((sysRTCTime.wYear - 2000 != BCDTODEC(RTCRegs[6])) ||
(sysRTCTime.wMonth != BCDTODEC(RTCRegs[5])) ||
(sysRTCTime.wDay != BCDTODEC(RTCRegs[4])) ||
(sysRTCTime.wDayOfWeek != BCDTODEC(RTCRegs[3])) ||
(sysRTCTime.wHour != BCDTODEC(RTCRegs[2])) ||
(sysRTCTime.wMinute != BCDTODEC(RTCRegs[1])))
{
SynchronizeRTCTime(pPCF50606);
}
}
if(pPCF50606->pcfRegisterCache[INT1] & INT1_SECOND)
{
DEBUGMSG(ZONE_VERBOSE,(TEXT("PCF50606: ************************************************.\r\n")));
}
// Clear all PCF50606 interrupts
// Interrupt registers
pPCF50606->pcfRegisterCache[INT1]=0x00;
pPCF50606->pcfRegisterCache[INT2]=0x00;
pPCF50606->pcfRegisterCache[INT3]=0x00;
}
return 0;
}
BOOL
SendQueueMessage(HANDLE pMsgQueue,
LPVOID dwMessage,
DWORD dwSize)
{
if (pMsgQueue)
return (WriteMsgQueue(pMsgQueue,
(LPVOID)dwMessage,
dwSize,
0,
0));
else
return FALSE;
}
static void
SendPowerChangeMessage(HANDLE pMsgQueue)
{
POWERPOLICYMESSAGE ppm;
// Send Power change power policy message only if the battery APIs are ready
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -