-
Notifications
You must be signed in to change notification settings - Fork 6.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
lsm6dsv16x: add RTIO async and fifo stream #81447
base: main
Are you sure you want to change the base?
lsm6dsv16x: add RTIO async and fifo stream #81447
Conversation
Save gyroscope range set from DT or SENSOR_ATTR in data structure. Signed-off-by: Armando Visconti <armando.visconti@st.com>
Add attr_get() driver API Signed-off-by: Armando Visconti <armando.visconti@st.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looking pretty good to me, I do think the workq could be avoided here with a little effort to do the reads asynchronously, or configure the sensor asynchronously (though I get this is a little bit of a hassle).
The workq does add some code size in trade for convenience.
#define LSM6DSV16X_SPI_RTIO_DEFINE(inst) \ | ||
SPI_DT_IODEV_DEFINE(lsm6dsv16x_iodev_##inst, \ | ||
DT_DRV_INST(inst), LSM6DSV16X_SPI_OP, 0U); \ | ||
RTIO_DEFINE(lsm6dsv16x_rtio_ctx_##inst, 16, 16); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
16 is quite a large number of submissions and completions to keep in the pool Each one is going to be ~32bytes, 16*32 512B of potential space here.
Likely only needs 2 to 4 depending on what kind of transactions you are doing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
/* | ||
* Instantiation macros used when a device is on an I2C bus. | ||
*/ | ||
|
||
#define LSM6DSV16X_I2C_RTIO_DEFINE(inst) \ | ||
I2C_DT_IODEV_DEFINE(lsm6dsv16x_iodev_##inst, DT_DRV_INST(inst));\ | ||
RTIO_DEFINE(lsm6dsv16x_rtio_ctx_##inst, 16, 16); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment as above, I'd recommend reducing the number of submissions (and completions) in the pool to something like 2 or 4 here. Likely 4 for doing the typical write a register, read a value, do a callback.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But other sensor drivers are using 8/16. Maybe I could fix it to 4?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If they are using 16, this is likely wasteful... I'd try fixing it to 4
read_fifo_status_reg->iodev_flags |= RTIO_IODEV_I2C_STOP | RTIO_IODEV_I2C_RESTART; | ||
} | ||
rtio_sqe_prep_callback(check_fifo_status_reg, | ||
lsm6dsv16x_read_fifo_cb, (void *)dev, NULL); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not required, but one possibility here is to look at the current request options and sensor config to assign an appropriate callback here avoiding some branching.
Potentially you could directly read the FIFO perhaps because the watermark is set, you can see if the data is requested with it.
Other possibilities to reduce branching are likely here but I get the current example drivers don't do this.
}; | ||
#endif | ||
|
||
static int lsm6dsv16x_get_shift(enum sensor_channel channel, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could a constant lookup table be used instead?
return ret; | ||
} | ||
|
||
static int lsm6dsv16x_convert_raw_to_q31(const struct lsm6dsv16x_decoder_header *hdr, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Converting from the sensors sample representation, almost always a fixed point value with its own scale, to the larger q31 format should be a simple integer multiplier provided by a lookup table.
E.g.
static inline void lsm6dsv16x_accel_to_q31(int16_t accel_raw, int accel_fs, q31_t *out)
{
*out = accel_raw * ACCEL_CONVERSION[accel_fs];
}
See issue #76968
Add RTIO async and RTIO stream functionalities that enables, among all the other things, the sensor data streaming from FIFO. RTIO stream is using both SENSOR_TRIG_FIFO_WATERMARK and SENSOR_TRIG_FIFO_FULL triggers. The decoder currently only supports following FIFO tags: - LSM6DSV16X_XL_NC_TAG - LSM6DSV16X_GY_NC_TAG - LSM6DSV16X_TEMP_NC_TAG Following FIFO parameters has to be defined in device tree to correctly stream sensor data: - fifo-watermark (defaults to 32) - accel-fifo-batch-rate (defaults to LSM6DSV16X_DT_XL_NOT_BATCHED) - gyro-fifo-batch-rate (defaults to LSM6DSV16X_DT_GY_NOT_BATCHED) - temp-fifo-batch-rate (defaults to LSM6DSV16X_DT_TEMP_NOT_BATCHED) Signed-off-by: Armando Visconti <armando.visconti@st.com>
0c5e2cb
to
8260eee
Compare
re-pushed with some fix in order to (hopefully) pass CI. Still need to go thru some of the review comments... |
Add RTIO async and RTIO stream functionalities that enables, among all the other things, the sensor data streaming from FIFO. RTIO stream is using both SENSOR_TRIG_FIFO_WATERMARK and SENSOR_TRIG_FIFO_FULL triggers. The decoder currently only supports following FIFO tags:
In DT it is possible to configure following FIFO params:
Since I do not have any boards with a chipset with I2C/SPI rtio supported zephyr driver, I tested this solution using I2C rtio default driver. Waiting for #71961 to be reviewed, as well as a proper solution for STM32 SPI.
Moreover, this PR does not contain any specific sample (in the future I may add one), but I'm using a modified version of
samples/sensor/accel_polling
to test the FIFO streaming.