sensors: Submit call returns void

The integer return of sensor_submit should be void as the call is
asynchronous and the response is meant to be delivered using RTIO APIs
signaling that the submission completed with error or success.

Change the function signature to void and fix all uses of the submit
API, fixing some bugs in the process.

Signed-off-by: Tom Burdick <thomas.burdick@intel.com>
This commit is contained in:
Tom Burdick 2024-06-12 10:46:29 -05:00 committed by Alberto Escolar
parent 8adec6d749
commit 3b94af2b5c
11 changed files with 47 additions and 50 deletions

View File

@ -93,6 +93,6 @@ int akm09918c_sample_fetch_helper(const struct device *dev, enum sensor_channel
int akm09918c_get_decoder(const struct device *dev, const struct sensor_decoder_api **decoder);
int akm09918c_submit(const struct device *dev, struct rtio_iodev_sqe *iodev_sqe);
void akm09918c_submit(const struct device *dev, struct rtio_iodev_sqe *iodev_sqe);
#endif /* ZEPHYR_DRIVERS_SENSOR_AKM09918C_AKM09918C_H_ */

View File

@ -9,7 +9,7 @@
LOG_MODULE_DECLARE(AKM09918C, CONFIG_SENSOR_LOG_LEVEL);
int akm09918c_submit(const struct device *dev, struct rtio_iodev_sqe *iodev_sqe)
void akm09918c_submit(const struct device *dev, struct rtio_iodev_sqe *iodev_sqe)
{
uint32_t min_buf_len = sizeof(struct akm09918c_encoded_data);
int rc;
@ -22,7 +22,7 @@ int akm09918c_submit(const struct device *dev, struct rtio_iodev_sqe *iodev_sqe)
if (rc != 0) {
LOG_ERR("Failed to get a read buffer of size %u bytes", min_buf_len);
rtio_iodev_sqe_err(iodev_sqe, rc);
return rc;
return;
}
edata = (struct akm09918c_encoded_data *)buf;
@ -33,10 +33,8 @@ int akm09918c_submit(const struct device *dev, struct rtio_iodev_sqe *iodev_sqe)
if (rc != 0) {
LOG_ERR("Failed to fetch samples");
rtio_iodev_sqe_err(iodev_sqe, rc);
return rc;
return;
}
rtio_iodev_sqe_ok(iodev_sqe, 0);
return 0;
}

View File

@ -338,7 +338,7 @@ static int bma4xx_temp_fetch(const struct device *dev, int8_t *temp)
* RTIO submit and encoding
*/
static int bma4xx_submit_one_shot(const struct device *dev, struct rtio_iodev_sqe *iodev_sqe)
static void bma4xx_submit_one_shot(const struct device *dev, struct rtio_iodev_sqe *iodev_sqe)
{
struct bma4xx_data *bma4xx = dev->data;
@ -357,7 +357,7 @@ static int bma4xx_submit_one_shot(const struct device *dev, struct rtio_iodev_sq
if (rc != 0) {
LOG_ERR("Failed to get a read buffer of size %u bytes", min_buf_len);
rtio_iodev_sqe_err(iodev_sqe, rc);
return rc;
return;
}
/* Prepare response */
@ -372,7 +372,8 @@ static int bma4xx_submit_one_shot(const struct device *dev, struct rtio_iodev_sq
for (int i = 0; i < num_channels; i++) {
if (channels[i].chan_idx != 0) {
LOG_ERR("Only channel index 0 supported");
return -ENOTSUP;
rtio_iodev_sqe_err(iodev_sqe, -ENOTSUP);
return;
}
switch (channels[i].chan_type) {
case SENSOR_CHAN_ALL:
@ -395,7 +396,8 @@ static int bma4xx_submit_one_shot(const struct device *dev, struct rtio_iodev_sq
default:
LOG_ERR("Requested unsupported channel type %d, idx %d",
channels[i].chan_type, channels[i].chan_idx);
return -ENOTSUP;
rtio_iodev_sqe_err(iodev_sqe, -ENOTSUP);
return;
}
}
@ -405,7 +407,7 @@ static int bma4xx_submit_one_shot(const struct device *dev, struct rtio_iodev_sq
if (rc != 0) {
LOG_ERR("Failed to fetch accel samples");
rtio_iodev_sqe_err(iodev_sqe, rc);
return rc;
return;
}
}
@ -415,26 +417,24 @@ static int bma4xx_submit_one_shot(const struct device *dev, struct rtio_iodev_sq
if (rc != 0) {
LOG_ERR("Failed to fetch temp sample");
rtio_iodev_sqe_err(iodev_sqe, rc);
return rc;
return;
}
}
#endif /* CONFIG_BMA4XX_TEMPERATURE */
rtio_iodev_sqe_ok(iodev_sqe, 0);
return 0;
}
static int bma4xx_submit(const struct device *dev, struct rtio_iodev_sqe *iodev_sqe)
static void bma4xx_submit(const struct device *dev, struct rtio_iodev_sqe *iodev_sqe)
{
const struct sensor_read_config *cfg = iodev_sqe->sqe.iodev->data;
if (!cfg->is_streaming) {
return bma4xx_submit_one_shot(dev, iodev_sqe);
}
/* TODO: Add streaming support */
return -ENOTSUP;
if (!cfg->is_streaming) {
bma4xx_submit_one_shot(dev, iodev_sqe);
} else {
rtio_iodev_sqe_err(iodev_sqe, -ENOTSUP);
}
}
/*

View File

@ -211,7 +211,7 @@ struct bme280_encoded_data {
int bme280_get_decoder(const struct device *dev, const struct sensor_decoder_api **decoder);
int bme280_submit(const struct device *dev, struct rtio_iodev_sqe *iodev_sqe);
void bme280_submit(const struct device *dev, struct rtio_iodev_sqe *iodev_sqe);
int bme280_sample_fetch(const struct device *dev,
enum sensor_channel chan);

View File

@ -9,7 +9,7 @@
LOG_MODULE_DECLARE(BME280, CONFIG_SENSOR_LOG_LEVEL);
int bme280_submit(const struct device *dev, struct rtio_iodev_sqe *iodev_sqe)
void bme280_submit(const struct device *dev, struct rtio_iodev_sqe *iodev_sqe)
{
uint32_t min_buf_len = sizeof(struct bme280_encoded_data);
int rc;
@ -31,7 +31,7 @@ int bme280_submit(const struct device *dev, struct rtio_iodev_sqe *iodev_sqe)
default:
LOG_ERR("Unsupported channel type %d", channels[i].chan_type);
rtio_iodev_sqe_err(iodev_sqe, -ENOTSUP);
return -ENOTSUP;
return;
}
}
@ -39,7 +39,7 @@ int bme280_submit(const struct device *dev, struct rtio_iodev_sqe *iodev_sqe)
if (rc != 0) {
LOG_ERR("Failed to get a read buffer of size %u bytes", min_buf_len);
rtio_iodev_sqe_err(iodev_sqe, rc);
return rc;
return;
}
struct bme280_encoded_data *edata;
@ -52,10 +52,8 @@ int bme280_submit(const struct device *dev, struct rtio_iodev_sqe *iodev_sqe)
if (rc != 0) {
LOG_ERR("Failed to fetch samples");
rtio_iodev_sqe_err(iodev_sqe, rc);
return rc;
return;
}
rtio_iodev_sqe_ok(iodev_sqe, 0);
return 0;
}

View File

@ -43,7 +43,7 @@ static int icm42688_rtio_sample_fetch(const struct device *dev, int16_t readings
return 0;
}
static int icm42688_submit_one_shot(const struct device *dev, struct rtio_iodev_sqe *iodev_sqe)
static void icm42688_submit_one_shot(const struct device *dev, struct rtio_iodev_sqe *iodev_sqe)
{
const struct sensor_read_config *cfg = iodev_sqe->sqe.iodev->data;
const struct sensor_chan_spec *const channels = cfg->channels;
@ -59,7 +59,7 @@ static int icm42688_submit_one_shot(const struct device *dev, struct rtio_iodev_
if (rc != 0) {
LOG_ERR("Failed to get a read buffer of size %u bytes", min_buf_len);
rtio_iodev_sqe_err(iodev_sqe, rc);
return rc;
return;
}
edata = (struct icm42688_encoded_data *)buf;
@ -71,24 +71,22 @@ static int icm42688_submit_one_shot(const struct device *dev, struct rtio_iodev_
if (rc != 0) {
LOG_ERR("Failed to fetch samples");
rtio_iodev_sqe_err(iodev_sqe, rc);
return rc;
return;
}
rtio_iodev_sqe_ok(iodev_sqe, 0);
return 0;
}
int icm42688_submit(const struct device *dev, struct rtio_iodev_sqe *iodev_sqe)
void icm42688_submit(const struct device *dev, struct rtio_iodev_sqe *iodev_sqe)
{
const struct sensor_read_config *cfg = iodev_sqe->sqe.iodev->data;
if (!cfg->is_streaming) {
return icm42688_submit_one_shot(dev, iodev_sqe);
icm42688_submit_one_shot(dev, iodev_sqe);
} else if (IS_ENABLED(CONFIG_ICM42688_STREAM)) {
return icm42688_submit_stream(dev, iodev_sqe);
icm42688_submit_stream(dev, iodev_sqe);
} else {
return -ENOTSUP;
rtio_iodev_sqe_err(iodev_sqe, -ENOTSUP);
}
}

View File

@ -10,9 +10,9 @@
#include <zephyr/device.h>
#include <zephyr/rtio/rtio.h>
int icm42688_submit(const struct device *sensor, struct rtio_iodev_sqe *iodev_sqe);
void icm42688_submit(const struct device *sensor, struct rtio_iodev_sqe *iodev_sqe);
int icm42688_submit_stream(const struct device *sensor, struct rtio_iodev_sqe *iodev_sqe);
void icm42688_submit_stream(const struct device *sensor, struct rtio_iodev_sqe *iodev_sqe);
void icm42688_fifo_event(const struct device *dev);

View File

@ -687,7 +687,7 @@ struct sensor_read_config {
RTIO_IODEV_DEFINE(name, &__sensor_iodev_api, &_CONCAT(__sensor_read_config_, name))
/* Used to submit an RTIO sqe to the sensor's iodev */
typedef int (*sensor_submit_t)(const struct device *sensor, struct rtio_iodev_sqe *sqe);
typedef void (*sensor_submit_t)(const struct device *sensor, struct rtio_iodev_sqe *sqe);
/* The default decoder API */
extern const struct sensor_decoder_api __sensor_default_decoder;

View File

@ -22,6 +22,7 @@ static void sensing_iodev_submit(struct rtio_iodev_sqe *iodev_sqe)
if (api->submit != NULL) {
api->submit(dev, iodev_sqe);
} else {
LOG_ERR("submit function not supported for device %p %s!\n", dev, dev->name);
rtio_iodev_sqe_err(iodev_sqe, -ENOTSUP);
}
}

View File

@ -79,17 +79,16 @@ static int hinge_attr_set(const struct device *dev,
return ret;
}
static int hinge_submit(const struct device *dev,
static void hinge_submit(const struct device *dev,
struct rtio_iodev_sqe *sqe)
{
struct hinge_angle_context *data = dev->data;
if (data->sqe) {
return -EBUSY;
rtio_iodev_sqe_err(sqe, -EBUSY);
} else {
data->sqe = sqe;
}
data->sqe = sqe;
return 0;
}
static const struct sensor_driver_api hinge_api = {
@ -146,7 +145,10 @@ static void hinge_reporter_on_data_event(sensing_sensor_handle_t handle,
sample->readings[0].v = calc_hinge_angle(data);
rtio_iodev_sqe_ok(data->sqe, 0);
struct rtio_iodev_sqe *sqe = data->sqe;
data->sqe = NULL;
rtio_iodev_sqe_ok(sqe, 0);
}
}

View File

@ -159,7 +159,7 @@ static int phy_3d_sensor_attr_set(const struct device *dev,
return ret;
}
static int phy_3d_sensor_submit(const struct device *dev,
static void phy_3d_sensor_submit(const struct device *dev,
struct rtio_iodev_sqe *sqe)
{
struct sensing_submit_config *config = (struct sensing_submit_config *)sqe->sqe.iodev->data;
@ -175,21 +175,21 @@ static int phy_3d_sensor_submit(const struct device *dev,
(uint8_t **)&sample, &buffer_len);
if (ret) {
rtio_iodev_sqe_err(sqe, ret);
return ret;
return;
}
ret = sensor_sample_fetch_chan(cfg->hw_dev, custom->chan_all);
if (ret) {
LOG_ERR("%s: sample fetch failed: %d", dev->name, ret);
rtio_iodev_sqe_err(sqe, ret);
return ret;
return;
}
ret = sensor_channel_get(cfg->hw_dev, custom->chan_all, value);
if (ret) {
LOG_ERR("%s: channel get failed: %d", dev->name, ret);
rtio_iodev_sqe_err(sqe, ret);
return ret;
return;
}
for (i = 0; i < ARRAY_SIZE(value); ++i) {
@ -206,7 +206,7 @@ static int phy_3d_sensor_submit(const struct device *dev,
sample->readings[0].z);
rtio_iodev_sqe_ok(sqe, 0);
return 0;
return;
}
static const struct sensor_driver_api phy_3d_sensor_api = {