0001
0002
0003
0004
0005
0006 #ifndef INV_ICM42600_TIMESTAMP_H_
0007 #define INV_ICM42600_TIMESTAMP_H_
0008
0009 #include <linux/kernel.h>
0010
0011 struct inv_icm42600_state;
0012
0013
0014
0015
0016
0017
0018 struct inv_icm42600_timestamp_interval {
0019 int64_t lo;
0020 int64_t up;
0021 };
0022
0023
0024
0025
0026
0027
0028
0029 struct inv_icm42600_timestamp_acc {
0030 uint32_t val;
0031 size_t idx;
0032 uint32_t values[32];
0033 };
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044 struct inv_icm42600_timestamp {
0045 struct inv_icm42600_timestamp_interval it;
0046 int64_t timestamp;
0047 uint32_t mult;
0048 uint32_t new_mult;
0049 uint32_t period;
0050 struct inv_icm42600_timestamp_acc chip_period;
0051 };
0052
0053 void inv_icm42600_timestamp_init(struct inv_icm42600_timestamp *ts,
0054 uint32_t period);
0055
0056 int inv_icm42600_timestamp_setup(struct inv_icm42600_state *st);
0057
0058 int inv_icm42600_timestamp_update_odr(struct inv_icm42600_timestamp *ts,
0059 uint32_t period, bool fifo);
0060
0061 void inv_icm42600_timestamp_interrupt(struct inv_icm42600_timestamp *ts,
0062 uint32_t fifo_period, size_t fifo_nb,
0063 size_t sensor_nb, int64_t timestamp);
0064
0065 static inline int64_t
0066 inv_icm42600_timestamp_pop(struct inv_icm42600_timestamp *ts)
0067 {
0068 ts->timestamp += ts->period;
0069 return ts->timestamp;
0070 }
0071
0072 void inv_icm42600_timestamp_apply_odr(struct inv_icm42600_timestamp *ts,
0073 uint32_t fifo_period, size_t fifo_nb,
0074 unsigned int fifo_no);
0075
0076 static inline void
0077 inv_icm42600_timestamp_reset(struct inv_icm42600_timestamp *ts)
0078 {
0079 const struct inv_icm42600_timestamp_interval interval_init = {0LL, 0LL};
0080
0081 ts->it = interval_init;
0082 ts->timestamp = 0;
0083 }
0084
0085 #endif