Zephyr API Documentation 4.1.99
A Scalable Open Source RTOS
 4.1.99
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
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
173#define DEVICE_DEINIT_DEFINE(dev_id, name, init_fn, deinit_fn, pm, data, \
174 config, level, prio, api) \
175 Z_DEVICE_STATE_DEFINE(dev_id); \
176 Z_DEVICE_DEFINE(DT_INVALID_NODE, dev_id, name, init_fn, deinit_fn, 0U, \
177 pm, data, config, level, prio, api, \
178 &Z_DEVICE_STATE_NAME(dev_id))
179
185#define DEVICE_DEFINE(dev_id, name, init_fn, pm, data, config, level, prio, \
186 api) \
187 DEVICE_DEINIT_DEFINE(dev_id, name, init_fn, NULL, pm, data, config, \
188 level, prio, api)
189
201#define DEVICE_DT_NAME(node_id) \
202 DT_PROP_OR(node_id, label, DT_NODE_FULL_NAME(node_id))
203
240#define DEVICE_DT_DEINIT_DEFINE(node_id, init_fn, deinit_fn, pm, data, config, \
241 level, prio, api, ...) \
242 Z_DEVICE_STATE_DEFINE(Z_DEVICE_DT_DEV_ID(node_id)); \
243 Z_DEVICE_DEFINE(node_id, Z_DEVICE_DT_DEV_ID(node_id), \
244 DEVICE_DT_NAME(node_id), init_fn, deinit_fn, \
245 Z_DEVICE_DT_FLAGS(node_id), pm, data, config, level, \
246 prio, api, \
247 &Z_DEVICE_STATE_NAME(Z_DEVICE_DT_DEV_ID(node_id)), \
248 __VA_ARGS__)
249
256#define DEVICE_DT_DEFINE(node_id, init_fn, pm, data, config, level, prio, api, \
257 ...) \
258 DEVICE_DT_DEINIT_DEFINE(node_id, init_fn, NULL, pm, data, config, \
259 level, prio, api, __VA_ARGS__)
260
269#define DEVICE_DT_INST_DEINIT_DEFINE(inst, ...) \
270 DEVICE_DT_DEINIT_DEFINE(DT_DRV_INST(inst), __VA_ARGS__)
271
280#define DEVICE_DT_INST_DEFINE(inst, ...) \
281 DEVICE_DT_DEFINE(DT_DRV_INST(inst), __VA_ARGS__)
282
297#define DEVICE_DT_NAME_GET(node_id) DEVICE_NAME_GET(Z_DEVICE_DT_DEV_ID(node_id))
298
314#define DEVICE_DT_GET(node_id) (&DEVICE_DT_NAME_GET(node_id))
315
325#define DEVICE_DT_INST_GET(inst) DEVICE_DT_GET(DT_DRV_INST(inst))
326
343#define DEVICE_DT_GET_ANY(compat) \
344 COND_CODE_1(DT_HAS_COMPAT_STATUS_OKAY(compat), \
345 (DEVICE_DT_GET(DT_COMPAT_GET_ANY_STATUS_OKAY(compat))), \
346 (NULL))
347
364#define DEVICE_DT_GET_ONE(compat) \
365 COND_CODE_1(DT_HAS_COMPAT_STATUS_OKAY(compat), \
366 (DEVICE_DT_GET(DT_COMPAT_GET_ANY_STATUS_OKAY(compat))), \
367 (ZERO_OR_COMPILE_ERROR(0)))
368
379#define DEVICE_DT_GET_OR_NULL(node_id) \
380 COND_CODE_1(DT_NODE_HAS_STATUS_OKAY(node_id), \
381 (DEVICE_DT_GET(node_id)), (NULL))
382
396#define DEVICE_DT_GET_BY_IDX(node_id, prop, idx) \
397 DEVICE_DT_GET(DT_PHANDLE_BY_IDX(node_id, prop, idx))
398
409#define DEVICE_GET(dev_id) (&DEVICE_NAME_GET(dev_id))
410
425#define DEVICE_DECLARE(dev_id) \
426 static const struct device DEVICE_NAME_GET(dev_id)
427
435#define DEVICE_INIT_DT_GET(node_id) \
436 (&Z_INIT_ENTRY_NAME(DEVICE_DT_NAME_GET(node_id)))
437
445#define DEVICE_INIT_GET(dev_id) (&Z_INIT_ENTRY_NAME(DEVICE_NAME_GET(dev_id)))
446
464
468 bool initialized : 1;
469};
470
471struct pm_device_base;
472struct pm_device;
473struct pm_device_isr;
474#if defined(CONFIG_DEVICE_DT_METADATA) || defined(__DOXYGEN__)
475struct device_dt_metadata;
476#endif
477
478#ifdef CONFIG_DEVICE_DEPS_DYNAMIC
479#define Z_DEVICE_DEPS_CONST
480#else
481#define Z_DEVICE_DEPS_CONST const
482#endif
483
486
493#define DEVICE_FLAG_INIT_DEFERRED BIT(0)
494
500 int (*init)(const struct device *dev);
501#ifdef CONFIG_DEVICE_DEINIT_SUPPORT
503 int (*deinit)(const struct device *dev);
504#endif /* CONFIG_DEVICE_DEINIT_SUPPORT */
505};
506
510struct device {
512 const char *name;
514 const void *config;
516 const void *api;
520 void *data;
525#if defined(CONFIG_DEVICE_DEPS) || defined(__DOXYGEN__)
534 Z_DEVICE_DEPS_CONST device_handle_t *deps;
535#endif /* CONFIG_DEVICE_DEPS */
536#if defined(CONFIG_PM_DEVICE) || defined(__DOXYGEN__)
541 union {
543 struct pm_device *pm;
545 };
546#endif
547#if defined(CONFIG_DEVICE_DT_METADATA) || defined(__DOXYGEN__)
548 const struct device_dt_metadata *dt_meta;
549#endif /* CONFIG_DEVICE_DT_METADATA */
550};
551
560static inline device_handle_t device_handle_get(const struct device *dev)
561{
564
565 /* TODO: If/when devices can be constructed that are not part of the
566 * fixed sequence we'll need another solution.
567 */
568 if (dev != NULL) {
569 ret = 1 + (device_handle_t)(dev - STRUCT_SECTION_START(device));
570 }
571
572 return ret;
573}
574
583static inline const struct device *
585{
587 const struct device *dev = NULL;
588 size_t numdev;
589
591
592 if ((dev_handle > 0) && ((size_t)dev_handle <= numdev)) {
593 dev = &STRUCT_SECTION_START(device)[dev_handle - 1];
594 }
595
596 return dev;
597}
598
599#if defined(CONFIG_DEVICE_DEPS) || defined(__DOXYGEN__)
600
619typedef int (*device_visitor_callback_t)(const struct device *dev,
620 void *context);
621
640static inline const device_handle_t *
641device_required_handles_get(const struct device *dev, size_t *count)
642{
643 const device_handle_t *rv = dev->deps;
644
645 if (rv != NULL) {
646 size_t i = 0;
647
648 while ((rv[i] != Z_DEVICE_DEPS_ENDS) &&
649 (rv[i] != Z_DEVICE_DEPS_SEP)) {
650 ++i;
651 }
652 *count = i;
653 }
654
655 return rv;
656}
657
676static inline const device_handle_t *
677device_injected_handles_get(const struct device *dev, size_t *count)
678{
679 const device_handle_t *rv = dev->deps;
680 size_t region = 0;
681 size_t i = 0;
682
683 if (rv != NULL) {
684 /* Fast forward to injected devices */
685 while (region != 1) {
686 if (*rv == Z_DEVICE_DEPS_SEP) {
687 region++;
688 }
689 rv++;
690 }
691 while ((rv[i] != Z_DEVICE_DEPS_ENDS) &&
692 (rv[i] != Z_DEVICE_DEPS_SEP)) {
693 ++i;
694 }
695 *count = i;
696 }
697
698 return rv;
699}
700
720static inline const device_handle_t *
721device_supported_handles_get(const struct device *dev, size_t *count)
722{
723 const device_handle_t *rv = dev->deps;
724 size_t region = 0;
725 size_t i = 0;
726
727 if (rv != NULL) {
728 /* Fast forward to supporting devices */
729 while (region != 2) {
730 if (*rv == Z_DEVICE_DEPS_SEP) {
731 region++;
732 }
733 rv++;
734 }
735 /* Count supporting devices.
736 * Trailing NULL's can be injected by gen_device_deps.py due to
737 * CONFIG_PM_DEVICE_POWER_DOMAIN_DYNAMIC_NUM
738 */
739 while ((rv[i] != Z_DEVICE_DEPS_ENDS) &&
740 (rv[i] != DEVICE_HANDLE_NULL)) {
741 ++i;
742 }
743 *count = i;
744 }
745
746 return rv;
747}
748
779int device_required_foreach(const struct device *dev,
780 device_visitor_callback_t visitor_cb,
781 void *context);
782
812int device_supported_foreach(const struct device *dev,
813 device_visitor_callback_t visitor_cb,
814 void *context);
815
816#endif /* CONFIG_DEVICE_DEPS */
817
838__syscall const struct device *device_get_binding(const char *name);
839
848size_t z_device_get_all_static(const struct device **devices);
849
866__syscall bool device_is_ready(const struct device *dev);
867
881__syscall int device_init(const struct device *dev);
882
903__syscall int device_deinit(const struct device *dev);
904
915#define Z_DEVICE_STATE_NAME(dev_id) _CONCAT(__devstate_, dev_id)
916
922#define Z_DEVICE_STATE_DEFINE(dev_id) \
923 static Z_DECL_ALIGN(struct device_state) Z_DEVICE_STATE_NAME(dev_id) \
924 __attribute__((__section__(".z_devstate")))
925
931#define Z_DEVICE_DT_FLAGS(node_id) \
932 (DT_PROP_OR(node_id, zephyr_deferred_init, 0U) * DEVICE_FLAG_INIT_DEFERRED)
933
934#if defined(CONFIG_DEVICE_DEPS) || defined(__DOXYGEN__)
935
942#define Z_DEVICE_DEPS_NAME(dev_id) _CONCAT(__devicedeps_, dev_id)
943
949#define Z_DEVICE_EXTRA_DEPS(...) \
950 FOR_EACH_NONEMPTY_TERM(IDENTITY, (,), __VA_ARGS__)
951
953#define Z_DEVICE_DEPS_SECTION \
954 __attribute__((__section__(".__device_deps_pass1")))
955
956#ifdef __cplusplus
957#define Z_DEVICE_DEPS_EXTERN extern
958#else
959#define Z_DEVICE_DEPS_EXTERN
960#endif
961
997#define Z_DEVICE_DEPS_DEFINE(node_id, dev_id, ...) \
998 extern Z_DEVICE_DEPS_CONST device_handle_t Z_DEVICE_DEPS_NAME( \
999 dev_id)[]; \
1000 Z_DEVICE_DEPS_CONST Z_DECL_ALIGN(device_handle_t) \
1001 Z_DEVICE_DEPS_SECTION Z_DEVICE_DEPS_EXTERN __weak \
1002 Z_DEVICE_DEPS_NAME(dev_id)[] = { \
1003 COND_CODE_1( \
1004 DT_NODE_EXISTS(node_id), \
1005 (DT_DEP_ORD(node_id), DT_REQUIRES_DEP_ORDS(node_id)), \
1006 (DEVICE_HANDLE_NULL,)) \
1007 Z_DEVICE_DEPS_SEP, \
1008 Z_DEVICE_EXTRA_DEPS(__VA_ARGS__) \
1009 Z_DEVICE_DEPS_SEP, \
1010 COND_CODE_1(DT_NODE_EXISTS(node_id), \
1011 (DT_SUPPORTS_DEP_ORDS(node_id)), ()) \
1012 }
1013
1014#endif /* CONFIG_DEVICE_DEPS */
1015#if defined(CONFIG_DEVICE_DT_METADATA) || defined(__DOXYGEN__)
1019struct device_dt_nodelabels {
1020 /* @brief number of elements in the nodelabels array */
1021 size_t num_nodelabels;
1022 /* @brief array of node labels as strings, exactly as they
1023 * appear in the final devicetree
1024 */
1025 const char *nodelabels[];
1026};
1027
1035struct device_dt_metadata {
1040 const struct device_dt_nodelabels *nl;
1041};
1042
1061__syscall const struct device *device_get_by_dt_nodelabel(const char *nodelabel);
1062
1068static inline const struct device_dt_nodelabels *
1069device_get_dt_nodelabels(const struct device *dev)
1070{
1071 if (dev->dt_meta == NULL) {
1072 return NULL;
1073 }
1074 return dev->dt_meta->nl;
1075}
1076
1083#define Z_DEVICE_MAX_NODELABEL_LEN Z_DEVICE_MAX_NAME_LEN
1084
1089#define Z_DEVICE_DT_METADATA_NAME_GET(dev_id) UTIL_CAT(__dev_dt_meta_, dev_id)
1090
1095#define Z_DEVICE_DT_NODELABELS_NAME_GET(dev_id) UTIL_CAT(__dev_dt_nodelabels_, dev_id)
1096
1103#define Z_DEVICE_DT_METADATA_DEFINE(node_id, dev_id) \
1104 static const struct device_dt_nodelabels \
1105 Z_DEVICE_DT_NODELABELS_NAME_GET(dev_id) = { \
1106 .num_nodelabels = DT_NUM_NODELABELS(node_id), \
1107 .nodelabels = DT_NODELABEL_STRING_ARRAY(node_id), \
1108 }; \
1109 \
1110 static const struct device_dt_metadata \
1111 Z_DEVICE_DT_METADATA_NAME_GET(dev_id) = { \
1112 .nl = &Z_DEVICE_DT_NODELABELS_NAME_GET(dev_id), \
1113 };
1114#endif /* CONFIG_DEVICE_DT_METADATA */
1115
1123#define Z_DEVICE_INIT_SUB_PRIO(node_id) \
1124 COND_CODE_1(DT_NODE_EXISTS(node_id), \
1125 (DT_DEP_ORD_STR_SORTABLE(node_id)), (0))
1126
1133#define Z_DEVICE_MAX_NAME_LEN 48U
1134
1140#define Z_DEVICE_NAME_CHECK(name) \
1141 BUILD_ASSERT(sizeof(Z_STRINGIFY(name)) <= Z_DEVICE_MAX_NAME_LEN, \
1142 Z_STRINGIFY(name) " too long")
1143
1150#define Z_DEVICE_OPS(init_fn_, deinit_fn_) \
1151 { \
1152 .init = (init_fn_), \
1153 IF_ENABLED(CONFIG_DEVICE_DEINIT_SUPPORT, \
1154 (.deinit = (deinit_fn_),)) \
1155 }
1156
1173#define Z_DEVICE_INIT(name_, init_fn_, deinit_fn_, flags_, pm_, data_, config_, api_, \
1174 state_, deps_, node_id_, dev_id_) \
1175 { \
1176 .name = name_, \
1177 .config = (config_), \
1178 .api = (api_), \
1179 .state = (state_), \
1180 .data = (data_), \
1181 .ops = Z_DEVICE_OPS(init_fn_, deinit_fn_), \
1182 .flags = (flags_), \
1183 IF_ENABLED(CONFIG_DEVICE_DEPS, (.deps = (deps_),)) \
1184 IF_ENABLED(CONFIG_PM_DEVICE, Z_DEVICE_INIT_PM_BASE(pm_)) \
1185 IF_ENABLED(CONFIG_DEVICE_DT_METADATA, \
1186 (IF_ENABLED(DT_NODE_EXISTS(node_id_), \
1187 (.dt_meta = &Z_DEVICE_DT_METADATA_NAME_GET( \
1188 dev_id_),)))) \
1189 }
1190
1191/*
1192 * Anonymous unions require C11. Some pre-C11 gcc versions have early support for anonymous
1193 * unions but they require these braces when combined with C99 designated initializers. For
1194 * more details see https://docs.zephyrproject.org/latest/develop/languages/cpp/
1195 */
1196#if defined(__STDC_VERSION__) && (__STDC_VERSION__) < 201100
1197# define Z_DEVICE_INIT_PM_BASE(pm_) ({ .pm_base = (pm_),},)
1198#else
1199# define Z_DEVICE_INIT_PM_BASE(pm_) (.pm_base = (pm_),)
1200#endif
1201
1208#define Z_DEVICE_SECTION_NAME(level, prio) \
1209 _CONCAT(INIT_LEVEL_ORD(level), _##prio)
1210
1230#define Z_DEVICE_BASE_DEFINE(node_id, dev_id, name, init_fn, deinit_fn, flags, pm, data, config, \
1231 level, prio, api, state, deps) \
1232 COND_CODE_1(DT_NODE_EXISTS(node_id), (), (static)) \
1233 COND_CODE_1(Z_DEVICE_IS_MUTABLE(node_id), (), (const)) \
1234 STRUCT_SECTION_ITERABLE_NAMED_ALTERNATE( \
1235 device, COND_CODE_1(Z_DEVICE_IS_MUTABLE(node_id), (device_mutable), (device)), \
1236 Z_DEVICE_SECTION_NAME(level, prio), DEVICE_NAME_GET(dev_id)) = \
1237 Z_DEVICE_INIT(name, init_fn, deinit_fn, flags, pm, data, config, api, state, deps, \
1238 node_id, dev_id)
1239
1245#define Z_DEVICE_CHECK_INIT_LEVEL(level) \
1246 COND_CODE_1(Z_INIT_PRE_KERNEL_1_##level, (), \
1247 (COND_CODE_1(Z_INIT_PRE_KERNEL_2_##level, (), \
1248 (COND_CODE_1(Z_INIT_POST_KERNEL_##level, (), \
1249 (ZERO_OR_COMPILE_ERROR(0)))))))
1250
1260#define Z_DEVICE_INIT_ENTRY_DEFINE(node_id, dev_id, level, prio) \
1261 Z_DEVICE_CHECK_INIT_LEVEL(level) \
1262 \
1263 static const Z_DECL_ALIGN(struct init_entry) __used __noasan Z_INIT_ENTRY_SECTION( \
1264 level, prio, Z_DEVICE_INIT_SUB_PRIO(node_id)) \
1265 Z_INIT_ENTRY_NAME(DEVICE_NAME_GET(dev_id)) = { \
1266 .init_fn = NULL, \
1267 .dev = (const struct device *)&DEVICE_NAME_GET(dev_id), \
1268 }
1269
1292#define Z_DEVICE_DEFINE(node_id, dev_id, name, init_fn, deinit_fn, flags, pm, \
1293 data, config, level, prio, api, state, ...) \
1294 Z_DEVICE_NAME_CHECK(name); \
1295 \
1296 IF_ENABLED(CONFIG_DEVICE_DEPS, \
1297 (Z_DEVICE_DEPS_DEFINE(node_id, dev_id, __VA_ARGS__);)) \
1298 \
1299 IF_ENABLED(CONFIG_DEVICE_DT_METADATA, \
1300 (IF_ENABLED(DT_NODE_EXISTS(node_id), \
1301 (Z_DEVICE_DT_METADATA_DEFINE(node_id, dev_id);))))\
1302 \
1303 Z_DEVICE_BASE_DEFINE(node_id, dev_id, name, init_fn, deinit_fn, flags, \
1304 pm, data, config, level, prio, api, state, \
1305 Z_DEVICE_DEPS_NAME(dev_id)); \
1306 \
1307 Z_DEVICE_INIT_ENTRY_DEFINE(node_id, dev_id, level, prio); \
1308 \
1309 IF_ENABLED(CONFIG_LLEXT_EXPORT_DEVICES, \
1310 (IF_ENABLED(DT_NODE_EXISTS(node_id), \
1311 (Z_DEVICE_EXPORT(node_id);))))
1312
1323#define Z_MAYBE_DEVICE_DECLARE_INTERNAL(node_id) \
1324 extern COND_CODE_1(Z_DEVICE_IS_MUTABLE(node_id), (), \
1325 (const)) struct device DEVICE_DT_NAME_GET(node_id);
1326
1327DT_FOREACH_STATUS_OKAY_NODE(Z_MAYBE_DEVICE_DECLARE_INTERNAL)
1328
1329
1330#define Z_DEVICE_API_TYPE(_class) _CONCAT(_class, _driver_api)
1331
1340#define DEVICE_API(_class, _name) const STRUCT_SECTION_ITERABLE(Z_DEVICE_API_TYPE(_class), _name)
1341
1350#define DEVICE_API_GET(_class, _dev) ((const struct Z_DEVICE_API_TYPE(_class) *)_dev->api)
1351
1362#define DEVICE_API_IS(_class, _dev) \
1363 ({ \
1364 STRUCT_SECTION_START_EXTERN(Z_DEVICE_API_TYPE(_class)); \
1365 STRUCT_SECTION_END_EXTERN(Z_DEVICE_API_TYPE(_class)); \
1366 (DEVICE_API_GET(_class, _dev) < STRUCT_SECTION_END(Z_DEVICE_API_TYPE(_class)) && \
1367 DEVICE_API_GET(_class, _dev) >= STRUCT_SECTION_START(Z_DEVICE_API_TYPE(_class))); \
1368 })
1369
1370#ifdef __cplusplus
1371}
1372#endif
1373
1374#include <zephyr/syscalls/device.h>
1375
1376#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:641
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:721
static device_handle_t device_handle_get(const struct device *dev)
Get the handle for a given device.
Definition device.h:560
#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:584
int device_deinit(const struct device *dev)
De-initialize a device.
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:619
bool device_is_ready(const struct device *dev)
Verify that a device is ready for use.
uint8_t device_flags_t
Device flags.
Definition device.h:485
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:677
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
#define NULL
Definition iar_missing_defs.h:20
Definitions of various linker Sections.
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
__INT16_TYPE__ int16_t
Definition stdint.h:73
Device operations.
Definition device.h:498
int(* init)(const struct device *dev)
Initialization function.
Definition device.h:500
Runtime device dynamic structure (in RAM) per driver instance.
Definition device.h:455
bool initialized
Indicates the device initialization function has been invoked.
Definition device.h:468
uint8_t init_res
Device initialization return code (positive errno value).
Definition device.h:463
Runtime device structure (in ROM) per driver instance.
Definition device.h:510
struct pm_device_base * pm_base
Definition device.h:542
const device_handle_t * deps
Optional pointer to dependencies associated with the device.
Definition device.h:534
struct pm_device_isr * pm_isr
Definition device.h:544
const char * name
Name of the device instance.
Definition device.h:512
struct pm_device * pm
Definition device.h:543
void * data
Address of the device instance private data.
Definition device.h:520
const void * api
Address of the API structure exposed by the device instance.
Definition device.h:516
device_flags_t flags
Device flags.
Definition device.h:524
struct device_ops ops
Device operations.
Definition device.h:522
struct device_state * state
Address of the common device state.
Definition device.h:518
const void * config
Address of device instance config information.
Definition device.h:514
const struct device_dt_metadata * dt_meta
Definition device.h:548
Device PM info.
Definition device.h:139
Runtime PM info for device with synchronous PM.
Definition device.h:187
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.