1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 * Copyright (C) 2020 Invensense, Inc.
6 #ifndef INV_SENSORS_TIMESTAMP_H_
7 #define INV_SENSORS_TIMESTAMP_H_
10 * struct inv_sensors_timestamp_chip - chip internal properties
11 * @clock_period: internal clock period in ns
12 * @jitter: acceptable jitter in per-mille
13 * @init_period: chip initial period at reset in ns
15 struct inv_sensors_timestamp_chip {
16 uint32_t clock_period;
22 * struct inv_sensors_timestamp_interval - timestamps interval
23 * @lo: interval lower bound
24 * @up: interval upper bound
26 struct inv_sensors_timestamp_interval {
32 * struct inv_sensors_timestamp_acc - accumulator for computing an estimation
33 * @val: current estimation of the value, the mean of all values
34 * @idx: current index of the next free place in values table
35 * @values: table of all measured values, use for computing the mean
37 struct inv_sensors_timestamp_acc {
44 * struct inv_sensors_timestamp - timestamp management states
45 * @chip: chip internal characteristics
46 * @min_period: minimal acceptable clock period
47 * @max_period: maximal acceptable clock period
48 * @it: interrupts interval timestamps
49 * @timestamp: store last timestamp for computing next data timestamp
50 * @mult: current internal period multiplier
51 * @new_mult: new set internal period multiplier (not yet effective)
52 * @period: measured current period of the sensor
53 * @chip_period: accumulator for computing internal chip period
55 struct inv_sensors_timestamp {
56 struct inv_sensors_timestamp_chip chip;
59 struct inv_sensors_timestamp_interval it;
64 struct inv_sensors_timestamp_acc chip_period;
67 void inv_sensors_timestamp_init(struct inv_sensors_timestamp *ts,
68 const struct inv_sensors_timestamp_chip *chip);
70 int inv_sensors_timestamp_update_odr(struct inv_sensors_timestamp *ts,
71 uint32_t period, bool fifo);
73 void inv_sensors_timestamp_interrupt(struct inv_sensors_timestamp *ts,
74 uint32_t fifo_period, size_t fifo_nb,
75 size_t sensor_nb, int64_t timestamp);
77 static inline int64_t inv_sensors_timestamp_pop(struct inv_sensors_timestamp *ts)
79 ts->timestamp += ts->period;
83 void inv_sensors_timestamp_apply_odr(struct inv_sensors_timestamp *ts,
84 uint32_t fifo_period, size_t fifo_nb,
85 unsigned int fifo_no);
87 static inline void inv_sensors_timestamp_reset(struct inv_sensors_timestamp *ts)
89 const struct inv_sensors_timestamp_interval interval_init = {0LL, 0LL};
91 ts->it = interval_init;