Skip to content

rtio: More useful callback OPs #93227

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 31 additions & 17 deletions include/zephyr/rtio/rtio.h
Original file line number Diff line number Diff line change
Expand Up @@ -277,17 +277,28 @@
* @brief Callback signature for RTIO_OP_CALLBACK
* @param r RTIO context being used with the callback
* @param sqe Submission for the callback op
* @param arg0 Argument option as part of the sqe
* @param res Result of the previously linked submission.
* @param arg0 Pointer to immutable argument option as part of the sqe
*/
typedef void (*rtio_callback_t)(struct rtio *r, const struct rtio_sqe *sqe, void *arg0);
typedef void (*rtio_callback_t)(struct rtio *r, const struct rtio_sqe *sqe, int res, const void *arg0);

Check warning on line 283 in include/zephyr/rtio/rtio.h

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LONG_LINE

include/zephyr/rtio/rtio.h:283 line length of 103 exceeds 100 columns

/**
* @typedef rtio_callback_mut_t
* @brief Callback signature for RTIO_OP_CALLBACK
* @param r RTIO context being used with the callback
* @param sqe Submission for the callback op
* @param res Result of the previously linked submission.
* @param arg0 Pointer to mutable argument option as part of the sqe
*/
typedef void (*rtio_callback_mut_t)(struct rtio *r, const struct rtio_sqe *sqe, int res, void *arg0);

Check warning on line 293 in include/zephyr/rtio/rtio.h

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LONG_LINE

include/zephyr/rtio/rtio.h:293 line length of 101 exceeds 100 columns

/**
* @typedef rtio_signaled_t
* @brief Callback signature for RTIO_OP_AWAIT signaled
* @param iodev_sqe IODEV submission for the await op
* @param userdata Userdata
*/
typedef void (*rtio_signaled_t)(struct rtio_iodev_sqe *iodev_sqe, void *userdata);
typedef void (*rtio_signaled_t)(struct rtio_iodev_sqe *iodev_sqe, const void *userdata);

/**
* @brief A submission queue event
Expand All @@ -310,7 +321,7 @@
* If unique identification of completions is desired this should be
* unique as well.
*/
void *userdata;
const void *userdata;

union {

Expand Down Expand Up @@ -556,11 +567,14 @@
/** An operation that transmits tiny writes by copying the data to write */
#define RTIO_OP_TINY_TX (RTIO_OP_TX+1)

/** An operation that calls a given function (callback) */
/** An operation that calls a given function (callback) with immutable data */
#define RTIO_OP_CALLBACK (RTIO_OP_TINY_TX+1)

/** An operation that calls a given function (callback) with mutable data */
#define RTIO_OP_CALLBACK_MUT (RTIO_OP_CALLBACK+1)

/** An operation that transceives (reads and writes simultaneously) */
#define RTIO_OP_TXRX (RTIO_OP_CALLBACK+1)
#define RTIO_OP_TXRX (RTIO_OP_CALLBACK_MUT+1)

/** An operation that takes a specified amount of time (asynchronously) before completing */
#define RTIO_OP_DELAY (RTIO_OP_TXRX+1)
Expand Down Expand Up @@ -588,7 +602,7 @@
*/
static inline void rtio_sqe_prep_nop(struct rtio_sqe *sqe,
const struct rtio_iodev *iodev,
void *userdata)
const void *userdata)
{
memset(sqe, 0, sizeof(struct rtio_sqe));
sqe->op = RTIO_OP_NOP;
Expand All @@ -604,7 +618,7 @@
int8_t prio,
uint8_t *buf,
uint32_t len,
void *userdata)
const void *userdata)
{
memset(sqe, 0, sizeof(struct rtio_sqe));
sqe->op = RTIO_OP_RX;
Expand All @@ -622,15 +636,15 @@
*/
static inline void rtio_sqe_prep_read_with_pool(struct rtio_sqe *sqe,
const struct rtio_iodev *iodev, int8_t prio,
void *userdata)
const void *userdata)
{
rtio_sqe_prep_read(sqe, iodev, prio, NULL, 0, userdata);
sqe->flags = RTIO_SQE_MEMPOOL_BUFFER;
}

static inline void rtio_sqe_prep_read_multishot(struct rtio_sqe *sqe,
const struct rtio_iodev *iodev, int8_t prio,
void *userdata)
const void *userdata)
{
rtio_sqe_prep_read_with_pool(sqe, iodev, prio, userdata);
sqe->flags |= RTIO_SQE_MULTISHOT;
Expand All @@ -644,7 +658,7 @@
int8_t prio,
const uint8_t *buf,
uint32_t len,
void *userdata)
const void *userdata)
{
memset(sqe, 0, sizeof(struct rtio_sqe));
sqe->op = RTIO_OP_TX;
Expand All @@ -670,7 +684,7 @@
int8_t prio,
const uint8_t *tiny_write_data,
uint8_t tiny_write_len,
void *userdata)
const void *userdata)
{
__ASSERT_NO_MSG(tiny_write_len <= sizeof(sqe->tiny_tx.buf));

Expand All @@ -694,7 +708,7 @@
static inline void rtio_sqe_prep_callback(struct rtio_sqe *sqe,
rtio_callback_t callback,
void *arg0,
void *userdata)
const void *userdata)
{
memset(sqe, 0, sizeof(struct rtio_sqe));
sqe->op = RTIO_OP_CALLBACK;
Expand All @@ -718,7 +732,7 @@
static inline void rtio_sqe_prep_callback_no_cqe(struct rtio_sqe *sqe,
rtio_callback_t callback,
void *arg0,
void *userdata)
const void *userdata)
{
rtio_sqe_prep_callback(sqe, callback, arg0, userdata);
sqe->flags |= RTIO_SQE_NO_RESPONSE;
Expand All @@ -733,7 +747,7 @@
const uint8_t *tx_buf,
uint8_t *rx_buf,
uint32_t buf_len,
void *userdata)
const void *userdata)
{
memset(sqe, 0, sizeof(struct rtio_sqe));
sqe->op = RTIO_OP_TXRX;
Expand All @@ -748,7 +762,7 @@
static inline void rtio_sqe_prep_await(struct rtio_sqe *sqe,
const struct rtio_iodev *iodev,
int8_t prio,
void *userdata)
const void *userdata)
{
memset(sqe, 0, sizeof(struct rtio_sqe));
sqe->op = RTIO_OP_AWAIT;
Expand All @@ -759,7 +773,7 @@

static inline void rtio_sqe_prep_delay(struct rtio_sqe *sqe,
k_timeout_t timeout,
void *userdata)
const void *userdata)
{
memset(sqe, 0, sizeof(struct rtio_sqe));
sqe->op = RTIO_OP_DELAY;
Expand Down
16 changes: 10 additions & 6 deletions subsys/rtio/rtio_executor.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,17 @@ LOG_MODULE_REGISTER(rtio_executor, CONFIG_RTIO_LOG_LEVEL);
/**
* @brief Executor handled submissions
*/
static void rtio_executor_op(struct rtio_iodev_sqe *iodev_sqe)
static void rtio_executor_op(struct rtio_iodev_sqe *iodev_sqe, int last_result)
{
const struct rtio_sqe *sqe = &iodev_sqe->sqe;

switch (sqe->op) {
case RTIO_OP_CALLBACK:
sqe->callback.callback(iodev_sqe->r, sqe, sqe->callback.arg0);
sqe->callback.callback(iodev_sqe->r, sqe, last_result, sqe->callback.arg0);
rtio_iodev_sqe_ok(iodev_sqe, 0);
break;
case RTIO_OP_CALLBACK_MUT:
sqe->callback_mut.callback(iodev_sqe->r, sqe, last_result, sqe->callback.arg0);
rtio_iodev_sqe_ok(iodev_sqe, 0);
break;
case RTIO_OP_DELAY:
Expand All @@ -40,7 +44,7 @@ static void rtio_executor_op(struct rtio_iodev_sqe *iodev_sqe)
*
* @param iodev_sqe Submission to work on
*/
static inline void rtio_iodev_submit(struct rtio_iodev_sqe *iodev_sqe)
static inline void rtio_iodev_submit(struct rtio_iodev_sqe *iodev_sqe, int last_result)
{
if (FIELD_GET(RTIO_SQE_CANCELED, iodev_sqe->sqe.flags)) {
rtio_iodev_sqe_err(iodev_sqe, -ECANCELED);
Expand All @@ -49,7 +53,7 @@ static inline void rtio_iodev_submit(struct rtio_iodev_sqe *iodev_sqe)

/* No iodev means its an executor specific operation */
if (iodev_sqe->sqe.iodev == NULL) {
rtio_executor_op(iodev_sqe);
rtio_executor_op(iodev_sqe, result);
return;
}

Expand Down Expand Up @@ -113,7 +117,7 @@ void rtio_executor_submit(struct rtio *r)
curr->next = NULL;
curr->r = r;

rtio_iodev_submit(iodev_sqe);
rtio_iodev_submit(iodev_sqe, 0);

node = mpsc_pop(&r->sq);
}
Expand Down Expand Up @@ -183,7 +187,7 @@ static inline void rtio_executor_done(struct rtio_iodev_sqe *iodev_sqe, int resu

/* curr should now be the last sqe in the transaction if that is what completed */
if (sqe_flags & RTIO_SQE_CHAINED) {
rtio_iodev_submit(curr);
rtio_iodev_submit(curr, result);
}
}

Expand Down
Loading