summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorYuval Peress <peress@chromium.org>2019-08-13 09:09:02 -0600
committerCommit Bot <commit-bot@chromium.org>2019-09-27 00:49:46 +0000
commit36b47ab3c06e477f5e95d6d9e84a5220248784e6 (patch)
treed4df5bb2b02e09de5494a1eddc84c24e208d9c24 /include
parent2d74095e5c923e40e6230f803537c1e968fd2631 (diff)
downloadchrome-ec-36b47ab3c06e477f5e95d6d9e84a5220248784e6.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=None TEST=buildall & run CTS on arcada Change-Id: I7aae45382b07d6c8858e07215c33e710c7ed27ec Signed-off-by: Yuval Peress <peress@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1704166 Reviewed-by: Jack Rosenthal <jrosenth@chromium.org>
Diffstat (limited to 'include')
-rw-r--r--include/motion_sense_fifo.h80
1 files changed, 47 insertions, 33 deletions
diff --git a/include/motion_sense_fifo.h b/include/motion_sense_fifo.h
index 6b306b5f29..d47c23af94 100644
--- a/include/motion_sense_fifo.h
+++ b/include/motion_sense_fifo.h
@@ -7,14 +7,8 @@
#define __CROS_EC_MOTION_SENSE_FIFO_H
#include "motion_sense.h"
-#include "task.h"
-
-extern struct queue motion_sense_fifo;
-extern int wake_up_needed;
-extern int fifo_int_enabled;
-extern int fifo_queue_count;
-extern int motion_sense_fifo_lost;
+/** Allowed async events. */
enum motion_sense_async_event {
ASYNC_EVENT_FLUSH = MOTIONSENSE_SENSOR_FLAG_FLUSH |
MOTIONSENSE_SENSOR_FLAG_TIMESTAMP,
@@ -22,6 +16,26 @@ enum motion_sense_async_event {
MOTIONSENSE_SENSOR_FLAG_TIMESTAMP,
};
+/** Whether or not we need to wake up the AP. */
+extern int motion_sense_fifo_wake_up_needed;
+
+/**
+ * Insert an async event into the fifo.
+ *
+ * @param sensor The sensor that generated the async event.
+ * @param event The event to insert.
+ */
+void motion_sense_fifo_insert_async_event(
+ struct motion_sensor_t *sensor,
+ enum motion_sense_async_event event);
+
+/**
+ * Insert a timestamp into the fifo.
+ *
+ * @param timestamp The timestamp to insert.
+ */
+void motion_sense_fifo_add_timestamp(uint32_t timestamp);
+
/**
* Stage data to the fifo, including a timestamp. This data will not be
* available to the AP until motion_sense_fifo_commit_data is called.
@@ -32,46 +46,46 @@ enum motion_sense_async_event {
* @param time accurate time (ideally measured in an interrupt) the sample
* was taken at
*/
-void motion_sense_fifo_stage_data(struct ec_response_motion_sensor_data *data,
- struct motion_sensor_t *sensor,
- int valid_data,
- uint32_t time);
+void motion_sense_fifo_stage_data(
+ struct ec_response_motion_sensor_data *data,
+ struct motion_sensor_t *sensor,
+ int valid_data,
+ uint32_t time);
/**
- * Commits all staged data to the fifo. If multiple readings were placed using
- * the same timestamps, they will be spread out.
+ * Commit all the currently staged data to the fifo. Doing so makes it readable
+ * to the AP.
*/
void motion_sense_fifo_commit_data(void);
/**
- * Insert an async event into the fifo.
- *
- * @param sensor Pointer to the sensor generating the event.
- * @param evt The event to insert.
- */
-void motion_sense_insert_async_event(struct motion_sensor_t *sensor,
- enum motion_sense_async_event evt);
-
-/**
- * Stage a timestamp into the fifo.
+ * Get information about the fifo.
*
- * @param timestamp The timestamp to stage.
+ * @param fifo_info The struct to modify with the current information about the
+ * fifo.
+ * @param reset Whether or not to reset statistics after reading them.
*/
-void motion_sense_fifo_stage_timestamp(uint32_t timestamp);
+void motion_sense_fifo_get_info(
+ struct ec_response_motion_sense_fifo_info *fifo_info,
+ int reset);
/**
- * Get information about the fifo.
+ * Check whether or not the fifo has gone over its threshold.
*
- * @param fifo_info The struct to store the info.
+ * @return 1 if yes, 0 for no.
*/
-void motion_sense_get_fifo_info(
- struct ec_response_motion_sense_fifo_info *fifo_info);
+int motion_sense_fifo_over_thres(void);
/**
- * Checks if either the AP should be woken up due to the fifo.
+ * Read available committed entries from the fifo.
*
- * @return 1 if the AP should be woken up, 0 otherwise.
+ * @param capacity_bytes The number of bytes available to be written to `out`.
+ * @param max_count The maximum number of entries to be placed in `out`.
+ * @param out The target to copy the data into.
+ * @param out_size The number of bytes written to `out`.
+ * @return The number of entries written to `out`.
*/
-int motion_sense_fifo_is_wake_up_needed(void);
+int motion_sense_fifo_read(int capacity_bytes, int max_count, void *out,
+ uint16_t *out_size);
-#endif /* __CROS_EC_MOTION_SENSE_FIFO_H */
+#endif /*__CROS_EC_MOTION_SENSE_FIFO_H */