summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGwendal Grignou <gwendal@chromium.org>2015-11-17 13:05:58 -0800
committerChromeOS bot <3su6n15k.default@developer.gserviceaccount.com>2015-11-18 22:55:52 +0000
commit0d6f272610645e8caae3bfe8c216fe91f1ec879d (patch)
tree78383883edbb882e7b7e11f3c048f2456109e23b
parent8a31aab6f9327610910505d762e83716c85fb167 (diff)
downloadchrome-ec-0d6f272610645e8caae3bfe8c216fe91f1ec879d.tar.gz
motion: Change units of ec_rate from us to ms.
To ease finer calculation of ec rate change units from ms to us. BRANCH=smaug BUG=b:24367625 TEST=compile, run run-motion_lid Change-Id: I52057c8ca1b1180a64b58d1ba0af9ec53f40b026 Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/312984 (cherry picked from commit 420099f74976b3af1f4b24dc24b9fec461b1037b) Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/313151
-rw-r--r--board/samus/board.c10
-rw-r--r--common/motion_sense.c22
-rw-r--r--include/motion_sense.h10
-rw-r--r--test/motion_lid.c8
4 files changed, 25 insertions, 25 deletions
diff --git a/board/samus/board.c b/board/samus/board.c
index 623b3ac712..2ea1d03fa1 100644
--- a/board/samus/board.c
+++ b/board/samus/board.c
@@ -315,16 +315,16 @@ struct motion_sensor_t motion_sensors[] = {
/* EC use accel for angle detection */
[SENSOR_CONFIG_EC_S0] = {
.odr = 119000 | ROUND_UP_FLAG,
- .ec_rate = 100,
+ .ec_rate = 100 * MSEC,
},
/* Used for double tap */
[SENSOR_CONFIG_EC_S3] = {
.odr = TAP_ODR | ROUND_UP_FLAG,
- .ec_rate = CONFIG_GESTURE_SAMPLING_INTERVAL_MS
+ .ec_rate = CONFIG_GESTURE_SAMPLING_INTERVAL_MS * MSEC,
},
[SENSOR_CONFIG_EC_S5] = {
.odr = TAP_ODR | ROUND_UP_FLAG,
- .ec_rate = CONFIG_GESTURE_SAMPLING_INTERVAL_MS
+ .ec_rate = CONFIG_GESTURE_SAMPLING_INTERVAL_MS * MSEC,
},
},
},
@@ -349,7 +349,7 @@ struct motion_sensor_t motion_sensors[] = {
/* EC use accel for angle detection */
[SENSOR_CONFIG_EC_S0] = {
.odr = 100000 | ROUND_UP_FLAG,
- .ec_rate = 100,
+ .ec_rate = 100 * MSEC,
},
/* unused */
[SENSOR_CONFIG_EC_S3] = {
@@ -383,7 +383,7 @@ struct motion_sensor_t motion_sensors[] = {
/* EC use accel for angle detection */
[SENSOR_CONFIG_EC_S0] = {
.odr = 119000 | ROUND_UP_FLAG,
- .ec_rate = 100,
+ .ec_rate = 100 * MSEC,
},
/* unused */
[SENSOR_CONFIG_EC_S3] = {
diff --git a/common/motion_sense.c b/common/motion_sense.c
index a37c7fdfac..470ec3ed86 100644
--- a/common/motion_sense.c
+++ b/common/motion_sense.c
@@ -245,12 +245,12 @@ static int motion_sense_select_ec_rate(
int rate = BASE_ODR(sensor->config[config_id].odr);
/* we have to run ec at the sensor frequency rate.*/
if (rate > 0)
- return 1000000 / rate;
+ return SECOND * 1000 / rate;
else
return 0;
} else
#endif
- return sensor->config[config_id].ec_rate;
+ return sensor->config[config_id].ec_rate;
}
/* motion_sense_ec_rate
@@ -274,7 +274,7 @@ static int motion_sense_ec_rate(struct motion_sensor_t *sensor)
if (ec_rate_from_cfg != 0)
if (ec_rate == 0 || ec_rate_from_cfg < ec_rate)
ec_rate = ec_rate_from_cfg;
- return ec_rate * MSEC;
+ return ec_rate;
}
/*
@@ -287,7 +287,7 @@ static int motion_sense_ec_rate(struct motion_sensor_t *sensor)
*/
static int motion_sense_set_motion_intervals(void)
{
- int i, sensor_ec_rate, ec_rate = 0, ec_int_rate_ms = 0, wake_up = 0;
+ int i, sensor_ec_rate, ec_rate = 0, ec_int_rate = 0, wake_up = 0;
struct motion_sensor_t *sensor;
for (i = 0; i < motion_sensor_count; ++i) {
sensor = &motion_sensors[i];
@@ -306,9 +306,9 @@ static int motion_sense_set_motion_intervals(void)
sensor_ec_rate = motion_sense_select_ec_rate(
sensor, SENSOR_CONFIG_AP);
- if (ec_int_rate_ms == 0 ||
- (sensor_ec_rate && sensor_ec_rate < ec_int_rate_ms))
- ec_int_rate_ms = sensor_ec_rate;
+ if (ec_int_rate == 0 ||
+ (sensor_ec_rate && sensor_ec_rate < ec_int_rate))
+ ec_int_rate = sensor_ec_rate;
}
/*
* Wake up the motion sense task: we want to sensor task to take
@@ -317,10 +317,10 @@ static int motion_sense_set_motion_intervals(void)
if ((motion_interval == 0 ||
(ec_rate > 0 && motion_interval > ec_rate)) ||
(motion_int_interval == 0 ||
- (ec_int_rate_ms > 0 && motion_int_interval > ec_int_rate_ms)))
+ (ec_int_rate > 0 && motion_int_interval > ec_int_rate)))
wake_up = 1;
motion_interval = ec_rate;
- motion_int_interval = ec_int_rate_ms * MSEC;
+ motion_int_interval = ec_int_rate;
if (wake_up)
task_wake(TASK_ID_MOTIONSENSE);
return motion_interval;
@@ -921,8 +921,8 @@ static int host_cmd_motion_sense(struct host_cmd_handler_args *args)
sensor->config[SENSOR_CONFIG_AP].ec_rate = 0;
else
sensor->config[SENSOR_CONFIG_AP].ec_rate =
- MAX(in->ec_rate.data,
- motion_min_interval / MSEC);
+ MAX(in->ec_rate.data * MSEC,
+ motion_min_interval);
/* Bound the new sampling rate. */
motion_sense_set_motion_intervals();
diff --git a/include/motion_sense.h b/include/motion_sense.h
index 696fe493e3..f1657b5a7d 100644
--- a/include/motion_sense.h
+++ b/include/motion_sense.h
@@ -49,15 +49,15 @@ struct motion_data_t {
/*
* data rate the sensor will measure, in mHz: 0 suspended.
* MSB is used to know if we are rounding up.
- * */
- unsigned odr;
- /* delay between collection by EC, in ms.
- * For non FIFO sensor, should be nead 1e6/odr to
+ */
+ unsigned int odr;
+ /* delay between collection by EC, in us.
+ * For non FIFO sensor, should be near 1e9/odr to
* collect events.
* For sensor with FIFO, can be much longer.
* 0: no collection.
*/
- unsigned short ec_rate;
+ unsigned int ec_rate;
};
struct motion_sensor_t {
diff --git a/test/motion_lid.c b/test/motion_lid.c
index 5fdd26b7fd..224b12a26b 100644
--- a/test/motion_lid.c
+++ b/test/motion_lid.c
@@ -26,7 +26,7 @@ extern unsigned motion_interval;
* Period in us for the motion task period.
* The task will read the vectors at that interval
*/
-#define TEST_LID_EC_RATE (10)
+#define TEST_LID_EC_RATE (10 * MSEC)
/*
* Time in ms to wait for the task to read the vectors.
@@ -186,10 +186,10 @@ static void wait_for_valid_sample(void)
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);
+ usleep(TEST_LID_EC_RATE);
task_wake(TASK_ID_MOTIONSENSE);
while ((*lpc_status & EC_MEMMAP_ACC_STATUS_SAMPLE_ID_MASK) == sample)
- msleep(TEST_LID_SLEEP_RATE);
+ usleep(TEST_LID_SLEEP_RATE);
}
static int test_lid_angle(void)
@@ -210,7 +210,7 @@ static int test_lid_angle(void)
msleep(1000);
TEST_ASSERT(sensor_active == SENSOR_ACTIVE_S0);
TEST_ASSERT(accel_get_data_rate(lid) == (119000 | ROUND_UP_FLAG));
- TEST_ASSERT(motion_interval == TEST_LID_EC_RATE * MSEC);
+ TEST_ASSERT(motion_interval == TEST_LID_EC_RATE);
/*
* Set the base accelerometer as if it were sitting flat on a desk