diff options
author | Randall Spangler <rspangler@chromium.org> | 2012-10-23 12:21:07 -0700 |
---|---|---|
committer | Gerrit <chrome-bot@google.com> | 2012-10-24 10:09:20 -0700 |
commit | 935824d617bc138e10b1a56fd3adddc70c452825 (patch) | |
tree | ee329fdc12b6ac21a6d62125523101b2e7c134e5 | |
parent | 06a7508187ec38e25fe85e93fb1a38d112a764be (diff) | |
download | chrome-ec-935824d617bc138e10b1a56fd3adddc70c452825.tar.gz |
Cleanup: battery
Tidy code. No functional changes.
BUG=chrome-os-partner:15579
BRANCH=none
TEST=discharge battery, then plug AC in and make sure it charges
Change-Id: I4cff018940ecb665be96655d6722f74dd6674f6d
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/36359
-rw-r--r-- | common/battery_link.c | 74 | ||||
-rw-r--r-- | include/battery_pack.h | 28 |
2 files changed, 48 insertions, 54 deletions
diff --git a/common/battery_link.c b/common/battery_link.c index 2a524dea38..ba394eb51f 100644 --- a/common/battery_link.c +++ b/common/battery_link.c @@ -7,19 +7,14 @@ #include "battery_pack.h" -/* Design capacity +/* + * Design capacity * Battery capacity = 8200 mAh * 1C = 8200 mA */ -#define C 8200 -#define C_001 (int)(C * 0.01) -/* - * Common charging currents: - * #define C_01 (int)(C * 0.1) == 820mA - * #define C_02 (int)(C * 0.2) == 1640mA - * #define C_05 (int)(C * 0.5) == 4100mA - * #define C_07 (int)(C * 0.7) == 5740mA - */ +#define DESIGN_CAPACITY 8200 + +#define CELSIUS_TO_DECI_KELVIN(temp_c) ((temp_c) * 10 + 2731) enum { TEMP_RANGE_10, @@ -37,7 +32,8 @@ enum { VOLT_RANGE_MAX }; -/* Vendor provided charging method +/* + * Vendor provided charging method * temp : < 7.2V, 7.2V ~ 8.0V, 8.0V ~ 8.4V * - 0 ~ 10 : 0.8A 1.6A 0.8A * - 10 ~ 23 : 1.6A 4.0A 1.6A @@ -54,7 +50,8 @@ static const int const current_limit[TEMP_RANGE_MAX][VOLT_RANGE_MAX] = { }; static const struct battery_info info = { - /* Designed voltage + /* + * Design voltage * max = 8.4V * normal = 7.4V * min = 6.0V @@ -63,29 +60,20 @@ static const struct battery_info info = { .voltage_normal = 7400, .voltage_min = 6000, - /* Operation temperation range - * 0 <= T_charge <= 50 deg C - * -20 <= T_discharge <= 60 deg C - * - * The temperature values below should be deci-Kelvin + /* + * Operational temperature range + * 0 <= T_charge <= 50 deg C + * -20 <= T_discharge <= 60 deg C */ - .temp_charge_min = 0 * 10 + 2731, - .temp_charge_max = 50 * 10 + 2731, - .temp_discharge_min = -20 * 10 + 2731, - .temp_discharge_max = 60 * 10 + 2731, + .temp_charge_min = CELSIUS_TO_DECI_KELVIN(0), + .temp_charge_max = CELSIUS_TO_DECI_KELVIN(50), + .temp_discharge_min = CELSIUS_TO_DECI_KELVIN(-20), + .temp_discharge_max = CELSIUS_TO_DECI_KELVIN(60), - /* Pre-charge voltage and current - * I <= 0.01C - */ - .precharge_current = C_001, + /* Pre-charge current: I <= 0.01C */ + .precharge_current = (int)(DESIGN_CAPACITY * 0.01), }; -/* Convert Celsius degree to Deci Kelvin degree */ -static inline int celsius_to_deci_kelvin(int degree_c) -{ - return degree_c * 10 + 2731; -} - static inline void limit_value(int *val, int limit) { if (*val > limit) @@ -97,18 +85,16 @@ const struct battery_info *battery_get_info(void) return &info; } -/* Vendor provided parameters for battery charging */ void battery_vendor_params(struct batt_params *batt) { int *desired_current = &batt->desired_current; int temp_range, volt_range; - /* Hard limits - * - charging voltage < 8.4V - * - charging temperature range 0 ~ 45 degree Celcius - * */ + /* Limit charging voltage */ if (batt->desired_voltage > info.voltage_max) batt->desired_voltage = info.voltage_max; + + /* Don't charge if outside of allowable temperature range */ if (batt->temperature >= info.temp_charge_max || batt->temperature <= info.temp_charge_min) { batt->desired_voltage = 0; @@ -116,13 +102,13 @@ void battery_vendor_params(struct batt_params *batt) return; } - if (batt->temperature <= celsius_to_deci_kelvin(10)) + if (batt->temperature <= CELSIUS_TO_DECI_KELVIN(10)) temp_range = TEMP_RANGE_10; - else if (batt->temperature <= celsius_to_deci_kelvin(23)) + else if (batt->temperature <= CELSIUS_TO_DECI_KELVIN(23)) temp_range = TEMP_RANGE_23; - else if (batt->temperature <= celsius_to_deci_kelvin(35)) + else if (batt->temperature <= CELSIUS_TO_DECI_KELVIN(35)) temp_range = TEMP_RANGE_35; - else if (batt->temperature <= celsius_to_deci_kelvin(45)) + else if (batt->temperature <= CELSIUS_TO_DECI_KELVIN(45)) temp_range = TEMP_RANGE_45; else temp_range = TEMP_RANGE_50; @@ -137,11 +123,13 @@ void battery_vendor_params(struct batt_params *batt) limit_value(desired_current, current_limit[temp_range][volt_range]); #ifndef CONFIG_SLOW_PRECHARGE - /* Trickle charging and pre-charging current should be 0.01 C */ + /* Always request some current for trickle charging and pre-charging */ + /* + * TODO: (crosbug.com/p/15573) Shouldn't we only do this if desired + * current is non-zero? + */ if (*desired_current < info.precharge_current) *desired_current = info.precharge_current; #endif /* CONFIG_SLOW_PRECHARGE */ } - - diff --git a/include/battery_pack.h b/include/battery_pack.h index c119c673c0..10022ddac1 100644 --- a/include/battery_pack.h +++ b/include/battery_pack.h @@ -9,33 +9,39 @@ /* Battery parameters */ struct batt_params { - int temperature; - int state_of_charge; - int voltage; - int current; - int desired_voltage; - int desired_current; + int temperature; /* Temperature in 0.1 K */ + int state_of_charge; /* State of charge (percent, 0-100) */ + int voltage; /* Battery voltage (mV) */ + int current; /* Battery current (mA) */ + int desired_voltage; /* Charging voltage desired by battery (mV) */ + int desired_current; /* Charging current desired by battery (mA) */ }; /* Battery constants */ struct battery_info { - /* Design voltage */ + /* Design voltage in mV */ int voltage_max; int voltage_normal; int voltage_min; - /* Working temperature */ + /* Working temperature range in 0.1 K increments */ int temp_charge_min; int temp_charge_max; int temp_discharge_min; int temp_discharge_max; - /* Pre-charge */ + /* Pre-charge current in mA */ int precharge_current; }; -/* Vendor provided battery constants */ +/** + * Return vendor-provided battery constants. + */ const struct battery_info *battery_get_info(void); -/* Vendor provided parameters for battery charging */ +/** + * Modify battery parameters to match vendor charging profile. + * + * @param batt Battery parameters to modify + */ void battery_vendor_params(struct batt_params *batt); #endif |