mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2026-01-12 19:04:59 +00:00
A temperature polling task is added to achieve temporal correction and also reduce the latency of reading temperature. Factor out sensor specific part to keep code clean. Signed-off-by: Vic Yang <victoryang@chromium.org> BUG=chrome-os-partner:7801 TEST=On link, 'temps' shows all temperature readings. Cover each sensor with hand and see object temperature rise. Compilation succeeded on bds/adv/daisy/discovery. Change-Id: I3c44c8b2e3ab2aa9ce640d3fc25e7fba56534b86
92 lines
1.8 KiB
C
92 lines
1.8 KiB
C
/* Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
* found in the LICENSE file.
|
|
*/
|
|
|
|
/* Temperature sensor module for Chrome EC */
|
|
|
|
#include "i2c.h"
|
|
#include "temp_sensor.h"
|
|
#include "uart.h"
|
|
#include "util.h"
|
|
#include "console.h"
|
|
#include "board.h"
|
|
#include "peci.h"
|
|
#include "tmp006.h"
|
|
#include "task.h"
|
|
#include "chip_temp_sensor.h"
|
|
|
|
/* Defined in board_temp_sensor.c. Must be in the same order as
|
|
* in enum temp_sensor_id.
|
|
*/
|
|
extern const struct temp_sensor_t temp_sensors[TEMP_SENSOR_COUNT];
|
|
|
|
int temp_sensor_read(enum temp_sensor_id id)
|
|
{
|
|
const struct temp_sensor_t *sensor;
|
|
|
|
if (id < 0 || id >= TEMP_SENSOR_COUNT)
|
|
return -1;
|
|
sensor = temp_sensors + id;
|
|
return sensor->read(sensor->idx);
|
|
}
|
|
|
|
void poll_all_sensors(void)
|
|
{
|
|
#ifdef CONFIG_TMP006
|
|
tmp006_poll();
|
|
#endif
|
|
#ifdef CONFIG_PECI
|
|
peci_temp_sensor_poll();
|
|
#endif
|
|
#ifdef CHIP_lm4
|
|
chip_temp_sensor_poll();
|
|
#endif
|
|
}
|
|
|
|
void temp_sensor_task(void)
|
|
{
|
|
while (1) {
|
|
poll_all_sensors();
|
|
/* Wait 1s */
|
|
task_wait_msg(1000000);
|
|
}
|
|
}
|
|
|
|
/*****************************************************************************/
|
|
/* Console commands */
|
|
|
|
static int command_temps(int argc, char **argv)
|
|
{
|
|
int i;
|
|
int rv = 0;
|
|
int t;
|
|
|
|
uart_puts("Reading temperature sensors...\n");
|
|
|
|
for (i = 0; i < TEMP_SENSOR_COUNT; ++i) {
|
|
uart_printf(" Temp from %s: ", temp_sensors[i].name);
|
|
t = temp_sensor_read(i);
|
|
if (t < 0) {
|
|
uart_printf("Error.\n\n");
|
|
rv = -1;
|
|
}
|
|
else
|
|
uart_printf("%d K = %d C\n\n", t, t - 273);
|
|
}
|
|
|
|
if (rv == -1)
|
|
return EC_ERROR_UNKNOWN;
|
|
|
|
return EC_SUCCESS;
|
|
}
|
|
DECLARE_CONSOLE_COMMAND(temps, command_temps);
|
|
|
|
/*****************************************************************************/
|
|
/* Initialization */
|
|
|
|
int temp_sensor_init(void)
|
|
{
|
|
return EC_SUCCESS;
|
|
}
|