diff options
author | Gwendal Grignou <gwendal@chromium.org> | 2020-10-19 14:36:10 -0700 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2020-10-20 20:15:03 +0000 |
commit | 512823a8aa87d4b6a83f88bab05fe586de6c14aa (patch) | |
tree | 5be9dc89304498414d1e33e0b578e9c53b990b41 | |
parent | 28fe21716cdacac0ecc025407b727eaf5a99b720 (diff) | |
download | chrome-ec-512823a8aa87d4b6a83f88bab05fe586de6c14aa.tar.gz |
common: online_calibration: Fix compilation issue
- Fix compilation error: sizeof() of an input array
was not calculated properly.
- Fix calling convention: use sensor pointer instead of
sensor number
- Use common formula to calculate sensor number.
BUG=none
BRANCH=none
TEST=compile, unittest, load on eve with online calibration added.
Change-Id: I06ff30eb5710cbe8f91c939b2ccc084c20a37847
Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2486304
Reviewed-by: Yuval Peress <peress@chromium.org>
-rw-r--r-- | common/motion_sense.c | 4 | ||||
-rw-r--r-- | common/online_calibration.c | 12 | ||||
-rw-r--r-- | include/online_calibration.h | 3 | ||||
-rw-r--r-- | test/online_calibration.c | 2 |
4 files changed, 11 insertions, 10 deletions
diff --git a/common/motion_sense.c b/common/motion_sense.c index e739bc8f75..a283ce7346 100644 --- a/common/motion_sense.c +++ b/common/motion_sense.c @@ -1354,9 +1354,7 @@ static enum ec_status host_cmd_motion_sense(struct host_cmd_handler_args *args) args->response_size = - online_calibration_read( - (int)(sensor - motion_sensors), - out->online_calib_read.data) + online_calibration_read(sensor, &out->online_calib_read) ? sizeof(struct ec_response_online_calibration_data) : 0; break; diff --git a/common/online_calibration.c b/common/online_calibration.c index ca7a5a620d..5cef26fd00 100644 --- a/common/online_calibration.c +++ b/common/online_calibration.c @@ -104,7 +104,7 @@ static void check_gyro_cal_new_bias(struct motion_sensor_t *sensor) (struct online_calib_data *)sensor->online_calib_data; struct gyro_cal_data *data = (struct gyro_cal_data *)calib_data->type_specific_data; - size_t sensor_num = motion_sensors - sensor; + int sensor_num = sensor - motion_sensors; int temp_out; fpv3_t bias_out; uint32_t timestamp_out; @@ -228,16 +228,18 @@ bool online_calibration_has_new_values(void) return has_dirty; } -bool online_calibration_read(int sensor_num, int16_t out[3]) +bool online_calibration_read(struct motion_sensor_t *sensor, + struct ec_response_online_calibration_data *out) { + int sensor_num = sensor - motion_sensors; bool has_valid; mutex_lock(&g_calib_cache_mutex); has_valid = (sensor_calib_cache_valid_map & BIT(sensor_num)) != 0; if (has_valid) { /* Update data in out */ - memcpy(out, motion_sensors[sensor_num].online_calib_data->cache, - sizeof(out)); + memcpy(out->data, sensor->online_calib_data->cache, + sizeof(out->data)); /* Clear dirty bit */ sensor_calib_cache_dirty_map &= ~(1 << sensor_num); } @@ -250,7 +252,7 @@ int online_calibration_process_data(struct ec_response_motion_sensor_data *data, struct motion_sensor_t *sensor, uint32_t timestamp) { - size_t sensor_num = motion_sensors - sensor; + int sensor_num = sensor - motion_sensors; int rc; int temperature; struct online_calib_data *calib_data; diff --git a/include/online_calibration.h b/include/online_calibration.h index 6f8fad33a7..e3b259e14d 100644 --- a/include/online_calibration.h +++ b/include/online_calibration.h @@ -41,6 +41,7 @@ bool online_calibration_has_new_values(void); * @param out The target to copy the data into. * @return True if a value was written to `out`. */ -bool online_calibration_read(int sensor_num, int16_t out[3]); +bool online_calibration_read(struct motion_sensor_t *sensor, + struct ec_response_online_calibration_data *out); #endif /* __CROS_EC_ONLINE_CALIBRATION_H */ diff --git a/test/online_calibration.c b/test/online_calibration.c index e9fff2430e..f0432d5893 100644 --- a/test/online_calibration.c +++ b/test/online_calibration.c @@ -210,7 +210,7 @@ static int test_new_calibration_value(void) TEST_EQ(rc, EC_SUCCESS, "%d"); TEST_EQ(online_calibration_has_new_values(), true, "%d"); - rc = online_calibration_read(BASE, cal_data.data); + rc = online_calibration_read(&motion_sensors[BASE], &cal_data); TEST_EQ(rc, true, "%d"); TEST_EQ(cal_data.data[X], 81, "%d"); TEST_EQ(cal_data.data[Y], -163, "%d"); |