summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGwendal Grignou <gwendal@chromium.org>2022-07-11 03:38:58 -0700
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2022-08-03 22:02:01 +0000
commita2efacf4a0a5857176bc6f39c9bd1e4cd2e1d6ec (patch)
treeff6d158b20f5bf76a57473a35dc68e762c5eb4d0
parent13c3d7e861b177d65ef996f9eb907aebdfc41538 (diff)
downloadchrome-ec-a2efacf4a0a5857176bc6f39c9bd1e4cd2e1d6ec.tar.gz
motion_sense_fifo: Move lost to motion_sensor_fifo
Move lost field from the sensor object to inside motion_sense_fifo: It is not used anywhere else. BUG=b:237305991 BRANCH=brya TEST=make -j BOARD=crota Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Change-Id: Idfb159ed9025e859e86bb494cf5da98df9cf4a36 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3754211 Reviewed-by: Yuval Peress <peress@google.com>
-rw-r--r--common/motion_sense.c4
-rw-r--r--common/motion_sense_fifo.c21
-rw-r--r--include/motion_sense.h6
-rw-r--r--test/motion_sense_fifo.c3
-rw-r--r--zephyr/test/drivers/default/src/host_cmd/motion_sense.c6
5 files changed, 19 insertions, 21 deletions
diff --git a/common/motion_sense.c b/common/motion_sense.c
index c47105a480..5a1f3a805c 100644
--- a/common/motion_sense.c
+++ b/common/motion_sense.c
@@ -1327,10 +1327,6 @@ static enum ec_status host_cmd_motion_sense(struct host_cmd_handler_args *args)
break;
}
motion_sense_fifo_get_info(&out->fifo_info, 1);
- for (i = 0; i < motion_sensor_count; i++) {
- out->fifo_info.lost[i] = motion_sensors[i].lost;
- motion_sensors[i].lost = 0;
- }
args->response_size = sizeof(out->fifo_info) +
sizeof(uint16_t) * motion_sensor_count;
break;
diff --git a/common/motion_sense_fifo.c b/common/motion_sense_fifo.c
index f1dcd52a25..ccd1ffaa97 100644
--- a/common/motion_sense_fifo.c
+++ b/common/motion_sense_fifo.c
@@ -50,6 +50,12 @@ static struct queue fifo = QUEUE_NULL(CONFIG_ACCEL_FIFO_SIZE,
struct ec_response_motion_sensor_data);
/** Count of the number of entries lost due to a small queue. */
static int fifo_lost;
+/*
+ * How many vector events are lost in the FIFO since last time
+ * FIFO info has been transmitted.
+ */
+static uint16_t fifo_sensor_lost[MAX_MOTION_SENSORS];
+
/** Metadata for the fifo, used for staging and spreading data. */
static struct fifo_staged fifo_staged;
@@ -149,7 +155,7 @@ static void fifo_pop(void)
/* Increment lost counter if we have valid data. */
if (!is_timestamp(head))
- motion_sensors[head->sensor_num].lost++;
+ fifo_sensor_lost[head->sensor_num]++;
/*
* We're done if the initial count was non-zero and we only advanced the
@@ -228,6 +234,7 @@ static inline bool is_new_timestamp(uint8_t sensor_num)
* @param data The data to stage.
* @param sensor The sensor that generated the data
* @param valid_data The number of readable data entries in the data.
+ * sensor can be NULL (for activity sensors). valid_data must be 0 then.
*/
static void fifo_stage_unit(struct ec_response_motion_sensor_data *data,
struct motion_sensor_t *sensor, int valid_data)
@@ -557,17 +564,24 @@ commit_data_end:
void motion_sense_fifo_get_info(
struct ec_response_motion_sense_fifo_info *fifo_info, int reset)
{
+ int i;
+
mutex_lock(&g_sensor_mutex);
fifo_info->size = fifo.buffer_units;
fifo_info->count = queue_count(&fifo);
fifo_info->total_lost = fifo_lost;
+ for (i = 0; i < MAX_MOTION_SENSORS; i++) {
+ fifo_info->lost[i] = fifo_sensor_lost[i];
+ }
mutex_unlock(&g_sensor_mutex);
#ifdef CONFIG_MKBP_EVENT
fifo_info->timestamp = mkbp_last_event_time;
#endif
- if (reset)
+ if (reset) {
fifo_lost = 0;
+ memset(fifo_sensor_lost, 0, sizeof(fifo_sensor_lost));
+ }
}
/* LCOV_EXCL_START - function cannot be tested due to limitations with mkbp */
@@ -610,10 +624,13 @@ int motion_sense_fifo_read(int capacity_bytes, int max_count, void *out,
void motion_sense_fifo_reset(void)
{
+ static struct ec_response_motion_sense_fifo_info fifo_info;
+
next_timestamp_initialized = 0;
memset(&fifo_staged, 0, sizeof(fifo_staged));
motion_sense_fifo_init();
queue_init(&fifo);
+ motion_sense_fifo_get_info(&fifo_info, /*reset=*/true);
}
#ifdef CONFIG_CMD_ACCEL_FIFO
diff --git a/include/motion_sense.h b/include/motion_sense.h
index 4545d388d0..b128dd600e 100644
--- a/include/motion_sense.h
+++ b/include/motion_sense.h
@@ -220,12 +220,6 @@ struct motion_sensor_t {
uint16_t oversampling_ratio;
/*
- * How many vector events are lost in the FIFO since last time
- * FIFO info has been transmitted.
- */
- uint16_t lost;
-
- /*
* For sensors in forced mode the ideal time to collect the next
* measurement.
*
diff --git a/test/motion_sense_fifo.c b/test/motion_sense_fifo.c
index afa9a4f5cf..e9c2b749f2 100644
--- a/test/motion_sense_fifo.c
+++ b/test/motion_sense_fifo.c
@@ -436,15 +436,12 @@ static int test_get_info_size(void)
void before_test(void)
{
- static struct ec_response_motion_sense_fifo_info fifo_info;
-
motion_sense_fifo_commit_data();
motion_sense_fifo_read(sizeof(data), CONFIG_ACCEL_FIFO_SIZE, &data,
&data_bytes_read);
motion_sense_fifo_reset_needed_flags();
memset(data, 0, sizeof(data));
motion_sense_fifo_reset();
- motion_sense_fifo_get_info(&fifo_info, /*reset=*/true);
}
void run_test(int argc, char **argv)
diff --git a/zephyr/test/drivers/default/src/host_cmd/motion_sense.c b/zephyr/test/drivers/default/src/host_cmd/motion_sense.c
index accc4193e0..72d28b0824 100644
--- a/zephyr/test/drivers/default/src/host_cmd/motion_sense.c
+++ b/zephyr/test/drivers/default/src/host_cmd/motion_sense.c
@@ -690,12 +690,9 @@ ZTEST(host_cmd_motion_sense, test_fifo_flush)
struct ec_response_motion_sense *response =
(struct ec_response_motion_sense *)response_buffer;
- motion_sensors[0].lost = 5;
zassert_ok(host_cmd_motion_sense_fifo_flush(/*sensor_num=*/0, response),
NULL);
zassert_equal(1, motion_sensors[0].flush_pending, NULL);
- zassert_equal(5, response->fifo_info.lost[0], NULL);
- zassert_equal(0, motion_sensors[0].lost, NULL);
}
ZTEST(host_cmd_motion_sense, test_fifo_info)
@@ -704,10 +701,7 @@ ZTEST(host_cmd_motion_sense, test_fifo_info)
struct ec_response_motion_sense *response =
(struct ec_response_motion_sense *)response_buffer;
- motion_sensors[0].lost = 4;
zassert_ok(host_cmd_motion_sense_fifo_info(response), NULL);
- zassert_equal(4, response->fifo_info.lost[0], NULL);
- zassert_equal(0, motion_sensors[0].lost, NULL);
}
ZTEST(host_cmd_motion_sense, test_fifo_read)