diff options
author | Sheng-Liang Song <ssl@chromium.org> | 2014-08-13 14:17:07 -0700 |
---|---|---|
committer | chrome-internal-fetch <chrome-internal-fetch@google.com> | 2014-08-26 03:05:55 +0000 |
commit | 7d40063d46aa9a8b6146355ee9be9db775af7f0d (patch) | |
tree | aed9ecdc51ff99d1dcb9b259e6727577986d2be6 /test | |
parent | c598e1ac06c4ceddf28399081ed669eaaa533ae9 (diff) | |
download | chrome-ec-7d40063d46aa9a8b6146355ee9be9db775af7f0d.tar.gz |
samus: added gyro support for lsm6ds0
Changed motion_sense task to assume sensors are unpowered in G3
and re-initialize sensors every time coming out of G3.
Added EC command line test utils as well.
Fixed some bug during unit tests.
BUG=chrome-os-partner:27313,27320
BRANCH=ToT
TEST=Verified on Samus.
Tested with accel EC CLIs
accelread, accelrange, accelrate, accelres
Tested accelcalib, a ACCEL calibration util, and it succeeded.
Tested sysfs interface:
cd /sys/bus/iio/devices/iio:device1
cat in_accel_*_gyro_raw
Signed-off-by: Sheng-Liang Song <ssl@chromium.org>
Change-Id: I5752b00c03e1942c790ea4f28610fda83fa2dcbc
Reviewed-on: https://chromium-review.googlesource.com/211484
Reviewed-by: Alec Berg <alecaberg@chromium.org>
Diffstat (limited to 'test')
-rw-r--r-- | test/math_util.c | 5 | ||||
-rw-r--r-- | test/motion_sense.c | 121 |
2 files changed, 54 insertions, 72 deletions
diff --git a/test/math_util.c b/test/math_util.c index e69005fcbc..3c5a3fae01 100644 --- a/test/math_util.c +++ b/test/math_util.c @@ -6,7 +6,7 @@ */ #include <math.h> - +#include <stdio.h> #include "math_util.h" #include "motion_sense.h" #include "test_util.h" @@ -14,7 +14,7 @@ /*****************************************************************************/ /* Need to define motion sensor globals just to compile. */ -const struct motion_sensor_t motion_sensors[] = {}; +struct motion_sensor_t motion_sensors[] = {}; const unsigned int motion_sensor_count = ARRAY_SIZE(motion_sensors); /*****************************************************************************/ @@ -41,7 +41,6 @@ static int test_acos(void) return EC_SUCCESS; } - void run_test(void) { test_reset(); diff --git a/test/motion_sense.c b/test/motion_sense.c index 941b6cc9e7..b9a928ef8c 100644 --- a/test/motion_sense.c +++ b/test/motion_sense.c @@ -9,6 +9,7 @@ #include "accelgyro.h" #include "common.h" +#include "hooks.h" #include "host_command.h" #include "motion_sense.h" #include "task.h" @@ -16,105 +17,82 @@ #include "timer.h" #include "util.h" -/* Mock acceleration values for motion sense task to read in. */ -int mock_x_acc[ACCEL_COUNT], mock_y_acc[ACCEL_COUNT], mock_z_acc[ACCEL_COUNT]; +/* For vector_3_t, define which coordinates are in which location. */ +enum { + X, Y, Z +}; /*****************************************************************************/ /* Mock functions */ - -static int accel_init(void *drv_data, int i2c_addr) +static int accel_init(const struct motion_sensor_t *s) { return EC_SUCCESS; } -static int accel_read_base(void *drv_data, int *x_acc, int *y_acc, int *z_acc) +static int accel_read(const struct motion_sensor_t *s, + int *x_acc, int *y_acc, int *z_acc) { - /* Return the mock values. */ - *x_acc = mock_x_acc[ACCEL_BASE]; - *y_acc = mock_y_acc[ACCEL_BASE]; - *z_acc = mock_z_acc[ACCEL_BASE]; - + *x_acc = s->xyz[X]; + *y_acc = s->xyz[Y]; + *z_acc = s->xyz[Z]; return EC_SUCCESS; } -static int accel_read_lid(void *drv_data, int *x_acc, int *y_acc, int *z_acc) -{ - /* Return the mock values. */ - *x_acc = mock_x_acc[ACCEL_LID]; - *y_acc = mock_y_acc[ACCEL_LID]; - *z_acc = mock_z_acc[ACCEL_LID]; - - return EC_SUCCESS; -} - -static int accel_set_range(void *drv_data, +static int accel_set_range(const struct motion_sensor_t *s, const int range, const int rnd) { return EC_SUCCESS; } -static int accel_get_range(void *drv_data, +static int accel_get_range(const struct motion_sensor_t *s, int * const range) { return EC_SUCCESS; } -static int accel_set_resolution(void *drv_data, +static int accel_set_resolution(const struct motion_sensor_t *s, const int res, const int rnd) { return EC_SUCCESS; } -static int accel_get_resolution(void *drv_data, +static int accel_get_resolution(const struct motion_sensor_t *s, int * const res) { return EC_SUCCESS; } -static int accel_set_datarate(void *drv_data, +static int accel_set_data_rate(const struct motion_sensor_t *s, const int rate, const int rnd) { return EC_SUCCESS; } -static int accel_get_datarate(void *drv_data, +static int accel_get_data_rate(const struct motion_sensor_t *s, int * const rate) { return EC_SUCCESS; } -const struct accelgyro_info test_motion_sense_base = { - .chip_type = CHIP_TEST, - .sensor_type = SENSOR_ACCELEROMETER, +const struct accelgyro_drv test_motion_sense = { .init = accel_init, - .read = accel_read_base, + .read = accel_read, .set_range = accel_set_range, .get_range = accel_get_range, .set_resolution = accel_set_resolution, .get_resolution = accel_get_resolution, - .set_datarate = accel_set_datarate, - .get_datarate = accel_get_datarate, + .set_data_rate = accel_set_data_rate, + .get_data_rate = accel_get_data_rate, }; -const struct accelgyro_info test_motion_sense_lid = { - .chip_type = CHIP_TEST, - .sensor_type = SENSOR_ACCELEROMETER, - .init = accel_init, - .read = accel_read_lid, - .set_range = accel_set_range, - .get_range = accel_get_range, - .set_resolution = accel_set_resolution, - .get_resolution = accel_get_resolution, - .set_datarate = accel_set_datarate, - .get_datarate = accel_get_datarate, -}; - -const struct motion_sensor_t motion_sensors[] = { - {"test base sensor", LOCATION_BASE, &test_motion_sense_base, NULL, 0}, - {"test lid sensor", LOCATION_LID, &test_motion_sense_lid, NULL, 0}, +struct motion_sensor_t motion_sensors[] = { + {"base", SENSOR_CHIP_LSM6DS0, SENSOR_ACCELEROMETER, LOCATION_BASE, + &test_motion_sense, NULL, NULL, 0}, + {"lid", SENSOR_CHIP_KXCJ9, SENSOR_ACCELEROMETER, LOCATION_LID, + &test_motion_sense, NULL, NULL, 0}, }; const unsigned int motion_sensor_count = ARRAY_SIZE(motion_sensors); @@ -125,16 +103,21 @@ static int test_lid_angle(void) uint8_t *lpc_status = host_get_memmap(EC_MEMMAP_ACC_STATUS); uint8_t sample; + struct motion_sensor_t *base = &motion_sensors[0]; + struct motion_sensor_t *lid = &motion_sensors[1]; + + hook_notify(HOOK_CHIPSET_STARTUP); + /* * Set the base accelerometer as if it were sitting flat on a desk * and set the lid to closed. */ - mock_x_acc[ACCEL_BASE] = 0; - mock_y_acc[ACCEL_BASE] = 0; - mock_z_acc[ACCEL_BASE] = 1000; - mock_x_acc[ACCEL_LID] = 0; - mock_y_acc[ACCEL_LID] = 0; - mock_z_acc[ACCEL_LID] = 1000; + base->xyz[X] = 0; + base->xyz[Y] = 0; + base->xyz[Z] = 1000; + lid->xyz[X] = 0; + lid->xyz[Y] = 0; + lid->xyz[Z] = 1000; 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) @@ -142,9 +125,9 @@ static int test_lid_angle(void) TEST_ASSERT(motion_get_lid_angle() == 0); /* Set lid open to 90 degrees. */ - mock_x_acc[ACCEL_LID] = -1000; - mock_y_acc[ACCEL_LID] = 0; - mock_z_acc[ACCEL_LID] = 0; + 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) @@ -152,9 +135,9 @@ static int test_lid_angle(void) TEST_ASSERT(motion_get_lid_angle() == 90); /* Set lid open to 225. */ - mock_x_acc[ACCEL_LID] = 500; - mock_y_acc[ACCEL_LID] = 0; - mock_z_acc[ACCEL_LID] = -500; + 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) @@ -165,9 +148,9 @@ static int test_lid_angle(void) * Align base with hinge and make sure it returns unreliable for angle. * In this test it doesn't matter what the lid acceleration vector is. */ - mock_x_acc[ACCEL_BASE] = 0; - mock_y_acc[ACCEL_BASE] = 1000; - mock_z_acc[ACCEL_BASE] = 0; + 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) @@ -178,12 +161,12 @@ static int test_lid_angle(void) * Use all three axes and set lid to negative base and make sure * angle is 180. */ - mock_x_acc[ACCEL_BASE] = 500; - mock_y_acc[ACCEL_BASE] = 400; - mock_z_acc[ACCEL_BASE] = 300; - mock_x_acc[ACCEL_LID] = -500; - mock_y_acc[ACCEL_LID] = -400; - mock_z_acc[ACCEL_LID] = -300; + base->xyz[X] = 500; + base->xyz[Y] = 400; + base->xyz[Z] = 300; + 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) |