diff options
author | Gwendal Grignou <gwendal@chromium.org> | 2020-11-04 16:01:18 -0800 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2020-12-01 02:37:52 +0000 |
commit | 2d723bc9961fd18a0f08db8b244ba59f31d7188b (patch) | |
tree | 7f312d423758ea16072738252473bc7eedee5688 /common | |
parent | dcdd0522d12ec52790f73963d6845b5da2b49308 (diff) | |
download | chrome-ec-2d723bc9961fd18a0f08db8b244ba59f31d7188b.tar.gz |
motion_sense: Stop collection when sensor is powered down
Set collection_rate to 0 when sensor is not in initialized state anymore.
It will prevent the motion_sense task to be neededlessly scheduled.
Export wait_us to be tested.
BUG=b:170703322
BRANCH=kukui
TEST=unit test
Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
Change-Id: I1dc4c7a07ff30fa10997ef87784114c725f100d5
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2520297
Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
Reviewed-by: Chen-Tsung Hsieh <chentsung@chromium.org>
Reviewed-by: Yuval Peress <peress@chromium.org>
Diffstat (limited to 'common')
-rw-r--r-- | common/motion_sense.c | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/common/motion_sense.c b/common/motion_sense.c index f708abb26f..df8168d31b 100644 --- a/common/motion_sense.c +++ b/common/motion_sense.c @@ -60,6 +60,12 @@ struct mutex g_sensor_mutex; */ test_export_static enum chipset_state_mask sensor_active; +/* + * Motion task interval. It does not have to be a global variable, + * but it allows to be tested. + */ +test_export_static int wait_us; + STATIC_IF(CONFIG_ACCEL_SPOOF_MODE) void print_spoof_mode_status(int id); STATIC_IF(CONFIG_GESTURE_DETECTION) void check_and_queue_gestures( uint32_t *event); @@ -158,13 +164,13 @@ int motion_sense_set_data_rate(struct motion_sensor_t *sensor) BASE_ODR(sensor->config[SENSOR_CONFIG_AP].odr)); mutex_lock(&g_sensor_mutex); + odr = sensor->drv->get_data_rate(sensor); if (ap_odr_mhz) /* * In case the AP want to run the sensors faster than it can, * be sure we don't see the ratio to 0. */ - sensor->oversampling_ratio = MAX(1, - sensor->drv->get_data_rate(sensor) / ap_odr_mhz); + sensor->oversampling_ratio = MAX(1, odr / ap_odr_mhz); else sensor->oversampling_ratio = 0; @@ -172,7 +178,6 @@ int motion_sense_set_data_rate(struct motion_sensor_t *sensor) * Reset last collection: the last collection may be so much in the past * it may appear to be in the future. */ - odr = sensor->drv->get_data_rate(sensor); sensor->collection_rate = odr > 0 ? SECOND * 1000 / odr : 0; sensor->next_collection = ts.le.lo + sensor->collection_rate; sensor->oversampling = 0; @@ -396,8 +401,10 @@ static void motion_sense_switch_sensor_rate(void) } } else { /* The sensors are being powered off */ - if (sensor->state == SENSOR_INITIALIZED) + if (sensor->state == SENSOR_INITIALIZED) { + sensor->collection_rate = 0; sensor->state = SENSOR_NOT_INITIALIZED; + } } } motion_sense_set_motion_intervals(); @@ -822,7 +829,7 @@ static void check_and_queue_gestures(uint32_t *event) */ void motion_sense_task(void *u) { - int i, ret, wait_us, sample_id = 0; + int i, ret, sample_id = 0; timestamp_t ts_begin_task, ts_end_task; int32_t time_diff; uint32_t event = 0; |