diff options
author | Yuval Peress <peress@chromium.org> | 2019-08-13 09:09:02 -0600 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2019-11-11 19:40:09 +0000 |
commit | 083ced83d71a6ab60204c7ada6c22d9c82731713 (patch) | |
tree | 84d730feb2e51f04bbb991a7aca4db54bfe7de8d /common/motion_sense.c | |
parent | 9f151350684fee0ac14deed0ce31ddfd520b2a36 (diff) | |
download | chrome-ec-083ced83d71a6ab60204c7ada6c22d9c82731713.tar.gz |
common: Refactor motion_sense_fifo
This change refactors the motion_sense_fifo to uniformly prefix
all the functions to avoid collisions. It also adds several unit
tests and fixes a few bugs with the fifo logic.
BUG=b:137758297
BRANCH=kukui
TEST=buildall
TEST=run CTS on arcada, kohaku, and kukui
TEST=boot kohaku (verify tablet mode works as expected)
Change-Id: I6e8492ae5fa474d0aa870088ab56f76b220a73e3
Signed-off-by: Yuval Peress <peress@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1835221
Reviewed-by: Jack Rosenthal <jrosenth@chromium.org>
Diffstat (limited to 'common/motion_sense.c')
-rw-r--r-- | common/motion_sense.c | 44 |
1 files changed, 17 insertions, 27 deletions
diff --git a/common/motion_sense.c b/common/motion_sense.c index 98c2979da1..7e1d06186b 100644 --- a/common/motion_sense.c +++ b/common/motion_sense.c @@ -78,6 +78,9 @@ static void print_spoof_mode_status(int id); /* Flags to control whether to send an ODR change event for a sensor */ static uint32_t odr_event_required; +/* Whether or not the FIFO interrupt should be enabled (set from the AP). */ +__maybe_unused static int fifo_int_enabled; + static inline int motion_sensor_in_forced_mode( const struct motion_sensor_t *sensor) { @@ -680,7 +683,7 @@ static int motion_sense_process(struct motion_sensor_t *sensor, int flush_pending = atomic_read_clear(&sensor->flush_pending); for (; flush_pending > 0; flush_pending--) { - motion_sense_insert_async_event( + motion_sense_fifo_insert_async_event( sensor, ASYNC_EVENT_FLUSH); } } @@ -690,7 +693,7 @@ static int motion_sense_process(struct motion_sensor_t *sensor, motion_sense_set_data_rate(sensor); motion_sense_set_motion_intervals(); if (IS_ENABLED(CONFIG_ACCEL_FIFO)) - motion_sense_insert_async_event( + motion_sense_fifo_insert_async_event( sensor, ASYNC_EVENT_ODR); } return ret; @@ -905,25 +908,18 @@ void motion_sense_task(void *u) * - we haven't done it for a while. */ if (IS_ENABLED(CONFIG_ACCEL_FIFO) && - (motion_sense_fifo_is_wake_up_needed() || + (motion_sense_fifo_wake_up_needed() || event & (TASK_EVENT_MOTION_ODR_CHANGE | TASK_EVENT_MOTION_FLUSH_PENDING) || + motion_sense_fifo_over_thres() || (ap_event_interval > 0 && time_after(ts_begin_task.le.lo, ts_last_int.le.lo + ap_event_interval)))) { if ((event & TASK_EVENT_MOTION_FLUSH_PENDING) == 0) { - motion_sense_fifo_stage_timestamp( + motion_sense_fifo_add_timestamp( __hw_clock_source_read()); - motion_sense_fifo_commit_data(); } ts_last_int = ts_begin_task; - /* - * Count the number of event the AP is allowed to - * collect. - */ - mutex_lock(&g_sensor_mutex); - fifo_queue_count = queue_count(&motion_sense_fifo); - mutex_unlock(&g_sensor_mutex); #ifdef CONFIG_MKBP_EVENT /* * Send an event if we know we are in S0 and the kernel @@ -933,9 +929,9 @@ void motion_sense_task(void *u) */ if ((fifo_int_enabled && sensor_active == SENSOR_ACTIVE_S0) || - wake_up_needed) { + motion_sense_fifo_wake_up_needed()) { mkbp_send_event(EC_MKBP_EVENT_SENSOR_FIFO); - wake_up_needed = 0; + motion_sense_fifo_reset_wake_up_needed(); } #endif /* CONFIG_MKBP_EVENT */ } @@ -1270,12 +1266,11 @@ static enum ec_status host_cmd_motion_sense(struct host_cmd_handler_args *args) args->response_size = sizeof(out->fifo_info); break; } - motion_sense_get_fifo_info(&out->fifo_info); + 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; } - motion_sense_fifo_lost = 0; args->response_size = sizeof(out->fifo_info) + sizeof(uint16_t) * motion_sensor_count; break; @@ -1283,17 +1278,12 @@ static enum ec_status host_cmd_motion_sense(struct host_cmd_handler_args *args) case MOTIONSENSE_CMD_FIFO_READ: if (!IS_ENABLED(CONFIG_ACCEL_FIFO)) return EC_RES_INVALID_PARAM; - mutex_lock(&g_sensor_mutex); - reported = MIN((args->response_max - sizeof(out->fifo_read)) / - motion_sense_fifo.unit_bytes, - MIN(queue_count(&motion_sense_fifo), - in->fifo_read.max_data_vector)); - reported = queue_remove_units(&motion_sense_fifo, - out->fifo_read.data, reported); - mutex_unlock(&g_sensor_mutex); - out->fifo_read.number_data = reported; - args->response_size = sizeof(out->fifo_read) + reported * - motion_sense_fifo.unit_bytes; + out->fifo_read.number_data = motion_sense_fifo_read( + args->response_max - sizeof(out->fifo_read), + in->fifo_read.max_data_vector, + out->fifo_read.data, + &(args->response_size)); + args->response_size += sizeof(out->fifo_read); break; case MOTIONSENSE_CMD_FIFO_INT_ENABLE: if (!IS_ENABLED(CONFIG_ACCEL_FIFO)) |