diff options
-rw-r--r-- | common/motion_sense.c | 25 | ||||
-rw-r--r-- | test/motion_lid.c | 16 |
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; } |