Bosch Sensortec Community

    cancel
    Showing results for 
    Search instead for 
    Did you mean: 
    SOLVED

    BMI160 driver asking for 0 bytes

    BMI160 driver asking for 0 bytes

    arurke
    Established Member

    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?

    7 REPLIES 7

    zgg
    Long-established Member

    Hello

     

    Could you please tell us which API/function was causing this? Thanks. 

    arurke
    Established Member

    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()

    arurke
    Established Member

    Any news on this? Do you need further information zgg?

     

    Hi,

    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 */
     uint8_t fifo_buff[300];
     
     /* 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)

    to

    if ((dev->fifo->length > bytes_to_read) &&  0 != bytes_to_read)

     

    Icon--AD-black-48x48Icon--address-consumer-data-black-48x48Icon--appointment-black-48x48Icon--back-left-black-48x48Icon--calendar-black-48x48Icon--center-alignedIcon--Checkbox-checkIcon--clock-black-48x48Icon--close-black-48x48Icon--compare-black-48x48Icon--confirmation-black-48x48Icon--dealer-details-black-48x48Icon--delete-black-48x48Icon--delivery-black-48x48Icon--down-black-48x48Icon--download-black-48x48Ic-OverlayAlertIcon--externallink-black-48x48Icon-Filledforward-right_adjustedIcon--grid-view-black-48x48IC_gd_Check-Circle170821_Icons_Community170823_Bosch_Icons170823_Bosch_Icons170821_Icons_CommunityIC-logout170821_Icons_Community170825_Bosch_Icons170821_Icons_CommunityIC-shopping-cart2170821_Icons_CommunityIC-upIC_UserIcon--imageIcon--info-i-black-48x48Icon--left-alignedIcon--Less-minimize-black-48x48Icon-FilledIcon--List-Check-grennIcon--List-Check-blackIcon--List-Cross-blackIcon--list-view-mobile-black-48x48Icon--list-view-black-48x48Icon--More-Maximize-black-48x48Icon--my-product-black-48x48Icon--newsletter-black-48x48Icon--payment-black-48x48Icon--print-black-48x48Icon--promotion-black-48x48Icon--registration-black-48x48Icon--Reset-black-48x48Icon--right-alignedshare-circle1Icon--share-black-48x48Icon--shopping-bag-black-48x48Icon-shopping-cartIcon--start-play-black-48x48Icon--store-locator-black-48x48Ic-OverlayAlertIcon--summary-black-48x48tumblrIcon-FilledvineIc-OverlayAlertwhishlist