Charger Battery Call Mode feature

Keywords: Android less Mobile

origin

user calls with a charger plugged in.
For the sake of safety,
Avoid damage to the cell phone caused by the charger at this time, indirectly causing damage to the user.
With this feature,

When battery voltage Vbat > 4V, it is not charged.
When battery voltage Vbat < 3.8V, it needs to be charged.

24 #define V_CC2TOPOFF_THRES               4000
...
2616 #if defined(STOP_CHARGING_IN_TAKLING)
2617 static PMU_STATUS mt_battery_CheckCallState(void)
2618 {
2619     PMU_STATUS status = PMU_STATUS_OK;
2620 
2625     if ((g_call_state == CALL_ACTIVE) && (battery_meter_get_battery_voltage(KAL_TRUE) > V_CC2TOPOFF_THRES))
2628     status = PMU_STATUS_FAIL;
2629 
2630     return status;
2631 }
2632 #endif
2484 static void mt_battery_CheckBatteryStatus(void)
2485 {
...
2707 #if defined(STOP_CHARGING_IN_TAKLING)
2708         if (mt_battery_CheckCallState() != PMU_STATUS_OK) {
2709                 BMT_status.bat_charging_state = CHR_HOLD;
2710                 return;
2711         }
2712 #endif
...
2888 }
1338 void mt_battery_charging_algorithm(void)
1339 {
1340         battery_charging_control(CHARGING_CMD_RESET_WATCH_DOG_TIMER, NULL);
1341 
1342         /* Generate AICR upper bound by AICL */
1343         if (!mtk_is_pep_series_connect()) {
1344                 battery_charging_control(CHARGING_CMD_RUN_AICL,
1345                         &g_aicr_upper_bound);
1346         }
1347 
1348         mtk_pep20_check_charger();
1349         mtk_pep_check_charger();
1350         switch (BMT_status.bat_charging_state) {
1351         case CHR_PRE:
1352                 BAT_PreChargeModeAction();
1353                 break;
1354 
1355         case CHR_CC:
1356                 BAT_ConstantCurrentModeAction();
1357                 break;
1358 
1359         case CHR_BATFULL:
1360                 BAT_BatteryFullAction();
1361                 break;
1362 
1363         case CHR_HOLD:
1364                 BAT_BatteryHoldAction();
1365                 break;
1366 
1367         case CHR_ERROR:
1368                 BAT_BatteryStatusFailAction();
1369                 break;
1370         }
1371 
1372         battery_charging_control(CHARGING_CMD_DUMP_REGISTER, NULL);
1373 }
1250 #define TALKING_RECHARGE_VOLTAGE 3800
...
1253 PMU_STATUS BAT_BatteryHoldAction(void)
1254 {
1255         unsigned int charging_enable;
1256 
1257         battery_log(BAT_LOG_CRTI, "[BATTERY] Hold mode !!\n\r");
1259
1263         if (battery_meter_get_battery_voltage(KAL_TRUE) < TALKING_RECHARGE_VOLTAGE ||
1264                 g_call_state == CALL_IDLE ||
1266                 xxxxx) {
1271                 BMT_status.bat_charging_state = CHR_CC;
1272                 battery_log(BAT_LOG_CRTI, "[BATTERY] Exit Hold mode and Enter CC mode !!\n\r");
1273         }
1274 
1275         /*  Disable charger */
1276         charging_enable = KAL_FALSE;
1277         battery_charging_control(CHARGING_CMD_ENABLE, &charging_enable);
1278 
1279         return PMU_STATUS_OK;
1280 }

Commentary 1

At first, I had some doubts about BAT_BatteryHoldAction().
Why not enable charging when vbat is less than TALKING_RECHARGE_VOLTAGE?

1263         if (battery_meter_get_battery_voltage(KAL_TRUE) < TALKING_RECHARGE_VOLTAGE ||
1264                 g_call_state == CALL_IDLE ||
1266                 xxxxx ) {
...
...                  enable_charging
...
1273         }

If in the judgment directly enable charging (as above),
There will be a situation.
There are two types of mobile phone usage that may enter hold action.
If one of them does not need to enter hold, the enabling charging condition, such as xxxx, will be turned on.
It happens to keep enabling charging.
Losing hold,
The correct process should be
Set BMT_status.bat_charging_state = CHR_CC; let it enter the normal process in the next cycle, check whether to enable charging,
And at the bottom of BAT_BatteryHoldAction(), disablecharge
that is
As long as hold occurs, that is disable charging.
Let it check again in the next cycle.

Commentary 2

Why disable charging at the bottom
Is it not necessary to enable charging when vbat is less than TALKING_RECHARGE_VOLTAGE?

It turned out to be

If Vbat is larger than V_CC2TOPOFF_THRES,
Set BMT_status.bat_charging_state = CHR_HOLD,
Execute BAT_BatteryHoldAction()

In BAT_BatteryHoldAction(), vbat is greater or less than TALKING_RECHARGE_VOLTAGE.
They all disable charging.

however
Set BMT_status.bat_charging_state = CHR_CC;
Let it enter CC charging the next time BAT_thread s are executed.
In this round, disable charging first.

and
PMU_ChargerStruct BMT_status; is a global variable.
BMT_status.bat_charging_state will always record state
So CHR_HOLD will always be maintained (unless set to BMT_status.bat_charging_state = CHR_CC)
Enter BAT_BatteryHoldAction().

Posted by oyinlola on Mon, 11 Feb 2019 07:27:19 -0800