We have experienced the BMI160 driver (https://github.com/BoschSensortec/BMI160_driver/) calling read() with a length of 0. What should the read() function we supply return in these cases? BMI160_OK?
Solved! Go to Solution.
Could you please tell us which API/function was causing this? Thanks.
We have only seen it from bmi160_get_fifo_data()
Note: We always set the length in "struct bmi160_fifo_frame" inside "struct bmi160_dev" to an appropriate value before passing it as parameter to bmi160_get_fifo_data()
Any news on this? Do you need further information zgg?
Generally, the default fifo read length should be initialized.
one example in README.md file is :
int8_t fifo_gyro_header_time_data(struct bmi160_dev *dev)
int8_t rslt = 0;
/* Declare memory to store the raw FIFO buffer information */
/* Modify the FIFO buffer instance and link to the device instance */
struct bmi160_fifo_frame fifo_frame;
fifo_frame.data = fifo_buff;
fifo_frame.length = 300;
dev->fifo = &fifo_frame;
uint16_t index = 0;
Back to function bmi160_get_fifo_data(struct bmi160_dev const *dev)
if dev->fifo->length is 0 , it will cause fifo read error in sentence:
rslt = dev->read(dev->id, addr, dev->fifo->data, dev->fifo->length);
so error should be returned.
After reviewing the API code, it is found that there is potential risk that the bytes_to_read may be 0 if random read the fifo in polling mode.
so it is recommended to modify the sentence from:
if (dev->fifo->length > bytes_to_read)
if ((dev->fifo->length > bytes_to_read) && 0 != bytes_to_read)