Skip to content

Commit 471e667

Browse files
josuahngphibang
authored andcommitted
drivers: video: modifications needed to get it to work
This contains only the mandatory modifications to get the drivers to work: - expose `struct rtio_iodev_sqe` to the drivers so that the functions `rtio_iodev_sqe_ok()` and `rtio_iodev_sqe_err()` can be called. - expose `stuct rtio_cqe` to the application so that the functions `rtio_cqe_release()` can be called with the same completion event (cqe) that was just dequeued. The implementation can be different, but these points seems to be mandatory to operate RTIO end-to-end.
1 parent 0cb2ab8 commit 471e667

File tree

4 files changed

+44
-22
lines changed

4 files changed

+44
-22
lines changed

drivers/video/video_buffer.c

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -178,23 +178,15 @@ int video_enqueue(const struct device *dev, struct video_buffer *buf)
178178
return 0;
179179
}
180180

181-
int video_dequeue(struct video_buffer **buf)
181+
struct rtio_cqe *video_dequeue(void)
182182
{
183-
struct rtio_cqe *cqe = rtio_cqe_consume_block(&rtio);
184-
*buf = cqe->userdata;
185-
186-
if (cqe->result < 0) {
187-
LOG_ERR("I/O operation failed");
188-
return cqe->result;
189-
}
190-
191-
return 0;
183+
return rtio_cqe_consume_block(&rtio);
192184
}
193185

194-
void video_release_buf()
186+
void video_release_buf(struct rtio_cqe *cqe)
195187
{
196188
/* Buffer will be re-queued thanks to RTIO_SQE_MULTISHOT */
197-
rtio_cqe_release(&rtio, rtio_cqe_consume_block(&rtio));
189+
rtio_cqe_release(&rtio, cqe);
198190
}
199191

200192
struct video_buffer *video_get_buf_sqe(struct mpsc *io_q)
@@ -217,6 +209,33 @@ struct video_buffer *video_get_buf_sqe(struct mpsc *io_q)
217209
return sqe->userdata;
218210
}
219211

212+
struct rtio_iodev_sqe *video_pop_io_q(struct mpsc *io_q)
213+
{
214+
struct mpsc_node *node;
215+
struct rtio_iodev_sqe *iodev_sqe;
216+
struct video_buffer *vbuf;
217+
218+
node = mpsc_pop(io_q);
219+
if (node == NULL) {
220+
return NULL;
221+
}
222+
223+
iodev_sqe = CONTAINER_OF(node, struct rtio_iodev_sqe, q);
224+
vbuf = iodev_sqe->sqe.userdata;
225+
226+
__ASSERT_NO_MSG(vbuf != NULL);
227+
228+
if ((vbuf->type == VIDEO_BUF_TYPE_OUTPUT && iodev_sqe->sqe.op == RTIO_OP_RX) ||
229+
(vbuf->type == VIDEO_BUF_TYPE_INPUT && iodev_sqe->sqe.op == RTIO_OP_TX)) {
230+
return iodev_sqe;
231+
} else {
232+
LOG_ERR("Unsupported RTIO operation (%d) or video buffer type (%d)",
233+
iodev_sqe->sqe.op, vbuf->type);
234+
rtio_iodev_sqe_err(iodev_sqe, -EINVAL);
235+
return NULL;
236+
}
237+
}
238+
220239
static void video_iodev_submit(struct rtio_iodev_sqe *iodev_sqe)
221240
{
222241
struct video_interface *vi = iodev_sqe->sqe.iodev->data;

drivers/video/video_buffer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
*/
66

77
struct video_buffer *video_get_buf_sqe(struct mpsc *io_q);
8+
struct rtio_iodev_sqe *video_pop_io_q(struct mpsc *io_q);

include/zephyr/drivers/video.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include <zephyr/device.h>
2929
#include <zephyr/kernel.h>
3030
#include <zephyr/types.h>
31+
#include <zephyr/rtio/rtio.h>
3132

3233
#ifdef __cplusplus
3334
extern "C" {
@@ -598,13 +599,11 @@ int video_enqueue(const struct device *dev, struct video_buffer *buf);
598599
*
599600
* @param buf Pointer a video buffer pointer.
600601
*
601-
* @retval 0 Is successful.
602-
* @retval -EINVAL If parameters are invalid.
603-
* @retval -EIO General input / output error.
602+
* @retval The RTIO completion event with the completed buffer.
604603
*/
605-
int video_dequeue(struct video_buffer **buf);
604+
struct rtio_cqe *video_dequeue(void);
606605

607-
void video_release_buf();
606+
void video_release_buf(struct rtio_cqe *cqe);
608607

609608
/**
610609
* @brief Flush endpoint buffers.

samples/drivers/video/capture/src/main.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
LOG_MODULE_REGISTER(main, LOG_LEVEL_DBG);
2121
#else
22-
LOG_MODULE_REGISTER(main, CONFIG_LOG_DEFAULT_LEVEL);
22+
LOG_MODULE_REGISTER(main, LOG_LEVEL_DBG);
2323
#endif
2424

2525
#if DT_HAS_CHOSEN(zephyr_display)
@@ -302,12 +302,15 @@ int main(void)
302302

303303
/* Grab video frames */
304304
while (1) {
305-
err = video_dequeue(&vbuf);
306-
if (err) {
307-
LOG_ERR("Unable to dequeue video buf");
305+
struct rtio_cqe *cqe = video_dequeue();
306+
struct video_buffer *vbuf = cqe->userdata;
307+
308+
if (cqe->result != 0) {
309+
LOG_ERR("The video buffer of size %u completed with errors", vbuf->size);
308310
return 0;
309311
}
310312

313+
311314
LOG_DBG("Got frame %u! size: %u; timestamp %u ms",
312315
frame++, vbuf->bytesused, vbuf->timestamp);
313316

@@ -321,6 +324,6 @@ int main(void)
321324
video_display_frame(display_dev, vbuf, fmt);
322325
#endif
323326

324-
video_release_buf();
327+
video_release_buf(cqe);
325328
}
326329
}

0 commit comments

Comments
 (0)