Zephyr Project API 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
362#define DEVICE_DT_GET_BY_IDX(node_id, prop, idx) \
363 DEVICE_DT_GET(DT_PHANDLE_BY_IDX(node_id, prop, idx))
364
375#define DEVICE_GET(dev_id) (&DEVICE_NAME_GET(dev_id))
376
391#define DEVICE_DECLARE(dev_id) \
392 static const struct device DEVICE_NAME_GET(dev_id)
393
401#define DEVICE_INIT_DT_GET(node_id) \
402 (&Z_INIT_ENTRY_NAME(DEVICE_DT_NAME_GET(node_id)))
403
411#define DEVICE_INIT_GET(dev_id) (&Z_INIT_ENTRY_NAME(DEVICE_NAME_GET(dev_id)))
412
430
434 bool initialized : 1;
435};
436
437struct pm_device_base;
438struct pm_device;
439struct pm_device_isr;
440#if defined(CONFIG_DEVICE_DT_METADATA) || defined(__DOXYGEN__)
441struct device_dt_metadata;
442#endif
443
444#ifdef CONFIG_DEVICE_DEPS_DYNAMIC
445#define Z_DEVICE_DEPS_CONST
446#else
447#define Z_DEVICE_DEPS_CONST const
448#endif
449
453struct device {
455 const char *name;
457 const void *config;
459 const void *api;
463 void *data;
464#if defined(CONFIG_DEVICE_DEPS) || defined(__DOXYGEN__)
473 Z_DEVICE_DEPS_CONST device_handle_t *deps;
474#endif /* CONFIG_DEVICE_DEPS */
475#if defined(CONFIG_PM_DEVICE) || defined(__DOXYGEN__)
480 union {
482 struct pm_device *pm;
484 };
485#endif
486#if defined(CONFIG_DEVICE_DT_METADATA) || defined(__DOXYGEN__)
487 const struct device_dt_metadata *dt_meta;
488#endif /* CONFIG_DEVICE_DT_METADATA */
489};
490
499static inline device_handle_t device_handle_get(const struct device *dev)
500{
503
504 /* TODO: If/when devices can be constructed that are not part of the
505 * fixed sequence we'll need another solution.
506 */
507 if (dev != NULL) {
508 ret = 1 + (device_handle_t)(dev - STRUCT_SECTION_START(device));
509 }
510
511 return ret;
512}
513
522static inline const struct device *
524{
526 const struct device *dev = NULL;
527 size_t numdev;
528
530
531 if ((dev_handle > 0) && ((size_t)dev_handle <= numdev)) {
532 dev = &STRUCT_SECTION_START(device)[dev_handle - 1];
533 }
534
535 return dev;
536}
537
538#if defined(CONFIG_DEVICE_DEPS) || defined(__DOXYGEN__)
539
558typedef int (*device_visitor_callback_t)(const struct device *dev,
559 void *context);
560
579static inline const device_handle_t *
580device_required_handles_get(const struct device *dev, size_t *count)
581{
582 const device_handle_t *rv = dev->deps;
583
584 if (rv != NULL) {
585 size_t i = 0;
586
587 while ((rv[i] != Z_DEVICE_DEPS_ENDS) &&
588 (rv[i] != Z_DEVICE_DEPS_SEP)) {
589 ++i;
590 }
591 *count = i;
592 }
593
594 return rv;
595}
596
615static inline const device_handle_t *
616device_injected_handles_get(const struct device *dev, size_t *count)
617{
618 const device_handle_t *rv = dev->deps;
619 size_t region = 0;
620 size_t i = 0;
621
622 if (rv != NULL) {
623 /* Fast forward to injected devices */
624 while (region != 1) {
625 if (*rv == Z_DEVICE_DEPS_SEP) {
626 region++;
627 }
628 rv++;
629 }
630 while ((rv[i] != Z_DEVICE_DEPS_ENDS) &&
631 (rv[i] != Z_DEVICE_DEPS_SEP)) {
632 ++i;
633 }
634 *count = i;
635 }
636
637 return rv;
638}
639
659static inline const device_handle_t *
660device_supported_handles_get(const struct device *dev, size_t *count)
661{
662 const device_handle_t *rv = dev->deps;
663 size_t region = 0;
664 size_t i = 0;
665
666 if (rv != NULL) {
667 /* Fast forward to supporting devices */
668 while (region != 2) {
669 if (*rv == Z_DEVICE_DEPS_SEP) {
670 region++;
671 }
672 rv++;
673 }
674 /* Count supporting devices.
675 * Trailing NULL's can be injected by gen_device_deps.py due to
676 * CONFIG_PM_DEVICE_POWER_DOMAIN_DYNAMIC_NUM
677 */
678 while ((rv[i] != Z_DEVICE_DEPS_ENDS) &&
679 (rv[i] != DEVICE_HANDLE_NULL)) {
680 ++i;
681 }
682 *count = i;
683 }
684
685 return rv;
686}
687
718int device_required_foreach(const struct device *dev,
719 device_visitor_callback_t visitor_cb,
720 void *context);
721
751int device_supported_foreach(const struct device *dev,
752 device_visitor_callback_t visitor_cb,
753 void *context);
754
755#endif /* CONFIG_DEVICE_DEPS */
756
777__syscall const struct device *device_get_binding(const char *name);
778
787size_t z_device_get_all_static(const struct device **devices);
788
805__syscall bool device_is_ready(const struct device *dev);
806
821__syscall int device_init(const struct device *dev);
822
833#define Z_DEVICE_STATE_NAME(dev_id) _CONCAT(__devstate_, dev_id)
834
840#define Z_DEVICE_STATE_DEFINE(dev_id) \
841 static Z_DECL_ALIGN(struct device_state) Z_DEVICE_STATE_NAME(dev_id) \
842 __attribute__((__section__(".z_devstate")))
843
844#if defined(CONFIG_DEVICE_DEPS) || defined(__DOXYGEN__)
845
852#define Z_DEVICE_DEPS_NAME(dev_id) _CONCAT(__devicedeps_, dev_id)
853
859#define Z_DEVICE_EXTRA_DEPS(...) \
860 FOR_EACH_NONEMPTY_TERM(IDENTITY, (,), __VA_ARGS__)
861
863#define Z_DEVICE_DEPS_SECTION \
864 __attribute__((__section__(".__device_deps_pass1")))
865
866#ifdef __cplusplus
867#define Z_DEVICE_DEPS_EXTERN extern
868#else
869#define Z_DEVICE_DEPS_EXTERN
870#endif
871
907#define Z_DEVICE_DEPS_DEFINE(node_id, dev_id, ...) \
908 extern Z_DEVICE_DEPS_CONST device_handle_t Z_DEVICE_DEPS_NAME( \
909 dev_id)[]; \
910 Z_DEVICE_DEPS_CONST Z_DECL_ALIGN(device_handle_t) \
911 Z_DEVICE_DEPS_SECTION Z_DEVICE_DEPS_EXTERN __weak \
912 Z_DEVICE_DEPS_NAME(dev_id)[] = { \
913 COND_CODE_1( \
914 DT_NODE_EXISTS(node_id), \
915 (DT_DEP_ORD(node_id), DT_REQUIRES_DEP_ORDS(node_id)), \
916 (DEVICE_HANDLE_NULL,)) \
917 Z_DEVICE_DEPS_SEP, \
918 Z_DEVICE_EXTRA_DEPS(__VA_ARGS__) \
919 Z_DEVICE_DEPS_SEP, \
920 COND_CODE_1(DT_NODE_EXISTS(node_id), \
921 (DT_SUPPORTS_DEP_ORDS(node_id)), ()) \
922 }
923
924#endif /* CONFIG_DEVICE_DEPS */
925#if defined(CONFIG_DEVICE_DT_METADATA) || defined(__DOXYGEN__)
929struct device_dt_nodelabels {
930 /* @brief number of elements in the nodelabels array */
931 size_t num_nodelabels;
932 /* @brief array of node labels as strings, exactly as they
933 * appear in the final devicetree
934 */
935 const char *nodelabels[];
936};
937
945struct device_dt_metadata {
950 const struct device_dt_nodelabels *nl;
951};
952
971__syscall const struct device *device_get_by_dt_nodelabel(const char *nodelabel);
972
978static inline const struct device_dt_nodelabels *
979device_get_dt_nodelabels(const struct device *dev)
980{
981 if (dev->dt_meta == NULL) {
982 return NULL;
983 }
984 return dev->dt_meta->nl;
985}
986
993#define Z_DEVICE_MAX_NODELABEL_LEN Z_DEVICE_MAX_NAME_LEN
994
999#define Z_DEVICE_DT_METADATA_NAME_GET(dev_id) UTIL_CAT(__dev_dt_meta_, dev_id)
1000
1005#define Z_DEVICE_DT_NODELABELS_NAME_GET(dev_id) UTIL_CAT(__dev_dt_nodelabels_, dev_id)
1006
1013#define Z_DEVICE_DT_METADATA_DEFINE(node_id, dev_id) \
1014 static const struct device_dt_nodelabels \
1015 Z_DEVICE_DT_NODELABELS_NAME_GET(dev_id) = { \
1016 .num_nodelabels = DT_NUM_NODELABELS(node_id), \
1017 .nodelabels = DT_NODELABEL_STRING_ARRAY(node_id), \
1018 }; \
1019 \
1020 static const struct device_dt_metadata \
1021 Z_DEVICE_DT_METADATA_NAME_GET(dev_id) = { \
1022 .nl = &Z_DEVICE_DT_NODELABELS_NAME_GET(dev_id), \
1023 };
1024#endif /* CONFIG_DEVICE_DT_METADATA */
1025
1033#define Z_DEVICE_INIT_SUB_PRIO(node_id) \
1034 COND_CODE_1(DT_NODE_EXISTS(node_id), \
1035 (DT_DEP_ORD_STR_SORTABLE(node_id)), (0))
1036
1043#define Z_DEVICE_MAX_NAME_LEN 48U
1044
1050#define Z_DEVICE_NAME_CHECK(name) \
1051 BUILD_ASSERT(sizeof(Z_STRINGIFY(name)) <= Z_DEVICE_MAX_NAME_LEN, \
1052 Z_STRINGIFY(name) " too long")
1053
1067#define Z_DEVICE_INIT(name_, pm_, data_, config_, api_, state_, deps_, node_id_, \
1068 dev_id_) \
1069 { \
1070 .name = name_, \
1071 .config = (config_), \
1072 .api = (api_), \
1073 .state = (state_), \
1074 .data = (data_), \
1075 IF_ENABLED(CONFIG_DEVICE_DEPS, (.deps = (deps_),)) \
1076 IF_ENABLED(CONFIG_PM_DEVICE, Z_DEVICE_INIT_PM_BASE(pm_)) \
1077 IF_ENABLED(CONFIG_DEVICE_DT_METADATA, \
1078 (IF_ENABLED(DT_NODE_EXISTS(node_id_), \
1079 (.dt_meta = &Z_DEVICE_DT_METADATA_NAME_GET( \
1080 dev_id_),)))) \
1081 }
1082
1083/*
1084 * Anonymous unions require C11. Some pre-C11 gcc versions have early support for anonymous
1085 * unions but they require these braces when combined with C99 designated initializers. For
1086 * more details see https://docs.zephyrproject.org/latest/develop/languages/cpp/
1087 */
1088#if defined(__STDC_VERSION__) && (__STDC_VERSION__) < 201100
1089# define Z_DEVICE_INIT_PM_BASE(pm_) ({ .pm_base = (pm_),},)
1090#else
1091# define Z_DEVICE_INIT_PM_BASE(pm_) (.pm_base = (pm_),)
1092#endif
1093
1100#define Z_DEVICE_SECTION_NAME(level, prio) \
1101 _CONCAT(INIT_LEVEL_ORD(level), _##prio)
1102
1119#define Z_DEVICE_BASE_DEFINE(node_id, dev_id, name, pm, data, config, level, prio, api, state, \
1120 deps) \
1121 COND_CODE_1(DT_NODE_EXISTS(node_id), (), (static)) \
1122 COND_CODE_1(Z_DEVICE_IS_MUTABLE(node_id), (), (const)) \
1123 STRUCT_SECTION_ITERABLE_NAMED_ALTERNATE( \
1124 device, COND_CODE_1(Z_DEVICE_IS_MUTABLE(node_id), (device_mutable), (device)), \
1125 Z_DEVICE_SECTION_NAME(level, prio), DEVICE_NAME_GET(dev_id)) = \
1126 Z_DEVICE_INIT(name, pm, data, config, api, state, deps, node_id, dev_id)
1127
1133#define Z_DEVICE_CHECK_INIT_LEVEL(level) \
1134 COND_CODE_1(Z_INIT_PRE_KERNEL_1_##level, (), \
1135 (COND_CODE_1(Z_INIT_PRE_KERNEL_2_##level, (), \
1136 (COND_CODE_1(Z_INIT_POST_KERNEL_##level, (), \
1137 (ZERO_OR_COMPILE_ERROR(0)))))))
1138
1149#define Z_DEVICE_INIT_ENTRY_DEFINE(node_id, dev_id, init_fn_, level, prio) \
1150 Z_DEVICE_CHECK_INIT_LEVEL(level) \
1151 \
1152 static const Z_DECL_ALIGN(struct init_entry) __used __noasan Z_INIT_ENTRY_SECTION( \
1153 level, prio, Z_DEVICE_INIT_SUB_PRIO(node_id)) \
1154 Z_INIT_ENTRY_NAME(DEVICE_NAME_GET(dev_id)) = { \
1155 .init_fn = {COND_CODE_1(Z_DEVICE_IS_MUTABLE(node_id), (.dev_rw), (.dev)) = \
1156 (init_fn_)}, \
1157 Z_DEVICE_INIT_ENTRY_DEV(node_id, dev_id), \
1158 }
1159
1160#define Z_DEFER_DEVICE_INIT_ENTRY_DEFINE(node_id, dev_id, init_fn_) \
1161 static const Z_DECL_ALIGN(struct init_entry) __used __noasan \
1162 __attribute__((__section__(".z_deferred_init"))) \
1163 Z_INIT_ENTRY_NAME(DEVICE_NAME_GET(dev_id)) = { \
1164 .init_fn = {COND_CODE_1(Z_DEVICE_IS_MUTABLE(node_id), (.dev_rw), (.dev)) = \
1165 (init_fn_)}, \
1166 Z_DEVICE_INIT_ENTRY_DEV(node_id, dev_id), \
1167 }
1168
1169/*
1170 * Anonymous unions require C11. Some pre-C11 gcc versions have early support for anonymous
1171 * unions but they require these braces when combined with C99 designated initializers. For
1172 * more details see https://docs.zephyrproject.org/latest/develop/languages/cpp/
1173 */
1174#if defined(__STDC_VERSION__) && (__STDC_VERSION__) < 201100
1175# define Z_DEVICE_INIT_ENTRY_DEV(node_id, dev_id) { Z_DEV_ENTRY_DEV(node_id, dev_id) }
1176#else
1177# define Z_DEVICE_INIT_ENTRY_DEV(node_id, dev_id) Z_DEV_ENTRY_DEV(node_id, dev_id)
1178#endif
1179
1180#define Z_DEV_ENTRY_DEV(node_id, dev_id) \
1181 COND_CODE_1(Z_DEVICE_IS_MUTABLE(node_id), (.dev_rw), (.dev)) = &DEVICE_NAME_GET(dev_id)
1182
1204#define Z_DEVICE_DEFINE(node_id, dev_id, name, init_fn, pm, data, config, \
1205 level, prio, api, state, ...) \
1206 Z_DEVICE_NAME_CHECK(name); \
1207 \
1208 IF_ENABLED(CONFIG_DEVICE_DEPS, \
1209 (Z_DEVICE_DEPS_DEFINE(node_id, dev_id, __VA_ARGS__);)) \
1210 \
1211 IF_ENABLED(CONFIG_DEVICE_DT_METADATA, \
1212 (IF_ENABLED(DT_NODE_EXISTS(node_id), \
1213 (Z_DEVICE_DT_METADATA_DEFINE(node_id, dev_id);))))\
1214 \
1215 Z_DEVICE_BASE_DEFINE(node_id, dev_id, name, pm, data, config, level, \
1216 prio, api, state, Z_DEVICE_DEPS_NAME(dev_id)); \
1217 COND_CODE_1(DEVICE_DT_DEFER(node_id), \
1218 (Z_DEFER_DEVICE_INIT_ENTRY_DEFINE(node_id, dev_id, \
1219 init_fn)), \
1220 (Z_DEVICE_INIT_ENTRY_DEFINE(node_id, dev_id, init_fn, \
1221 level, prio))); \
1222 IF_ENABLED(CONFIG_LLEXT_EXPORT_DEVICES, \
1223 (IF_ENABLED(DT_NODE_EXISTS(node_id), \
1224 (Z_DEVICE_EXPORT(node_id);))))
1225
1236#define Z_MAYBE_DEVICE_DECLARE_INTERNAL(node_id) \
1237 extern COND_CODE_1(Z_DEVICE_IS_MUTABLE(node_id), (), \
1238 (const)) struct device DEVICE_DT_NAME_GET(node_id);
1239
1240DT_FOREACH_STATUS_OKAY_NODE(Z_MAYBE_DEVICE_DECLARE_INTERNAL)
1241
1242
1243#define Z_DEVICE_API_TYPE(_class) _CONCAT(_class, _driver_api)
1244
1253#define DEVICE_API(_class, _name) const STRUCT_SECTION_ITERABLE(Z_DEVICE_API_TYPE(_class), _name)
1254
1263#define DEVICE_API_GET(_class, _dev) ((const struct Z_DEVICE_API_TYPE(_class) *)_dev->api)
1264
1275#define DEVICE_API_IS(_class, _dev) \
1276 ({ \
1277 STRUCT_SECTION_START_EXTERN(Z_DEVICE_API_TYPE(_class)); \
1278 STRUCT_SECTION_END_EXTERN(Z_DEVICE_API_TYPE(_class)); \
1279 (DEVICE_API_GET(_class, _dev) < STRUCT_SECTION_END(Z_DEVICE_API_TYPE(_class)) && \
1280 DEVICE_API_GET(_class, _dev) >= STRUCT_SECTION_START(Z_DEVICE_API_TYPE(_class))); \
1281 })
1282
1283#ifdef __cplusplus
1284}
1285#endif
1286
1287#include <zephyr/syscalls/device.h>
1288
1289#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:580
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:660
static device_handle_t device_handle_get(const struct device *dev)
Get the handle for a given device.
Definition device.h:499
#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:523
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:558
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:616
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:3000
#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:421
bool initialized
Indicates the device initialization function has been invoked.
Definition device.h:434
uint8_t init_res
Device initialization return code (positive errno value).
Definition device.h:429
Runtime device structure (in ROM) per driver instance.
Definition device.h:453
struct pm_device_base * pm_base
Definition device.h:481
const device_handle_t * deps
Optional pointer to dependencies associated with the device.
Definition device.h:473
struct pm_device_isr * pm_isr
Definition device.h:483
const char * name
Name of the device instance.
Definition device.h:455
struct pm_device * pm
Definition device.h:482
void * data
Address of the device instance private data.
Definition device.h:463
const void * api
Address of the API structure exposed by the device instance.
Definition device.h:459
struct device_state * state
Address of the common device state.
Definition device.h:461
const void * config
Address of device instance config information.
Definition device.h:457
const struct device_dt_metadata * dt_meta
Definition device.h:487
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.