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
171#define DEVICE_DEINIT_DEFINE(dev_id, name, init_fn, deinit_fn, pm, data, \
172 config, level, prio, api) \
173 Z_DEVICE_STATE_DEFINE(dev_id); \
174 Z_DEVICE_DEFINE(DT_INVALID_NODE, dev_id, name, init_fn, deinit_fn, 0U, \
175 pm, data, config, level, prio, api, \
176 &Z_DEVICE_STATE_NAME(dev_id))
177
183#define DEVICE_DEFINE(dev_id, name, init_fn, pm, data, config, level, prio, \
184 api) \
185 DEVICE_DEINIT_DEFINE(dev_id, name, init_fn, NULL, pm, data, config, \
186 level, prio, api)
187
199#define DEVICE_DT_NAME(node_id) \
200 DT_PROP_OR(node_id, label, DT_NODE_FULL_NAME(node_id))
201
236#define DEVICE_DT_DEINIT_DEFINE(node_id, init_fn, deinit_fn, pm, data, config, \
237 level, prio, api, ...) \
238 Z_DEVICE_STATE_DEFINE(Z_DEVICE_DT_DEV_ID(node_id)); \
239 Z_DEVICE_DEFINE(node_id, Z_DEVICE_DT_DEV_ID(node_id), \
240 DEVICE_DT_NAME(node_id), init_fn, deinit_fn, \
241 Z_DEVICE_DT_FLAGS(node_id), pm, data, config, level, \
242 prio, api, \
243 &Z_DEVICE_STATE_NAME(Z_DEVICE_DT_DEV_ID(node_id)), \
244 __VA_ARGS__)
245
252#define DEVICE_DT_DEFINE(node_id, init_fn, pm, data, config, level, prio, api, \
253 ...) \
254 DEVICE_DT_DEINIT_DEFINE(node_id, init_fn, NULL, pm, data, config, \
255 level, prio, api, __VA_ARGS__)
256
265#define DEVICE_DT_INST_DEINIT_DEFINE(inst, ...) \
266 DEVICE_DT_DEINIT_DEFINE(DT_DRV_INST(inst), __VA_ARGS__)
267
276#define DEVICE_DT_INST_DEFINE(inst, ...) \
277 DEVICE_DT_DEFINE(DT_DRV_INST(inst), __VA_ARGS__)
278
293#define DEVICE_DT_NAME_GET(node_id) DEVICE_NAME_GET(Z_DEVICE_DT_DEV_ID(node_id))
294
310#define DEVICE_DT_GET(node_id) (&DEVICE_DT_NAME_GET(node_id))
311
321#define DEVICE_DT_INST_GET(inst) DEVICE_DT_GET(DT_DRV_INST(inst))
322
339#define DEVICE_DT_GET_ANY(compat) \
340 COND_CODE_1(DT_HAS_COMPAT_STATUS_OKAY(compat), \
341 (DEVICE_DT_GET(DT_COMPAT_GET_ANY_STATUS_OKAY(compat))), \
342 (NULL))
343
360#define DEVICE_DT_GET_ONE(compat) \
361 COND_CODE_1(DT_HAS_COMPAT_STATUS_OKAY(compat), \
362 (DEVICE_DT_GET(DT_COMPAT_GET_ANY_STATUS_OKAY(compat))), \
363 (ZERO_OR_COMPILE_ERROR(0)))
364
375#define DEVICE_DT_GET_OR_NULL(node_id) \
376 COND_CODE_1(DT_NODE_HAS_STATUS_OKAY(node_id), \
377 (DEVICE_DT_GET(node_id)), (NULL))
378
392#define DEVICE_DT_GET_BY_IDX(node_id, prop, idx) \
393 DEVICE_DT_GET(DT_PHANDLE_BY_IDX(node_id, prop, idx))
394
405#define DEVICE_GET(dev_id) (&DEVICE_NAME_GET(dev_id))
406
421#define DEVICE_DECLARE(dev_id) \
422 static const struct device DEVICE_NAME_GET(dev_id)
423
431#define DEVICE_INIT_DT_GET(node_id) \
432 (&Z_INIT_ENTRY_NAME(DEVICE_DT_NAME_GET(node_id)))
433
441#define DEVICE_INIT_GET(dev_id) (&Z_INIT_ENTRY_NAME(DEVICE_NAME_GET(dev_id)))
442
460
464 bool initialized : 1;
465};
466
467struct pm_device_base;
468struct pm_device;
469struct pm_device_isr;
470#if defined(CONFIG_DEVICE_DT_METADATA) || defined(__DOXYGEN__)
471struct device_dt_metadata;
472#endif
473
474#ifdef CONFIG_DEVICE_DEPS_DYNAMIC
475#define Z_DEVICE_DEPS_CONST
476#else
477#define Z_DEVICE_DEPS_CONST const
478#endif
479
482
489#define DEVICE_FLAG_INIT_DEFERRED BIT(0)
490
496 int (*init)(const struct device *dev);
498 int (*deinit)(const struct device *dev);
499};
500
504struct device {
506 const char *name;
508 const void *config;
510 const void *api;
514 void *data;
519#if defined(CONFIG_DEVICE_DEPS) || defined(__DOXYGEN__)
528 Z_DEVICE_DEPS_CONST device_handle_t *deps;
529#endif /* CONFIG_DEVICE_DEPS */
530#if defined(CONFIG_PM_DEVICE) || defined(__DOXYGEN__)
535 union {
537 struct pm_device *pm;
539 };
540#endif
541#if defined(CONFIG_DEVICE_DT_METADATA) || defined(__DOXYGEN__)
542 const struct device_dt_metadata *dt_meta;
543#endif /* CONFIG_DEVICE_DT_METADATA */
544};
545
554static inline device_handle_t device_handle_get(const struct device *dev)
555{
558
559 /* TODO: If/when devices can be constructed that are not part of the
560 * fixed sequence we'll need another solution.
561 */
562 if (dev != NULL) {
563 ret = 1 + (device_handle_t)(dev - STRUCT_SECTION_START(device));
564 }
565
566 return ret;
567}
568
577static inline const struct device *
579{
581 const struct device *dev = NULL;
582 size_t numdev;
583
585
586 if ((dev_handle > 0) && ((size_t)dev_handle <= numdev)) {
587 dev = &STRUCT_SECTION_START(device)[dev_handle - 1];
588 }
589
590 return dev;
591}
592
593#if defined(CONFIG_DEVICE_DEPS) || defined(__DOXYGEN__)
594
613typedef int (*device_visitor_callback_t)(const struct device *dev,
614 void *context);
615
634static inline const device_handle_t *
635device_required_handles_get(const struct device *dev, size_t *count)
636{
637 const device_handle_t *rv = dev->deps;
638
639 if (rv != NULL) {
640 size_t i = 0;
641
642 while ((rv[i] != Z_DEVICE_DEPS_ENDS) &&
643 (rv[i] != Z_DEVICE_DEPS_SEP)) {
644 ++i;
645 }
646 *count = i;
647 }
648
649 return rv;
650}
651
670static inline const device_handle_t *
671device_injected_handles_get(const struct device *dev, size_t *count)
672{
673 const device_handle_t *rv = dev->deps;
674 size_t region = 0;
675 size_t i = 0;
676
677 if (rv != NULL) {
678 /* Fast forward to injected devices */
679 while (region != 1) {
680 if (*rv == Z_DEVICE_DEPS_SEP) {
681 region++;
682 }
683 rv++;
684 }
685 while ((rv[i] != Z_DEVICE_DEPS_ENDS) &&
686 (rv[i] != Z_DEVICE_DEPS_SEP)) {
687 ++i;
688 }
689 *count = i;
690 }
691
692 return rv;
693}
694
714static inline const device_handle_t *
715device_supported_handles_get(const struct device *dev, size_t *count)
716{
717 const device_handle_t *rv = dev->deps;
718 size_t region = 0;
719 size_t i = 0;
720
721 if (rv != NULL) {
722 /* Fast forward to supporting devices */
723 while (region != 2) {
724 if (*rv == Z_DEVICE_DEPS_SEP) {
725 region++;
726 }
727 rv++;
728 }
729 /* Count supporting devices.
730 * Trailing NULL's can be injected by gen_device_deps.py due to
731 * CONFIG_PM_DEVICE_POWER_DOMAIN_DYNAMIC_NUM
732 */
733 while ((rv[i] != Z_DEVICE_DEPS_ENDS) &&
734 (rv[i] != DEVICE_HANDLE_NULL)) {
735 ++i;
736 }
737 *count = i;
738 }
739
740 return rv;
741}
742
773int device_required_foreach(const struct device *dev,
774 device_visitor_callback_t visitor_cb,
775 void *context);
776
806int device_supported_foreach(const struct device *dev,
807 device_visitor_callback_t visitor_cb,
808 void *context);
809
810#endif /* CONFIG_DEVICE_DEPS */
811
832__syscall const struct device *device_get_binding(const char *name);
833
842size_t z_device_get_all_static(const struct device **devices);
843
860__syscall bool device_is_ready(const struct device *dev);
861
875__syscall int device_init(const struct device *dev);
876
894__syscall int device_deinit(const struct device *dev);
895
906#define Z_DEVICE_STATE_NAME(dev_id) _CONCAT(__devstate_, dev_id)
907
913#define Z_DEVICE_STATE_DEFINE(dev_id) \
914 static Z_DECL_ALIGN(struct device_state) Z_DEVICE_STATE_NAME(dev_id) \
915 __attribute__((__section__(".z_devstate")))
916
922#define Z_DEVICE_DT_FLAGS(node_id) \
923 (DT_PROP_OR(node_id, zephyr_deferred_init, 0U) * DEVICE_FLAG_INIT_DEFERRED)
924
925#if defined(CONFIG_DEVICE_DEPS) || defined(__DOXYGEN__)
926
933#define Z_DEVICE_DEPS_NAME(dev_id) _CONCAT(__devicedeps_, dev_id)
934
940#define Z_DEVICE_EXTRA_DEPS(...) \
941 FOR_EACH_NONEMPTY_TERM(IDENTITY, (,), __VA_ARGS__)
942
944#define Z_DEVICE_DEPS_SECTION \
945 __attribute__((__section__(".__device_deps_pass1")))
946
947#ifdef __cplusplus
948#define Z_DEVICE_DEPS_EXTERN extern
949#else
950#define Z_DEVICE_DEPS_EXTERN
951#endif
952
988#define Z_DEVICE_DEPS_DEFINE(node_id, dev_id, ...) \
989 extern Z_DEVICE_DEPS_CONST device_handle_t Z_DEVICE_DEPS_NAME( \
990 dev_id)[]; \
991 Z_DEVICE_DEPS_CONST Z_DECL_ALIGN(device_handle_t) \
992 Z_DEVICE_DEPS_SECTION Z_DEVICE_DEPS_EXTERN __weak \
993 Z_DEVICE_DEPS_NAME(dev_id)[] = { \
994 COND_CODE_1( \
995 DT_NODE_EXISTS(node_id), \
996 (DT_DEP_ORD(node_id), DT_REQUIRES_DEP_ORDS(node_id)), \
997 (DEVICE_HANDLE_NULL,)) \
998 Z_DEVICE_DEPS_SEP, \
999 Z_DEVICE_EXTRA_DEPS(__VA_ARGS__) \
1000 Z_DEVICE_DEPS_SEP, \
1001 COND_CODE_1(DT_NODE_EXISTS(node_id), \
1002 (DT_SUPPORTS_DEP_ORDS(node_id)), ()) \
1003 }
1004
1005#endif /* CONFIG_DEVICE_DEPS */
1006#if defined(CONFIG_DEVICE_DT_METADATA) || defined(__DOXYGEN__)
1010struct device_dt_nodelabels {
1011 /* @brief number of elements in the nodelabels array */
1012 size_t num_nodelabels;
1013 /* @brief array of node labels as strings, exactly as they
1014 * appear in the final devicetree
1015 */
1016 const char *nodelabels[];
1017};
1018
1026struct device_dt_metadata {
1031 const struct device_dt_nodelabels *nl;
1032};
1033
1052__syscall const struct device *device_get_by_dt_nodelabel(const char *nodelabel);
1053
1059static inline const struct device_dt_nodelabels *
1060device_get_dt_nodelabels(const struct device *dev)
1061{
1062 if (dev->dt_meta == NULL) {
1063 return NULL;
1064 }
1065 return dev->dt_meta->nl;
1066}
1067
1074#define Z_DEVICE_MAX_NODELABEL_LEN Z_DEVICE_MAX_NAME_LEN
1075
1080#define Z_DEVICE_DT_METADATA_NAME_GET(dev_id) UTIL_CAT(__dev_dt_meta_, dev_id)
1081
1086#define Z_DEVICE_DT_NODELABELS_NAME_GET(dev_id) UTIL_CAT(__dev_dt_nodelabels_, dev_id)
1087
1094#define Z_DEVICE_DT_METADATA_DEFINE(node_id, dev_id) \
1095 static const struct device_dt_nodelabels \
1096 Z_DEVICE_DT_NODELABELS_NAME_GET(dev_id) = { \
1097 .num_nodelabels = DT_NUM_NODELABELS(node_id), \
1098 .nodelabels = DT_NODELABEL_STRING_ARRAY(node_id), \
1099 }; \
1100 \
1101 static const struct device_dt_metadata \
1102 Z_DEVICE_DT_METADATA_NAME_GET(dev_id) = { \
1103 .nl = &Z_DEVICE_DT_NODELABELS_NAME_GET(dev_id), \
1104 };
1105#endif /* CONFIG_DEVICE_DT_METADATA */
1106
1114#define Z_DEVICE_INIT_SUB_PRIO(node_id) \
1115 COND_CODE_1(DT_NODE_EXISTS(node_id), \
1116 (DT_DEP_ORD_STR_SORTABLE(node_id)), (0))
1117
1124#define Z_DEVICE_MAX_NAME_LEN 48U
1125
1131#define Z_DEVICE_NAME_CHECK(name) \
1132 BUILD_ASSERT(sizeof(Z_STRINGIFY(name)) <= Z_DEVICE_MAX_NAME_LEN, \
1133 Z_STRINGIFY(name) " too long")
1134
1151#define Z_DEVICE_INIT(name_, init_fn_, deinit_fn_, flags_, pm_, data_, config_, api_, \
1152 state_, deps_, node_id_, dev_id_) \
1153 { \
1154 .name = name_, \
1155 .config = (config_), \
1156 .api = (api_), \
1157 .state = (state_), \
1158 .data = (data_), \
1159 .ops = { .init = (init_fn_), .deinit = (deinit_fn_) }, \
1160 .flags = (flags_), \
1161 IF_ENABLED(CONFIG_DEVICE_DEPS, (.deps = (deps_),)) \
1162 IF_ENABLED(CONFIG_PM_DEVICE, Z_DEVICE_INIT_PM_BASE(pm_)) \
1163 IF_ENABLED(CONFIG_DEVICE_DT_METADATA, \
1164 (IF_ENABLED(DT_NODE_EXISTS(node_id_), \
1165 (.dt_meta = &Z_DEVICE_DT_METADATA_NAME_GET( \
1166 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_PM_BASE(pm_) ({ .pm_base = (pm_),},)
1176#else
1177# define Z_DEVICE_INIT_PM_BASE(pm_) (.pm_base = (pm_),)
1178#endif
1179
1186#define Z_DEVICE_SECTION_NAME(level, prio) \
1187 _CONCAT(INIT_LEVEL_ORD(level), _##prio)
1188
1208#define Z_DEVICE_BASE_DEFINE(node_id, dev_id, name, init_fn, deinit_fn, flags, pm, data, config, \
1209 level, prio, api, state, deps) \
1210 COND_CODE_1(DT_NODE_EXISTS(node_id), (), (static)) \
1211 COND_CODE_1(Z_DEVICE_IS_MUTABLE(node_id), (), (const)) \
1212 STRUCT_SECTION_ITERABLE_NAMED_ALTERNATE( \
1213 device, COND_CODE_1(Z_DEVICE_IS_MUTABLE(node_id), (device_mutable), (device)), \
1214 Z_DEVICE_SECTION_NAME(level, prio), DEVICE_NAME_GET(dev_id)) = \
1215 Z_DEVICE_INIT(name, init_fn, deinit_fn, flags, pm, data, config, api, state, deps, \
1216 node_id, dev_id)
1217
1223#define Z_DEVICE_CHECK_INIT_LEVEL(level) \
1224 COND_CODE_1(Z_INIT_PRE_KERNEL_1_##level, (), \
1225 (COND_CODE_1(Z_INIT_PRE_KERNEL_2_##level, (), \
1226 (COND_CODE_1(Z_INIT_POST_KERNEL_##level, (), \
1227 (ZERO_OR_COMPILE_ERROR(0)))))))
1228
1238#define Z_DEVICE_INIT_ENTRY_DEFINE(node_id, dev_id, level, prio) \
1239 Z_DEVICE_CHECK_INIT_LEVEL(level) \
1240 \
1241 static const Z_DECL_ALIGN(struct init_entry) __used __noasan Z_INIT_ENTRY_SECTION( \
1242 level, prio, Z_DEVICE_INIT_SUB_PRIO(node_id)) \
1243 Z_INIT_ENTRY_NAME(DEVICE_NAME_GET(dev_id)) = { \
1244 .init_fn = NULL, \
1245 .dev = (const struct device *)&DEVICE_NAME_GET(dev_id), \
1246 }
1247
1270#define Z_DEVICE_DEFINE(node_id, dev_id, name, init_fn, deinit_fn, flags, pm, \
1271 data, config, level, prio, api, state, ...) \
1272 Z_DEVICE_NAME_CHECK(name); \
1273 \
1274 IF_ENABLED(CONFIG_DEVICE_DEPS, \
1275 (Z_DEVICE_DEPS_DEFINE(node_id, dev_id, __VA_ARGS__);)) \
1276 \
1277 IF_ENABLED(CONFIG_DEVICE_DT_METADATA, \
1278 (IF_ENABLED(DT_NODE_EXISTS(node_id), \
1279 (Z_DEVICE_DT_METADATA_DEFINE(node_id, dev_id);))))\
1280 \
1281 Z_DEVICE_BASE_DEFINE(node_id, dev_id, name, init_fn, deinit_fn, flags, \
1282 pm, data, config, level, prio, api, state, \
1283 Z_DEVICE_DEPS_NAME(dev_id)); \
1284 \
1285 Z_DEVICE_INIT_ENTRY_DEFINE(node_id, dev_id, level, prio); \
1286 \
1287 IF_ENABLED(CONFIG_LLEXT_EXPORT_DEVICES, \
1288 (IF_ENABLED(DT_NODE_EXISTS(node_id), \
1289 (Z_DEVICE_EXPORT(node_id);))))
1290
1301#define Z_MAYBE_DEVICE_DECLARE_INTERNAL(node_id) \
1302 extern COND_CODE_1(Z_DEVICE_IS_MUTABLE(node_id), (), \
1303 (const)) struct device DEVICE_DT_NAME_GET(node_id);
1304
1305DT_FOREACH_STATUS_OKAY_NODE(Z_MAYBE_DEVICE_DECLARE_INTERNAL)
1306
1307
1308#define Z_DEVICE_API_TYPE(_class) _CONCAT(_class, _driver_api)
1309
1318#define DEVICE_API(_class, _name) const STRUCT_SECTION_ITERABLE(Z_DEVICE_API_TYPE(_class), _name)
1319
1328#define DEVICE_API_GET(_class, _dev) ((const struct Z_DEVICE_API_TYPE(_class) *)_dev->api)
1329
1340#define DEVICE_API_IS(_class, _dev) \
1341 ({ \
1342 STRUCT_SECTION_START_EXTERN(Z_DEVICE_API_TYPE(_class)); \
1343 STRUCT_SECTION_END_EXTERN(Z_DEVICE_API_TYPE(_class)); \
1344 (DEVICE_API_GET(_class, _dev) < STRUCT_SECTION_END(Z_DEVICE_API_TYPE(_class)) && \
1345 DEVICE_API_GET(_class, _dev) >= STRUCT_SECTION_START(Z_DEVICE_API_TYPE(_class))); \
1346 })
1347
1348#ifdef __cplusplus
1349}
1350#endif
1351
1352#include <zephyr/syscalls/device.h>
1353
1354#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:635
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:715
static device_handle_t device_handle_get(const struct device *dev)
Get the handle for a given device.
Definition device.h:554
#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:578
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:613
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:481
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:671
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:494
int(* init)(const struct device *dev)
Initialization function.
Definition device.h:496
int(* deinit)(const struct device *dev)
De-initialization function.
Definition device.h:498
Runtime device dynamic structure (in RAM) per driver instance.
Definition device.h:451
bool initialized
Indicates the device initialization function has been invoked.
Definition device.h:464
uint8_t init_res
Device initialization return code (positive errno value).
Definition device.h:459
Runtime device structure (in ROM) per driver instance.
Definition device.h:504
struct pm_device_base * pm_base
Definition device.h:536
const device_handle_t * deps
Optional pointer to dependencies associated with the device.
Definition device.h:528
struct pm_device_isr * pm_isr
Definition device.h:538
const char * name
Name of the device instance.
Definition device.h:506
struct pm_device * pm
Definition device.h:537
void * data
Address of the device instance private data.
Definition device.h:514
const void * api
Address of the API structure exposed by the device instance.
Definition device.h:510
device_flags_t flags
Device flags.
Definition device.h:518
struct device_ops ops
Device operations.
Definition device.h:516
struct device_state * state
Address of the common device state.
Definition device.h:512
const void * config
Address of device instance config information.
Definition device.h:508
const struct device_dt_metadata * dt_meta
Definition device.h:542
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.