Skip to content

Commit cc139b8

Browse files
ubiedanashif
authored andcommitted
sensor: Enable RTIO Semaphores for Async API
In order to decouple the read request from its implementation, we need to be able to yield to potential lower-priority threads, which is not possible with k_yield() itself. As such, using RTIO Consume semaphore enables us to achieve this. This patch also refactors blocking API (sensor_read) to also block upon consumption, so as not to require RTIO_SUBMIT_SEM enabled. Signed-off-by: Luis Ubieda <[email protected]>
1 parent 6d4fba1 commit cc139b8

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

drivers/sensor/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ config SENSOR_ASYNC_API
2424
bool "Async Sensor API"
2525
select RTIO
2626
select RTIO_SYS_MEM_BLOCKS
27+
select RTIO_CONSUME_SEM
2728
help
2829
Enables the asynchronous sensor API by leveraging the RTIO subsystem.
2930

include/zephyr/drivers/sensor.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,9 +1056,9 @@ static inline int sensor_read(struct rtio_iodev *iodev, struct rtio *ctx, uint8_
10561056
}
10571057
rtio_sqe_prep_read(sqe, iodev, RTIO_PRIO_NORM, buf, buf_len, buf);
10581058
}
1059-
rtio_submit(ctx, 1);
1059+
rtio_submit(ctx, 0);
10601060

1061-
struct rtio_cqe *cqe = rtio_cqe_consume(ctx);
1061+
struct rtio_cqe *cqe = rtio_cqe_consume_block(ctx);
10621062
int res = cqe->result;
10631063

10641064
__ASSERT(cqe->userdata != buf,

0 commit comments

Comments
 (0)