mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2025-12-27 18:25:05 +00:00
Use macros for C <-> K conversions
This just replaces all the "X - 273", "Y + 273" stuff with a macro. BUG=none BRANCH=falco,peppy TEST=manual Run the EC console command "temps". It should print human-readable things. Change-Id: Icc4284c89fdbc0cd3b206a0faacf121973652a63 Signed-off-by: Bill Richardson <wfrichar@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/65005 Reviewed-by: Randall Spangler <rspangler@chromium.org>
This commit is contained in:
committed by
ChromeBot
parent
e98bde3fec
commit
6f8e276cc8
@@ -8,6 +8,7 @@
|
||||
#include "adc.h"
|
||||
#include "clock.h"
|
||||
#include "console.h"
|
||||
#include "common.h"
|
||||
#include "gpio.h"
|
||||
#include "hooks.h"
|
||||
#include "lm4_adc.h"
|
||||
@@ -161,7 +162,7 @@ DECLARE_IRQ(LM4_IRQ_ADC0_SS3, ss3_interrupt, 2);
|
||||
static int command_ectemp(int argc, char **argv)
|
||||
{
|
||||
int t = adc_read_channel(ADC_CH_EC_TEMP);
|
||||
ccprintf("EC temperature is %d K = %d C\n", t, t-273);
|
||||
ccprintf("EC temperature is %d K = %d C\n", t, K_TO_C(t));
|
||||
return EC_SUCCESS;
|
||||
}
|
||||
DECLARE_CONSOLE_COMMAND(ectemp, command_ectemp,
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
#include "lm4_adc.h"
|
||||
|
||||
/* Initialize temperature reading to a sane value (27 C) */
|
||||
static int last_val = 300;
|
||||
static int last_val = C_TO_K(27);
|
||||
|
||||
static void chip_temp_sensor_poll(void)
|
||||
{
|
||||
|
||||
@@ -136,7 +136,7 @@ static int command_peci_temp(int argc, char **argv)
|
||||
ccprintf("PECI error 0x%04x\n", LM4_PECI_M0D0 & 0xffff);
|
||||
return EC_ERROR_UNKNOWN;
|
||||
}
|
||||
ccprintf("CPU temp = %d K = %d C\n", t, t - 273);
|
||||
ccprintf("CPU temp = %d K = %d C\n", t, K_TO_C(t));
|
||||
return EC_SUCCESS;
|
||||
}
|
||||
DECLARE_CONSOLE_COMMAND(pecitemp, command_peci_temp,
|
||||
|
||||
@@ -59,28 +59,23 @@ static void enable_charging(int enable)
|
||||
gpio_set_level(GPIO_CHARGER_EN, enable);
|
||||
}
|
||||
|
||||
static int battery_temperature_celsius(int deci_k)
|
||||
{
|
||||
return (deci_k - 2731) / 10;
|
||||
}
|
||||
|
||||
static int battery_start_charging_range(int deci_k)
|
||||
{
|
||||
int8_t temp_c = battery_temperature_celsius(deci_k);
|
||||
int8_t temp_c = DECI_KELVIN_TO_CELSIUS(deci_k);
|
||||
return (temp_c >= bat_temp_ranges.start_charging_min_c &&
|
||||
temp_c < bat_temp_ranges.start_charging_max_c);
|
||||
}
|
||||
|
||||
static int battery_charging_range(int deci_k)
|
||||
{
|
||||
int8_t temp_c = battery_temperature_celsius(deci_k);
|
||||
int8_t temp_c = DECI_KELVIN_TO_CELSIUS(deci_k);
|
||||
return (temp_c >= bat_temp_ranges.charging_min_c &&
|
||||
temp_c < bat_temp_ranges.charging_max_c);
|
||||
}
|
||||
|
||||
static int battery_discharging_range(int deci_k)
|
||||
{
|
||||
int8_t temp_c = battery_temperature_celsius(deci_k);
|
||||
int8_t temp_c = DECI_KELVIN_TO_CELSIUS(deci_k);
|
||||
return (temp_c >= bat_temp_ranges.discharging_min_c &&
|
||||
temp_c < bat_temp_ranges.discharging_max_c);
|
||||
}
|
||||
@@ -260,7 +255,7 @@ static int calc_next_state(int state)
|
||||
} else if (!battery_charging_range(batt_temp)) {
|
||||
CPRINTF("[pmu] charging: temperature out of range "
|
||||
"%dC\n",
|
||||
battery_temperature_celsius(batt_temp));
|
||||
DECI_KELVIN_TO_CELSIUS(batt_temp));
|
||||
return ST_CHARGING_ERROR;
|
||||
}
|
||||
|
||||
@@ -342,7 +337,7 @@ static int calc_next_state(int state)
|
||||
if (!battery_discharging_range(batt_temp)) {
|
||||
CPRINTF("[pmu] discharging: temperature out of"
|
||||
"range %dC\n",
|
||||
battery_temperature_celsius(batt_temp));
|
||||
DECI_KELVIN_TO_CELSIUS(batt_temp));
|
||||
return system_off();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,7 +119,7 @@ static int command_temps(int argc, char **argv)
|
||||
|
||||
switch (rv) {
|
||||
case EC_SUCCESS:
|
||||
ccprintf("%d K = %d C\n", t, t - 273);
|
||||
ccprintf("%d K = %d C\n", t, K_TO_C(t));
|
||||
break;
|
||||
case EC_ERROR_NOT_POWERED:
|
||||
ccprintf("Not powered\n");
|
||||
|
||||
@@ -40,6 +40,6 @@ int g781_get_val(int idx, int *temp_ptr)
|
||||
temp_raw = ~(~temp_raw & 0xff) + 1;
|
||||
|
||||
/* Temperature from sensor is in degrees Celsius */
|
||||
*temp_ptr = temp_raw + 273;
|
||||
*temp_ptr = C_TO_K(temp_raw);
|
||||
return EC_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -9,9 +9,6 @@
|
||||
|
||||
#include "common.h"
|
||||
|
||||
#define CELSIUS_TO_DECI_KELVIN(temp_c) ((temp_c) * 10 + 2731)
|
||||
#define DECI_KELVIN_TO_CELSIUS(temp_dk) ((temp_dk - 2731) / 10)
|
||||
|
||||
/* Battery parameters */
|
||||
struct batt_params {
|
||||
int temperature; /* Temperature in 0.1 K */
|
||||
|
||||
@@ -44,6 +44,12 @@
|
||||
#define __packed __attribute__((packed))
|
||||
#endif
|
||||
|
||||
/* There isn't really a better place for this */
|
||||
#define C_TO_K(temp_c) ((temp_c) + 273)
|
||||
#define K_TO_C(temp_c) ((temp_c) - 273)
|
||||
#define CELSIUS_TO_DECI_KELVIN(temp_c) ((temp_c) * 10 + 2731)
|
||||
#define DECI_KELVIN_TO_CELSIUS(temp_dk) ((temp_dk - 2731) / 10)
|
||||
|
||||
/* Include top-level configuration file */
|
||||
#include "config.h"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user