Zephyr API Documentation 4.0.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
device.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2015 Intel Corporation.
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7#ifndef ZEPHYR_INCLUDE_DEVICE_H_
8#define ZEPHYR_INCLUDE_DEVICE_H_
9
10#include <stdint.h>
11
12#include <zephyr/devicetree.h>
13#include <zephyr/init.h>
15#include <zephyr/pm/state.h>
18#include <zephyr/sys/util.h>
19#include <zephyr/toolchain.h>
20
21#ifdef CONFIG_LLEXT
22#include <zephyr/llext/symbol.h>
23#endif
24
25#ifdef __cplusplus
26extern "C" {
27#endif
28
43#define Z_DEVICE_DEPS_SEP INT16_MIN
44
49#define Z_DEVICE_DEPS_ENDS INT16_MAX
50
52#define Z_DEVICE_IS_MUTABLE(node_id) \
53 COND_CODE_1(IS_ENABLED(CONFIG_DEVICE_MUTABLE), (DT_PROP(node_id, zephyr_mutable)), (0))
54
73
75#define DEVICE_HANDLE_NULL 0
76
96#define DEVICE_NAME_GET(dev_id) _CONCAT(__device_, dev_id)
97
98/* This macro synthesizes a unique dev_id from a devicetree node by using
99 * the node's dependency ordinal.
100 *
101 * The ordinal used in this name can be mapped to the path by
102 * examining zephyr/include/generated/zephyr/devicetree_generated.h.
103 */
104#define Z_DEVICE_DT_DEP_ORD(node_id) _CONCAT(dts_ord_, DT_DEP_ORD(node_id))
105
106/* Same as above, but uses the hash of the node path instead of the ordinal.
107 *
108 * The hash used in this name can be mapped to the path by
109 * examining zephyr/include/generated/zephyr/devicetree_generated.h.
110 */
111#define Z_DEVICE_DT_HASH(node_id) _CONCAT(dts_, DT_NODE_HASH(node_id))
112
113/* By default, device identifiers are obtained using the dependency ordinal.
114 * When LLEXT_EXPORT_DEV_IDS_BY_HASH is defined, the main Zephyr binary exports
115 * DT identifiers via EXPORT_SYMBOL_NAMED as hashed versions of their paths.
116 * When matching extensions are built, that is what they need to look for.
117 *
118 * The ordinal or hash used in this name can be mapped to the path by
119 * examining zephyr/include/generated/zephyr/devicetree_generated.h.
120 */
121#if defined(LL_EXTENSION_BUILD) && defined(CONFIG_LLEXT_EXPORT_DEV_IDS_BY_HASH)
122#define Z_DEVICE_DT_DEV_ID(node_id) Z_DEVICE_DT_HASH(node_id)
123#else
124#define Z_DEVICE_DT_DEV_ID(node_id) Z_DEVICE_DT_DEP_ORD(node_id)
125#endif
126
127#if defined(CONFIG_LLEXT_EXPORT_DEV_IDS_BY_HASH)
128/* Export device identifiers by hash */
129#define Z_DEVICE_EXPORT(node_id) \
130 EXPORT_SYMBOL_NAMED(DEVICE_DT_NAME_GET(node_id), \
131 DEVICE_NAME_GET(Z_DEVICE_DT_HASH(node_id)))
132#elif defined(CONFIG_LLEXT_EXPORT_DEVICES)
133/* Export device identifiers using the builtin name */
134#define Z_DEVICE_EXPORT(node_id) EXPORT_SYMBOL(DEVICE_DT_NAME_GET(node_id))
135#endif
136
167#define DEVICE_DEFINE(dev_id, name, init_fn, pm, data, config, level, prio, \
168 api) \
169 Z_DEVICE_STATE_DEFINE(dev_id); \
170 Z_DEVICE_DEFINE(DT_INVALID_NODE, dev_id, name, init_fn, pm, data, \
171 config, level, prio, api, \
172 &Z_DEVICE_STATE_NAME(dev_id))
173
185#define DEVICE_DT_NAME(node_id) \
186 DT_PROP_OR(node_id, label, DT_NODE_FULL_NAME(node_id))
187
195#define DEVICE_DT_DEFER(node_id) \
196 DT_PROP(node_id, zephyr_deferred_init)
197
229#define DEVICE_DT_DEFINE(node_id, init_fn, pm, data, config, level, prio, api, \
230 ...) \
231 Z_DEVICE_STATE_DEFINE(Z_DEVICE_DT_DEV_ID(node_id)); \
232 Z_DEVICE_DEFINE(node_id, Z_DEVICE_DT_DEV_ID(node_id), \
233 DEVICE_DT_NAME(node_id), init_fn, pm, data, config, \
234 level, prio, api, \
235 &Z_DEVICE_STATE_NAME(Z_DEVICE_DT_DEV_ID(node_id)), \
236 __VA_ARGS__)
237
246#define DEVICE_DT_INST_DEFINE(inst, ...) \
247 DEVICE_DT_DEFINE(DT_DRV_INST(inst), __VA_ARGS__)
248
263#define DEVICE_DT_NAME_GET(node_id) DEVICE_NAME_GET(Z_DEVICE_DT_DEV_ID(node_id))
264
280#define DEVICE_DT_GET(node_id) (&DEVICE_DT_NAME_GET(node_id))
281
291#define DEVICE_DT_INST_GET(inst) DEVICE_DT_GET(DT_DRV_INST(inst))
292
309#define DEVICE_DT_GET_ANY(compat) \
310 COND_CODE_1(DT_HAS_COMPAT_STATUS_OKAY(compat), \
311 (DEVICE_DT_GET(DT_COMPAT_GET_ANY_STATUS_OKAY(compat))), \
312 (NULL))
313
330#define DEVICE_DT_GET_ONE(compat) \
331 COND_CODE_1(DT_HAS_COMPAT_STATUS_OKAY(compat), \
332 (DEVICE_DT_GET(DT_COMPAT_GET_ANY_STATUS_OKAY(compat))), \
333 (ZERO_OR_COMPILE_ERROR(0)))
334
345#define DEVICE_DT_GET_OR_NULL(node_id) \
346 COND_CODE_1(DT_NODE_HAS_STATUS_OKAY(node_id), \
347 (DEVICE_DT_GET(node_id)), (NULL))
348
359#define DEVICE_GET(dev_id) (&DEVICE_NAME_GET(dev_id))
360
375#define DEVICE_DECLARE(dev_id) \
376 static const struct device DEVICE_NAME_GET(dev_id)
377
385#define DEVICE_INIT_DT_GET(node_id) \
386 (&Z_INIT_ENTRY_NAME(DEVICE_DT_NAME_GET(node_id)))
387
395#define DEVICE_INIT_GET(dev_id) (&Z_INIT_ENTRY_NAME(DEVICE_NAME_GET(dev_id)))
396
414
418 bool initialized : 1;
419};
420
421struct pm_device_base;
422struct pm_device;
423struct pm_device_isr;
424#if defined(CONFIG_DEVICE_DT_METADATA) || defined(__DOXYGEN__)
425struct device_dt_metadata;
426#endif
427
428#ifdef CONFIG_DEVICE_DEPS_DYNAMIC
429#define Z_DEVICE_DEPS_CONST
430#else
431#define Z_DEVICE_DEPS_CONST const
432#endif
433
437struct device {
439 const char *name;
441 const void *config;
443 const void *api;
447 void *data;
448#if defined(CONFIG_DEVICE_DEPS) || defined(__DOXYGEN__)
457 Z_DEVICE_DEPS_CONST device_handle_t *deps;
458#endif /* CONFIG_DEVICE_DEPS */
459#if defined(CONFIG_PM_DEVICE) || defined(__DOXYGEN__)
464 union {
466 struct pm_device *pm;
468 };
469#endif
470#if defined(CONFIG_DEVICE_DT_METADATA) || defined(__DOXYGEN__)
471 const struct device_dt_metadata *dt_meta;
472#endif /* CONFIG_DEVICE_DT_METADATA */
473};
474
483static inline device_handle_t device_handle_get(const struct device *dev)
484{
487
488 /* TODO: If/when devices can be constructed that are not part of the
489 * fixed sequence we'll need another solution.
490 */
491 if (dev != NULL) {
492 ret = 1 + (device_handle_t)(dev - STRUCT_SECTION_START(device));
493 }
494
495 return ret;
496}
497
506static inline const struct device *
508{
510 const struct device *dev = NULL;
511 size_t numdev;
512
514
515 if ((dev_handle > 0) && ((size_t)dev_handle <= numdev)) {
516 dev = &STRUCT_SECTION_START(device)[dev_handle - 1];
517 }
518
519 return dev;
520}
521
522#if defined(CONFIG_DEVICE_DEPS) || defined(__DOXYGEN__)
523
542typedef int (*device_visitor_callback_t)(const struct device *dev,
543 void *context);
544
563static inline const device_handle_t *
564device_required_handles_get(const struct device *dev, size_t *count)
565{
566 const device_handle_t *rv = dev->deps;
567
568 if (rv != NULL) {
569 size_t i = 0;
570
571 while ((rv[i] != Z_DEVICE_DEPS_ENDS) &&
572 (rv[i] != Z_DEVICE_DEPS_SEP)) {
573 ++i;
574 }
575 *count = i;
576 }
577
578 return rv;
579}
580
599static inline const device_handle_t *
600device_injected_handles_get(const struct device *dev, size_t *count)
601{
602 const device_handle_t *rv = dev->deps;
603 size_t region = 0;
604 size_t i = 0;
605
606 if (rv != NULL) {
607 /* Fast forward to injected devices */
608 while (region != 1) {
609 if (*rv == Z_DEVICE_DEPS_SEP) {
610 region++;
611 }
612 rv++;
613 }
614 while ((rv[i] != Z_DEVICE_DEPS_ENDS) &&
615 (rv[i] != Z_DEVICE_DEPS_SEP)) {
616 ++i;
617 }
618 *count = i;
619 }
620
621 return rv;
622}
623
643static inline const device_handle_t *
644device_supported_handles_get(const struct device *dev, size_t *count)
645{
646 const device_handle_t *rv = dev->deps;
647 size_t region = 0;
648 size_t i = 0;
649
650 if (rv != NULL) {
651 /* Fast forward to supporting devices */
652 while (region != 2) {
653 if (*rv == Z_DEVICE_DEPS_SEP) {
654 region++;
655 }
656 rv++;
657 }
658 /* Count supporting devices.
659 * Trailing NULL's can be injected by gen_device_deps.py due to
660 * CONFIG_PM_DEVICE_POWER_DOMAIN_DYNAMIC_NUM
661 */
662 while ((rv[i] != Z_DEVICE_DEPS_ENDS) &&
663 (rv[i] != DEVICE_HANDLE_NULL)) {
664 ++i;
665 }
666 *count = i;
667 }
668
669 return rv;
670}
671
702int device_required_foreach(const struct device *dev,
703 device_visitor_callback_t visitor_cb,
704 void *context);
705
735int device_supported_foreach(const struct device *dev,
736 device_visitor_callback_t visitor_cb,
737 void *context);
738
739#endif /* CONFIG_DEVICE_DEPS */
740
761__syscall const struct device *device_get_binding(const char *name);
762
771size_t z_device_get_all_static(const struct device **devices);
772
789__syscall bool device_is_ready(const struct device *dev);
790
805__syscall int device_init(const struct device *dev);
806
817#define Z_DEVICE_STATE_NAME(dev_id) _CONCAT(__devstate_, dev_id)
818
824#define Z_DEVICE_STATE_DEFINE(dev_id) \
825 static Z_DECL_ALIGN(struct device_state) Z_DEVICE_STATE_NAME(dev_id) \
826 __attribute__((__section__(".z_devstate")))
827
828#if defined(CONFIG_DEVICE_DEPS) || defined(__DOXYGEN__)
829
836#define Z_DEVICE_DEPS_NAME(dev_id) _CONCAT(__devicedeps_, dev_id)
837
843#define Z_DEVICE_EXTRA_DEPS(...) \
844 FOR_EACH_NONEMPTY_TERM(IDENTITY, (,), __VA_ARGS__)
845
847#define Z_DEVICE_DEPS_SECTION \
848 __attribute__((__section__(".__device_deps_pass1")))
849
850#ifdef __cplusplus
851#define Z_DEVICE_DEPS_EXTERN extern
852#else
853#define Z_DEVICE_DEPS_EXTERN
854#endif
855
891#define Z_DEVICE_DEPS_DEFINE(node_id, dev_id, ...) \
892 extern Z_DEVICE_DEPS_CONST device_handle_t Z_DEVICE_DEPS_NAME( \
893 dev_id)[]; \
894 Z_DEVICE_DEPS_CONST Z_DECL_ALIGN(device_handle_t) \
895 Z_DEVICE_DEPS_SECTION Z_DEVICE_DEPS_EXTERN __weak \
896 Z_DEVICE_DEPS_NAME(dev_id)[] = { \
897 COND_CODE_1( \
898 DT_NODE_EXISTS(node_id), \
899 (DT_DEP_ORD(node_id), DT_REQUIRES_DEP_ORDS(node_id)), \
900 (DEVICE_HANDLE_NULL,)) \
901 Z_DEVICE_DEPS_SEP, \
902 Z_DEVICE_EXTRA_DEPS(__VA_ARGS__) \
903 Z_DEVICE_DEPS_SEP, \
904 COND_CODE_1(DT_NODE_EXISTS(node_id), \
905 (DT_SUPPORTS_DEP_ORDS(node_id)), ()) \
906 }
907
908#endif /* CONFIG_DEVICE_DEPS */
909#if defined(CONFIG_DEVICE_DT_METADATA) || defined(__DOXYGEN__)
913struct device_dt_nodelabels {
914 /* @brief number of elements in the nodelabels array */
915 size_t num_nodelabels;
916 /* @brief array of node labels as strings, exactly as they
917 * appear in the final devicetree
918 */
919 const char *nodelabels[];
920};
921
929struct device_dt_metadata {
934 const struct device_dt_nodelabels *nl;
935};
936
955__syscall const struct device *device_get_by_dt_nodelabel(const char *nodelabel);
956
962static inline const struct device_dt_nodelabels *
963device_get_dt_nodelabels(const struct device *dev)
964{
965 if (dev->dt_meta == NULL) {
966 return NULL;
967 }
968 return dev->dt_meta->nl;
969}
970
977#define Z_DEVICE_MAX_NODELABEL_LEN Z_DEVICE_MAX_NAME_LEN
978
983#define Z_DEVICE_DT_METADATA_NAME_GET(dev_id) UTIL_CAT(__dev_dt_meta_, dev_id)
984
989#define Z_DEVICE_DT_NODELABELS_NAME_GET(dev_id) UTIL_CAT(__dev_dt_nodelabels_, dev_id)
990
997#define Z_DEVICE_DT_METADATA_DEFINE(node_id, dev_id) \
998 static const struct device_dt_nodelabels \
999 Z_DEVICE_DT_NODELABELS_NAME_GET(dev_id) = { \
1000 .num_nodelabels = DT_NUM_NODELABELS(node_id), \
1001 .nodelabels = DT_NODELABEL_STRING_ARRAY(node_id), \
1002 }; \
1003 \
1004 static const struct device_dt_metadata \
1005 Z_DEVICE_DT_METADATA_NAME_GET(dev_id) = { \
1006 .nl = &Z_DEVICE_DT_NODELABELS_NAME_GET(dev_id), \
1007 };
1008#endif /* CONFIG_DEVICE_DT_METADATA */
1009
1017#define Z_DEVICE_INIT_SUB_PRIO(node_id) \
1018 COND_CODE_1(DT_NODE_EXISTS(node_id), \
1019 (DT_DEP_ORD_STR_SORTABLE(node_id)), (0))
1020
1027#define Z_DEVICE_MAX_NAME_LEN 48U
1028
1034#define Z_DEVICE_NAME_CHECK(name) \
1035 BUILD_ASSERT(sizeof(Z_STRINGIFY(name)) <= Z_DEVICE_MAX_NAME_LEN, \
1036 Z_STRINGIFY(name) " too long")
1037
1051#define Z_DEVICE_INIT(name_, pm_, data_, config_, api_, state_, deps_, node_id_, \
1052 dev_id_) \
1053 { \
1054 .name = name_, \
1055 .config = (config_), \
1056 .api = (api_), \
1057 .state = (state_), \
1058 .data = (data_), \
1059 IF_ENABLED(CONFIG_DEVICE_DEPS, (.deps = (deps_),)) \
1060 IF_ENABLED(CONFIG_PM_DEVICE, Z_DEVICE_INIT_PM_BASE(pm_)) \
1061 IF_ENABLED(CONFIG_DEVICE_DT_METADATA, \
1062 (IF_ENABLED(DT_NODE_EXISTS(node_id_), \
1063 (.dt_meta = &Z_DEVICE_DT_METADATA_NAME_GET( \
1064 dev_id_),)))) \
1065 }
1066
1067/*
1068 * Anonymous unions require C11. Some pre-C11 gcc versions have early support for anonymous
1069 * unions but they require these braces when combined with C99 designated initializers. For
1070 * more details see https://docs.zephyrproject.org/latest/develop/languages/cpp/
1071 */
1072#if defined(__STDC_VERSION__) && (__STDC_VERSION__) < 201100
1073# define Z_DEVICE_INIT_PM_BASE(pm_) ({ .pm_base = (pm_),},)
1074#else
1075# define Z_DEVICE_INIT_PM_BASE(pm_) (.pm_base = (pm_),)
1076#endif
1077
1084#define Z_DEVICE_SECTION_NAME(level, prio) \
1085 _CONCAT(INIT_LEVEL_ORD(level), _##prio)
1086
1103#define Z_DEVICE_BASE_DEFINE(node_id, dev_id, name, pm, data, config, level, prio, api, state, \
1104 deps) \
1105 COND_CODE_1(DT_NODE_EXISTS(node_id), (), (static)) \
1106 COND_CODE_1(Z_DEVICE_IS_MUTABLE(node_id), (), (const)) \
1107 STRUCT_SECTION_ITERABLE_NAMED_ALTERNATE( \
1108 device, COND_CODE_1(Z_DEVICE_IS_MUTABLE(node_id), (device_mutable), (device)), \
1109 Z_DEVICE_SECTION_NAME(level, prio), DEVICE_NAME_GET(dev_id)) = \
1110 Z_DEVICE_INIT(name, pm, data, config, api, state, deps, node_id, dev_id)
1111
1117#define Z_DEVICE_CHECK_INIT_LEVEL(level) \
1118 COND_CODE_1(Z_INIT_PRE_KERNEL_1_##level, (), \
1119 (COND_CODE_1(Z_INIT_PRE_KERNEL_2_##level, (), \
1120 (COND_CODE_1(Z_INIT_POST_KERNEL_##level, (), \
1121 (ZERO_OR_COMPILE_ERROR(0)))))))
1122
1133#define Z_DEVICE_INIT_ENTRY_DEFINE(node_id, dev_id, init_fn_, level, prio) \
1134 Z_DEVICE_CHECK_INIT_LEVEL(level) \
1135 \
1136 static const Z_DECL_ALIGN(struct init_entry) __used __noasan Z_INIT_ENTRY_SECTION( \
1137 level, prio, Z_DEVICE_INIT_SUB_PRIO(node_id)) \
1138 Z_INIT_ENTRY_NAME(DEVICE_NAME_GET(dev_id)) = { \
1139 .init_fn = {COND_CODE_1(Z_DEVICE_IS_MUTABLE(node_id), (.dev_rw), (.dev)) = \
1140 (init_fn_)}, \
1141 Z_DEVICE_INIT_ENTRY_DEV(node_id, dev_id), \
1142 }
1143
1144#define Z_DEFER_DEVICE_INIT_ENTRY_DEFINE(node_id, dev_id, init_fn_) \
1145 static const Z_DECL_ALIGN(struct init_entry) __used __noasan \
1146 __attribute__((__section__(".z_deferred_init"))) \
1147 Z_INIT_ENTRY_NAME(DEVICE_NAME_GET(dev_id)) = { \
1148 .init_fn = {COND_CODE_1(Z_DEVICE_IS_MUTABLE(node_id), (.dev_rw), (.dev)) = \
1149 (init_fn_)}, \
1150 Z_DEVICE_INIT_ENTRY_DEV(node_id, dev_id), \
1151 }
1152
1153/*
1154 * Anonymous unions require C11. Some pre-C11 gcc versions have early support for anonymous
1155 * unions but they require these braces when combined with C99 designated initializers. For
1156 * more details see https://docs.zephyrproject.org/latest/develop/languages/cpp/
1157 */
1158#if defined(__STDC_VERSION__) && (__STDC_VERSION__) < 201100
1159# define Z_DEVICE_INIT_ENTRY_DEV(node_id, dev_id) { Z_DEV_ENTRY_DEV(node_id, dev_id) }
1160#else
1161# define Z_DEVICE_INIT_ENTRY_DEV(node_id, dev_id) Z_DEV_ENTRY_DEV(node_id, dev_id)
1162#endif
1163
1164#define Z_DEV_ENTRY_DEV(node_id, dev_id) \
1165 COND_CODE_1(Z_DEVICE_IS_MUTABLE(node_id), (.dev_rw), (.dev)) = &DEVICE_NAME_GET(dev_id)
1166
1188#define Z_DEVICE_DEFINE(node_id, dev_id, name, init_fn, pm, data, config, \
1189 level, prio, api, state, ...) \
1190 Z_DEVICE_NAME_CHECK(name); \
1191 \
1192 IF_ENABLED(CONFIG_DEVICE_DEPS, \
1193 (Z_DEVICE_DEPS_DEFINE(node_id, dev_id, __VA_ARGS__);)) \
1194 \
1195 IF_ENABLED(CONFIG_DEVICE_DT_METADATA, \
1196 (IF_ENABLED(DT_NODE_EXISTS(node_id), \
1197 (Z_DEVICE_DT_METADATA_DEFINE(node_id, dev_id);))))\
1198 \
1199 Z_DEVICE_BASE_DEFINE(node_id, dev_id, name, pm, data, config, level, \
1200 prio, api, state, Z_DEVICE_DEPS_NAME(dev_id)); \
1201 COND_CODE_1(DEVICE_DT_DEFER(node_id), \
1202 (Z_DEFER_DEVICE_INIT_ENTRY_DEFINE(node_id, dev_id, \
1203 init_fn)), \
1204 (Z_DEVICE_INIT_ENTRY_DEFINE(node_id, dev_id, init_fn, \
1205 level, prio))); \
1206 IF_ENABLED(CONFIG_LLEXT_EXPORT_DEVICES, \
1207 (IF_ENABLED(DT_NODE_EXISTS(node_id), \
1208 (Z_DEVICE_EXPORT(node_id);))))
1209
1220#define Z_MAYBE_DEVICE_DECLARE_INTERNAL(node_id) \
1221 extern COND_CODE_1(Z_DEVICE_IS_MUTABLE(node_id), (), \
1222 (const)) struct device DEVICE_DT_NAME_GET(node_id);
1223
1224DT_FOREACH_STATUS_OKAY_NODE(Z_MAYBE_DEVICE_DECLARE_INTERNAL)
1225
1226
1227#define Z_DEVICE_API_TYPE(_class) _CONCAT(_class, _driver_api)
1228
1237#define DEVICE_API(_class, _name) const STRUCT_SECTION_ITERABLE(Z_DEVICE_API_TYPE(_class), _name)
1238
1247#define DEVICE_API_GET(_class, _dev) ((const struct Z_DEVICE_API_TYPE(_class) *)_dev->api)
1248
1259#define DEVICE_API_IS(_class, _dev) \
1260 ({ \
1261 STRUCT_SECTION_START_EXTERN(Z_DEVICE_API_TYPE(_class)); \
1262 STRUCT_SECTION_END_EXTERN(Z_DEVICE_API_TYPE(_class)); \
1263 (DEVICE_API_GET(_class, _dev) < STRUCT_SECTION_END(Z_DEVICE_API_TYPE(_class)) && \
1264 DEVICE_API_GET(_class, _dev) >= STRUCT_SECTION_START(Z_DEVICE_API_TYPE(_class))); \
1265 })
1266
1267#ifdef __cplusplus
1268}
1269#endif
1270
1271#include <zephyr/syscalls/device.h>
1272
1273#endif /* ZEPHYR_INCLUDE_DEVICE_H_ */
Devicetree main header.
const struct device * device_get_binding(const char *name)
Get a device reference from its device::name field.
int16_t device_handle_t
Type used to represent a "handle" for a device.
Definition device.h:72
static const device_handle_t * device_required_handles_get(const struct device *dev, size_t *count)
Get the device handles for devicetree dependencies of this device.
Definition device.h:564
static const device_handle_t * device_supported_handles_get(const struct device *dev, size_t *count)
Get the set of handles that this device supports.
Definition device.h:644
static device_handle_t device_handle_get(const struct device *dev)
Get the handle for a given device.
Definition device.h:483
#define DEVICE_HANDLE_NULL
Flag value used to identify an unknown device.
Definition device.h:75
int device_required_foreach(const struct device *dev, device_visitor_callback_t visitor_cb, void *context)
Visit every device that dev directly requires.
static const struct device * device_from_handle(device_handle_t dev_handle)
Get the device corresponding to a handle.
Definition device.h:507
int(* device_visitor_callback_t)(const struct device *dev, void *context)
Prototype for functions used when iterating over a set of devices.
Definition device.h:542
bool device_is_ready(const struct device *dev)
Verify that a device is ready for use.
static const device_handle_t * device_injected_handles_get(const struct device *dev, size_t *count)
Get the device handles for injected dependencies of this device.
Definition device.h:600
int device_init(const struct device *dev)
Initialize a device.
int device_supported_foreach(const struct device *dev, device_visitor_callback_t visitor_cb, void *context)
Visit every device that dev directly supports.
#define DT_FOREACH_STATUS_OKAY_NODE(fn)
Invokes fn for every status okay node in the tree.
Definition devicetree.h:2970
#define STRUCT_SECTION_START_EXTERN(struct_type)
iterable section extern for start symbol for a struct
Definition iterable_sections.h:159
#define STRUCT_SECTION_START(struct_type)
iterable section start symbol for a struct type
Definition iterable_sections.h:149
#define STRUCT_SECTION_COUNT(struct_type, dst)
Count elements in a section.
Definition iterable_sections.h:291
Definitions of various linker Sections.
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
__INT16_TYPE__ int16_t
Definition stdint.h:73
Runtime device dynamic structure (in RAM) per driver instance.
Definition device.h:405
bool initialized
Indicates the device initialization function has been invoked.
Definition device.h:418
uint8_t init_res
Device initialization return code (positive errno value).
Definition device.h:413
Runtime device structure (in ROM) per driver instance.
Definition device.h:437
struct pm_device_base * pm_base
Definition device.h:465
const device_handle_t * deps
Optional pointer to dependencies associated with the device.
Definition device.h:457
struct pm_device_isr * pm_isr
Definition device.h:467
const char * name
Name of the device instance.
Definition device.h:439
struct pm_device * pm
Definition device.h:466
void * data
Address of the device instance private data.
Definition device.h:447
const void * api
Address of the API structure exposed by the device instance.
Definition device.h:443
struct device_state * state
Address of the common device state.
Definition device.h:445
const void * config
Address of device instance config information.
Definition device.h:441
const struct device_dt_metadata * dt_meta
Definition device.h:471
Device PM info.
Definition device.h:139
Runtime PM info for device with synchronous PM.
Definition device.h:185
Runtime PM info for device with generic PM.
Definition device.h:163
Linkable loadable extension symbol definitions.
Misc utilities.
Macros to abstract toolchain specific capabilities.