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

📄 battdrvr.cpp

📁 freescale i.mx31 BSP CE5.0全部源码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
//------------------------------------------------------------------------------
//
//  Copyright (C) 2005, Motorola Inc. All Rights Reserved
//
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
//
//  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

#define CHARGE_END_CURRENT (0.01 * Batt_FullCapacity)
#define CURRENT_COUNT_CALC_TIMES    6
#define BATTERY_VOL_CALC_TIMES      120 
#define VOLTAGE_LIMIT_LEVEL  4 //4.25V
#define CURRENT_LIMIT_LEVEL  11 //1073mA
#define VOLTAGE_LIMIT_VALUE 4250
#define VOLTAGE_LIMIT_DELTA 20

#define TRICKLEL   1
#define TRICKLEM   3
#define TRICKLEH   6
#define TRICKLEN   0  //disable trickle charging

#define IS_TRICKLECHARGING(state) ((state == STATE_TRICKLECHARGING_I) ||\
                                   (state == STATE_TRICKLECHARGING_II))
#define IS_NORMALCHARGING(state) (state == STATE_NORMALCHARGING)
                                    

//------------------------------------------------------------------------------
// Types
typedef enum
{
    STATE_TRICKLECHARGING_I,
    STATE_TRICKLECHARGING_II,
    STATE_NORMALCHARGING,
    STATE_DISCHARGING_WITHCHARGER,
    STATE_DISCHARGING_WITHOUTCHARGER,
    STATE_EXTERNAL, 
    STATE_OTHERS 
} CHARGING_STATE;
//------------------------------------------------------------------------------
// Global Variables



//------------------------------------------------------------------------------
// Local Variables


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        Batt_BATTLVoltage    =    2700;
static DWORD        Batt_BATTONVoltage   =    3200;
/*tatic DWORD        Batt_BATTHVoltage   =     3700;*/

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
static UINT32        percentage_charging = 0; 

static DWORD          totalCurrent = 0;
static UINT32         timesForCurrentCount = 0;

static UINT32         timesForBtteryVoltage = 0;

static CHARGING_STATE prev_state = STATE_OTHERS;
static CHARGING_STATE next_state = STATE_OTHERS;

//------------------------------------------------------------------------------
// 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);


    BSPBattAttach();
    
    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
        //Init_check = TRUE;
    }
   
    DEBUGMSG(ZONE_FUNCTION, (TEXT("-BatteryPDDPowerHandler\r\n")));
}


//-----------------------------------------------------------------------------
//
// Function: BatteryPDDGetStatus
//
// This routine obtains the most current battery/power status available on the platform.  It fills 
// in the structures pointed to by its parameters
//
// Parameters:
//      pstatus
//          [in] pointer to the battery status structure

⌨️ 快捷键说明

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