Zephyr API Documentation 4.0.0
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
sensing_sensor.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2022-2023 Intel Corporation.
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7#ifndef ZEPHYR_INCLUDE_SENSING_SENSOR_H_
8#define ZEPHYR_INCLUDE_SENSING_SENSOR_H_
9
10#include <stdbool.h>
11#include <zephyr/device.h>
14
28#ifdef __cplusplus
29extern "C" {
30#endif
31
59
67enum {
68 EVENT_CONFIG_READY,
69};
70
76enum {
77 SENSOR_LATER_CFG_BIT,
78};
79
83struct sensing_connection {
84 sys_snode_t snode;
85 struct sensing_sensor *source;
86 struct sensing_sensor *sink;
87 uint32_t interval;
89 int sensitivity[CONFIG_SENSING_MAX_SENSITIVITY_COUNT];
90 void *data;
92 uint64_t next_consume_time;
93 struct sensing_callback_list *callback_list;
94};
95
105struct sensing_sensor {
106 const struct device *dev;
107 const struct sensing_sensor_info *info;
109 const struct sensing_sensor_register_info *register_info;
110 const uint16_t reporter_num;
111 sys_slist_t client_list;
112 uint32_t interval;
113 uint8_t sensitivity_count;
115 int sensitivity[CONFIG_SENSING_MAX_SENSITIVITY_COUNT];
117 struct rtio_iodev *iodev;
118 struct k_timer timer;
119 struct rtio_sqe *stream_sqe;
120 atomic_t flag;
121 struct sensing_connection *conns;
122};
123
132#define SENSING_SENSOR_INFO_NAME(node, idx) \
133 _CONCAT(_CONCAT(__sensing_sensor_info_, idx), DEVICE_DT_NAME_GET(node))
134
145#define SENSING_SENSOR_INFO_DEFINE(node, idx) \
146 const static STRUCT_SECTION_ITERABLE(sensing_sensor_info, \
147 SENSING_SENSOR_INFO_NAME(node, idx)) = { \
148 .type = DT_PROP_BY_IDX(node, sensor_types, idx), \
149 .name = DT_NODE_FULL_NAME(node), \
150 .friendly_name = DT_PROP(node, friendly_name), \
151 .vendor = DT_NODE_VENDOR_OR(node, NULL), \
152 .model = DT_NODE_MODEL_OR(node, NULL), \
153 .minimal_interval = DT_PROP(node, minimal_interval), \
154 };
155
163#define SENSING_CONNECTIONS_NAME(node) \
164 _CONCAT(__sensing_connections_, DEVICE_DT_NAME_GET(node))
165
174#define SENSING_SENSOR_SOURCE_NAME(idx, node) \
175 SENSING_SENSOR_NAME(DT_PHANDLE_BY_IDX(node, reporters, idx), \
176 DT_PROP_BY_IDX(node, reporters_index, idx))
177
186#define SENSING_SENSOR_SOURCE_EXTERN(idx, node) \
187extern struct sensing_sensor SENSING_SENSOR_SOURCE_NAME(idx, node);
188
197#define SENSING_CONNECTION_INITIALIZER(source_name, cb_list_ptr) \
198{ \
199 .callback_list = cb_list_ptr, \
200 .source = &source_name, \
201}
202
212#define SENSING_CONNECTION_DEFINE(idx, node, cb_list_ptr) \
213 SENSING_CONNECTION_INITIALIZER(SENSING_SENSOR_SOURCE_NAME(idx, node), \
214 cb_list_ptr)
215
226#define SENSING_CONNECTIONS_DEFINE(node, num, cb_list_ptr) \
227 LISTIFY(num, SENSING_SENSOR_SOURCE_EXTERN, \
228 (), node) \
229 static struct sensing_connection \
230 SENSING_CONNECTIONS_NAME(node)[(num)] = { \
231 LISTIFY(num, SENSING_CONNECTION_DEFINE, \
232 (,), node, cb_list_ptr) \
233 };
234
241struct sensing_submit_config {
242 enum sensor_channel chan;
243 const int info_index;
244 const bool is_streaming;
245};
246
252extern const struct rtio_iodev_api __sensing_iodev_api;
253
262#define SENSING_SUBMIT_CFG_NAME(node, idx) \
263 _CONCAT(_CONCAT(__sensing_submit_cfg_, idx), DEVICE_DT_NAME_GET(node))
264
273#define SENSING_SENSOR_IODEV_NAME(node, idx) \
274 _CONCAT(_CONCAT(__sensing_iodev_, idx), DEVICE_DT_NAME_GET(node))
275
285#define SENSING_SENSOR_IODEV_DEFINE(node, idx) \
286 static struct sensing_submit_config SENSING_SUBMIT_CFG_NAME(node, idx) = { \
287 .is_streaming = DT_PROP(node, stream_mode), \
288 .info_index = idx, \
289 }; \
290 RTIO_IODEV_DEFINE(SENSING_SENSOR_IODEV_NAME(node, idx), \
291 &__sensing_iodev_api, \
292 &SENSING_SUBMIT_CFG_NAME(node, idx));
293
302#define SENSING_SENSOR_NAME(node, idx) \
303 _CONCAT(_CONCAT(__sensing_sensor_, idx), DEVICE_DT_NAME_GET(node))
304
318#define SENSING_SENSOR_DEFINE(node, prop, idx, reg_ptr, cb_list_ptr) \
319 SENSING_SENSOR_INFO_DEFINE(node, idx) \
320 SENSING_SENSOR_IODEV_DEFINE(node, idx) \
321 STRUCT_SECTION_ITERABLE(sensing_sensor, \
322 SENSING_SENSOR_NAME(node, idx)) = { \
323 .dev = DEVICE_DT_GET(node), \
324 .info = &SENSING_SENSOR_INFO_NAME(node, idx), \
325 .register_info = reg_ptr, \
326 .reporter_num = DT_PROP_LEN_OR(node, reporters, 0), \
327 .conns = SENSING_CONNECTIONS_NAME(node), \
328 .iodev = &SENSING_SENSOR_IODEV_NAME(node, idx), \
329 };
330
341#define SENSING_SENSORS_DEFINE(node, reg_ptr, cb_list_ptr) \
342 DT_FOREACH_PROP_ELEM_VARGS(node, sensor_types, \
343 SENSING_SENSOR_DEFINE, reg_ptr, cb_list_ptr)
344
369#define SENSING_SENSORS_DT_DEFINE(node, reg_ptr, cb_list_ptr, \
370 init_fn, pm_device, \
371 data_ptr, cfg_ptr, level, prio, \
372 api_ptr, ...) \
373 SENSOR_DEVICE_DT_DEFINE(node, init_fn, pm_device, \
374 data_ptr, cfg_ptr, level, prio, \
375 api_ptr, __VA_ARGS__); \
376 SENSING_CONNECTIONS_DEFINE(node, \
377 DT_PROP_LEN_OR(node, reporters, 0), \
378 cb_list_ptr); \
379 SENSING_SENSORS_DEFINE(node, reg_ptr, cb_list_ptr);
380
389#define SENSING_SENSORS_DT_INST_DEFINE(inst, ...) \
390 SENSING_SENSORS_DT_DEFINE(DT_DRV_INST(inst), __VA_ARGS__)
391
405 const struct device *dev, int type,
406 sensing_sensor_handle_t *reporter_handles, int max_handles);
407
416 const struct device *dev, int type);
417
426 const struct device *dev,
428
433#ifdef __cplusplus
434}
435#endif
436
437#endif /*ZEPHYR_INCLUDE_SENSING_SENSOR_H_*/
long atomic_t
Definition atomic_types.h:15
sensing_sensor_state
Sensing subsystem sensor state.
Definition sensing.h:89
void * sensing_sensor_handle_t
Define Sensing subsystem sensor handle.
Definition sensing.h:113
int sensing_sensor_get_reporters_count(const struct device *dev, int type)
Get reporters count of a given sensor instance by sensor type.
int sensing_sensor_get_reporters(const struct device *dev, int type, sensing_sensor_handle_t *reporter_handles, int max_handles)
Get reporter handles of a given sensor instance by sensor type.
int sensing_sensor_get_state(const struct device *dev, enum sensing_sensor_state *state)
Get this sensor's state.
sensor_channel
Sensor channels.
Definition sensor.h:61
struct _slist sys_slist_t
Single-linked list structure.
Definition slist.h:49
struct _snode sys_snode_t
Single-linked list node structure.
Definition slist.h:39
state
Definition parser_state.h:29
Public APIs for the sensor driver.
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
__UINT64_TYPE__ uint64_t
Definition stdint.h:91
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
__UINT16_TYPE__ uint16_t
Definition stdint.h:89
Runtime device structure (in ROM) per driver instance.
Definition device.h:412
API that an RTIO IO device should implement.
Definition rtio.h:439
An IO device with a function table for submitting requests.
Definition rtio.h:454
A submission queue event.
Definition rtio.h:232
Sensing subsystem event callback list.
Definition sensing.h:157
Sensor basic constant information.
Definition sensing.h:132
Sensor registration information.
Definition sensing_sensor.h:36
uint16_t sample_size
Sample size in bytes for a single sample of the registered sensor.
Definition sensing_sensor.h:46
uint16_t flags
Sensor flags.
Definition sensing_sensor.h:40
uint8_t sensitivity_count
The number of sensor sensitivities.
Definition sensing_sensor.h:51
struct sensing_sensor_version version
Sensor version.
Definition sensing_sensor.h:57
Sensor Version.
Definition sensing.h:39