Skip to content

Commit aff6e31

Browse files
ubiedanashif
authored andcommitted
sensor: fallback: Decouple RTIO request using RTIO workqueues service
Incorporate RTIO workqueues to turn sensor_submit_callback into an asynchronous request. Signed-off-by: Luis Ubieda <[email protected]>
1 parent 5686ac4 commit aff6e31

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

drivers/sensor/Kconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Sensor configuration options
22

33
# Copyright (c) 2016 Intel Corporation
4+
# Copyright (c) 2024 Croxel Inc
45
# SPDX-License-Identifier: Apache-2.0
56

67
menuconfig SENSOR
@@ -25,6 +26,7 @@ config SENSOR_ASYNC_API
2526
select RTIO
2627
select RTIO_SYS_MEM_BLOCKS
2728
select RTIO_CONSUME_SEM
29+
select RTIO_WORKQ
2830
help
2931
Enables the asynchronous sensor API by leveraging the RTIO subsystem.
3032

drivers/sensor/default_rtio_sensor.c

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*
22
* Copyright (c) 2023 Google LLC.
3+
* Copyright (c) 2024 Croxel Inc.
34
*
45
* SPDX-License-Identifier: Apache-2.0
56
*/
@@ -9,6 +10,7 @@
910
#include <zephyr/drivers/sensor.h>
1011
#include <zephyr/dsp/types.h>
1112
#include <zephyr/logging/log.h>
13+
#include <zephyr/rtio/work.h>
1214

1315
LOG_MODULE_REGISTER(sensor_compat, CONFIG_SENSOR_LOG_LEVEL);
1416

@@ -106,14 +108,14 @@ static inline int check_header_contains_channel(const struct sensor_data_generic
106108
}
107109

108110
/**
109-
* @brief Fallback function for retrofiting old drivers to rtio
111+
* @brief Fallback function for retrofiting old drivers to rtio (sync)
110112
*
111-
* @param[in] dev The sensor device to read
112113
* @param[in] iodev_sqe The read submission queue event
113114
*/
114-
static void sensor_submit_fallback(const struct device *dev, struct rtio_iodev_sqe *iodev_sqe)
115+
static void sensor_submit_fallback_sync(struct rtio_iodev_sqe *iodev_sqe)
115116
{
116117
const struct sensor_read_config *cfg = iodev_sqe->sqe.iodev->data;
118+
const struct device *dev = cfg->sensor;
117119
const struct sensor_chan_spec *const channels = cfg->channels;
118120
const int num_output_samples = compute_num_samples(channels, cfg->count);
119121
uint32_t min_buf_len = compute_min_buf_len(num_output_samples);
@@ -253,6 +255,21 @@ static void sensor_submit_fallback(const struct device *dev, struct rtio_iodev_s
253255
rtio_iodev_sqe_ok(iodev_sqe, 0);
254256
}
255257

258+
/**
259+
* @brief Fallback function for retrofiting old drivers to rtio
260+
*
261+
* @param[in] dev The sensor device to read
262+
* @param[in] iodev_sqe The read submission queue event
263+
*/
264+
static void sensor_submit_fallback(const struct device *dev, struct rtio_iodev_sqe *iodev_sqe)
265+
{
266+
struct rtio_work_req *req = rtio_work_req_alloc();
267+
268+
__ASSERT_NO_MSG(req);
269+
270+
rtio_work_req_submit(req, iodev_sqe, sensor_submit_fallback_sync);
271+
}
272+
256273
void sensor_processing_with_callback(struct rtio *ctx, sensor_processing_callback_t cb)
257274
{
258275
void *userdata = NULL;

0 commit comments

Comments
 (0)