📄 battdrvr.cpp
字号:
//------------------------------------------------------------------------------
//
// Copyright (C) 2005, Motorola Inc. All Rights Reserved
//
//------------------------------------------------------------------------------
//
// Copyright (C) 2006, Freescale Semiconductor, Inc. All Rights Reserved.
// THIS SOURCE CODE, AND ITS USE AND DISTRIBUTION, IS SUBJECT TO THE TERMS
// AND CONDITIONS OF THE APPLICABLE LICENSE AGREEMENT
//
//------------------------------------------------------------------------------
//
// File: battdrvr.cpp
//
// This file implements the PDD layer APIs for battery driver
//
//------------------------------------------------------------------------------
#include <windows.h>
#include <Devload.h>
#include <ceddk.h>
#include <battimpl.h>
#include <Mmsystem.h>
#include "bspbattdrvr.h"
#include "battdrvrUtility.h"
//------------------------------------------------------------------------------
// External Functions
//------------------------------------------------------------------------------
// External Variables
//------------------------------------------------------------------------------
// Defines
#define C_HR_TO_SEC 3600 // convert factor from hour to sec
#define C_S_TO_MS 1000 // convert factor from sec to milli sec
#define LIMIT_LOW 20 // lower limit for battery capacity
#define LIMIT_HIGH 65 // higher limit for battery capacity
#define MAX_TIME 0xFFFFFFFF
//------------------------------------------------------------------------------
// Types
//------------------------------------------------------------------------------
// Global Variables
//------------------------------------------------------------------------------
// Local Variables
static BOOL Init_check; //flag to determine whether need to perform the init check
static DWORD Batt_FullLifeTime; // full batt life time from registry
static DWORD Batt_FullCapacity; // full batt capacity from registry
static DWORD Batt_MaxVoltage; // max batt voltage from registry
static DWORD Batt_MinVoltage; // min batt voltage from registry
static DWORD Batt_PeukertNumber; // batt peukert number from registry
static DWORD Batt_ChargeEff; // batt charge efficiency from registry
static DWORD t1; // time stamp to determine the duration between each call
static DWORD t2;
static UINT32 capacity; // batt capacity
static UINT32 percentage; // percentage of batt capacity
//------------------------------------------------------------------------------
// Local Functions
//-----------------------------------------------------------------------------
//
// Function: BatteryPDDInitialize
//
// This function performs the deinit to the battery pdd
//
// Parameters:
// pszRegistryContext
// [in] pointer of the reigistry context
//
// Returns:
// TRUE for success FALSE if else
//
//-----------------------------------------------------------------------------
BOOL WINAPI BatteryPDDInitialize(LPCTSTR pszRegistryContext)
{
HKEY hKey;
DWORD dwStatus;
DWORD dwType;
DWORD dwSize;
DEBUGMSG(ZONE_FUNCTION, (TEXT("+BatteryPDDInitialize\r\n")));
//Get Info from registry
//obtain the default full battery capacity in mAHr
hKey = OpenDeviceKey(pszRegistryContext); //open the device key
if(!hKey)
{
DEBUGMSG(ZONE_ERROR, (TEXT("BatteryPDDInitialize: OpenDeviceKey failed\r\n")));
goto InitFail;
}
dwSize = sizeof(DWORD);
//obtain the batt full life time
dwStatus = RegQueryValueEx(hKey, BATT_FULL_LIFETIME_SUBKEY, NULL, &dwType, (LPBYTE) &Batt_FullLifeTime, &dwSize);
if(dwStatus != ERROR_SUCCESS)
{
DEBUGMSG(ZONE_ERROR, (TEXT("BatteryPDDInitialize: RegQueryValueEx(Batt_FullLifeTime) failed\r\n")));
goto InitFail;
}
DEBUGMSG(ZONE_BATTERY, (TEXT("Batt_FullLifeTime is %X\r\n"), Batt_FullLifeTime));
//obtain the batt full capacity
dwStatus = RegQueryValueEx(hKey, BATT_FULL_CAPACITY_SUBKEY, NULL, &dwType, (LPBYTE) &Batt_FullCapacity, &dwSize);
if(dwStatus != ERROR_SUCCESS)
{
DEBUGMSG(ZONE_ERROR, (TEXT("BatteryPDDInitialize: RegQueryValueEx(Batt_FullCapacity) failed\r\n")));
goto InitFail;
}
DEBUGMSG(ZONE_BATTERY, (TEXT("Batt_FullCapacity is %X\r\n"), Batt_FullCapacity));
//obtain the batt max voltage
dwStatus = RegQueryValueEx(hKey, BATT_MAX_VOLTAGE_SUBKEY, NULL, &dwType, (LPBYTE) &Batt_MaxVoltage, &dwSize);
if(dwStatus != ERROR_SUCCESS)
{
DEBUGMSG(ZONE_ERROR, (TEXT("BatteryPDDInitialize: RegQueryValueEx(Batt_MaxVoltage) failed\r\n")));
goto InitFail;
}
DEBUGMSG(ZONE_BATTERY, (TEXT("Batt_MaxVoltage is %X\r\n"), Batt_MaxVoltage));
//obtain the batt min voltage
dwStatus = RegQueryValueEx(hKey, BATT_MIN_VOLTAGE_SUBKEY, NULL, &dwType, (LPBYTE) &Batt_MinVoltage, &dwSize);
if(dwStatus != ERROR_SUCCESS)
{
DEBUGMSG(ZONE_ERROR, (TEXT("BatteryPDDInitialize: RegQueryValueEx(Batt_MinVoltage) failed\r\n")));
goto InitFail;
}
DEBUGMSG(ZONE_BATTERY, (TEXT("Batt_MinVoltage is %X\r\n"), Batt_MinVoltage));
//obtain the batt peukert number
dwStatus = RegQueryValueEx(hKey, BATT_PEUKERT_NUMBER_SUBKEY, NULL, &dwType, (LPBYTE) &Batt_PeukertNumber, &dwSize);
if(dwStatus != ERROR_SUCCESS)
{
DEBUGMSG(ZONE_ERROR, (TEXT("BatteryPDDInitialize: RegQueryValueEx(Batt_PeukertNumber) failed\r\n")));
goto InitFail;
}
DEBUGMSG(ZONE_BATTERY, (TEXT("Batt_PeukertNumber is %X\r\n"), Batt_PeukertNumber));
//obtain the batt charge efficiency
dwStatus = RegQueryValueEx(hKey, BATT_CHARGE_EFF_SUBKEY, NULL, &dwType, (LPBYTE) &Batt_ChargeEff, &dwSize);
if(dwStatus != ERROR_SUCCESS)
{
DEBUGMSG(ZONE_ERROR, (TEXT("BatteryPDDInitialize: RegQueryValueEx(Batt_ChargeEff) failed\r\n")));
goto InitFail;
}
DEBUGMSG(ZONE_BATTERY, (TEXT("Batt_ChargeEff is %X\r\n"), Batt_ChargeEff));
RegCloseKey(hKey);
//force the driver to do the initial checking
Init_check = TRUE;
DEBUGMSG(ZONE_FUNCTION, (TEXT("-BatteryPDDInitialize\r\n")));
return TRUE;
InitFail:
if(hKey)
RegCloseKey(hKey);
return FALSE;
}
//-----------------------------------------------------------------------------
//
// Function: BatteryPDDDeinitialize
//
// This function performs the deinit to the battery pdd
//
// Parameters:
// void
//
// Returns:
// void
//
//-----------------------------------------------------------------------------
void WINAPI BatteryPDDDeinitialize(void)
{
DEBUGMSG(ZONE_FUNCTION, (TEXT("+BatteryPDDDeinitialize\r\n")));
DEBUGMSG(ZONE_FUNCTION, (TEXT("-BatteryPDDDeinitialize\r\n")));
}
//-----------------------------------------------------------------------------
//
// Function: BatteryPDDResume
//
// This function performs hardware-specific battery processing in a thread context
// following system resume
//
// Parameters:
// void
//
// Returns:
// void
//
//-----------------------------------------------------------------------------
void WINAPI BatteryPDDResume(void)
{
DEBUGMSG(ZONE_FUNCTION, (TEXT("+BatteryPDDResume\r\n")));
DEBUGMSG(ZONE_FUNCTION, (TEXT("-BatteryPDDResume\r\n")));
}
//-----------------------------------------------------------------------------
//
// Function: BatteryPDDPowerHandler
//
// This power callback performs hardware-specific processing for the battery driver
//
// Parameters:
// bOff
// [in] TRUE if suspending, FALSE if resuming.
//
// Returns:
// void
//
//-----------------------------------------------------------------------------
void WINAPI BatteryPDDPowerHandler(BOOL bOff)
{
DEBUGMSG(ZONE_FUNCTION, (TEXT("+BatteryPDDPowerHandler\r\n")));
// in resuming case, do the init check
if (bOff == FALSE)
{
//force the driver to do the initial checking
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -