From c4249aecdc905604d19e654e7ab7f75b4a2b321b Mon Sep 17 00:00:00 2001 From: Ramona Gradinariu Date: Tue, 23 Apr 2024 14:03:35 +0300 Subject: [PATCH] drivers: imu: adis: Rework burst read API Rework burst read API such that it can be used for devices which have 32-bit temperature data and 32-bit data counter. Furthermore, some devices support burst reading with 16-bit LSB first, while other support burst reading with 16-bit MSB first in burst data, thus memcpy cannot be used anymore to simply copy the whole burst data, instead, a burst data structure has been created which should be populated accordingly by each driver. The iio_adis generic implementation now populates the iio buffer using this structure. Rework the unit tests accordingly. Signed-off-by: Ramona Gradinariu --- drivers/imu/adis.c | 106 +++++++----- drivers/imu/adis.h | 28 +++- drivers/imu/adis1657x.c | 103 ++++++++---- drivers/imu/adis_internals.h | 5 +- drivers/imu/iio_adis.c | 182 +++++++++++++++------ drivers/imu/iio_adis_internals.h | 2 +- tests/drivers/imu/test/support/test_adis.c | 71 +++----- tests/drivers/imu/test/test_adis1650x.c | 5 +- tests/drivers/imu/test/test_adis1657x.c | 3 +- 9 files changed, 313 insertions(+), 192 deletions(-) diff --git a/drivers/imu/adis.c b/drivers/imu/adis.c index 9dadfc4f091..27458282cad 100644 --- a/drivers/imu/adis.c +++ b/drivers/imu/adis.c @@ -2456,10 +2456,7 @@ int adis_read_fls_mem_wr_cntr(struct adis_dev *adis, uint32_t *fls_mem_wr_cntr) /** * @brief Read burst data. * @param adis - The adis device. - * @param buff_size - Size of buff, if burst32 is true size must be - * higher or equal to 30, if burst32 is false size - * must be higher or equal to 18 - * @param buff - Array filled with read data. + * @param data - The burst read data structure to be populated. * @param burst32 - True if 32-bit data is requested for accel * and gyro (or delta angle and delta velocity) * measurements, false if 16-bit data is requested. @@ -2468,18 +2465,12 @@ int adis_read_fls_mem_wr_cntr(struct adis_dev *adis, uint32_t *fls_mem_wr_cntr) * @param fifo_pop - In case FIFO is present, will pop the fifo if * true. Unused if FIFO is not present. * @return 0 in case of success, error code otherwise. + * -EAGAIN in case the request has to be sent again due to data being unavailable + * at the time of the request. */ -int adis_read_burst_data(struct adis_dev *adis, uint8_t buff_size, - uint16_t *buff, bool burst32, uint8_t burst_sel, - bool fifo_pop) +int adis_read_burst_data(struct adis_dev *adis, struct adis_burst_data *data, + bool burst32, uint8_t burst_sel, bool fifo_pop) { - /* If custom implementation is available, use it. */ - if (adis->info->read_burst_data) - return adis->info->read_burst_data(adis, buff_size, buff, burst32, burst_sel, - fifo_pop); - int ret; - uint8_t msg_size, idx; - /* Device does not support delta data readings with burst method */ if (!(adis->info->flags & ADIS_HAS_BURST_DELTA_DATA) && burst_sel) return -EINVAL; @@ -2488,32 +2479,37 @@ int adis_read_burst_data(struct adis_dev *adis, uint8_t buff_size, if (!(adis->info->flags & ADIS_HAS_BURST32) && burst32) return -EINVAL; - /* Make sure enough size is allocated if burst32 is true */ - /* burst 32 data: 1 * 2 (diag) + 6 * 4 + 1 * 2 (temp) + 1 * 2 (counter) = 30 */ - if (burst32 && buff_size < 30) - return -EINVAL; + /* If custom implementation is available, use it. */ + if (adis->info->read_burst_data) + return adis->info->read_burst_data(adis, data, burst32, burst_sel, fifo_pop); - /* Make sure enough size is allocated if burst32 is false */ - /* burst 32 data: 1 * 2 (diag) + 6 * 2 + 1 * 2 (temp) + 1 * 2 (counter) = 18 */ - if (!burst32 && buff_size < 18) - return -EINVAL; + int ret = 0; + uint8_t msg_size = ADIS_MSG_SIZE_16_BIT_BURST; if (adis->info->flags & ADIS_HAS_BURST32) { if (adis->burst32 != burst32) { ret = adis_write_burst32(adis, burst32); if (ret) return ret; + ret = -EAGAIN; } if (adis->burst_sel != burst_sel) { ret = adis_write_burst_sel(adis, burst_sel); if (ret) return ret; + ret = -EAGAIN; } - msg_size = ADIS_MSG_SIZE_16_BIT_BURST; - } else { - msg_size = ADIS_MSG_SIZE_32_BIT_BURST; } + /* If burst32 or burst select has changed, wait for the next reading + request to actually read the data, because the according data will be available + only after the next data ready impulse. */ + if (ret == -EAGAIN) + return ret; + + if (burst32) + msg_size = ADIS_MSG_SIZE_32_BIT_BURST; + uint8_t buffer[msg_size + ADIS_READ_BURST_DATA_CMD_SIZE]; buffer[0] = ADIS_READ_BURST_DATA_CMD_MSB; @@ -2532,29 +2528,49 @@ int adis_read_burst_data(struct adis_dev *adis, uint8_t buff_size, adis->diag_flags.checksum_err = false; - if (burst32 && !(adis->info->flags & ADIS_HAS_BURST32)) { - /* burst32 requested, but device does not support burst32 readings, - thus reading directly from registers */ - uint32_t reg_val; - /* Diag data */ - buff[0] = buffer[ADIS_READ_BURST_DATA_CMD_SIZE]; - - for (idx = 0; idx < 6; idx++) { - buff[idx * 2] = buffer[idx + ADIS_READ_BURST_DATA_CMD_SIZE + 1]; - ret = adis_read_reg(adis, adis->info->field_map->x_gyro.reg_addr + idx * 4, - ®_val, 2); - if (ret) - return ret; - buff[idx * 2 + 1] = reg_val; - } - /* Temp data */ - buff[13] = buffer[7]; - /* Counter data */ - buff[14] = buffer[8]; + uint8_t axis_data_size = 12; + if (burst32) + axis_data_size = 24; + + uint8_t axis_data_offset = ADIS_READ_BURST_DATA_CMD_SIZE + 2; + uint8_t temp_offset = axis_data_offset + axis_data_size; + uint8_t data_cntr_offset = temp_offset + 2; + + if (burst32) { + memcpy(&data->x_gyro_lsb, &buffer[axis_data_offset], 2); + memcpy(&data->x_gyro_msb, &buffer[axis_data_offset + 2], 2); + memcpy(&data->y_gyro_lsb, &buffer[axis_data_offset + 4], 2); + memcpy(&data->y_gyro_msb, &buffer[axis_data_offset + 6], 2); + memcpy(&data->z_gyro_lsb, &buffer[axis_data_offset + 8], 2); + memcpy(&data->z_gyro_msb, &buffer[axis_data_offset + 10], 2); + memcpy(&data->x_accel_lsb, &buffer[axis_data_offset + 12], 2); + memcpy(&data->x_accel_msb, &buffer[axis_data_offset + 14], 2); + memcpy(&data->y_accel_lsb, &buffer[axis_data_offset + 16], 2); + memcpy(&data->y_accel_msb, &buffer[axis_data_offset + 18], 2); + memcpy(&data->z_accel_lsb, &buffer[axis_data_offset + 20], 2); + memcpy(&data->z_accel_msb, &buffer[axis_data_offset + 22], 2); } else { - memcpy(buff, &buffer[ADIS_READ_BURST_DATA_CMD_SIZE], buff_size); + data->x_gyro_lsb = 0; + memcpy(&data->x_gyro_msb, &buffer[axis_data_offset], 2); + data->y_gyro_lsb = 0; + memcpy(&data->y_gyro_msb, &buffer[axis_data_offset + 2], 2); + data->z_gyro_lsb = 0; + memcpy(&data->z_gyro_msb, &buffer[axis_data_offset + 4], 2); + data->x_accel_lsb = 0; + memcpy(&data->x_accel_msb, &buffer[axis_data_offset + 6], 2); + data->y_accel_lsb = 0; + memcpy(&data->y_accel_msb, &buffer[axis_data_offset + 8], 2); + data->z_accel_lsb = 0; + memcpy(&data->z_accel_msb, &buffer[axis_data_offset + 10], 2); } + data->temp_msb = 0; + /* Temp data */ + memcpy(&data->temp_lsb, &buffer[temp_offset], 2); + /* Counter data - aligned */ + data->data_cntr_lsb = no_os_get_unaligned_be16(&buffer[data_cntr_offset]); + data->data_cntr_msb = 0; + /* Update diagnosis flags at each reading */ adis_update_diag_flags(adis, buffer[ADIS_READ_BURST_DATA_CMD_SIZE]); diff --git a/drivers/imu/adis.h b/drivers/imu/adis.h index c833de3361f..f46f262f0a6 100644 --- a/drivers/imu/adis.h +++ b/drivers/imu/adis.h @@ -180,6 +180,29 @@ struct adis_scale_fractional_log2 { uint32_t power; }; + +/** @struct adis_burst_data + * @brief ADIS burst data structure + */ +struct adis_burst_data { + uint16_t temp_lsb; + uint16_t temp_msb; + uint16_t data_cntr_lsb; + uint16_t data_cntr_msb; + uint16_t x_gyro_lsb; + uint16_t x_gyro_msb; + uint16_t y_gyro_lsb; + uint16_t y_gyro_msb; + uint16_t z_gyro_lsb; + uint16_t z_gyro_msb; + uint16_t x_accel_lsb; + uint16_t x_accel_msb; + uint16_t y_accel_lsb; + uint16_t y_accel_msb; + uint16_t z_accel_lsb; + uint16_t z_accel_msb; +}; + /** @struct adis_dev * @brief ADIS device descriptor structure */ @@ -596,9 +619,8 @@ int adis_write_usr_scr_3(struct adis_dev *adis, uint32_t usr_scr_3); int adis_read_fls_mem_wr_cntr(struct adis_dev *adis, uint32_t *fls_mem_wr_cntr); /*! Read burst data */ -int adis_read_burst_data(struct adis_dev *adis, uint8_t buff_size, - uint16_t *buff, bool burst32, uint8_t burst_sel, - bool fifo_pop); +int adis_read_burst_data(struct adis_dev *adis,struct adis_burst_data *data, + bool burst32, uint8_t burst_sel, bool fifo_pop); /*! Update external clock frequency. */ int adis_update_ext_clk_freq(struct adis_dev *adis, uint32_t clk_freq); diff --git a/drivers/imu/adis1657x.c b/drivers/imu/adis1657x.c index 096a2c3ddbd..caa9659dfb8 100644 --- a/drivers/imu/adis1657x.c +++ b/drivers/imu/adis1657x.c @@ -260,52 +260,49 @@ static int adis1657x_get_scale(struct adis_dev *adis, /** * @brief Read burst data. * @param adis - The adis device. - * @param buff_size - Size of buff, if burst32 is true size must be - * higher or equal to 30, if burst32 is false size - * must be higher or equal to 18 - * @param buff - Array filled with read data. + * @param data - The burst read data structure to be populated. * @param burst32 - True if 32-bit data is requested for accel * and gyro (or delta angle and delta velocity) * measurements, false if 16-bit data is requested. * @param burst_sel - 0 if accel and gyro data is requested, 1 * if delta angle and delta velocity is requested. - * @param fifo_pop - Will pop the fifo if true. + * @param fifo_pop - In case FIFO is present, will pop the fifo if + * true. Unused if FIFO is not present. * @return 0 in case of success, error code otherwise. + * -EAGAIN in case the request has to be sent again due to data being unavailable + * at the time of the request. */ -int adis1657x_read_burst_data(struct adis_dev *adis, uint8_t buff_size, - uint16_t *buff, bool burst32, uint8_t burst_sel, - bool fifo_pop) +int adis1657x_read_burst_data(struct adis_dev *adis, + struct adis_burst_data *data, + bool burst32, uint8_t burst_sel, bool fifo_pop) { - int ret; - uint8_t msg_size; + int ret = 0; + uint8_t msg_size = ADIS1657X_MSG_SIZE_16_BIT_BURST_FIFO; uint8_t idx; - /* Make sure enough size is allocated if burst32 is true */ - /* burst 32 data: 1 * 2 (diag) + 6 * 4 + 1 * 2 (temp) + 1 * 2 (counter) = 30 */ - if (burst32 && buff_size < 30) - return -EINVAL; - - /* Make sure enough size is allocated if burst32 is false */ - /* burst 32 data: 1 * 2 (diag) + 6 * 2 + 1 * 2 (temp) + 1 * 2 (counter) = 18 */ - if (!burst32 && buff_size < 18) - return -EINVAL; - - if (adis->burst32 != burst32) { - ret = adis_write_burst32(adis, burst32); - if (ret) - return ret; - } - if (adis->burst_sel != burst_sel) { - ret = adis_write_burst_sel(adis, burst_sel); - if (ret) - return ret; + if (adis->info->flags & ADIS_HAS_BURST32) { + if (adis->burst32 != burst32) { + ret = adis_write_burst32(adis, burst32); + if (ret) + return ret; + ret = -EAGAIN; + } + if (adis->burst_sel != burst_sel) { + ret = adis_write_burst_sel(adis, burst_sel); + if (ret) + return ret; + ret = -EAGAIN; + } } + /* If burst32 or burst select has changed, wait for the next reading + request to actually read the data, because the according data will be available + only after the next data ready impulse. */ + if (ret == -EAGAIN) + return ret; + if (burst32) msg_size = ADIS1657X_MSG_SIZE_32_BIT_BURST_FIFO; - else - msg_size = ADIS1657X_MSG_SIZE_16_BIT_BURST_FIFO; - uint8_t buffer[msg_size + ADIS_READ_BURST_DATA_CMD_SIZE]; @@ -337,8 +334,48 @@ int adis1657x_read_burst_data(struct adis_dev *adis, uint8_t buff_size, adis->diag_flags.checksum_err = false; - memcpy(buff, &buffer[ADIS_READ_BURST_DATA_CMD_SIZE], buff_size); + uint8_t axis_data_size = 12; + if (burst32) + axis_data_size = 24; + + uint8_t axis_data_offset = ADIS_READ_BURST_DATA_CMD_SIZE + 2; + uint8_t temp_offset = axis_data_offset + axis_data_size; + uint8_t data_cntr_offset = temp_offset + 2; + + if (burst32) { + memcpy(&data->x_gyro_lsb, &buffer[axis_data_offset], 2); + memcpy(&data->x_gyro_msb, &buffer[axis_data_offset + 2], 2); + memcpy(&data->y_gyro_lsb, &buffer[axis_data_offset + 4], 2); + memcpy(&data->y_gyro_msb, &buffer[axis_data_offset + 6], 2); + memcpy(&data->z_gyro_lsb, &buffer[axis_data_offset + 8], 2); + memcpy(&data->z_gyro_msb, &buffer[axis_data_offset + 10], 2); + memcpy(&data->x_accel_lsb, &buffer[axis_data_offset + 12], 2); + memcpy(&data->x_accel_msb, &buffer[axis_data_offset + 14], 2); + memcpy(&data->y_accel_lsb, &buffer[axis_data_offset + 16], 2); + memcpy(&data->y_accel_msb, &buffer[axis_data_offset + 18], 2); + memcpy(&data->z_accel_lsb, &buffer[axis_data_offset + 20], 2); + memcpy(&data->z_accel_msb, &buffer[axis_data_offset + 22], 2); + } else { + data->x_gyro_lsb = 0; + memcpy(&data->x_gyro_msb, &buffer[axis_data_offset], 2); + data->y_gyro_lsb = 0; + memcpy(&data->y_gyro_msb, &buffer[axis_data_offset + 2], 2); + data->z_gyro_lsb = 0; + memcpy(&data->z_gyro_msb, &buffer[axis_data_offset + 4], 2); + data->x_accel_lsb = 0; + memcpy(&data->x_accel_msb, &buffer[axis_data_offset + 6], 2); + data->y_accel_lsb = 0; + memcpy(&data->y_accel_msb, &buffer[axis_data_offset + 8], 2); + data->z_accel_lsb = 0; + memcpy(&data->z_accel_msb, &buffer[axis_data_offset + 10], 2); + } + data->temp_msb = 0; + /* Temp data */ + memcpy(&data->temp_lsb, &buffer[temp_offset], 2); + /* Counter data - aligned */ + data->data_cntr_lsb = no_os_get_unaligned_be16(&buffer[data_cntr_offset]);; + data->data_cntr_msb = 0; /* Update diagnosis flags at each reading */ adis_update_diag_flags(adis, buffer[ADIS_READ_BURST_DATA_CMD_SIZE]); diff --git a/drivers/imu/adis_internals.h b/drivers/imu/adis_internals.h index 1c1decde972..8f4adeeb7f8 100644 --- a/drivers/imu/adis_internals.h +++ b/drivers/imu/adis_internals.h @@ -364,9 +364,8 @@ struct adis_chip_info { int (*write_reg)(struct adis_dev *adis, uint32_t reg, uint32_t val, uint32_t size); /** Chip specifc implementation for reading burst data. */ - int (*read_burst_data)(struct adis_dev *adis, uint8_t buff_size, - uint16_t *buff, bool burst32, uint8_t burst_sel, - bool fifo_pop); + int (*read_burst_data)(struct adis_dev *adis,struct adis_burst_data *data, + bool burst32, uint8_t burst_sel, bool fifo_pop); }; /*! Check if the checksum for burst data is correct. */ diff --git a/drivers/imu/iio_adis.c b/drivers/imu/iio_adis.c index 98db4868394..567586bfb26 100644 --- a/drivers/imu/iio_adis.c +++ b/drivers/imu/iio_adis.c @@ -1073,18 +1073,12 @@ int adis_iio_pre_enable(void* dev, uint32_t mask) iio_adis->burst_sel = 1; else iio_adis->burst_sel = 0; - ret = adis_write_burst_sel(adis, iio_adis->burst_sel); - if (ret) - return ret; } - if (adis->info->flags & ADIS_HAS_BURST32) { - ret = adis_read_burst32(adis, &iio_adis->burst_size); - if (ret) - return ret; - } else { + if (adis->info->flags & ADIS_HAS_BURST32) + iio_adis->burst_size = 1; + else iio_adis->burst_size = 0; - } iio_adis->samples_lost = 0; iio_adis->data_cntr = 0; @@ -1146,33 +1140,26 @@ static int adis_iio_trigger_push_single_sample(struct adis_iio_dev *iio_adis, { struct adis_dev *adis; int ret; - uint16_t buff[15]; + struct adis_burst_data data; uint8_t i = 0; - uint8_t buff_idx; - uint8_t temp_offset; - uint8_t data_cntr_offset; - uint16_t current_data_cntr; uint32_t res1; uint32_t res2; uint8_t chan; adis = iio_adis->adis_dev; - ret = adis_read_burst_data(adis, sizeof(buff), buff, iio_adis->burst_size, + ret = adis_read_burst_data(adis, &data, iio_adis->burst_size, iio_adis->burst_sel, pop); /* If ret == EAGAIN then no data is available to read (will happen - for a burst request) */ + for a burst request or in case burst32 or burst select has been changed) */ if (ret == -EAGAIN) return 0; if (ret) return ret; - temp_offset = iio_adis->burst_size ? 13 : 7; - data_cntr_offset = iio_adis->burst_size ? 14 : 8; - - current_data_cntr = no_os_bswap_constant_16(buff[data_cntr_offset]); + uint32_t current_data_cntr = data.data_cntr_lsb | data.data_cntr_msb << 16; if (iio_adis->data_cntr) { if(current_data_cntr > iio_adis->data_cntr) { @@ -1207,8 +1194,11 @@ static int adis_iio_trigger_push_single_sample(struct adis_iio_dev *iio_adis, if (mask & (1 << chan)) { switch(chan) { case ADIS_TEMP: - iio_adis->data[i++] = buff[temp_offset]; + if (iio_adis->iio_dev->channels[chan].scan_type->storagebits == 32) + iio_adis->data[i++] = data.temp_msb; + + iio_adis->data[i++] = data.temp_lsb; /* * The temperature channel has 16-bit storage size. * We need to perform the padding to have the buffer @@ -1217,46 +1207,140 @@ static int adis_iio_trigger_push_single_sample(struct adis_iio_dev *iio_adis, * scan index higher than the temperature channel scan * index. */ - if (mask & NO_OS_GENMASK(ADIS_DELTA_VEL_Z, ADIS_DELTA_ANGL_X)) + if (mask & NO_OS_GENMASK(ADIS_DELTA_VEL_Z, ADIS_DELTA_ANGL_X) + && iio_adis->iio_dev->channels[chan].scan_type->storagebits == 16) iio_adis->data[i++] = 0; break; - case ADIS_GYRO_X ... ADIS_ACCEL_Z: - /* - * The first 2 bytes on the received data are the - * DIAG_STAT reg, hence the +1 offset here... - */ + case ADIS_GYRO_X: + if(iio_adis->burst_sel) { + iio_adis->data[i++] = 0; + iio_adis->data[i++] = 0; + } else { + /* upper 16 */ + iio_adis->data[i++] = data.x_gyro_msb; + /* lower 16 */ + iio_adis->data[i++] = data.x_gyro_lsb; + } + break; + case ADIS_GYRO_Y: + if(iio_adis->burst_sel) { + iio_adis->data[i++] = 0; + iio_adis->data[i++] = 0; + } else { + /* upper 16 */ + iio_adis->data[i++] = data.y_gyro_msb; + /* lower 16 */ + iio_adis->data[i++] = data.y_gyro_lsb; + } + break; + case ADIS_GYRO_Z: + if(iio_adis->burst_sel) { + iio_adis->data[i++] = 0; + iio_adis->data[i++] = 0; + } else { + /* upper 16 */ + iio_adis->data[i++] = data.z_gyro_msb; + /* lower 16 */ + iio_adis->data[i++] = data.z_gyro_lsb; + } + break; + case ADIS_ACCEL_X: + if(iio_adis->burst_sel) { + iio_adis->data[i++] = 0; + iio_adis->data[i++] = 0; + } else { + /* upper 16 */ + iio_adis->data[i++] = data.x_accel_msb; + /* lower 16 */ + iio_adis->data[i++] = data.x_accel_lsb; + } + break; + case ADIS_ACCEL_Y: + if(iio_adis->burst_sel) { + iio_adis->data[i++] = 0; + iio_adis->data[i++] = 0; + } else { + /* upper 16 */ + iio_adis->data[i++] = data.y_accel_msb; + /* lower 16 */ + iio_adis->data[i++] = data.y_accel_lsb; + } + break; + case ADIS_ACCEL_Z: if(iio_adis->burst_sel) { iio_adis->data[i++] = 0; iio_adis->data[i++] = 0; } else { - if (iio_adis->burst_size) { - /* upper 16 */ - iio_adis->data[i++] = buff[chan * 2 + 2]; - /* lower 16 */ - iio_adis->data[i++] = buff[chan * 2 + 1]; - } else { - iio_adis->data[i++] = buff[chan + 1]; - /* lower not used */ - iio_adis->data[i++] = 0; - } + /* upper 16 */ + iio_adis->data[i++] = data.z_accel_msb; + /* lower 16 */ + iio_adis->data[i++] = data.z_accel_lsb; + } + break; + case ADIS_DELTA_ANGL_X: + if(!iio_adis->burst_sel) { + iio_adis->data[i++] = 0; + iio_adis->data[i++] = 0; + } else { + /* upper 16 */ + iio_adis->data[i++] = data.x_gyro_msb; + /* lower 16 */ + iio_adis->data[i++] = data.x_gyro_lsb; + } + break; + case ADIS_DELTA_ANGL_Y: + if(!iio_adis->burst_sel) { + iio_adis->data[i++] = 0; + iio_adis->data[i++] = 0; + } else { + /* upper 16 */ + iio_adis->data[i++] = data.y_gyro_msb; + /* lower 16 */ + iio_adis->data[i++] = data.y_gyro_lsb; + } + break; + case ADIS_DELTA_ANGL_Z: + if(!iio_adis->burst_sel) { + iio_adis->data[i++] = 0; + iio_adis->data[i++] = 0; + } else { + /* upper 16 */ + iio_adis->data[i++] = data.z_gyro_msb; + /* lower 16 */ + iio_adis->data[i++] = data.z_gyro_lsb; + } + break; + case ADIS_DELTA_VEL_X: + if(!iio_adis->burst_sel) { + iio_adis->data[i++] = 0; + iio_adis->data[i++] = 0; + } else { + /* upper 16 */ + iio_adis->data[i++] = data.x_accel_msb; + /* lower 16 */ + iio_adis->data[i++] = data.x_accel_lsb; + } + break; + case ADIS_DELTA_VEL_Y: + if(!iio_adis->burst_sel) { + iio_adis->data[i++] = 0; + iio_adis->data[i++] = 0; + } else { + /* upper 16 */ + iio_adis->data[i++] = data.y_accel_msb; + /* lower 16 */ + iio_adis->data[i++] = data.y_accel_lsb; } break; - case ADIS_DELTA_ANGL_X ... ADIS_DELTA_VEL_Z: + case ADIS_DELTA_VEL_Z: if(!iio_adis->burst_sel) { iio_adis->data[i++] = 0; iio_adis->data[i++] = 0; } else { - buff_idx = chan - ADIS_DELTA_ANGL_X; - if (iio_adis->burst_size) { - /* upper 16 */ - iio_adis->data[i++] = buff[buff_idx * 2 + 2]; - /* lower 16 */ - iio_adis->data[i++] = buff[buff_idx * 2 + 1]; - } else { - iio_adis->data[i++] = buff[buff_idx + 1]; - /* lower not used */ - iio_adis->data[i++] = 0; - } + /* upper 16 */ + iio_adis->data[i++] = data.z_accel_msb; + /* lower 16 */ + iio_adis->data[i++] = data.z_accel_lsb; } break; default: diff --git a/drivers/imu/iio_adis_internals.h b/drivers/imu/iio_adis_internals.h index a87903c8bd5..90b0a17862e 100644 --- a/drivers/imu/iio_adis_internals.h +++ b/drivers/imu/iio_adis_internals.h @@ -185,7 +185,7 @@ struct adis_iio_dev { /** Number of lost samples for the current buffer reading. */ uint16_t samples_lost; /** Current data counter for the current buffer reading.*/ - uint16_t data_cntr; + uint32_t data_cntr; /** ADIS sampling frequency. */ uint32_t sampling_frequency; /** Current setting for adis burst size. */ diff --git a/tests/drivers/imu/test/support/test_adis.c b/tests/drivers/imu/test/support/test_adis.c index 01aca54c8df..0f86b6a8a65 100644 --- a/tests/drivers/imu/test/support/test_adis.c +++ b/tests/drivers/imu/test/support/test_adis.c @@ -3858,65 +3858,31 @@ void test_adis_read_fls_mem_wr_cntr_3(void) void test_adis_read_burst_data_1(void) { device_alloc.info = adis_chip_info; - uint16_t burst_data[9] = {0}; + struct adis_burst_data data; device_alloc.burst32 = 0; device_alloc.burst_sel = 0; no_os_spi_write_and_read_IgnoreAndReturn(-1); - retval = adis_read_burst_data(&device_alloc, sizeof(burst_data), burst_data, + retval = adis_read_burst_data(&device_alloc, &data, device_alloc.burst32, device_alloc.burst_sel, false); TEST_ASSERT_EQUAL_INT(-1, retval); } -/** - * @brief Test adis_read_burst_data with invalid buffer size with burst32 = 1 - * and burst_sel = 0 . - */ -void test_adis_read_burst_data_2(void) -{ - device_alloc.info = adis_chip_info; - uint16_t burst_data[9] = {0}; - - device_alloc.burst32 = 1; - device_alloc.burst_sel = 0; - - retval = adis_read_burst_data(&device_alloc, sizeof(burst_data), burst_data, - device_alloc.burst32, device_alloc.burst_sel, false); - TEST_ASSERT_EQUAL_INT(-22, retval); -} - -/** - * @brief Test adis_read_burst_data with invalid buffer size with burst32 = 0 - * and burst_sel = 0 . - */ -void test_adis_read_burst_data_3(void) -{ - device_alloc.info = adis_chip_info; - uint16_t burst_data[8] = {0}; - - device_alloc.burst32 = 0; - device_alloc.burst_sel = 0; - - retval = adis_read_burst_data(&device_alloc, sizeof(burst_data), burst_data, - device_alloc.burst32, device_alloc.burst_sel, false); - TEST_ASSERT_EQUAL_INT(-22, retval); -} - /** * @brief Test adis_read_burst_data with burst32 update request and invalid spi * transfer. */ -void test_adis_read_burst_data_4(void) +void test_adis_read_burst_data_2(void) { device_alloc.info = adis_chip_info; - uint16_t burst_data[15] = {0}; + struct adis_burst_data data; device_alloc.burst32 = 0; device_alloc.burst_sel = 0; no_os_field_get_IgnoreAndReturn(!device_alloc.burst32); no_os_spi_transfer_IgnoreAndReturn(-1); - retval = adis_read_burst_data(&device_alloc, sizeof(burst_data), burst_data, + retval = adis_read_burst_data(&device_alloc, &data, !device_alloc.burst32, device_alloc.burst_sel, false); TEST_ASSERT_EQUAL_INT(-1, retval); } @@ -3925,16 +3891,16 @@ void test_adis_read_burst_data_4(void) * @brief Test adis_read_burst_data with burst_sel update request and invalid spi * transfer. */ -void test_adis_read_burst_data_5(void) +void test_adis_read_burst_data_3(void) { device_alloc.info = adis_chip_info; - uint16_t burst_data[15] = {0}; + struct adis_burst_data data; device_alloc.burst32 = 0; device_alloc.burst_sel = 0; no_os_field_get_IgnoreAndReturn(!device_alloc.burst_sel); no_os_spi_transfer_IgnoreAndReturn(-1); - retval = adis_read_burst_data(&device_alloc, sizeof(burst_data), burst_data, + retval = adis_read_burst_data(&device_alloc, &data, device_alloc.burst32, !device_alloc.burst_sel, false); TEST_ASSERT_EQUAL_INT(-1, retval); } @@ -3942,27 +3908,28 @@ void test_adis_read_burst_data_5(void) /** * @brief Test adis_read_burst_data with burst request requested with fifo */ -void test_adis_read_burst_data_6(void) +void test_adis_read_burst_data_4(void) { device_alloc.info = adis_chip_info; - uint16_t burst_data[9] = {0}; + struct adis_burst_data data; device_alloc.burst32 = 0; device_alloc.burst_sel = 0; no_os_spi_write_and_read_IgnoreAndReturn(0); - retval = adis_read_burst_data(&device_alloc, sizeof(burst_data), burst_data, + no_os_get_unaligned_be16_IgnoreAndReturn(0); + retval = adis_read_burst_data(&device_alloc, &data, device_alloc.burst32, device_alloc.burst_sel, true); - TEST_ASSERT_EQUAL_INT(-EAGAIN, retval); + TEST_ASSERT_EQUAL_INT(-EINVAL, retval); } /** * @brief Test adis_read_burst_data with checksum error. */ -void test_adis_read_burst_data_7(void) +void test_adis_read_burst_data_5(void) { device_alloc.info = adis_chip_info; - uint16_t burst_data[9] = {0}; + struct adis_burst_data data; device_alloc.burst32 = 0; device_alloc.burst_sel = 0; @@ -3970,7 +3937,7 @@ void test_adis_read_burst_data_7(void) device_alloc.info = adis_chip_info; no_os_spi_write_and_read_IgnoreAndReturn(0); no_os_get_unaligned_be16_IgnoreAndReturn(0); - retval = adis_read_burst_data(&device_alloc, sizeof(burst_data), burst_data, + retval = adis_read_burst_data(&device_alloc, &data, device_alloc.burst32, device_alloc.burst_sel, false); TEST_ASSERT_EQUAL_INT(-EINVAL, retval); TEST_ASSERT_EQUAL_INT(true, device_alloc.diag_flags.checksum_err); @@ -3979,17 +3946,17 @@ void test_adis_read_burst_data_7(void) /** * @brief Test adis_read_burst_data with burst request requested without fifo */ -void test_adis_read_burst_data_8(void) +void test_adis_read_burst_data_6(void) { device_alloc.info = adis_chip_info; - uint16_t burst_data[9] = {0}; + struct adis_burst_data data; device_alloc.burst32 = 0; device_alloc.burst_sel = 0; no_os_spi_write_and_read_IgnoreAndReturn(0); no_os_get_unaligned_be16_IgnoreAndReturn(0); - retval = adis_read_burst_data(&device_alloc, sizeof(burst_data), burst_data, + retval = adis_read_burst_data(&device_alloc, &data, device_alloc.burst32, device_alloc.burst_sel, true); TEST_ASSERT_EQUAL_INT(-EINVAL, retval); } diff --git a/tests/drivers/imu/test/test_adis1650x.c b/tests/drivers/imu/test/test_adis1650x.c index 26d19de69be..946abd75576 100644 --- a/tests/drivers/imu/test/test_adis1650x.c +++ b/tests/drivers/imu/test/test_adis1650x.c @@ -576,10 +576,7 @@ void test_adis1650x_read_burst_data(void) test_adis_read_burst_data_1(); test_adis_read_burst_data_2(); test_adis_read_burst_data_3(); - test_adis_read_burst_data_4(); - test_adis_read_burst_data_5(); - test_adis_read_burst_data_7(); - test_adis_read_burst_data_8(); + test_adis_read_burst_data_6(); } void test_adis1650x_update_ext_clk_freq(void) diff --git a/tests/drivers/imu/test/test_adis1657x.c b/tests/drivers/imu/test/test_adis1657x.c index 44c390f2c63..4d690d89bf1 100644 --- a/tests/drivers/imu/test/test_adis1657x.c +++ b/tests/drivers/imu/test/test_adis1657x.c @@ -801,8 +801,7 @@ void test_adis1657x_read_burst_data(void) test_adis_read_burst_data_2(); test_adis_read_burst_data_3(); test_adis_read_burst_data_4(); - test_adis_read_burst_data_5(); - test_adis_read_burst_data_7(); + test_adis_read_burst_data_6(); } void test_adis1657x_update_ext_clk_freq(void)