@@ -145,42 +145,29 @@ static int lsm6dsv16x_decoder_get_frame_count(const uint8_t *buffer,
145145 * frame_count = 1 ;
146146 return 0 ;
147147 default :
148+ * frame_count = 0 ;
148149 return - ENOTSUP ;
149150 }
150151
151152 return 0 ;
152153 }
153154
154155#ifdef CONFIG_LSM6DSV16X_STREAM
155- * frame_count = data -> fifo_count ;
156- #endif
157- return 0 ;
158- }
159-
160- #ifdef CONFIG_LSM6DSV16X_STREAM
161- static int lsm6dsv16x_decode_fifo (const uint8_t * buffer , struct sensor_chan_spec chan_spec ,
162- uint32_t * fit , uint16_t max_count , void * data_out )
163- {
164156 const struct lsm6dsv16x_fifo_data * edata = (const struct lsm6dsv16x_fifo_data * )buffer ;
165- const uint8_t * buffer_end , * tmp_buffer ;
166- const struct lsm6dsv16x_decoder_header * header = & edata -> header ;
167- int count = 0 ;
157+ const uint8_t * buffer_end ;
168158 uint8_t fifo_tag ;
169- uint16_t xl_count = 0 , gy_count = 0 ;
170159 uint8_t tot_accel_fifo_words = 0 , tot_gyro_fifo_words = 0 ;
171160
172161#if defined(CONFIG_LSM6DSV16X_ENABLE_TEMP )
173162 uint8_t tot_temp_fifo_words = 0 ;
174- uint16_t temp_count = 0 ;
175163#endif
176164
177165 buffer += sizeof (struct lsm6dsv16x_fifo_data );
178166 buffer_end = buffer + LSM6DSV16X_FIFO_SIZE (edata -> fifo_count );
179167
180168 /* count total FIFO word for each tag */
181- tmp_buffer = buffer ;
182- while (tmp_buffer < buffer_end ) {
183- fifo_tag = (tmp_buffer [0 ] >> 3 );
169+ while (buffer < buffer_end ) {
170+ fifo_tag = (buffer [0 ] >> 3 );
184171
185172 switch (fifo_tag ) {
186173 case LSM6DSV16X_XL_NC_TAG :
@@ -198,9 +185,63 @@ static int lsm6dsv16x_decode_fifo(const uint8_t *buffer, struct sensor_chan_spec
198185 break ;
199186 }
200187
201- tmp_buffer += LSM6DSV16X_FIFO_ITEM_LEN ;
188+ buffer += LSM6DSV16X_FIFO_ITEM_LEN ;
189+ }
190+
191+ switch (chan_spec .chan_type ) {
192+ case SENSOR_CHAN_ACCEL_X :
193+ case SENSOR_CHAN_ACCEL_Y :
194+ case SENSOR_CHAN_ACCEL_Z :
195+ case SENSOR_CHAN_ACCEL_XYZ :
196+ * frame_count = tot_accel_fifo_words ;
197+ break ;
198+
199+ case SENSOR_CHAN_GYRO_X :
200+ case SENSOR_CHAN_GYRO_Y :
201+ case SENSOR_CHAN_GYRO_Z :
202+ case SENSOR_CHAN_GYRO_XYZ :
203+ * frame_count = tot_gyro_fifo_words ;
204+ break ;
205+
206+ #if defined(CONFIG_LSM6DSV16X_ENABLE_TEMP )
207+ case SENSOR_CHAN_DIE_TEMP :
208+ * frame_count = tot_temp_fifo_words ;
209+ break ;
210+ #endif
211+ default :
212+ * frame_count = 0 ;
213+ break ;
214+ }
215+ #endif
216+ return 0 ;
217+ }
218+
219+ #ifdef CONFIG_LSM6DSV16X_STREAM
220+ static int lsm6dsv16x_decode_fifo (const uint8_t * buffer , struct sensor_chan_spec chan_spec ,
221+ uint32_t * fit , uint16_t max_count , void * data_out )
222+ {
223+ const struct lsm6dsv16x_fifo_data * edata = (const struct lsm6dsv16x_fifo_data * )buffer ;
224+ const uint8_t * buffer_end ;
225+ const struct lsm6dsv16x_decoder_header * header = & edata -> header ;
226+ int count = 0 ;
227+ uint8_t fifo_tag ;
228+ uint16_t xl_count = 0 , gy_count = 0 ;
229+ uint16_t tot_chan_fifo_words = 0 ;
230+
231+ #if defined(CONFIG_LSM6DSV16X_ENABLE_TEMP )
232+ uint16_t temp_count = 0 ;
233+ #endif
234+ int ret ;
235+
236+ /* count total FIFO word for each tag */
237+ ret = lsm6dsv16x_decoder_get_frame_count (buffer , chan_spec , & tot_chan_fifo_words );
238+ if (ret < 0 ) {
239+ return 0 ;
202240 }
203241
242+ buffer += sizeof (struct lsm6dsv16x_fifo_data );
243+ buffer_end = buffer + LSM6DSV16X_FIFO_SIZE (edata -> fifo_count );
244+
204245 /*
205246 * Timestamp in header is set when FIFO threshold is reached, so
206247 * set time baseline going back in past according to total number
@@ -209,16 +250,16 @@ static int lsm6dsv16x_decode_fifo(const uint8_t *buffer, struct sensor_chan_spec
209250 if (SENSOR_CHANNEL_IS_ACCEL (chan_spec .chan_type )) {
210251 ((struct sensor_data_header * )data_out )-> base_timestamp_ns =
211252 edata -> header .timestamp -
212- (tot_accel_fifo_words - 1 ) * accel_period_ns [edata -> accel_batch_odr ];
253+ (tot_chan_fifo_words - 1 ) * accel_period_ns [edata -> accel_batch_odr ];
213254 } else if (SENSOR_CHANNEL_IS_GYRO (chan_spec .chan_type )) {
214255 ((struct sensor_data_header * )data_out )-> base_timestamp_ns =
215256 edata -> header .timestamp -
216- (tot_gyro_fifo_words - 1 ) * gyro_period_ns [edata -> gyro_batch_odr ];
257+ (tot_chan_fifo_words - 1 ) * gyro_period_ns [edata -> gyro_batch_odr ];
217258#if defined(CONFIG_LSM6DSV16X_ENABLE_TEMP )
218259 } else if (chan_spec .chan_type == SENSOR_CHAN_DIE_TEMP ) {
219260 ((struct sensor_data_header * )data_out )-> base_timestamp_ns =
220261 edata -> header .timestamp -
221- (tot_temp_fifo_words - 1 ) * temp_period_ns [edata -> temp_batch_odr ];
262+ (tot_chan_fifo_words - 1 ) * temp_period_ns [edata -> temp_batch_odr ];
222263#endif
223264 }
224265
0 commit comments