|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
//***************************************************************************//
// BATTERY.C //
// //
// Copyright (c) ene Corporation 2003. //
// All rights reserved. //
// //
// EnE reserves the right to amend this code without notice at any time. //
// EnE assumes no responsibility for any errors appeared in the code, //
// and EnE disclaims any express or implied warranty, relating to sale //
// and/or use of this code including liability or warranties relating //
// to fitness for a particular purpose, or infringement of any patent, //
// copyright or other intellectual property right. //
// //
// Revision : 0.1 //
// //
//***************************************************************************//
#include <GLOBAV.H>
#include <OEMFUNC.H>
#include "oemport.h"
#include "oemio.h"
#include <stdio.h>
#define Battery2S_OverVolt 8400 //Max voltate 8.4V
#define Battery2S_UnderVolt 6300 //MIN voltage 6.3V
#define Battery2S_OverChgI 1850
#define Kelvin_0 2730 //273*10
#define Kelvin_55 3280 //(273+55)*10
#define Kelvin_65 3380 //(273+65)*10
extern unsigned char OEMIO(unsigned int Index);
extern unsigned char OEMO(unsigned int Index,unsigned int Index3);
extern unsigned char DelayCountFunction(unsigned int DelayC);
extern void Read_Smbus(unsigned char command,unsigned char address,unsigned char protocol,unsigned char length, unsigned char databuffer[]);
void CheckAdapterPlugInOut(void)
{ if(OEMIO(AC_IN)==TRUE)
{
bAdapterOnLine=1;
}
else
{
bAdapterOnLine=0;
ResetChargerSetting();
}
}
void CheckBatteryPlugInOut(void)
{
if(OEMIO(BATT_ID)==TRUE)
{
bBatteryOnLine=1;
}
else
{
bBatteryOnLine=0;
bBatterySMBusOK = 0;
OEMO(_CHG_LED,HIGH);
ResetChargerSetting();
}
}
void ResetChargerSetting(void)
{
// xCHARGER_MODE = 0x00;
CHARGER_STEP = 0x00;
CHARGER_TIME_HOUR = 0x00;
CHARGER_TIME_MIN = 0x00;
CHARGER_TIME_SEC = 0x00;
xBATTERY_FLAG = 0;
}
void BatteryInformationAccess(void)
{
if(bBatteryOnLine)
{
BATTERY_SCAN_STEP++;
}
else
{
return;
}
switch( BATTERY_SCAN_STEP)
{
case 0x01:
Read_Smbus(_CMD_BatteryStatus,_SMB_BatteryAddr,READ_WORD,0x02,BAT1_BatteryStatus);
break;
case 0x02:
Read_Smbus(_CMD_FullChargeCapacity,_SMB_BatteryAddr,READ_WORD,0x02,Max_Rating_Capacity); //here read LAST full Capacity as the MAX Rating
break;
case 0x03:
Read_Smbus(_CMD_Voltage,_SMB_BatteryAddr,READ_WORD,0x02,Current_Voltage);
break;
case 0x04:
Read_Smbus(_CMD_RemainingCapacity,_SMB_BatteryAddr,READ_WORD,0x02,Current_Capacity);
break;
case 0x05:
Read_Smbus(_CMD_RelativeStateOfCharge,_SMB_BatteryAddr,READ_WORD,0x01,&Batt_Percent);
// BEC_Batt_Percent=Batt_Percent;
break;
case 0x06:
Read_Smbus(_CMD_Temperature,_SMB_BatteryAddr,READ_WORD,0x02,Temperature);
break;
case 0x07:
Read_Smbus(_CMD_AverageCurrent,_SMB_BatteryAddr,READ_WORD,0x02,Average_Current_Rate);
break;
case 0x08:
Read_Smbus(_CMD_Voltage,_SMB_BatteryAddr,READ_WORD,0x02,Design_Voltage);
default:
BATTERY_SCAN_STEP = 0x00;
break;
}
}
void ProcessBatteryCharging(void)
{
if(bBatteryOnLine && bAdapterOnLine)
{
CHARGE_PROG_SCAN++;
}
else
{
return;
}
switch( CHARGE_PROG_SCAN)
{
case 0x01:
GetChargingParameter();
break;
case 0x02:
CheckBatteryChargingVoltage();
break;
case 0x03:
CheckBatteryChargingCurrent();
break;
case 0x04:
CheckBatteryCapacityPercent();
break;
case 0x05:
CheckBatteryChargingTemperature();
break;
case 0x06:
ChargingOutputControl();
default:
CHARGE_PROG_SCAN = 0x00;
break;
}
}
void GetChargingParameter(void)
{
// CheckAdapterPlugInOut();
// CheckBatteryPlugInOut();
switch( CHARGER_STEP)
{
case 0x00:
if(bBatteryOnLine && bAdapterOnLine)
{
CHARGER_STEP = 0x01;
}
break;
case 0x01:
if((Batt_Percent == 0)|| ((Current_Capacity[0] == 0)&&(Current_Capacity[1]==0)) //
|| ((Current_Voltage[1] == 0 )&&(Current_Voltage[0] == 0))
|| ((Temperature[1]==0)&& (Temperature[1]==0) )) //smbus is wrong, can not read smbus
{
Counter++;
if(Counter>=300) //if charge for 3 min, batt_percent==0, battery is corrupted.
{
bBatterySMBusOK= 0;
return;
}
else
{
// Counter=0;
bBatterySMBusOK = 1;
CHARGER_STEP = 0x02;
}
}
else
{
Counter=0;
bBatterySMBusOK = 1;
CHARGER_STEP = 0x02;
}
case 0x02:
// BAT1_BatteryStatus1=BAT1_BatteryStatus[0];
// BAT1_BatteryStatus2=BAT1_BatteryStatus[1];
// if((BAT1_BatteryStatus1&0x20)>0) //bit5 represent bat is fully charged
// {
// bSet_ChargerEnabled = 0;
// return;
// }
if(CHARGER_TIME_HOUR>7) //charge for 7Hour, failed
{
bSet_Chg_Overtime = 1;
return;
}
else
{
bSet_Chg_Overtime = 0;
CHARGER_STEP = 0x03;
}
break;
case 0x03:
if(CORE_PMFLAG_S3) //wakeup state, normal charge
{
bSet_FastCharge=0;
}
else //standby state, Fast Charge
{
bSet_FastCharge=1;
}
default:
CHARGER_STEP=0x00;
break;
}
} |
|