Skip to content

Commit 9e99b93

Browse files
ubiedafabiobaltieri
authored andcommitted
bmp581: Set streaming handle to NULL when done
To follow with error-handling of multi-shot items, they won't be marked as cancelled. Instead, we expect them to stop being submitted, hence we dispose the handle upon finishing every shot. Signed-off-by: Luis Ubieda <[email protected]>
1 parent 24c0583 commit 9e99b93

File tree

1 file changed

+23
-15
lines changed

1 file changed

+23
-15
lines changed

drivers/sensor/bosch/bmp581/bmp581_stream.c

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,19 @@ enum bmp581_stream_state {
2222
BMP581_STREAM_BUSY = 2,
2323
};
2424

25+
static inline void bmp581_stream_result(const struct device *dev, int err)
26+
{
27+
struct bmp581_data *data = dev->data;
28+
struct rtio_iodev_sqe *iodev_sqe = data->stream.iodev_sqe;
29+
30+
data->stream.iodev_sqe = NULL;
31+
if (err < 0) {
32+
rtio_iodev_sqe_err(iodev_sqe, err);
33+
} else {
34+
rtio_iodev_sqe_ok(iodev_sqe, 0);
35+
}
36+
}
37+
2538
static void bmp581_stream_event_complete(struct rtio *ctx, const struct rtio_sqe *sqe, void *arg0)
2639
{
2740
struct rtio_iodev_sqe *iodev_sqe = (struct rtio_iodev_sqe *)arg0;
@@ -65,12 +78,7 @@ static void bmp581_stream_event_complete(struct rtio *ctx, const struct rtio_sqe
6578

6679
bmp581_stream_evt_finish:
6780
atomic_set(&data->stream.state, BMP581_STREAM_ON);
68-
69-
if (err < 0) {
70-
rtio_iodev_sqe_err(iodev_sqe, err);
71-
} else {
72-
rtio_iodev_sqe_ok(iodev_sqe, 0);
73-
}
81+
bmp581_stream_result(dev, err);
7482
}
7583

7684
static void bmp581_event_handler(const struct device *dev)
@@ -115,7 +123,7 @@ static void bmp581_event_handler(const struct device *dev)
115123
&buf, &buf_len);
116124
CHECKIF(err != 0 || buf_len < sizeof(struct bmp581_encoded_data)) {
117125
LOG_ERR("Failed to allocate BMP581 encoded buffer: %d", err);
118-
rtio_iodev_sqe_err(iodev_sqe, -ENOMEM);
126+
bmp581_stream_result(dev, -ENOMEM);
119127
return;
120128
}
121129

@@ -126,7 +134,7 @@ static void bmp581_event_handler(const struct device *dev)
126134
edata->payload, sizeof(edata->payload),
127135
&read_sqe);
128136
CHECKIF(err < 0 || !read_sqe) {
129-
rtio_iodev_sqe_err(iodev_sqe, err);
137+
bmp581_stream_result(dev, err);
130138
return;
131139
}
132140
read_sqe->flags |= RTIO_SQE_CHAINED;
@@ -141,7 +149,7 @@ static void bmp581_event_handler(const struct device *dev)
141149

142150
CHECKIF(err != 0 || (buf_len < len_required)) {
143151
LOG_ERR("Failed to allocate BMP581 encoded buffer: %d", err);
144-
rtio_iodev_sqe_err(iodev_sqe, -ENOMEM);
152+
bmp581_stream_result(dev, -ENOMEM);
145153
return;
146154
}
147155

@@ -152,7 +160,7 @@ static void bmp581_event_handler(const struct device *dev)
152160
(uint8_t *)edata->frame, len_data,
153161
&read_sqe);
154162
CHECKIF(err < 0 || !read_sqe) {
155-
rtio_iodev_sqe_err(iodev_sqe, err);
163+
bmp581_stream_result(dev, err);
156164
return;
157165
}
158166
read_sqe->flags |= RTIO_SQE_CHAINED;
@@ -179,7 +187,7 @@ static void bmp581_event_handler(const struct device *dev)
179187
cb_sqe = rtio_sqe_acquire(cfg->bus.rtio.ctx);
180188
if (cb_sqe == NULL) {
181189
LOG_ERR("Failed to acquire callback SQE");
182-
rtio_iodev_sqe_err(iodev_sqe, -ENOMEM);
190+
bmp581_stream_result(dev, -ENOMEM);
183191
return;
184192
}
185193

@@ -299,7 +307,7 @@ void bmp581_stream_submit(const struct device *dev,
299307
if ((enabled_mask & BMP581_EVENT_FIFO_WM) != 0) {
300308
err = bmp581_stream_prep_fifo_wm_async(dev);
301309
if (err < 0) {
302-
rtio_iodev_sqe_err(iodev_sqe, err);
310+
bmp581_stream_result(dev, err);
303311
return;
304312
}
305313
}
@@ -312,7 +320,7 @@ void bmp581_stream_submit(const struct device *dev,
312320
err = bmp581_prep_reg_write_rtio_async(&cfg->bus, BMP5_REG_INT_SOURCE, &val, 1,
313321
&int_src_sqe);
314322
if (err < 0) {
315-
rtio_iodev_sqe_err(iodev_sqe, err);
323+
bmp581_stream_result(dev, err);
316324
return;
317325
}
318326
int_src_sqe->flags |= RTIO_SQE_CHAINED;
@@ -325,15 +333,15 @@ void bmp581_stream_submit(const struct device *dev,
325333
err = bmp581_prep_reg_write_rtio_async(&cfg->bus, BMP5_REG_INT_CONFIG, &val, 1,
326334
NULL);
327335
if (err < 0) {
328-
rtio_iodev_sqe_err(iodev_sqe, err);
336+
bmp581_stream_result(dev, err);
329337
return;
330338
}
331339

332340
(void)rtio_submit(cfg->bus.rtio.ctx, 0);
333341

334342
err = gpio_pin_interrupt_configure_dt(&cfg->int_gpio, GPIO_INT_EDGE_TO_ACTIVE);
335343
if (err < 0) {
336-
rtio_iodev_sqe_err(iodev_sqe, err);
344+
bmp581_stream_result(dev, err);
337345
}
338346
}
339347
}

0 commit comments

Comments
 (0)