Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-or-later */
0002 /*
0003  * Copyright (C) 2020 Invensense, Inc.
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  * struct inv_icm42600_timestamp_interval - timestamps interval
0015  * @lo: interval lower bound
0016  * @up: interval upper bound
0017  */
0018 struct inv_icm42600_timestamp_interval {
0019     int64_t lo;
0020     int64_t up;
0021 };
0022 
0023 /**
0024  * struct inv_icm42600_timestamp_acc - accumulator for computing an estimation
0025  * @val:    current estimation of the value, the mean of all values
0026  * @idx:    current index of the next free place in values table
0027  * @values: table of all measured values, use for computing the mean
0028  */
0029 struct inv_icm42600_timestamp_acc {
0030     uint32_t val;
0031     size_t idx;
0032     uint32_t values[32];
0033 };
0034 
0035 /**
0036  * struct inv_icm42600_timestamp - timestamp management states
0037  * @it:         interrupts interval timestamps
0038  * @timestamp:      store last timestamp for computing next data timestamp
0039  * @mult:       current internal period multiplier
0040  * @new_mult:       new set internal period multiplier (not yet effective)
0041  * @period:     measured current period of the sensor
0042  * @chip_period:    accumulator for computing internal chip period
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