summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGwendal Grignou <gwendal@chromium.org>2015-11-17 13:05:58 -0800
committerChromeOS Commit Bot <chromeos-commit-bot@chromium.org>2017-05-01 21:19:48 +0000
commit258786a378de4ebab91cc71689ba3bfa1e22de18 (patch)
treef8a010cafcfceeaa42bbbcdd4367fe5251a90492
parentc69936bbff1725543eedb9236650d2ded7ce315b (diff)
downloadchrome-ec-258786a378de4ebab91cc71689ba3bfa1e22de18.tar.gz
BACKPORT: 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, cyan, ultima BUG=b:24367625, b:27849483, b:36973851 TEST=compile 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/359397 Reviewed-on: https://chromium-review.googlesource.com/409484 Reviewed-by: Aseda Aboagye <aaboagye@chromium.org> (cherry picked from commit ae89cdaba1b25f48dab1a06420d6a8318a7c9dc5) Change-Id: I52057c8ca1b1180a64b58d1ba0af9ec53f40b026 Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/489757
-rw-r--r--common/motion_sense.c22
-rw-r--r--include/motion_sense.h8
-rw-r--r--test/motion_lid.c8
3 files changed, 19 insertions, 19 deletions
diff --git a/common/motion_sense.c b/common/motion_sense.c
index ded4ad4832..775de8385b 100644
--- a/common/motion_sense.c
+++ b/common/motion_sense.c
@@ -246,12 +246,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
@@ -275,7 +275,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;
}
/*
@@ -288,7 +288,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];
@@ -307,9 +307,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
@@ -318,10 +318,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;
@@ -903,8 +903,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 89203dd040..b16c309db7 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.
+ */
+ unsigned int odr;
+ /* delay between collection by EC, in us.
* For non FIFO sensor, should be need 1e6/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 cd31a59a72..005307a17a 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.
@@ -189,10 +189,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)
@@ -213,7 +213,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