Skip to content

Commit 0c376c2

Browse files
committed
sensor: RTIO API support for FIFO streaming
Provides the necessary APIs to stream a sensors FIFO using RTIO Adds an API call to enable explicitly reading the fifo from the sensor at any time. The thinking is that while the sensors gpio trigger might be one source of triggering a fifo read, external sources should be possible. Signed-off-by: Tom Burdick <[email protected]>
1 parent 7c882a7 commit 0c376c2

File tree

1 file changed

+105
-0
lines changed

1 file changed

+105
-0
lines changed

include/zephyr/drivers/sensor.h

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
#include <zephyr/types.h>
2323
#include <zephyr/device.h>
24+
#include <zephyr/rtio/rtio.h>
2425
#include <errno.h>
2526

2627
#ifdef __cplusplus
@@ -318,6 +319,10 @@ enum sensor_attribute {
318319
* to the new sampling frequency.
319320
*/
320321
SENSOR_ATTR_FF_DUR,
322+
/** FIFO watermark attribute */
323+
SENSOR_ATTR_FIFO_WATERMARK,
324+
/** FIFO enable/disable fifo related interrupts */
325+
SENSOR_ATTR_FIFO_INTERRUPT,
321326
/**
322327
* Number of all common sensor attributes.
323328
*/
@@ -394,12 +399,48 @@ typedef int (*sensor_channel_get_t)(const struct device *dev,
394399
enum sensor_channel chan,
395400
struct sensor_value *val);
396401

402+
#ifdef CONFIG_RTIO
403+
404+
/**
405+
* @type sensor_fifo_iodev_t
406+
* @brief Callback API for obtaining a reference to a sensors FIFO iodev.
407+
*/
408+
typedef int (*sensor_fifo_iodev_t)(const struct device *dev, struct rtio_iodev **iodev_sqe);
409+
410+
/**
411+
* @type sensor_fifo_read_t
412+
* @brief Callback API for immediately triggering a FIFO read.
413+
*/
414+
typedef int (*sensor_fifo_read_t)(const struct device *dev);
415+
416+
/**
417+
* @type sensor_fifo_start_t
418+
* @brief Callback API to start FIFO streaming.
419+
*/
420+
typedef int (*sensor_fifo_start_t)(const struct device *dev);
421+
422+
/**
423+
* @type sensor_fifo_stop_t
424+
* @brief Callback API to stop FIFO streaming.
425+
*/
426+
typedef int (*sensor_fifo_stop_t)(const struct device *dev);
427+
428+
429+
#endif /* CONFIG_RTIO */
430+
397431
__subsystem struct sensor_driver_api {
398432
sensor_attr_set_t attr_set;
399433
sensor_attr_get_t attr_get;
400434
sensor_trigger_set_t trigger_set;
401435
sensor_sample_fetch_t sample_fetch;
402436
sensor_channel_get_t channel_get;
437+
438+
#ifdef CONFIG_RTIO
439+
sensor_fifo_iodev_t fifo_iodev;
440+
sensor_fifo_read_t fifo_read;
441+
sensor_fifo_start_t fifo_start;
442+
sensor_fifo_stop_t fifo_stop;
443+
#endif /* CONFIG_RTIO */
403444
};
404445

405446
/**
@@ -593,6 +634,70 @@ static inline int z_impl_sensor_channel_get(const struct device *dev,
593634
return api->channel_get(dev, chan, val);
594635
}
595636

637+
/**
638+
* @brief Submit a request for the fifo stream (iodev) for this sensor.
639+
*/
640+
static inline int sensor_fifo_iodev(const struct device *dev, struct rtio_iodev **iodev)
641+
{
642+
#ifdef CONFIG_RTIO
643+
644+
const struct sensor_driver_api *api =
645+
(const struct sensor_driver_api *)dev->api;
646+
647+
return api->fifo_iodev(dev, iodev);
648+
#else
649+
return -ENOSYS;
650+
#endif
651+
}
652+
653+
/**
654+
* @brief Checkin a rtio_iodev pointer for this sensor, only one per device.
655+
*/
656+
static inline int sensor_fifo_read(const struct device *dev)
657+
{
658+
#ifdef CONFIG_RTIO
659+
660+
const struct sensor_driver_api *api =
661+
(const struct sensor_driver_api *)dev->api;
662+
663+
return api->fifo_read(dev);
664+
#else
665+
return -ENOSYS;
666+
#endif
667+
}
668+
669+
/**
670+
* @brief Start streaming the fifo for this sensor.
671+
*/
672+
static inline int sensor_fifo_start(const struct device *dev)
673+
{
674+
#ifdef CONFIG_RTIO
675+
676+
const struct sensor_driver_api *api =
677+
(const struct sensor_driver_api *)dev->api;
678+
679+
return api->fifo_start(dev);
680+
#else
681+
return -ENOSYS;
682+
#endif
683+
}
684+
685+
/**
686+
* @brief Stop streaming the fifo for this sensor.
687+
*/
688+
static inline int sensor_fifo_stop(const struct device *dev)
689+
{
690+
#ifdef CONFIG_RTIO
691+
692+
const struct sensor_driver_api *api =
693+
(const struct sensor_driver_api *)dev->api;
694+
695+
return api->fifo_stop(dev);
696+
#else
697+
return -ENOSYS;
698+
#endif
699+
}
700+
596701
/**
597702
* @brief The value of gravitational constant in micro m/s^2.
598703
*/

0 commit comments

Comments
 (0)