summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorGwendal Grignou <gwendal@chromium.org>2020-11-04 16:01:18 -0800
committerCommit Bot <commit-bot@chromium.org>2020-12-02 01:41:20 +0000
commitf3ce27d93f78c06bcb59d79d6c2559f7e0764a84 (patch)
treebce7210702289e9f27b9ce5ba200f0150c302e76 /common
parentb6670925f0c87c3ed3443c51b02876915135abfb (diff)
downloadchrome-ec-f3ce27d93f78c06bcb59d79d6c2559f7e0764a84.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/+/2567132 Reviewed-by: Mike Lee <mike5@huaqin.corp-partner.google.com> Tested-by: Mike Lee <mike5@huaqin.corp-partner.google.com>
Diffstat (limited to 'common')
-rw-r--r--common/motion_sense.c25
1 files changed, 17 insertions, 8 deletions
diff --git a/common/motion_sense.c b/common/motion_sense.c
index 9464259de6..7495a29fe0 100644
--- a/common/motion_sense.c
+++ b/common/motion_sense.c
@@ -71,9 +71,17 @@ struct mutex g_sensor_mutex;
*/
test_export_static enum chipset_state_mask sensor_active;
-#ifdef CONFIG_ACCEL_SPOOF_MODE
-static void print_spoof_mode_status(int id);
-#endif /* defined(CONFIG_ACCEL_SPOOF_MODE) */
+/*
+ * 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);
+STATIC_IF(CONFIG_MOTION_FILL_LPC_SENSE_DATA) void update_sense_data(
+ uint8_t *lpc_status, int *psample_id);
/* Flags to control whether to send an ODR change event for a sensor */
static uint32_t odr_event_required;
@@ -167,13 +175,13 @@ int motion_sense_set_data_rate(struct motion_sensor_t *sensor)
BASE_ODR(sensor->config[SENSOR_CONFIG_AP].odr));
#endif
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;
@@ -181,7 +189,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;
@@ -395,8 +402,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();
@@ -824,7 +833,7 @@ static void check_and_queue_gestures(uint32_t *event)
*/
void motion_sense_task(void *u)
{
- int i, ret, wait_us;
+ int i, ret;
timestamp_t ts_begin_task, ts_end_task;
int32_t time_diff;
uint32_t event = 0;