|
38 | 38 | #include <zephyr/sys/atomic.h> |
39 | 39 | #include <zephyr/device.h> |
40 | 40 | #include <zephyr/kernel.h> |
| 41 | +#include <string.h> |
41 | 42 |
|
42 | 43 | #ifdef __cplusplus |
43 | 44 | extern "C" { |
@@ -133,20 +134,34 @@ struct rtio_sqe { |
133 | 134 | const struct rtio_iodev *iodev; /**< Device to operation on */ |
134 | 135 |
|
135 | 136 | /** |
136 | | - * User provided pointer to data which is returned upon operation |
137 | | - * completion |
| 137 | + * User provided data which is returned upon operation |
| 138 | + * completion. Could be a pointer or integer. |
138 | 139 | * |
139 | 140 | * If unique identification of completions is desired this should be |
140 | 141 | * unique as well. |
141 | 142 | */ |
142 | 143 | void *userdata; |
143 | 144 |
|
144 | 145 | union { |
| 146 | + |
| 147 | + /** OP_TX, OP_RX */ |
145 | 148 | struct { |
146 | 149 | uint32_t buf_len; /**< Length of buffer */ |
147 | 150 |
|
148 | 151 | uint8_t *buf; /**< Buffer to use*/ |
149 | 152 | }; |
| 153 | + |
| 154 | + /** OP_TINY_TX */ |
| 155 | + struct { |
| 156 | + uint8_t tiny_buf_len; /**< Length of tiny buffer */ |
| 157 | + uint8_t tiny_buf[7]; /**< Tiny buffer */ |
| 158 | + }; |
| 159 | + |
| 160 | + /** OP_CALLBACK */ |
| 161 | + struct { |
| 162 | + void (*callback)(struct rtio *r, struct rtio_sqe *sqe, void *arg0); |
| 163 | + void *arg0; |
| 164 | + }; |
150 | 165 | }; |
151 | 166 | }; |
152 | 167 |
|
@@ -321,10 +336,17 @@ struct rtio_iodev { |
321 | 336 | #define RTIO_OP_NOP 0 |
322 | 337 |
|
323 | 338 | /** An operation that receives (reads) */ |
324 | | -#define RTIO_OP_RX 1 |
| 339 | +#define RTIO_OP_RX (RTIO_OP_NOP+1) |
325 | 340 |
|
326 | 341 | /** An operation that transmits (writes) */ |
327 | | -#define RTIO_OP_TX 2 |
| 342 | +#define RTIO_OP_TX (RTIO_OP_RX+1) |
| 343 | + |
| 344 | +/** An operation that transmits tiny writes */ |
| 345 | +#define RTIO_OP_TINY_TX (RTIO_OP_TX+1) |
| 346 | + |
| 347 | +/** An operation that does some small functional work */ |
| 348 | +#define RTIO_OP_FUNC (RTIO_OP_TINY_TX+1) |
| 349 | + |
328 | 350 |
|
329 | 351 | /** |
330 | 352 | * @brief Prepare a nop (no op) submission |
@@ -377,6 +399,34 @@ static inline void rtio_sqe_prep_write(struct rtio_sqe *sqe, |
377 | 399 | sqe->userdata = userdata; |
378 | 400 | } |
379 | 401 |
|
| 402 | +/** |
| 403 | + * @brief Prepare a tiny write op submission |
| 404 | + * |
| 405 | + * Unlike the normal write operation where the source buffer must outlive the call |
| 406 | + * the tiny write data in this case is copied to the sqe. It must be tiny to fit |
| 407 | + * within the specified size of a rtio_sqe. |
| 408 | + * |
| 409 | + * This is useful in many scenarios with RTL logic where a write of the register to |
| 410 | + * subsequently read must be done. |
| 411 | + */ |
| 412 | +static inline void rtio_sqe_prep_tiny_write(struct rtio_sqe *sqe, |
| 413 | + const struct rtio_iodev *iodev, |
| 414 | + int8_t prio, |
| 415 | + const uint8_t *tiny_write_data, |
| 416 | + uint8_t tiny_write_len, |
| 417 | + void *userdata) |
| 418 | +{ |
| 419 | + __ASSERT_NO_MSG(tiny_write_len <= sizeof(sqe->tiny_buf)); |
| 420 | + |
| 421 | + sqe->op = RTIO_OP_TINY_TX; |
| 422 | + sqe->prio = prio; |
| 423 | + sqe->flags = 0; |
| 424 | + sqe->iodev = iodev; |
| 425 | + sqe->tiny_buf_len = tiny_write_len; |
| 426 | + memcpy(sqe->tiny_buf, tiny_write_data, tiny_write_len); |
| 427 | + sqe->userdata = userdata; |
| 428 | +} |
| 429 | + |
380 | 430 | /** |
381 | 431 | * @brief Statically define and initialize a fixed length submission queue. |
382 | 432 | * |
|
0 commit comments