Initialize temperature reading buffer to sane values

This is to prevent temperature value being read before the first time we
poll sensors causes unexpected error.

BUG=chrome-os-partner:12614
TEST="sysjump RW" and then "temps" immediately. Check all temperature
     readings are near 300 K.

Change-Id: I5c84d9696b4876fdfcf14c3a416cbc09c040d4ee
Signed-off-by: Vic Yang <victoryang@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/30138
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
This commit is contained in:
Vic Yang
2012-08-14 12:49:30 +08:00
committed by Gerrit
parent 847a3feca6
commit dc4ee57307
4 changed files with 57 additions and 5 deletions

View File

@@ -7,6 +7,7 @@
#include "adc.h"
#include "board.h"
#include "hooks.h"
#include "temp_sensor.h"
static int last_val;
@@ -22,3 +23,11 @@ int chip_temp_sensor_get_val(int idx)
{
return last_val;
}
static int chip_temp_sensor_init(void)
{
/* Initialize temperature reading to a sane value. */
last_val = 300; /* 27 C */
return EC_SUCCESS;
}
DECLARE_HOOK(HOOK_INIT, chip_temp_sensor_init, HOOK_PRIO_DEFAULT);

View File

@@ -139,6 +139,7 @@ DECLARE_CONSOLE_COMMAND(pecitemp, command_peci_temp,
static int peci_init(void)
{
volatile uint32_t scratch __attribute__((unused));
int i;
/* Enable the PECI module and delay a few clocks */
LM4_SYSTEM_RCGCPECI = 1;
@@ -150,6 +151,10 @@ static int peci_init(void)
/* Set initial clock frequency */
peci_freq_changed();
/* Initialize temperature reading buffer to a sane value. */
for (i = 0; i < TEMP_AVG_LENGTH; ++i)
temp_vals[i] = 300; /* 27 C */
return EC_SUCCESS;
}
DECLARE_HOOK(HOOK_INIT, peci_init, HOOK_PRIO_DEFAULT);

View File

@@ -106,12 +106,30 @@ static void update_mapped_memory(void)
void temp_sensor_task(void)
{
int i;
uint8_t *base, *base_b;
/* Initialize memory-mapped data */
memset(host_get_memmap(EC_MEMMAP_TEMP_SENSOR),
EC_TEMP_SENSOR_NOT_PRESENT, EC_TEMP_SENSOR_ENTRIES);
memset(host_get_memmap(EC_MEMMAP_TEMP_SENSOR_B),
EC_TEMP_SENSOR_NOT_PRESENT, EC_TEMP_SENSOR_B_ENTRIES);
/*
* Initialize memory-mapped data. We initialize valid sensors to 23 C
* so that if a temperature value is read before we actually poll the
* sensors, we don't end up with an insane value.
*/
base = host_get_memmap(EC_MEMMAP_TEMP_SENSOR);
base_b = host_get_memmap(EC_MEMMAP_TEMP_SENSOR_B);
for (i = 0; i < TEMP_SENSOR_COUNT; ++i) {
if (i < EC_TEMP_SENSOR_ENTRIES)
base[i] = 0x60; /* 23 C */
else
base_b[i - EC_TEMP_SENSOR_ENTRIES] = 0x60; /* 23 C */
}
/* Set the rest of memory region to SENSOR_NOT_PRESENT */
for (; i < EC_TEMP_SENSOR_ENTRIES + EC_TEMP_SENSOR_B_ENTRIES; ++i) {
if (i < EC_TEMP_SENSOR_ENTRIES)
base[i] = EC_TEMP_SENSOR_NOT_PRESENT;
else
base_b[i - EC_TEMP_SENSOR_ENTRIES] =
EC_TEMP_SENSOR_NOT_PRESENT;
}
/* Temp sensor data is present, with B range supported. */
*host_get_memmap(EC_MEMMAP_THERMAL_VERSION) = 2;

View File

@@ -10,6 +10,7 @@
#include "console.h"
#include "fpu.h"
#include "gpio.h"
#include "hooks.h"
#include "i2c.h"
#include "math.h"
#include "task.h"
@@ -273,6 +274,25 @@ int tmp006_poll(void)
return rv1;
}
static int tmp006_init(void)
{
int i, j;
/*
* Set temperature value to 27 C and we will update it later when
* polled by temperature sensor module.
*/
for (i = 0; i < TMP006_COUNT; ++i) {
for (j = 0; j < 4; ++j)
tmp006_data[i].t[j] = 30000; /* 27 C */
tmp006_data[i].tidx = 0;
/* TODO(victoryang): Default value for V? */
}
return EC_SUCCESS;
}
DECLARE_HOOK(HOOK_INIT, tmp006_init, HOOK_PRIO_DEFAULT);
/*****************************************************************************/
/* Console commands */