summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGwendal Grignou <gwendal@chromium.org>2015-11-09 15:52:50 -0800
committerchrome-bot <chrome-bot@chromium.org>2015-11-13 01:00:39 -0800
commit66a72f0b6e379edc3a2a52fa2e9b0f66c557a447 (patch)
treecea7dc81e2b5b747b40af326ec0f2631976cf8f4
parent0922cc81ce22204264a2b96cec4bf2195939e516 (diff)
downloadchrome-ec-66a72f0b6e379edc3a2a52fa2e9b0f66c557a447.tar.gz
motion: minium interval between motion task now a variable
On Ryu EVT2, where sensors share a 100kb i2c bus with other device, when the sensors set to their maximal frequency and sampling interval set to 5ms, the power management task would wait forever for the i2c lock. Increase the minimal amount of time the task can wait from 3ms to 8ms in that case. This is not an issue for Ryu PVT where the sensors are on a separate SPI bus. However, on EVT, when setting the accelerometer/gyro over 125Hz, EC won't be able to deliver the data in non-batched mode. BRANCH=smaug BUG=b:25510300 TEST=Without this change, an evt2 board would crash when plugging/unplugging the charger while the sensors are set with: echo 200000 > iio:device0/frequency # Accel echo 5 > iio:device0/sampling_frequency echo 200000 > iio:device1/frequency # Gyro echo 25000 > iio:device2/frequency # Mag Change-Id: Idb30da9ab8da61284388db73365c37be3a250dec Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/311755 Reviewed-by: Alec Berg <alecaberg@chromium.org>
-rw-r--r--board/ryu/board.c6
-rw-r--r--common/motion_sense.c10
-rw-r--r--include/config.h6
-rw-r--r--include/motion_sense.h7
4 files changed, 21 insertions, 8 deletions
diff --git a/board/ryu/board.c b/board/ryu/board.c
index 44cc2db069..a6712aa21b 100644
--- a/board/ryu/board.c
+++ b/board/ryu/board.c
@@ -197,6 +197,12 @@ static void board_init(void)
CPRINTS("Board using SPI sensors");
} else { /* I2C sensors on rev v6/7/8 */
CPRINTS("Board using I2C sensors");
+ /*
+ * On EVT2, when the sensors are on the same bus as other
+ * sensors, motion task would not leave enough time for
+ * processing as soon as its frequency is around ~200Hz.
+ */
+ motion_min_interval = 8 * MSEC;
}
}
DECLARE_HOOK(HOOK_INIT, board_init, HOOK_PRIO_DEFAULT);
diff --git a/common/motion_sense.c b/common/motion_sense.c
index c72165bc7e..7602d62334 100644
--- a/common/motion_sense.c
+++ b/common/motion_sense.c
@@ -39,6 +39,8 @@ test_export_static unsigned int motion_interval;
/* Delay between FIFO interruption. */
static unsigned int motion_int_interval;
+/* Minimum time in between running motion sense task loop. */
+unsigned int motion_min_interval = CONFIG_MOTION_MIN_SENSE_WAIT_TIME * MSEC;
#ifdef CONFIG_CMD_ACCEL_INFO
static int accel_disp;
#endif
@@ -769,8 +771,8 @@ void motion_sense_task(void)
* Guarantee some minimum delay to allow other lower
* priority tasks to run.
*/
- if (wait_us < MIN_MOTION_SENSE_WAIT_TIME)
- wait_us = MIN_MOTION_SENSE_WAIT_TIME;
+ if (wait_us < motion_min_interval)
+ wait_us = motion_min_interval;
} else {
wait_us = -1;
}
@@ -914,7 +916,7 @@ static int host_cmd_motion_sense(struct host_cmd_handler_args *args)
else
sensor->config[SENSOR_CONFIG_AP].ec_rate =
MAX(in->ec_rate.data,
- MIN_MOTION_SENSE_WAIT_TIME / MSEC);
+ motion_min_interval / MSEC);
/* Bound the new sampling rate. */
motion_sense_set_motion_intervals();
@@ -1327,7 +1329,7 @@ static int command_accel_read_xyz(int argc, char **argv)
ccprintf("vector not ready\n");
ccprintf("Last calib. data %d: %-5d %-5d %-5d\n",
id, sensor->xyz[X], sensor->xyz[Y], sensor->xyz[Z]);
- task_wait_event(MIN_MOTION_SENSE_WAIT_TIME);
+ task_wait_event(motion_min_interval);
}
return EC_SUCCESS;
}
diff --git a/include/config.h b/include/config.h
index c396517a4a..f0effc425b 100644
--- a/include/config.h
+++ b/include/config.h
@@ -966,6 +966,12 @@
/* H2RAM Host LPC I/O base memory address */
#undef CONFIG_H2RAM_HOST_LPC_IO_BASE
+/*
+ * Define the minimal amount of time (in ms) betwen running motion sense task
+ * loop.
+ */
+#define CONFIG_MOTION_MIN_SENSE_WAIT_TIME 3
+
/*****************************************************************************/
/*
* Support the host asking the EC about the status of the most recent host
diff --git a/include/motion_sense.h b/include/motion_sense.h
index 26ba029c96..7dd9fd747d 100644
--- a/include/motion_sense.h
+++ b/include/motion_sense.h
@@ -42,10 +42,6 @@ enum sensor_config {
/* Next 8 events for sensor interrupt lines */
#define TASK_EVENT_MOTION_INTERRUPT_MASK (0xff << 2)
-/* Minimum time in between running motion sense task loop. */
-#define MIN_MOTION_SENSE_WAIT_TIME (3 * MSEC)
-#define MAX_MOTION_SENSE_WAIT_TIME (60000 * MSEC)
-
#define ROUND_UP_FLAG (1 << 31)
#define BASE_ODR(_odr) ((_odr) & ~ROUND_UP_FLAG)
@@ -135,6 +131,9 @@ struct motion_sensor_t {
extern struct motion_sensor_t motion_sensors[];
extern const unsigned motion_sensor_count;
+/* optionally defined at board level */
+extern unsigned int motion_min_interval;
+
/*
* Priority of the motion sense resume/suspend hooks, to be sure associated
* hooks are scheduled properly.