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>
This commit is contained in:
parent
dcdd0522d1
commit
2d723bc996
|
@ -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;
|
||||
|
|
|
@ -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.
|
||||
|
@ -160,6 +161,9 @@ static int test_lid_angle(void)
|
|||
msleep(50);
|
||||
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);
|
||||
|
@ -167,6 +171,9 @@ static int test_lid_angle(void)
|
|||
msleep(50);
|
||||
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
|
||||
|
@ -300,6 +307,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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue