if voltage >3.75V ,and has charger,then charge to 3.9v
if voltage >3.75V ,and has no charger ,then power up、
if voltage >3.75V ,and has no charger ,then power up、
if voltage <3.75V ,and has charger, then charge to 3.9V
if voltage <3.75V ,and has no charger, then power down
void PrechargeCheck()
{
int avg_voltage = 0;
int counts = 0;
int i, j;
UINT8_T val;
printf(NULL, "TAHITI prcharge enable.");
avg_voltage = Get_Voltage();
if(avg_voltage < 3750){
if ( Detect_charging() ){
printf (NULL, "Charger is inserted !");
precharge_init();
}
else{
AddMessage((UINT8_T*) ("voltage is less than 3.5 and do not has charger .\0"));
do_powerdown();
}
}
else {
if ( Detect_charging() ){
printf (NULL, "Charger is inserted !");
precharge_init();
}
else{
AddMessage((UINT8_T*) ("no charger ,power up .\0"));
return;
}
}
do{
avg_voltage = Get_Voltage();
if ( Detect_charging() == 0 ){
do_powerdown();
}
printf(NULL, "voltage = %d. ", avg_voltage );
for(i = 0; i < 5 ; i++){
for(j = 0; j < 1000; j++){
Delay(1000);
}
}
}while( avg_voltage < 3900 );
precharge_off();
}