summaryrefslogtreecommitdiff
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
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>
-rw-r--r--common/motion_sense.c25
-rw-r--r--test/motion_lid.c16
2 files changed, 33 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;
diff --git a/test/motion_lid.c b/test/motion_lid.c
index d25de9e3fe..45d14189bb 100644
--- a/test/motion_lid.c
+++ b/test/motion_lid.c
@@ -21,6 +21,7 @@
#include "util.h"
extern enum chipset_state_mask sensor_active;
+extern int wait_us;
/*
* Period in us for the motion task period.
@@ -182,6 +183,9 @@ static int test_lid_angle(void)
hook_notify(HOOK_CHIPSET_SHUTDOWN);
TEST_ASSERT(sensor_active == SENSOR_ACTIVE_S5);
TEST_ASSERT(accel_get_data_rate(lid) == 0);
+ TEST_ASSERT(base->collection_rate == 0);
+ TEST_ASSERT(lid->collection_rate == 0);
+ TEST_ASSERT(wait_us == -1);
/* Go to S0 state */
hook_notify(HOOK_CHIPSET_SUSPEND);
@@ -189,6 +193,9 @@ static int test_lid_angle(void)
msleep(1000);
TEST_ASSERT(sensor_active == SENSOR_ACTIVE_S0);
TEST_ASSERT(accel_get_data_rate(lid) == 119000);
+ TEST_ASSERT(base->collection_rate != 0);
+ TEST_ASSERT(lid->collection_rate != 0);
+ TEST_ASSERT(wait_us > 0);
/*
* Set the base accelerometer as if it were sitting flat on a desk
@@ -328,6 +335,15 @@ static int test_lid_angle(void)
wait_for_valid_sample();
TEST_ASSERT(motion_lid_get_angle() == 10);
+ hook_notify(HOOK_CHIPSET_SHUTDOWN);
+ msleep(1000);
+ TEST_ASSERT(sensor_active == SENSOR_ACTIVE_S5);
+ /* Base ODR is 0, collection rate is 0. */
+ TEST_ASSERT(base->collection_rate == 0);
+ /* Lid is powered off, collection rate is 0. */
+ TEST_ASSERT(lid->collection_rate == 0);
+ TEST_ASSERT(wait_us == -1);
+
return EC_SUCCESS;
}