⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 battif.c

📁 SAMSUNG S3C6410 CPU BSP for winmobile6
💻 C
字号:
//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//

//
// This module contains a stub implementation of the battery PDD.  OEMs
// that want to support the battery APIs on their platform can copy this
// file to their platform and link it into their own version of the power
// manager DLL.
//
// If the platform-specific power manager provides its own version of these
// entry points, this module will not be pulled into the link map from
// the pm_battapi library.
//

//--------------------------------------------------------------------------------------------------
// Includes
//--------------------------------------------------------------------------------------------------
#include <battimpl.h>
#include <ceddk.h>
#include <bsp.h>
#include <Drvlib.h>

#define DBGBAT 0

volatile static BSP_ARGS *v_pBSPArgs;

unsigned __int8 GetChargePercent(void);



//-------------------------------------------------------------------------------------------------
// Global Variables
//--------------------------------------------------------------------------------------------------

unsigned __int8 ChargePercent;


//------------------------------------------------------------------------------------------------------------
// Function: GetChargePercent
// 
// Purpose:  Get Charge capacity from battery check hardware
// Returns:  unsigned __int8
//
//-------------------------------------------------------------------------------------------------------------
unsigned __int8 GetChargePercent(void)
{
	unsigned __int8 ChargePercetValue; // sample data
	RETAILMSG(DBGBAT,(TEXT("++GetChargePercent\r\n")));	
	ChargePercetValue = 80;  //Sample data
	RETAILMSG(DBGBAT,(TEXT("--GetChargePercent\r\n")));
	return 	ChargePercetValue;
}



//------------------------------------------------------------------------------------------------------------
// Function: InitBatteryDriver
// 
// Purpose:  Initialises the battery driver and allocates the necessary memory.
// Returns:  void
//
//-------------------------------------------------------------------------------------------------------------

void InitBatteryDriver()
{
	RETAILMSG(DBGBAT,(TEXT("++InitBatteryDriver\r\n"))); 

    	//Now, SMDK6410 have no Battery Check hardware
        //Implement initialized code for Battery driver. 
	RETAILMSG(DBGBAT,(TEXT("--InitBatteryDriver\r\n")));        

}

//------------------------------------------------------------------------------------------------------------
// Function: IsACOnline
// 
// Purpose:  Simply indicates whether we are running out of AC or out of Battery.
// Returns:  TRUE indicates we are running out of the AC wall power supply.
//           FALSE indicates we are running out of Battery.
//
//-------------------------------------------------------------------------------------------------------------
BOOL WINAPI IsACOnline(void)
{
    BOOL AcOnlineStatus = FALSE;  //TRUE:AC FALSE:DC
	RETAILMSG(DBGBAT,(TEXT("++IsACOnline\r\n"))); 	
    // Implement Check code for whether AC or Battery. 
    v_pBSPArgs->bPowerStatus = AcOnlineStatus;
    RETAILMSG(DBGBAT,(TEXT("--IsACOnline\r\n"))); 
    return AcOnlineStatus;
}

BOOL WINAPI 
BatteryPDDInitialize(LPCTSTR pszRegistryContext)
{
    BOOL fOk = TRUE;
    RETAILMSG(1,(TEXT("++BatteryPDDInitialize\r\n"))); 
    
    v_pBSPArgs = (volatile BSP_ARGS *)DrvLib_MapIoSpace(IMAGE_SHARE_ARGS_PA_START, sizeof(BSP_ARGS), FALSE);
	if (v_pBSPArgs == NULL)
	{
		RETAILMSG(1, (TEXT("#####Battery: v_pBSPArgs DrvLib_MapIoSpace() Failed \n\r")));
		return FALSE;
	}
    UNREFERENCED_PARAMETER(pszRegistryContext);
    
    RETAILMSG(1,(TEXT("--BatteryPDDInitialize\r\n"))); 

    return fOk;
}

void WINAPI 
BatteryPDDDeinitialize(void)
{
    RETAILMSG(DBGBAT,(TEXT("++BatteryPDDDeinitialize\r\n"))); 
    
    RETAILMSG(DBGBAT,(TEXT("--BatteryPDDDeinitialize\r\n")));    
}

void WINAPI 
BatteryPDDResume(void)
{
    RETAILMSG(DBGBAT,(TEXT("++BatteryPDDResume\r\n"))); 
    
    RETAILMSG(DBGBAT,(TEXT("--BatteryPDDResume\r\n")));  
}

void WINAPI 
BatteryPDDPowerHandler(BOOL bOff)
{
    RETAILMSG(DBGBAT,(TEXT("++BatteryPDDPowerHandler\r\n"))); 
    
    RETAILMSG(DBGBAT,(TEXT("--BatteryPDDPowerHandler\r\n"))); 
}

// This routine obtains the most current battery/power status available
// on the platform.  It fills in the structures pointed to by its parameters
// and returns TRUE if successful.  If there's an error, it returns FALSE.
BOOL WINAPI
BatteryPDDGetStatus(
                    PSYSTEM_POWER_STATUS_EX2 pstatus,
                    PBOOL pfBatteriesChangedSinceLastCall
                    )
{

    // this function is used to report the battery status
    // now, temperature, and terminal voltage
    unsigned __int8 sample;
    BOOL PowerStatus;
    static BOOL first_time = TRUE;
    BYTE BatteryFlag = 0;

	RETAILMSG(DBGBAT,(TEXT("++BatteryPDDGetStatus\r\n")));
    if(first_time)
    {
        InitBatteryDriver();
        ChargePercent = 100;
        first_time=FALSE;
    }

    PowerStatus = IsACOnline();
    sample = GetChargePercent();
    if (sample > 100) {
        sample = 100;
    }

    if (PowerStatus)
    {
        pstatus->ACLineStatus = AC_LINE_ONLINE;
        ChargePercent = sample;
        BatteryFlag |= BATTERY_FLAG_CHARGING;
    } 
    else
    {
        pstatus->ACLineStatus = AC_LINE_OFFLINE;
        ChargePercent = sample;
    }


    // Level Indicator 
    if(ChargePercent >= 65)
        BatteryFlag |= BATTERY_FLAG_HIGH;
    else if ((ChargePercent < 65) && (ChargePercent >= 20))
        BatteryFlag |= BATTERY_FLAG_LOW;
    else
        BatteryFlag |= BATTERY_FLAG_CRITICAL;

    pstatus->BatteryFlag                = BatteryFlag;
    pstatus->BatteryLifePercent         = ChargePercent;
    pstatus->Reserved1                  = 0;
    pstatus->BatteryLifeTime            = BATTERY_LIFE_UNKNOWN;
    pstatus->BatteryFullLifeTime        = BATTERY_LIFE_UNKNOWN;

    pstatus->Reserved2                  = 0;
    pstatus->BackupBatteryFlag          = BATTERY_FLAG_UNKNOWN;
    pstatus->BackupBatteryLifePercent   = 0;
    pstatus->Reserved3                  = 0;
    pstatus->BackupBatteryLifeTime      = BATTERY_LIFE_UNKNOWN;
    pstatus->BackupBatteryFullLifeTime  = BATTERY_LIFE_UNKNOWN;

    pstatus->BatteryChemistry           = BATTERY_CHEMISTRY_LION;
    pstatus->BatteryVoltage             = 1200;   //Sample Data
    pstatus->BatteryCurrent             = 0;
    pstatus->BatteryAverageCurrent      = 0;
    pstatus->BatteryAverageInterval     = 0;
    pstatus->BatterymAHourConsumed      = 0;
    pstatus->BatteryTemperature         = 0;
    pstatus->BackupBatteryVoltage       = 0;
   
   *pfBatteriesChangedSinceLastCall = FALSE;
   
	RETAILMSG(DBGBAT,(TEXT("--BatteryPDDGetStatus\r\n")));
	
    return (TRUE);
}



// This routine indicates how many battery levels will be reported
// in the BatteryFlag and BackupBatteryFlag fields of the PSYSTEM_POWER_STATUS_EX2
// filed in by BatteryPDDGetStatus().  This number ranges from 0 through 3 --
// see the Platform Builder documentation for details.  The main battery
// level count is reported in the low word of the return value; the count 
// for the backup battery is in the high word.
LONG
BatteryPDDGetLevels(
    void
        )
{
    LONG lLevels = MAKELONG (3 /* main battery levels   */,  
                             3 /* backup battery levels */);
	
	RETAILMSG(DBGBAT,(TEXT("++BatteryPDDGetLevels\r\n")));

    RETAILMSG(DBGBAT, (TEXT("(%d main levels, %d backup levels)\r\n"),LOWORD(lLevels), HIWORD(lLevels)));

	RETAILMSG(DBGBAT,(TEXT("--BatteryPDDGetLevels\r\n")));
    return lLevels;
}



// This routine returns TRUE to indicate that the pfBatteriesChangedSinceLastCall
// value filled in by BatteryPDDGetStatus() is valid.  If there is no way to
// tell that the platform's batteries have been changed this routine should
// return FALSE.
BOOL
BatteryPDDSupportsChangeNotification(
    void
        )
{
    BOOL fSupportsChange = FALSE;
    SETFNAME(_T("BatteryPDDPowerHandler"));

    DEBUGMSG(ZONE_PDD, (_T("%s: returning %d\r\n"), pszFname, fSupportsChange));

    return fSupportsChange;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -