summaryrefslogtreecommitdiff
path: root/include/motion_sense.h
diff options
context:
space:
mode:
authorGwendal Grignou <gwendal@chromium.org>2015-06-26 16:15:37 -0700
committerChromeOS Commit Bot <chromeos-commit-bot@chromium.org>2015-07-15 02:07:01 +0000
commitc0f78b4c0aca20203fefbc96c7e52c709455c06b (patch)
tree847f40c9332ee97b3855200520010b8e078e045c /include/motion_sense.h
parent3b55292cdb76f1acd540b89ce16a24fda863bc62 (diff)
downloadchrome-ec-c0f78b4c0aca20203fefbc96c7e52c709455c06b.tar.gz
motion: Add sample frequency per sensor
Store at which frequency each sensor should be sampled. This frequency is different from the sensor frequency: - sensor frequency: frequency at which the sensor produce information. - sensor sampling frequency: frequency at the which the EC gater information. If 2 sensors must be sampled at very different frequency, we don't want to oversample the slow one, and filling the software FIFO unnecessarily. BRANCH=smaug TEST=Unit test. Check that frequency is correct when sensor frequencies change from IIO driver. BUG=chrome-os-partner:39900 Change-Id: I4272963413f53d4ca004e26639dc7a2affd317eb Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/284616 Reviewed-by: Alec Berg <alecaberg@chromium.org>
Diffstat (limited to 'include/motion_sense.h')
-rw-r--r--include/motion_sense.h47
1 files changed, 40 insertions, 7 deletions
diff --git a/include/motion_sense.h b/include/motion_sense.h
index 1aeb569dd0..82a492719c 100644
--- a/include/motion_sense.h
+++ b/include/motion_sense.h
@@ -28,11 +28,35 @@ enum sensor_state {
#define SENSOR_ACTIVE_S0_S3 (SENSOR_ACTIVE_S3 | SENSOR_ACTIVE_S0)
#define SENSOR_ACTIVE_S0_S3_S5 (SENSOR_ACTIVE_S0_S3 | SENSOR_ACTIVE_S5)
+/* Events the motion sense task may have to process.*/
+#define TASK_EVENT_MOTION_FLUSH_PENDING TASK_EVENT_CUSTOM(1)
+#define TASK_EVENT_MOTION_INTERRUPT TASK_EVENT_CUSTOM(2)
+#define TASK_EVENT_MOTION_ODR_CHANGE TASK_EVENT_CUSTOM(4)
+
+/* Define sensor sampling interval in suspend. */
+#ifdef CONFIG_GESTURE_DETECTION
+#define SUSPEND_SAMPLING_INTERVAL (CONFIG_GESTURE_SAMPLING_INTERVAL_MS * MSEC)
+#elif defined(CONFIG_ACCEL_FIFO)
+#define SUSPEND_SAMPLING_INTERVAL (1000 * MSEC)
+#else
+#define SUSPEND_SAMPLING_INTERVAL (100 * MSEC)
+#endif
+
+/* 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)
+
struct motion_data_t {
/* data rate the sensor will measure, in mHz */
int odr;
/* range of measurement in SI */
int range;
+ /* delay between collection by EC, in ms.
+ * For non FIFO sensor, should be nead 1e6/odr to
+ * collect events.
+ * For sensor with FIFO, can be much longer.
+ */
+ unsigned ec_rate;
};
struct motion_sensor_t {
@@ -68,11 +92,26 @@ struct motion_sensor_t {
* FIFO info has been transmitted.
*/
uint16_t lost;
+
+ /*
+ * Time since iast collection:
+ * For sensor with hardware FIFO, time since last sample
+ * has move from the hardware FIFO to the FIFO (used if fifo rate != 0).
+ * For sensor without FIFO, time since the last event was collect
+ * from sensor registers.
+ */
+ int last_collection;
};
/* Defined at board level. */
extern struct motion_sensor_t motion_sensors[];
-extern const unsigned int motion_sensor_count;
+extern const unsigned motion_sensor_count;
+
+/* For testing purposes: export the sampling interval. */
+extern unsigned accel_interval;
+int motion_sense_set_accel_interval(
+ struct motion_sensor_t *driving_sensor,
+ unsigned data);
/*
* Priority of the motion sense resume/suspend hooks, to be sure associated
@@ -103,10 +142,4 @@ void motion_sense_fifo_add_unit(struct ec_response_motion_sensor_data *data,
const struct motion_sensor_t *sensor);
#endif
-
-/* Events the motion sense task may have to process.*/
-#define TASK_EVENT_MOTION_FLUSH_PENDING TASK_EVENT_CUSTOM(1)
-#define TASK_EVENT_MOTION_INTERRUPT TASK_EVENT_CUSTOM(2)
-#define TASK_EVENT_MOTION_ODR_CHANGE TASK_EVENT_CUSTOM(4)
-
#endif /* __CROS_EC_MOTION_SENSE_H */