@@ -219,6 +219,55 @@ ZTEST(i2c_ram, test_ram_rtio)
219
219
"Written and Read data should match" );
220
220
}
221
221
222
+ ZTEST (i2c_ram , test_ram_rtio_write_with_transaction )
223
+ {
224
+ /** Many drivers and API rely on two write OPs in a single transaction
225
+ * to write register addr + register data in a single go.
226
+ * Hence why is validated in a separate test-case.
227
+ */
228
+ struct rtio_sqe * wraddr_sqe , * wrdata_sqe , * wr_sqe , * rd_sqe ;
229
+ struct rtio_cqe * wr_cqe , * rd_cqe ;
230
+
231
+ uint8_t reg_data [] = {'h' , 'e' , 'l' , 'l' , 'o' };
232
+
233
+ TC_PRINT ("submitting write from thread %p addr %x\n" , k_current_get (), addr );
234
+ wraddr_sqe = rtio_sqe_acquire (& i2c_rtio );
235
+ rtio_sqe_prep_write (wraddr_sqe , & i2c_iodev , 0 , (uint8_t * )& addr , sizeof (addr ), NULL );
236
+ wraddr_sqe -> flags |= RTIO_SQE_TRANSACTION ;
237
+
238
+ wrdata_sqe = rtio_sqe_acquire (& i2c_rtio );
239
+ rtio_sqe_prep_write (wrdata_sqe , & i2c_iodev , 0 , reg_data , ARRAY_SIZE (reg_data ), NULL );
240
+ wrdata_sqe -> iodev_flags |= RTIO_IODEV_I2C_STOP ;
241
+
242
+ zassert_ok (rtio_submit (& i2c_rtio , 2 ), "submit should succeed" );
243
+
244
+ wr_cqe = rtio_cqe_consume (& i2c_rtio );
245
+ zassert_ok (wr_cqe -> result , "i2c write should succeed" );
246
+ rtio_cqe_release (& i2c_rtio , wr_cqe );
247
+ wr_cqe = rtio_cqe_consume (& i2c_rtio );
248
+ zassert_ok (wr_cqe -> result , "i2c write should succeed" );
249
+ rtio_cqe_release (& i2c_rtio , wr_cqe );
250
+
251
+ /** Now read the register address to confirm the write was performed */
252
+ wr_sqe = rtio_sqe_acquire (& i2c_rtio );
253
+ rd_sqe = rtio_sqe_acquire (& i2c_rtio );
254
+ rtio_sqe_prep_write (wr_sqe , & i2c_iodev , 0 , (uint8_t * )& addr , sizeof (addr ), NULL );
255
+ rtio_sqe_prep_read (rd_sqe , & i2c_iodev , 0 , rx_data , ARRAY_SIZE (reg_data ), NULL );
256
+ wr_sqe -> flags |= RTIO_SQE_TRANSACTION ;
257
+ rd_sqe -> iodev_flags |= RTIO_IODEV_I2C_STOP | RTIO_IODEV_I2C_RESTART ;
258
+ zassert_ok (rtio_submit (& i2c_rtio , 2 ), "submit should succeed" );
259
+
260
+ wr_cqe = rtio_cqe_consume (& i2c_rtio );
261
+ rd_cqe = rtio_cqe_consume (& i2c_rtio );
262
+ zassert_ok (wr_cqe -> result , "i2c write should succeed" );
263
+ zassert_ok (rd_cqe -> result , "i2c read should succeed" );
264
+ rtio_cqe_release (& i2c_rtio , wr_cqe );
265
+ rtio_cqe_release (& i2c_rtio , rd_cqe );
266
+
267
+ zassert_equal (memcmp (& reg_data [0 ], & rx_data [0 ], ARRAY_SIZE (reg_data )), 0 ,
268
+ "Written and Read data should match" );
269
+ }
270
+
222
271
static enum isr_rtio_state {
223
272
INIT ,
224
273
WRITE_WAIT ,
0 commit comments