summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorGwendal Grignou <gwendal@chromium.org>2015-06-26 16:15:37 -0700
committerChromeOS Commit Bot <chromeos-commit-bot@chromium.org>2015-07-15 02:07:01 +0000
commitc0f78b4c0aca20203fefbc96c7e52c709455c06b (patch)
tree847f40c9332ee97b3855200520010b8e078e045c /test
parent3b55292cdb76f1acd540b89ce16a24fda863bc62 (diff)
downloadchrome-ec-c0f78b4c0aca20203fefbc96c7e52c709455c06b.tar.gz
motion: Add sample frequency per sensor
Store at which frequency each sensor should be sampled. This frequency is different from the sensor frequency: - sensor frequency: frequency at which the sensor produce information. - sensor sampling frequency: frequency at the which the EC gater information. If 2 sensors must be sampled at very different frequency, we don't want to oversample the slow one, and filling the software FIFO unnecessarily. BRANCH=smaug TEST=Unit test. Check that frequency is correct when sensor frequencies change from IIO driver. BUG=chrome-os-partner:39900 Change-Id: I4272963413f53d4ca004e26639dc7a2affd317eb Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/284616 Reviewed-by: Alec Berg <alecaberg@chromium.org>
Diffstat (limited to 'test')
-rw-r--r--test/motion_lid.c75
1 files changed, 49 insertions, 26 deletions
diff --git a/test/motion_lid.c b/test/motion_lid.c
index 84a539e226..d06a76135d 100644
--- a/test/motion_lid.c
+++ b/test/motion_lid.c
@@ -19,6 +19,18 @@
#include "timer.h"
#include "util.h"
+
+/*
+ * Period in us for the motion task period.
+ * The task will read the vectors at that interval
+ */
+#define TEST_LID_EC_RATE (SUSPEND_SAMPLING_INTERVAL / 10)
+
+/*
+ * Time in ms to wait for the task to read the vectors.
+ */
+#define TEST_LID_SLEEP_RATE (TEST_LID_EC_RATE / (5 * MSEC))
+
/*****************************************************************************/
/* Mock functions */
static int accel_init(const struct motion_sensor_t *s)
@@ -109,10 +121,11 @@ struct motion_sensor_t motion_sensors[] = {
.rot_standard_ref = &base_standard_ref,
.default_config = {
.odr = 119000,
- .range = 2
+ .range = 2,
+ .ec_rate = SUSPEND_SAMPLING_INTERVAL,
}
},
- {.name = "base",
+ {.name = "lid",
.active_mask = SENSOR_ACTIVE_S0,
.chip = MOTIONSENSE_CHIP_KXCJ9,
.type = MOTIONSENSE_TYPE_ACCEL,
@@ -124,7 +137,8 @@ struct motion_sensor_t motion_sensors[] = {
.rot_standard_ref = &lid_standard_ref,
.default_config = {
.odr = 119000,
- .range = 2
+ .range = 2,
+ .ec_rate = SUSPEND_SAMPLING_INTERVAL,
}
},
};
@@ -132,19 +146,38 @@ const unsigned int motion_sensor_count = ARRAY_SIZE(motion_sensors);
/*****************************************************************************/
/* Test utilities */
-static int test_lid_angle(void)
+static void wait_for_valid_sample(void)
{
- uint8_t *lpc_status = host_get_memmap(EC_MEMMAP_ACC_STATUS);
uint8_t sample;
+ uint8_t *lpc_status = host_get_memmap(EC_MEMMAP_ACC_STATUS);
+
+ sample = *lpc_status & EC_MEMMAP_ACC_STATUS_SAMPLE_ID_MASK;
+ msleep(TEST_LID_EC_RATE/MSEC);
+ task_wake(TASK_ID_MOTIONSENSE);
+ while ((*lpc_status & EC_MEMMAP_ACC_STATUS_SAMPLE_ID_MASK) == sample)
+ msleep(TEST_LID_SLEEP_RATE);
+}
+
+static int test_lid_angle(void)
+{
struct motion_sensor_t *base = &motion_sensors[0];
struct motion_sensor_t *lid = &motion_sensors[1];
/* Go to S3 state */
- hook_notify(HOOK_CHIPSET_STARTUP);
+ TEST_ASSERT(accel_interval == SUSPEND_SAMPLING_INTERVAL);
+ TEST_ASSERT(motion_sensors[0].active == SENSOR_ACTIVE_S5);
/* Go to S0 state */
hook_notify(HOOK_CHIPSET_RESUME);
+ TEST_ASSERT(accel_interval == SUSPEND_SAMPLING_INTERVAL);
+ TEST_ASSERT(motion_sensors[0].active == SENSOR_ACTIVE_S0);
+
+ motion_sense_set_accel_interval(base, TEST_LID_EC_RATE);
+ TEST_ASSERT(accel_interval == TEST_LID_EC_RATE);
+
+ motion_sense_set_accel_interval(lid, TEST_LID_EC_RATE);
+ TEST_ASSERT(accel_interval == TEST_LID_EC_RATE);
/*
* Set the base accelerometer as if it were sitting flat on a desk
@@ -156,32 +189,28 @@ static int test_lid_angle(void)
lid->xyz[X] = 0;
lid->xyz[Y] = 0;
lid->xyz[Z] = 1000;
- sample = *lpc_status & EC_MEMMAP_ACC_STATUS_SAMPLE_ID_MASK;
+ /* Initial wake up, like init does */
task_wake(TASK_ID_MOTIONSENSE);
- msleep(5);
+
+ /* wait for the EC sampling period to expire */
+ msleep(TEST_LID_EC_RATE/MSEC);
task_wake(TASK_ID_MOTIONSENSE);
- while ((*lpc_status & EC_MEMMAP_ACC_STATUS_SAMPLE_ID_MASK) == sample)
- msleep(5);
+
+ wait_for_valid_sample();
TEST_ASSERT(motion_lid_get_angle() == 0);
/* Set lid open to 90 degrees. */
lid->xyz[X] = -1000;
lid->xyz[Y] = 0;
lid->xyz[Z] = 0;
- sample = *lpc_status & EC_MEMMAP_ACC_STATUS_SAMPLE_ID_MASK;
- task_wake(TASK_ID_MOTIONSENSE);
- while ((*lpc_status & EC_MEMMAP_ACC_STATUS_SAMPLE_ID_MASK) == sample)
- msleep(5);
+ wait_for_valid_sample();
TEST_ASSERT(motion_lid_get_angle() == 90);
/* Set lid open to 225. */
lid->xyz[X] = 500;
lid->xyz[Y] = 0;
lid->xyz[Z] = -500;
- sample = *lpc_status & EC_MEMMAP_ACC_STATUS_SAMPLE_ID_MASK;
- task_wake(TASK_ID_MOTIONSENSE);
- while ((*lpc_status & EC_MEMMAP_ACC_STATUS_SAMPLE_ID_MASK) == sample)
- msleep(5);
+ wait_for_valid_sample();
TEST_ASSERT(motion_lid_get_angle() == 225);
/*
@@ -191,10 +220,7 @@ static int test_lid_angle(void)
base->xyz[X] = 0;
base->xyz[Y] = 1000;
base->xyz[Z] = 0;
- sample = *lpc_status & EC_MEMMAP_ACC_STATUS_SAMPLE_ID_MASK;
- task_wake(TASK_ID_MOTIONSENSE);
- while ((*lpc_status & EC_MEMMAP_ACC_STATUS_SAMPLE_ID_MASK) == sample)
- msleep(5);
+ wait_for_valid_sample();
TEST_ASSERT(motion_lid_get_angle() == LID_ANGLE_UNRELIABLE);
/*
@@ -207,10 +233,7 @@ static int test_lid_angle(void)
lid->xyz[X] = -500;
lid->xyz[Y] = -400;
lid->xyz[Z] = -300;
- sample = *lpc_status & EC_MEMMAP_ACC_STATUS_SAMPLE_ID_MASK;
- task_wake(TASK_ID_MOTIONSENSE);
- while ((*lpc_status & EC_MEMMAP_ACC_STATUS_SAMPLE_ID_MASK) == sample)
- msleep(5);
+ wait_for_valid_sample();
TEST_ASSERT(motion_lid_get_angle() == 180);
return EC_SUCCESS;