summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGwendal Grignou <gwendal@chromium.org>2015-11-19 10:00:33 -0800
committerChromeOS bot <3su6n15k.default@developer.gserviceaccount.com>2015-11-20 04:40:05 +0000
commitfccc378405dd4cdc7784647dff39b34ea336502f (patch)
tree7e4b7fcdac21842dce1f79643877e38a2e7a3b19
parentebcdcabbd3ad4fc033a6262ab152bb6bd902aa53 (diff)
downloadchrome-ec-fccc378405dd4cdc7784647dff39b34ea336502f.tar.gz
motion: improve readability by adding units to variable names.
Throughout the code, there are comparison between frequency (in mHz) and period (in us). To improve readability, append units (_mhz, _us) after variable names. BRANCH=smaug BUG=none TEST=compile. Change-Id: Icc9c66d9f06c526fc3b74fd85ca9759b702ee416 Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/313221 Reviewed-by: Alec Berg <alecaberg@chromium.org> (cherry picked from commit 87a60df71f24aca95a485662e30a94076c75b0e0) Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/313482
-rw-r--r--common/motion_sense.c43
1 files changed, 22 insertions, 21 deletions
diff --git a/common/motion_sense.c b/common/motion_sense.c
index cf342a4191..7be3340293 100644
--- a/common/motion_sense.c
+++ b/common/motion_sense.c
@@ -166,15 +166,16 @@ static void motion_sense_get_fifo_info(
static inline int motion_sensor_time_to_read(const timestamp_t *ts,
const struct motion_sensor_t *sensor)
{
- int rate = sensor->drv->get_data_rate(sensor);
- if (rate == 0)
+ int rate_mhz = sensor->drv->get_data_rate(sensor);
+
+ if (rate_mhz == 0)
return 0;
/*
* converting from kHz to us.
* If within 95% of the time, check sensor.
*/
return time_after(ts->le.lo,
- sensor->last_collection + SECOND * 950 / rate);
+ sensor->last_collection + SECOND * 950 / rate_mhz);
}
static enum sensor_config motion_sense_get_ec_config(void)
@@ -199,7 +200,7 @@ static enum sensor_config motion_sense_get_ec_config(void)
*/
int motion_sense_set_data_rate(struct motion_sensor_t *sensor)
{
- int roundup, ap_odr = 0, ec_odr, odr, ret;
+ int roundup, ap_odr_mhz = 0, ec_odr_mhz, odr, ret;
enum sensor_config config_id;
timestamp_t ts = get_time();
@@ -207,15 +208,15 @@ int motion_sense_set_data_rate(struct motion_sensor_t *sensor)
/* Check the AP setting first. */
if (sensor_active != SENSOR_ACTIVE_S5)
- ap_odr = BASE_ODR(sensor->config[SENSOR_CONFIG_AP].odr);
+ ap_odr_mhz = BASE_ODR(sensor->config[SENSOR_CONFIG_AP].odr);
/* check if the EC set the sensor ODR at a higher frequency */
config_id = motion_sense_get_ec_config();
- ec_odr = BASE_ODR(sensor->config[config_id].odr);
- if (ec_odr > ap_odr) {
- odr = ec_odr;
+ ec_odr_mhz = BASE_ODR(sensor->config[config_id].odr);
+ if (ec_odr_mhz > ap_odr_mhz) {
+ odr = ec_odr_mhz;
} else {
- odr = ap_odr;
+ odr = ap_odr_mhz;
config_id = SENSOR_CONFIG_AP;
}
roundup = !!(sensor->config[config_id].odr & ROUND_UP_FLAG);
@@ -227,9 +228,9 @@ int motion_sense_set_data_rate(struct motion_sensor_t *sensor)
sensor->name, odr, roundup, config_id,
BASE_ODR(sensor->config[SENSOR_CONFIG_AP].odr));
mutex_lock(&g_sensor_mutex);
- if (ap_odr)
+ if (ap_odr_mhz)
sensor->oversampling_ratio =
- sensor->drv->get_data_rate(sensor) / ap_odr;
+ sensor->drv->get_data_rate(sensor) / ap_odr_mhz;
else
sensor->oversampling_ratio = 0;
@@ -245,17 +246,17 @@ int motion_sense_set_data_rate(struct motion_sensor_t *sensor)
static int motion_sense_set_ec_rate_from_ap(
const struct motion_sensor_t *sensor,
- unsigned int new_rate)
+ unsigned int new_rate_us)
{
- int ap_odr = BASE_ODR(sensor->config[SENSOR_CONFIG_AP].odr);
+ int ap_odr_mhz = BASE_ODR(sensor->config[SENSOR_CONFIG_AP].odr);
- if (new_rate == 0)
+ if (new_rate_us == 0)
return 0;
#ifdef CONFIG_ACCEL_FORCE_MODE_MASK
if (CONFIG_ACCEL_FORCE_MODE_MASK & (1 << (sensor - motion_sensors)))
goto end_set_ec_rate_from_ap;
#endif
- if (ap_odr == 0)
+ if (ap_odr_mhz == 0)
goto end_set_ec_rate_from_ap;
/*
@@ -269,11 +270,11 @@ static int motion_sense_set_ec_rate_from_ap(
* We wll apply that correction only if the ec rate is within 10% of
* the data rate.
*/
- if (SECOND * 1100 / ap_odr > new_rate)
- new_rate = new_rate / 100 * 105;
+ if (SECOND * 1100 / ap_odr_mhz > new_rate_us)
+ new_rate_us = new_rate_us / 100 * 105;
end_set_ec_rate_from_ap:
- return MAX(new_rate, motion_min_interval);
+ return MAX(new_rate_us, motion_min_interval);
}
@@ -284,10 +285,10 @@ static int motion_sense_select_ec_rate(
{
#ifdef CONFIG_ACCEL_FORCE_MODE_MASK
if (CONFIG_ACCEL_FORCE_MODE_MASK & (1 << (sensor - motion_sensors))) {
- int rate = BASE_ODR(sensor->config[config_id].odr);
+ int rate_mhz = BASE_ODR(sensor->config[config_id].odr);
/* we have to run ec at the sensor frequency rate.*/
- if (rate > 0)
- return SECOND * 1000 / rate;
+ if (rate_mhz > 0)
+ return SECOND * 1000 / rate_mhz;
else
return 0;
} else