Skip to content

Commit 18a964f

Browse files
JordanYatesnashif
authored andcommitted
i2c: nrfx_twi: fix RTIO utility functions
Route `configure` and `recover_bus` through the RTIO framework to avoid race conditions. Update `RTIO_OP_I2C_RECOVER` implementation to actually recover the bus, instead of triggering a loop. Signed-off-by: Jordan Yates <[email protected]>
1 parent 0d796ee commit 18a964f

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

drivers/i2c/i2c_nrfx_twi_rtio.c

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ static bool i2c_nrfx_twi_rtio_start(const struct device *dev)
8181
(void)i2c_nrfx_twi_configure(dev, sqe->i2c_config);
8282
return false;
8383
case RTIO_OP_I2C_RECOVER:
84-
(void)i2c_rtio_recover(ctx);
84+
(void)i2c_nrfx_twi_recover_bus(dev);
8585
return false;
8686
default:
8787
LOG_ERR("Invalid op code %d for submission %p\n", sqe->op, (void *)sqe);
@@ -104,6 +104,14 @@ static void i2c_nrfx_twi_rtio_complete(const struct device *dev, int status)
104104
}
105105
}
106106

107+
static int i2c_nrfx_twi_rtio_configure(const struct device *dev, uint32_t i2c_config)
108+
{
109+
struct i2c_rtio *const ctx = ((struct i2c_nrfx_twi_rtio_data *)
110+
dev->data)->ctx;
111+
112+
return i2c_rtio_configure(ctx, i2c_config);
113+
}
114+
107115
static int i2c_nrfx_twi_rtio_transfer(const struct device *dev, struct i2c_msg *msgs,
108116
uint8_t num_msgs, uint16_t addr)
109117
{
@@ -113,6 +121,14 @@ static int i2c_nrfx_twi_rtio_transfer(const struct device *dev, struct i2c_msg *
113121
return i2c_rtio_transfer(ctx, msgs, num_msgs, addr);
114122
}
115123

124+
static int i2c_nrfx_twi_rtio_recover_bus(const struct device *dev)
125+
{
126+
struct i2c_rtio *const ctx = ((struct i2c_nrfx_twi_rtio_data *)
127+
dev->data)->ctx;
128+
129+
return i2c_rtio_recover(ctx);
130+
}
131+
116132
static void event_handler(nrfx_twi_evt_t const *p_event, void *p_context)
117133
{
118134
const struct device *dev = p_context;
@@ -136,9 +152,9 @@ static void i2c_nrfx_twi_rtio_submit(const struct device *dev, struct rtio_iodev
136152
}
137153

138154
static const struct i2c_driver_api i2c_nrfx_twi_rtio_driver_api = {
139-
.configure = i2c_nrfx_twi_configure,
155+
.configure = i2c_nrfx_twi_rtio_configure,
140156
.transfer = i2c_nrfx_twi_rtio_transfer,
141-
.recover_bus = i2c_nrfx_twi_recover_bus,
157+
.recover_bus = i2c_nrfx_twi_rtio_recover_bus,
142158
.iodev_submit = i2c_nrfx_twi_rtio_submit,
143159
};
144160

0 commit comments

Comments
 (0)