summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRandall Spangler <rspangler@chromium.org>2012-10-26 16:33:30 -0700
committerGerrit <chrome-bot@google.com>2012-11-01 12:45:22 -0700
commitd83f42bdc8b61773efc17e0194e5abe26109128d (patch)
treee8351b0f756dff9aac9d6b919037c1f3b283c644
parent742ec5a1ff3a058bf6f1753bafde9e3e57d44f58 (diff)
downloadchrome-ec-d83f42bdc8b61773efc17e0194e5abe26109128d.tar.gz
Switch temp sensor polling to use hooks instead of task
This reduces memory / code size, and gets rid of ifdefs in temp_sensor.c. BUG=chrome-os-partner:15714 BRANCH=none TEST=boot system and run 'ectool temps all' every few seconds - ectool temps all The numbers should update over time. Change-Id: Idaac7e6e4cbc1d6689f5d3b607c623a5cc536a4f Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/36940
-rw-r--r--board/link/board.h1
-rw-r--r--board/link/board_temp_sensor.c2
-rw-r--r--board/link/ec.tasklist1
-rw-r--r--chip/lm4/build.mk3
-rw-r--r--chip/lm4/chip_temp_sensor.c7
-rw-r--r--chip/lm4/peci.c66
-rw-r--r--common/build.mk2
-rw-r--r--common/temp_sensor.c34
-rw-r--r--common/tmp006.c20
-rw-r--r--include/chip_temp_sensor.h5
-rw-r--r--include/peci.h11
-rw-r--r--include/temp_sensor.h2
-rw-r--r--include/tmp006.h6
-rw-r--r--test/thermal.tasklist1
14 files changed, 59 insertions, 102 deletions
diff --git a/board/link/board.h b/board/link/board.h
index 9663365429..0b1ab851ca 100644
--- a/board/link/board.h
+++ b/board/link/board.h
@@ -25,6 +25,7 @@
#define CONFIG_POWER_LED
#define CONFIG_PWM
#define CONFIG_TASK_PROFILING
+#define CONFIG_TEMP_SENSOR
#define CONFIG_TMP006
#define CONFIG_USB_CHARGE
diff --git a/board/link/board_temp_sensor.c b/board/link/board_temp_sensor.c
index 304cc254b0..3427461469 100644
--- a/board/link/board_temp_sensor.c
+++ b/board/link/board_temp_sensor.c
@@ -35,7 +35,7 @@ const struct temp_sensor_t temp_sensors[TEMP_SENSOR_COUNT] = {
{"I2C-Charger D-Die", TEMP_SENSOR_TYPE_BOARD, tmp006_get_val, 6, 7},
{"I2C-Charger D-Object", TEMP_SENSOR_TYPE_CASE, tmp006_get_val, 7, 7},
#endif
-#ifdef CONFIG_TASK_TEMPSENSOR
+#ifdef CONFIG_ADC
{"ECInternal", TEMP_SENSOR_TYPE_BOARD, chip_temp_sensor_get_val, 0, 4},
#endif
#ifdef CONFIG_PECI
diff --git a/board/link/ec.tasklist b/board/link/ec.tasklist
index 5b2c3ba956..51ec29cdd6 100644
--- a/board/link/ec.tasklist
+++ b/board/link/ec.tasklist
@@ -19,7 +19,6 @@
TASK(VBOOTHASH, vboot_hash_task, NULL, LARGER_TASK_STACK_SIZE) \
TASK(LIGHTBAR, lightbar_task, NULL, TASK_STACK_SIZE) \
TASK(CHARGER, charge_state_machine_task, NULL, TASK_STACK_SIZE) \
- TASK(TEMPSENSOR, temp_sensor_task, NULL, TASK_STACK_SIZE) \
TASK(THERMAL, thermal_task, NULL, TASK_STACK_SIZE) \
TASK(TYPEMATIC, keyboard_typematic_task, NULL, TASK_STACK_SIZE) \
TASK(X86POWER, x86_power_task, NULL, TASK_STACK_SIZE) \
diff --git a/chip/lm4/build.mk b/chip/lm4/build.mk
index b2e99b20b4..83a97b3ba5 100644
--- a/chip/lm4/build.mk
+++ b/chip/lm4/build.mk
@@ -13,7 +13,7 @@ CORE:=cortex-m
chip-y=clock.o gpio.o hwtimer.o jtag.o system.o uart.o
# Optional chip modules
-chip-$(CONFIG_ADC)+=adc.o
+chip-$(CONFIG_ADC)+=adc.o chip_temp_sensor.o
chip-$(CONFIG_EEPROM)+=eeprom.o
chip-$(CONFIG_FLASH)+=flash.o
chip-$(CONFIG_I2C)+=i2c.o
@@ -24,5 +24,4 @@ chip-$(CONFIG_PWM)+=pwm.o
chip-$(CONFIG_SPI)+=spi.o
chip-$(CONFIG_TASK_KEYSCAN)+=keyboard_scan.o keyboard_scan_stub.o
chip-$(CONFIG_TASK_SWITCH)+=switch.o
-chip-$(CONFIG_TASK_TEMPSENSOR)+=chip_temp_sensor.o
chip-$(CONFIG_WATCHDOG)+=watchdog.o
diff --git a/chip/lm4/chip_temp_sensor.c b/chip/lm4/chip_temp_sensor.c
index 077806ba73..2377806023 100644
--- a/chip/lm4/chip_temp_sensor.c
+++ b/chip/lm4/chip_temp_sensor.c
@@ -7,18 +7,17 @@
#include "adc.h"
#include "common.h"
+#include "hooks.h"
#include "lm4_adc.h"
-#include "temp_sensor.h"
/* Initialize temperature reading to a sane value (27 C) */
static int last_val = 300;
-int chip_temp_sensor_poll(void)
+static void chip_temp_sensor_poll(void)
{
last_val = adc_read_channel(ADC_CH_EC_TEMP);
-
- return EC_SUCCESS;
}
+DECLARE_HOOK(HOOK_SECOND, chip_temp_sensor_poll, HOOK_PRIO_DEFAULT);
int chip_temp_sensor_get_val(int idx, int *temp_ptr)
{
diff --git a/chip/lm4/peci.c b/chip/lm4/peci.c
index ff56f7ec47..b547165b49 100644
--- a/chip/lm4/peci.c
+++ b/chip/lm4/peci.c
@@ -40,7 +40,9 @@
static int temp_vals[TEMP_AVG_LENGTH];
static int temp_idx = 0;
-/* Configures the GPIOs for the PECI module. */
+/**
+ * Configure the GPIOs for the PECI module.
+ */
static void configure_gpios(void)
{
/* PJ6 alternate function 1 = PECI Tx */
@@ -50,7 +52,6 @@ static void configure_gpios(void)
LM4_GPIO_DEN(LM4_GPIO_J) &= ~0x80;
}
-
int peci_get_cpu_temp(void)
{
int v = LM4_PECI_M0D0 & 0xffff;
@@ -61,15 +62,6 @@ int peci_get_cpu_temp(void)
return v >> 6;
}
-
-int peci_temp_sensor_poll(void)
-{
- temp_vals[temp_idx] = peci_get_cpu_temp();
- temp_idx = (temp_idx + 1) & (TEMP_AVG_LENGTH - 1);
- return EC_SUCCESS;
-}
-
-
int peci_temp_sensor_get_val(int idx, int *temp_ptr)
{
int sum = 0;
@@ -93,6 +85,13 @@ int peci_temp_sensor_get_val(int idx, int *temp_ptr)
return EC_SUCCESS;
}
+static void peci_temp_sensor_poll(void)
+{
+ temp_vals[temp_idx] = peci_get_cpu_temp();
+ temp_idx = (temp_idx + 1) & (TEMP_AVG_LENGTH - 1);
+}
+DECLARE_HOOK(HOOK_TICK, peci_temp_sensor_poll, HOOK_PRIO_DEFAULT);
+
static void peci_freq_changed(void)
{
int freq = clock_get_freq();
@@ -101,8 +100,10 @@ static void peci_freq_changed(void)
/* Disable polling while reconfiguring */
LM4_PECI_CTL = 0;
- /* Calculate baud setting from desired rate, compensating for internal
- * and external delays. */
+ /*
+ * Calculate baud setting from desired rate, compensating for internal
+ * and external delays.
+ */
baud = freq / (4 * PECI_BAUD_RATE) - 2;
baud -= (freq / 1000000) * (PECI_TD_FET_NS + PECI_TD_INT_NS) / 1000;
@@ -117,27 +118,6 @@ static void peci_freq_changed(void)
}
DECLARE_HOOK(HOOK_FREQ_CHANGE, peci_freq_changed, HOOK_PRIO_DEFAULT - 1);
-/*****************************************************************************/
-/* Console commands */
-
-static int command_peci_temp(int argc, char **argv)
-{
- int t = peci_get_cpu_temp();
- if (t == -1) {
- 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);
- return EC_SUCCESS;
-}
-DECLARE_CONSOLE_COMMAND(pecitemp, command_peci_temp,
- NULL,
- "Print CPU temperature",
- NULL);
-
-/*****************************************************************************/
-/* Initialization */
-
static void peci_init(void)
{
volatile uint32_t scratch __attribute__((unused));
@@ -158,3 +138,21 @@ static void peci_init(void)
temp_vals[i] = 300; /* 27 C */
}
DECLARE_HOOK(HOOK_INIT, peci_init, HOOK_PRIO_DEFAULT);
+
+/*****************************************************************************/
+/* Console commands */
+
+static int command_peci_temp(int argc, char **argv)
+{
+ int t = peci_get_cpu_temp();
+ if (t == -1) {
+ 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);
+ return EC_SUCCESS;
+}
+DECLARE_CONSOLE_COMMAND(pecitemp, command_peci_temp,
+ NULL,
+ "Print CPU temperature",
+ NULL);
diff --git a/common/build.mk b/common/build.mk
index 45c3ce636f..a115d84651 100644
--- a/common/build.mk
+++ b/common/build.mk
@@ -28,9 +28,9 @@ common-$(CONFIG_TASK_GAIAPOWER)+=gaia_power.o
common-$(CONFIG_TASK_HOSTCMD)+=host_command.o host_event_commands.o
common-$(CONFIG_TASK_I8042CMD)+=i8042.o keyboard.o
common-$(CONFIG_TASK_LIGHTBAR)+=lightbar.o
-common-$(CONFIG_TASK_TEMPSENSOR)+=temp_sensor.o
common-$(CONFIG_TASK_THERMAL)+=thermal.o
common-$(CONFIG_TASK_VBOOTHASH)+=sha256.o vboot_hash.o
common-$(CONFIG_TASK_X86POWER)+=x86_power.o
+common-$(CONFIG_TEMP_SENSOR)+=temp_sensor.o
common-$(CONFIG_TMP006)+=tmp006.o
common-$(CONFIG_USB_CHARGE)+=usb_charge.o
diff --git a/common/temp_sensor.c b/common/temp_sensor.c
index 6cfbb8cfee..3079e3b2a8 100644
--- a/common/temp_sensor.c
+++ b/common/temp_sensor.c
@@ -11,6 +11,7 @@
#include "console.h"
#include "gpio.h"
#include "i2c.h"
+#include "hooks.h"
#include "host_command.h"
#include "peci.h"
#include "task.h"
@@ -34,25 +35,6 @@ int temp_sensor_read(enum temp_sensor_id id, int *temp_ptr)
return sensor->read(sensor->idx, temp_ptr);
}
-void poll_slow_sensors(void)
-{
- /* Poll every second */
-#ifdef CONFIG_TMP006
- tmp006_poll();
-#endif
-#ifdef CHIP_lm4
- chip_temp_sensor_poll();
-#endif
-}
-
-static void poll_fast_sensors(void)
-{
- /* Poll every 1/4 second */
-#ifdef CONFIG_PECI
- peci_temp_sensor_poll();
-#endif
-}
-
static void update_mapped_memory(void)
{
int i, t;
@@ -84,8 +66,10 @@ static void update_mapped_memory(void)
}
}
}
+/* Run after other tick tasks, so sensors will have updated first. */
+DECLARE_HOOK(HOOK_SECOND, update_mapped_memory, HOOK_PRIO_DEFAULT + 1);
-void temp_sensor_task(void)
+static void temp_sensor_init(void)
{
int i;
uint8_t *base, *base_b;
@@ -116,16 +100,8 @@ void temp_sensor_task(void)
/* Temp sensor data is present, with B range supported. */
*host_get_memmap(EC_MEMMAP_THERMAL_VERSION) = 2;
-
- while (1) {
- for (i = 0; i < 4; ++i) {
- msleep(250);
- poll_fast_sensors();
- }
- poll_slow_sensors();
- update_mapped_memory();
- }
}
+DECLARE_HOOK(HOOK_INIT, temp_sensor_init, HOOK_PRIO_DEFAULT);
/*****************************************************************************/
/* Console commands */
diff --git a/common/tmp006.c b/common/tmp006.c
index 67d9d41af3..b4a1a8b967 100644
--- a/common/tmp006.c
+++ b/common/tmp006.c
@@ -232,23 +232,17 @@ int tmp006_get_val(int idx, int *temp_ptr)
return tmp006_read_object_temp(tdata, temp_ptr);
}
-int tmp006_poll(void)
+/*****************************************************************************/
+/* Hooks */
+
+static void tmp006_poll(void)
{
int i;
- int rv;
- int rv1 = EC_SUCCESS;
- for (i = 0; i < TMP006_COUNT; ++i) {
- rv = tmp006_poll_sensor(i);
- if (rv != EC_SUCCESS)
- rv1 = rv;
- }
-
- return rv1;
+ for (i = 0; i < TMP006_COUNT; ++i)
+ tmp006_poll_sensor(i);
}
-
-/*****************************************************************************/
-/* Hooks */
+DECLARE_HOOK(HOOK_SECOND, tmp006_poll, HOOK_PRIO_DEFAULT);
static void tmp006_init(void)
{
diff --git a/include/chip_temp_sensor.h b/include/chip_temp_sensor.h
index c7ca1e1caf..9b5f126d44 100644
--- a/include/chip_temp_sensor.h
+++ b/include/chip_temp_sensor.h
@@ -8,11 +8,6 @@
#ifndef __CROS_EC_CHIP_TEMP_SENSOR_H
#define __CROS_EC_CHIP_TEMP_SENSOR_H
-struct temp_sensor_t;
-
-/* Temperature polling function. */
-int chip_temp_sensor_poll(void);
-
/**
* Get the last polled value of the sensor.
*
diff --git a/include/peci.h b/include/peci.h
index 4776002a42..c3bb4d62b2 100644
--- a/include/peci.h
+++ b/include/peci.h
@@ -10,10 +10,14 @@
#include "common.h"
-/* Return the current CPU temperature in degrees K, or -1 if error.
+/**
+ * Get the current CPU temperature.
*
* Note that the PECI interface is currently a little flaky; if you get an
- * error, retry a bit later. */
+ * error, retry a bit later.
+ *
+ * @return the CPU temperature in degrees K, or -1 if error.
+ */
int peci_get_cpu_temp(void);
/**
@@ -26,7 +30,4 @@ int peci_get_cpu_temp(void);
*/
int peci_temp_sensor_get_val(int idx, int *temp_ptr);
-/* Temperature polling of CPU temperature sensor via PECI. */
-int peci_temp_sensor_poll(void);
-
#endif /* __CROS_EC_PECI_H */
diff --git a/include/temp_sensor.h b/include/temp_sensor.h
index 687618fa63..6ef71952bf 100644
--- a/include/temp_sensor.h
+++ b/include/temp_sensor.h
@@ -41,11 +41,13 @@ struct temp_sensor_t {
int action_delay_sec;
};
+#ifdef CONFIG_TEMP_SENSOR
/*
* 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];
+#endif
/**
* Get the most recently measured temperature for the sensor.
diff --git a/include/tmp006.h b/include/tmp006.h
index 3a1c47f49c..78f8e0044a 100644
--- a/include/tmp006.h
+++ b/include/tmp006.h
@@ -18,12 +18,6 @@ struct tmp006_t {
};
/**
- * Poll all TMP006 sensors.
- *
- * @return 0 if successful, non-zero if error. */
-int tmp006_poll(void);
-
-/**
* Get the last polled value of a sensor.
*
* @param idx Index to read. The low bit in idx indicates whether
diff --git a/test/thermal.tasklist b/test/thermal.tasklist
index fa92984118..ad112f814a 100644
--- a/test/thermal.tasklist
+++ b/test/thermal.tasklist
@@ -17,7 +17,6 @@
#define CONFIG_TASK_LIST \
TASK(TICK, hook_task, NULL, TASK_STACK_SIZE) \
TASK(VBOOTHASH, vboot_hash_task, NULL, TASK_STACK_SIZE) \
- TASK(TEMPSENSOR, temp_sensor_task, NULL, TASK_STACK_SIZE) \
TASK(THERMAL, thermal_task, NULL, TASK_STACK_SIZE) \
TASK(X86POWER, x86_power_task, NULL, TASK_STACK_SIZE) \
TASK(HOSTCMD, host_command_task, NULL, TASK_STACK_SIZE) \