Zephyr Project API 4.2.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
regmap.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2025 STMicroelectronics
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7#ifndef ZEPHYR_INCLUDE_RTIO_REGMAP_H_
8#define ZEPHYR_INCLUDE_RTIO_REGMAP_H_
9
10#include <zephyr/rtio/rtio.h>
11
12#ifdef __cplusplus
13extern "C" {
14#endif
15
20struct rtio_regs {
23
27
30
32 size_t len;
33 } *rtio_regs_list;
34};
35
47
53static inline bool rtio_is_spi(rtio_bus_type bus_type)
54{
55 return (bus_type == RTIO_BUS_SPI);
56}
57
63static inline bool rtio_is_i2c(rtio_bus_type bus_type)
64{
65 return (bus_type == RTIO_BUS_I2C);
66}
67
73static inline bool rtio_is_i3c(rtio_bus_type bus_type)
74{
75 return (bus_type == RTIO_BUS_I3C);
76}
77
78/*
79 * @brief Create a chain of SQEs representing a bus transaction to read a reg.
80 *
81 * The RTIO-enabled bus driver is instrumented to perform bus read ops
82 * for each register in the list.
83 *
84 * Usage:
85 *
86 * @code{.c}
87 * struct rtio_regs regs;
88 * struct rtio_reg_list regs_list[] = {{regs_addr1, mem_addr_1, mem_len_1},
89 * {regs_addr2, mem_addr_2, mem_len_2},
90 * ...
91 * };
92 * regs.rtio_regs_list = regs_list;
93 * regs.rtio_regs_num = ARRAY_SIZE(regs_list);
94 *
95 * rtio_read_regs_async(rtio,
96 * iodev,
97 * RTIO_BUS_SPI,
98 * &regs,
99 * sqe,
100 * dev,
101 * op_cb);
102 * @endcode
103 *
104 * @param r RTIO context
105 * @param iodev IO device
106 * @param bus_type Type of bus (I2C, SPI, I3C)
107 * @param regs pointer to list of registers to be read. Raise proper bit in case of SPI bus
108 * @param iodev_sqe IODEV submission for the await op
109 * @param dev pointer to the device structure
110 * @param complete_op_cb callback routine at the end of op
111 */
112static inline void rtio_read_regs_async(struct rtio *r, struct rtio_iodev *iodev,
113 rtio_bus_type bus_type, struct rtio_regs *regs,
114 struct rtio_iodev_sqe *iodev_sqe, const struct device *dev,
115 rtio_callback_t complete_op_cb)
116{
117 struct rtio_sqe *write_addr;
118 struct rtio_sqe *read_reg;
119 struct rtio_sqe *complete_op;
120
121 for (uint8_t i = 0; i < regs->rtio_regs_num; i++) {
122
123 write_addr = rtio_sqe_acquire(r);
124 read_reg = rtio_sqe_acquire(r);
125
126 if (write_addr == NULL || read_reg == NULL) {
127 rtio_iodev_sqe_err(iodev_sqe, -ENOMEM);
129 return;
130 }
131
133 &regs->rtio_regs_list[i].reg_addr, 1, NULL);
134 write_addr->flags = RTIO_SQE_TRANSACTION;
135
137 regs->rtio_regs_list[i].len, NULL);
138 read_reg->flags = RTIO_SQE_CHAINED;
139
140 switch (bus_type) {
141 case RTIO_BUS_I2C:
143 break;
144 case RTIO_BUS_I3C:
146 break;
147 case RTIO_BUS_SPI:
148 default:
149 break;
150 }
151 }
152
153 complete_op = rtio_sqe_acquire(r);
154 if (complete_op == NULL) {
155 rtio_iodev_sqe_err(iodev_sqe, -ENOMEM);
157 return;
158 }
159
160 rtio_sqe_prep_callback_no_cqe(complete_op, complete_op_cb, (void *)dev, iodev_sqe);
161
162 rtio_submit(r, 0);
163}
164
165#ifdef __cplusplus
166}
167#endif
168
169#endif /* ZEPHYR_INCLUDE_RTIO_REGMAP_H_ */
workaround assembler barfing for ST r
Definition asm-macro-32-bit-gnu.h:24
#define RTIO_SQE_TRANSACTION
The next request in the queue is part of a transaction.
Definition rtio.h:109
#define RTIO_SQE_CHAINED
The next request in the queue should wait on this one.
Definition rtio.h:97
#define RTIO_PRIO_NORM
Normal priority.
Definition rtio.h:71
static void rtio_sqe_prep_tiny_write(struct rtio_sqe *sqe, const struct rtio_iodev *iodev, int8_t prio, const uint8_t *tiny_write_data, uint8_t tiny_write_len, void *userdata)
Prepare a tiny write op submission.
Definition rtio.h:668
#define RTIO_IODEV_I3C_STOP
Equivalent to the I3C_MSG_STOP flag.
Definition rtio.h:214
static void rtio_sqe_prep_read(struct rtio_sqe *sqe, const struct rtio_iodev *iodev, int8_t prio, uint8_t *buf, uint32_t len, void *userdata)
Prepare a read op submission.
Definition rtio.h:602
static struct rtio_sqe * rtio_sqe_acquire(struct rtio *r)
Acquire a single submission queue event if available.
Definition rtio.h:1054
static void rtio_sqe_drop_all(struct rtio *r)
Drop all previously acquired sqe.
Definition rtio.h:1072
#define RTIO_IODEV_I3C_RESTART
Equivalent to the I3C_MSG_RESTART flag.
Definition rtio.h:219
static void rtio_iodev_sqe_err(struct rtio_iodev_sqe *iodev_sqe, int result)
Inform the executor of a submissions completion with error.
Definition rtio.h:1285
void(* rtio_callback_t)(struct rtio *r, const struct rtio_sqe *sqe, void *arg0)
Callback signature for RTIO_OP_CALLBACK.
Definition rtio.h:282
#define RTIO_IODEV_I2C_RESTART
Equivalent to the I2C_MSG_RESTART flag.
Definition rtio.h:204
static void rtio_sqe_prep_callback_no_cqe(struct rtio_sqe *sqe, rtio_callback_t callback, void *arg0, void *userdata)
Prepare a callback op submission that does not create a CQE.
Definition rtio.h:718
#define RTIO_IODEV_I2C_STOP
Equivalent to the I2C_MSG_STOP flag.
Definition rtio.h:199
int rtio_submit(struct rtio *r, uint32_t wait_count)
Submit I/O requests to the underlying executor.
#define ENOMEM
Not enough core.
Definition errno.h:50
#define NULL
Definition iar_missing_defs.h:20
static void rtio_read_regs_async(struct rtio *r, struct rtio_iodev *iodev, rtio_bus_type bus_type, struct rtio_regs *regs, struct rtio_iodev_sqe *iodev_sqe, const struct device *dev, rtio_callback_t complete_op_cb)
Definition regmap.h:112
rtio_bus_type
bus type
Definition regmap.h:42
@ RTIO_BUS_I2C
Definition regmap.h:43
@ RTIO_BUS_I3C
Definition regmap.h:45
@ RTIO_BUS_SPI
Definition regmap.h:44
static bool rtio_is_i3c(rtio_bus_type bus_type)
check if bus is I3C
Definition regmap.h:73
static bool rtio_is_spi(rtio_bus_type bus_type)
check if bus is SPI
Definition regmap.h:53
static bool rtio_is_i2c(rtio_bus_type bus_type)
check if bus is I2C
Definition regmap.h:63
Real-Time IO device API for moving bytes with low effort.
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
Runtime device structure (in ROM) per driver instance.
Definition device.h:510
Compute the mempool block index for a given pointer.
Definition rtio.h:514
An IO device with a function table for submitting requests.
Definition rtio.h:539
Definition regmap.h:24
uint8_t * bufp
Valid pointer to a data buffer.
Definition regmap.h:29
size_t len
Length of the buffer in bytes.
Definition regmap.h:32
uint8_t reg_addr
Register address.
Definition regmap.h:26
A structure to describe a list of not-consecutive memory chunks for RTIO operations.
Definition regmap.h:20
size_t rtio_regs_num
Number of registers in the list.
Definition regmap.h:22
struct rtio_regs::rtio_regs_list * rtio_regs_list
A submission queue event.
Definition rtio.h:295
const struct rtio_iodev * iodev
Device to operation on.
Definition rtio.h:304
uint32_t iodev_flags
Op iodev flags.
Definition rtio.h:302
uint16_t flags
Op Flags.
Definition rtio.h:300
An RTIO context containing what can be viewed as a pair of queues.
Definition rtio.h:418