Zephyr API Documentation 4.3.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
36
38
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
56
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_GROUP_SYMBOL_NAMED as hashed versions of their
116 * paths. When matching extensions are built, that is what they need to look
117 * for.
118 *
119 * The ordinal or hash used in this name can be mapped to the path by
120 * examining zephyr/include/generated/zephyr/devicetree_generated.h.
121 */
122#if defined(LL_EXTENSION_BUILD) && defined(CONFIG_LLEXT_EXPORT_DEV_IDS_BY_HASH)
123#define Z_DEVICE_DT_DEV_ID(node_id) Z_DEVICE_DT_HASH(node_id)
124#else
125#define Z_DEVICE_DT_DEV_ID(node_id) Z_DEVICE_DT_DEP_ORD(node_id)
126#endif
127
128#if defined(CONFIG_LLEXT_EXPORT_DEV_IDS_BY_HASH)
129/* Export device identifiers by hash */
130#define Z_DEVICE_EXPORT(node_id) \
131 EXPORT_GROUP_SYMBOL_NAMED(DEVICE, \
132 DEVICE_DT_NAME_GET(node_id), \
133 DEVICE_NAME_GET(Z_DEVICE_DT_HASH(node_id)))
134#else
135/* Export device identifiers using the builtin name */
136#define Z_DEVICE_EXPORT(node_id) \
137 EXPORT_GROUP_SYMBOL(DEVICE, DEVICE_DT_NAME_GET(node_id))
138#endif
139
176#define DEVICE_DEINIT_DEFINE(dev_id, name, init_fn, deinit_fn, pm, data, \
177 config, level, prio, api) \
178 Z_DEVICE_STATE_DEFINE(dev_id); \
179 Z_DEVICE_DEFINE(DT_INVALID_NODE, dev_id, name, init_fn, deinit_fn, 0U, \
180 pm, data, config, level, prio, api, \
181 &Z_DEVICE_STATE_NAME(dev_id))
182
188#define DEVICE_DEFINE(dev_id, name, init_fn, pm, data, config, level, prio, \
189 api) \
190 DEVICE_DEINIT_DEFINE(dev_id, name, init_fn, NULL, pm, data, config, \
191 level, prio, api)
192
204#define DEVICE_DT_NAME(node_id) \
205 DT_PROP_OR(node_id, label, DT_NODE_FULL_NAME(node_id))
206
243#define DEVICE_DT_DEINIT_DEFINE(node_id, init_fn, deinit_fn, pm, data, config, \
244 level, prio, api, ...) \
245 Z_DEVICE_STATE_DEFINE(Z_DEVICE_DT_DEV_ID(node_id)); \
246 Z_DEVICE_DEFINE(node_id, Z_DEVICE_DT_DEV_ID(node_id), \
247 DEVICE_DT_NAME(node_id), init_fn, deinit_fn, \
248 Z_DEVICE_DT_FLAGS(node_id), pm, data, config, level, \
249 prio, api, \
250 &Z_DEVICE_STATE_NAME(Z_DEVICE_DT_DEV_ID(node_id)), \
251 __VA_ARGS__)
252
259#define DEVICE_DT_DEFINE(node_id, init_fn, pm, data, config, level, prio, api, \
260 ...) \
261 DEVICE_DT_DEINIT_DEFINE(node_id, init_fn, NULL, pm, data, config, \
262 level, prio, api, __VA_ARGS__)
263
272#define DEVICE_DT_INST_DEINIT_DEFINE(inst, ...) \
273 DEVICE_DT_DEINIT_DEFINE(DT_DRV_INST(inst), __VA_ARGS__)
274
283#define DEVICE_DT_INST_DEFINE(inst, ...) \
284 DEVICE_DT_DEFINE(DT_DRV_INST(inst), __VA_ARGS__)
285
300#define DEVICE_DT_NAME_GET(node_id) DEVICE_NAME_GET(Z_DEVICE_DT_DEV_ID(node_id))
301
317#define DEVICE_DT_GET(node_id) (&DEVICE_DT_NAME_GET(node_id))
318
328#define DEVICE_DT_INST_GET(inst) DEVICE_DT_GET(DT_DRV_INST(inst))
329
346#define DEVICE_DT_GET_ANY(compat) \
347 COND_CODE_1(DT_HAS_COMPAT_STATUS_OKAY(compat), \
348 (DEVICE_DT_GET(DT_COMPAT_GET_ANY_STATUS_OKAY(compat))), \
349 (NULL))
350
367#define DEVICE_DT_GET_ONE(compat) \
368 COND_CODE_1(DT_HAS_COMPAT_STATUS_OKAY(compat), \
369 (DEVICE_DT_GET(DT_COMPAT_GET_ANY_STATUS_OKAY(compat))), \
370 (ZERO_OR_COMPILE_ERROR(0)))
371
382#define DEVICE_DT_GET_OR_NULL(node_id) \
383 COND_CODE_1(DT_NODE_HAS_STATUS_OKAY(node_id), \
384 (DEVICE_DT_GET(node_id)), (NULL))
385
399#define DEVICE_DT_GET_BY_IDX(node_id, prop, idx) \
400 DEVICE_DT_GET(DT_PHANDLE_BY_IDX(node_id, prop, idx))
401
412#define DEVICE_GET(dev_id) (&DEVICE_NAME_GET(dev_id))
413
428#define DEVICE_DECLARE(dev_id) \
429 static const struct device DEVICE_NAME_GET(dev_id)
430
438#define DEVICE_INIT_DT_GET(node_id) \
439 (&Z_INIT_ENTRY_NAME(DEVICE_DT_NAME_GET(node_id)))
440
448#define DEVICE_INIT_GET(dev_id) (&Z_INIT_ENTRY_NAME(DEVICE_NAME_GET(dev_id)))
449
467
471 bool initialized : 1;
472};
473
474struct pm_device_base;
475struct pm_device;
476struct pm_device_isr;
477#if defined(CONFIG_DEVICE_DT_METADATA) || defined(__DOXYGEN__)
478struct device_dt_metadata;
479#endif
480
481#ifdef CONFIG_DEVICE_DEPS_DYNAMIC
482#define Z_DEVICE_DEPS_CONST
483#else
484#define Z_DEVICE_DEPS_CONST const
485#endif
486
489
494
496#define DEVICE_FLAG_INIT_DEFERRED BIT(0)
497
499
503 int (*init)(const struct device *dev);
504#ifdef CONFIG_DEVICE_DEINIT_SUPPORT
506 int (*deinit)(const struct device *dev);
507#endif /* CONFIG_DEVICE_DEINIT_SUPPORT */
508};
509
513struct device {
515 const char *name;
517 const void *config;
519 const void *api;
523 void *data;
528#if defined(CONFIG_DEVICE_DEPS) || defined(__DOXYGEN__)
537 Z_DEVICE_DEPS_CONST device_handle_t *deps;
538#endif /* CONFIG_DEVICE_DEPS */
539#if defined(CONFIG_PM_DEVICE) || defined(__DOXYGEN__)
544 union {
546 struct pm_device *pm;
548 };
549#endif
550#if defined(CONFIG_DEVICE_DT_METADATA) || defined(__DOXYGEN__)
551 const struct device_dt_metadata *dt_meta;
552#endif /* CONFIG_DEVICE_DT_METADATA */
553};
554
563static inline device_handle_t device_handle_get(const struct device *dev)
564{
567
568 /* TODO: If/when devices can be constructed that are not part of the
569 * fixed sequence we'll need another solution.
570 */
571 if (dev != NULL) {
572 ret = 1 + (device_handle_t)(dev - STRUCT_SECTION_START(device));
573 }
574
575 return ret;
576}
577
586static inline const struct device *
588{
590 const struct device *dev = NULL;
591 size_t numdev;
592
594
595 if ((dev_handle > 0) && ((size_t)dev_handle <= numdev)) {
596 dev = &STRUCT_SECTION_START(device)[dev_handle - 1];
597 }
598
599 return dev;
600}
601
602#if defined(CONFIG_DEVICE_DEPS) || defined(__DOXYGEN__)
603
622typedef int (*device_visitor_callback_t)(const struct device *dev,
623 void *context);
624
643static inline const device_handle_t *
644device_required_handles_get(const struct device *dev, size_t *count)
645{
646 const device_handle_t *rv = dev->deps;
647
648 if (rv != NULL) {
649 size_t i = 0;
650
651 while ((rv[i] != Z_DEVICE_DEPS_ENDS) &&
652 (rv[i] != Z_DEVICE_DEPS_SEP)) {
653 ++i;
654 }
655 *count = i;
656 }
657
658 return rv;
659}
660
679static inline const device_handle_t *
680device_injected_handles_get(const struct device *dev, size_t *count)
681{
682 const device_handle_t *rv = dev->deps;
683 size_t region = 0;
684 size_t i = 0;
685
686 if (rv != NULL) {
687 /* Fast forward to injected devices */
688 while (region != 1) {
689 if (*rv == Z_DEVICE_DEPS_SEP) {
690 region++;
691 }
692 rv++;
693 }
694 while ((rv[i] != Z_DEVICE_DEPS_ENDS) &&
695 (rv[i] != Z_DEVICE_DEPS_SEP)) {
696 ++i;
697 }
698 *count = i;
699 }
700
701 return rv;
702}
703
723static inline const device_handle_t *
724device_supported_handles_get(const struct device *dev, size_t *count)
725{
726 const device_handle_t *rv = dev->deps;
727 size_t region = 0;
728 size_t i = 0;
729
730 if (rv != NULL) {
731 /* Fast forward to supporting devices */
732 while (region != 2) {
733 if (*rv == Z_DEVICE_DEPS_SEP) {
734 region++;
735 }
736 rv++;
737 }
738 /* Count supporting devices.
739 * Trailing NULL's can be injected by gen_device_deps.py due to
740 * CONFIG_PM_DEVICE_POWER_DOMAIN_DYNAMIC_NUM
741 */
742 while ((rv[i] != Z_DEVICE_DEPS_ENDS) &&
743 (rv[i] != DEVICE_HANDLE_NULL)) {
744 ++i;
745 }
746 *count = i;
747 }
748
749 return rv;
750}
751
782int device_required_foreach(const struct device *dev,
783 device_visitor_callback_t visitor_cb,
784 void *context);
785
815int device_supported_foreach(const struct device *dev,
816 device_visitor_callback_t visitor_cb,
817 void *context);
818
819#endif /* CONFIG_DEVICE_DEPS */
820
841__syscall const struct device *device_get_binding(const char *name);
842
851size_t z_device_get_all_static(const struct device **devices);
852
869__syscall bool device_is_ready(const struct device *dev);
870
884__syscall int device_init(const struct device *dev);
885
906__syscall int device_deinit(const struct device *dev);
907
911
913
918#define Z_DEVICE_STATE_NAME(dev_id) _CONCAT(__devstate_, dev_id)
919
925#define Z_DEVICE_STATE_DEFINE(dev_id) \
926 static Z_DECL_ALIGN(struct device_state) Z_DEVICE_STATE_NAME(dev_id) \
927 __attribute__((__section__(".z_devstate")))
928
934#define Z_DEVICE_DT_FLAGS(node_id) \
935 (DT_PROP_OR(node_id, zephyr_deferred_init, 0U) * DEVICE_FLAG_INIT_DEFERRED)
936
937#if defined(CONFIG_DEVICE_DEPS) || defined(__DOXYGEN__)
938
945#define Z_DEVICE_DEPS_NAME(dev_id) _CONCAT(__devicedeps_, dev_id)
946
952#define Z_DEVICE_EXTRA_DEPS(...) \
953 FOR_EACH_NONEMPTY_TERM(IDENTITY, (,), __VA_ARGS__)
954
956#define Z_DEVICE_DEPS_SECTION \
957 __attribute__((__section__(".__device_deps_pass1")))
958
959#ifdef __cplusplus
960#define Z_DEVICE_DEPS_EXTERN extern
961#else
962#define Z_DEVICE_DEPS_EXTERN
963#endif
964
1000#define Z_DEVICE_DEPS_DEFINE(node_id, dev_id, ...) \
1001 extern Z_DEVICE_DEPS_CONST device_handle_t Z_DEVICE_DEPS_NAME( \
1002 dev_id)[]; \
1003 Z_DEVICE_DEPS_CONST Z_DECL_ALIGN(device_handle_t) \
1004 Z_DEVICE_DEPS_SECTION Z_DEVICE_DEPS_EXTERN __weak \
1005 Z_DEVICE_DEPS_NAME(dev_id)[] = { \
1006 COND_CODE_1( \
1007 DT_NODE_EXISTS(node_id), \
1008 (DT_DEP_ORD(node_id), DT_REQUIRES_DEP_ORDS(node_id)), \
1009 (DEVICE_HANDLE_NULL,)) /**/ \
1010 Z_DEVICE_DEPS_SEP, \
1011 Z_DEVICE_EXTRA_DEPS(__VA_ARGS__) /**/ \
1012 Z_DEVICE_DEPS_SEP, \
1013 COND_CODE_1(DT_NODE_EXISTS(node_id), \
1014 (DT_SUPPORTS_DEP_ORDS(node_id)), ()) /**/ \
1015 }
1016
1017#endif /* CONFIG_DEVICE_DEPS */
1018#if defined(CONFIG_DEVICE_DT_METADATA) || defined(__DOXYGEN__)
1022struct device_dt_nodelabels {
1023 /* @brief number of elements in the nodelabels array */
1024 size_t num_nodelabels;
1025 /* @brief array of node labels as strings, exactly as they
1026 * appear in the final devicetree
1027 */
1028 const char *nodelabels[];
1029};
1030
1038struct device_dt_metadata {
1043 const struct device_dt_nodelabels *nl;
1044};
1045
1064__syscall const struct device *device_get_by_dt_nodelabel(const char *nodelabel);
1065
1071static inline const struct device_dt_nodelabels *
1072device_get_dt_nodelabels(const struct device *dev)
1073{
1074 if (dev->dt_meta == NULL) {
1075 return NULL;
1076 }
1077 return dev->dt_meta->nl;
1078}
1079
1086#define Z_DEVICE_MAX_NODELABEL_LEN Z_DEVICE_MAX_NAME_LEN
1087
1092#define Z_DEVICE_DT_METADATA_NAME_GET(dev_id) UTIL_CAT(__dev_dt_meta_, dev_id)
1093
1098#define Z_DEVICE_DT_NODELABELS_NAME_GET(dev_id) UTIL_CAT(__dev_dt_nodelabels_, dev_id)
1099
1106#define Z_DEVICE_DT_METADATA_DEFINE(node_id, dev_id) \
1107 static const struct device_dt_nodelabels \
1108 Z_DEVICE_DT_NODELABELS_NAME_GET(dev_id) = { \
1109 .num_nodelabels = DT_NUM_NODELABELS(node_id), \
1110 .nodelabels = DT_NODELABEL_STRING_ARRAY(node_id), \
1111 }; \
1112 \
1113 static const struct device_dt_metadata \
1114 Z_DEVICE_DT_METADATA_NAME_GET(dev_id) = { \
1115 .nl = &Z_DEVICE_DT_NODELABELS_NAME_GET(dev_id), \
1116 };
1117#endif /* CONFIG_DEVICE_DT_METADATA */
1118
1126#define Z_DEVICE_INIT_SUB_PRIO(node_id) \
1127 COND_CODE_1(DT_NODE_EXISTS(node_id), \
1128 (DT_DEP_ORD_STR_SORTABLE(node_id)), (0))
1129
1136#define Z_DEVICE_MAX_NAME_LEN 48U
1137
1143#define Z_DEVICE_NAME_CHECK(name) \
1144 BUILD_ASSERT(sizeof(Z_STRINGIFY(name)) <= Z_DEVICE_MAX_NAME_LEN, \
1145 Z_STRINGIFY(name) " too long")
1146
1153#define Z_DEVICE_OPS(init_fn_, deinit_fn_) \
1154 { \
1155 .init = (init_fn_), \
1156 IF_ENABLED(CONFIG_DEVICE_DEINIT_SUPPORT, \
1157 (.deinit = (deinit_fn_),)) \
1158 }
1159
1176#define Z_DEVICE_INIT(name_, init_fn_, deinit_fn_, flags_, pm_, data_, config_, api_, \
1177 state_, deps_, node_id_, dev_id_) \
1178 { \
1179 .name = name_, \
1180 .config = (config_), \
1181 .api = (api_), \
1182 .state = (state_), \
1183 .data = (data_), \
1184 .ops = Z_DEVICE_OPS(init_fn_, deinit_fn_), \
1185 .flags = (flags_), \
1186 IF_ENABLED(CONFIG_DEVICE_DEPS, (.deps = (deps_),)) /**/ \
1187 IF_ENABLED(CONFIG_PM_DEVICE, Z_DEVICE_INIT_PM_BASE(pm_)) /**/ \
1188 IF_ENABLED(CONFIG_DEVICE_DT_METADATA, \
1189 (IF_ENABLED(DT_NODE_EXISTS(node_id_), \
1190 (.dt_meta = &Z_DEVICE_DT_METADATA_NAME_GET( \
1191 dev_id_),)))) \
1192 }
1193
1194/*
1195 * Anonymous unions require C11. Some pre-C11 gcc versions have early support for anonymous
1196 * unions but they require these braces when combined with C99 designated initializers. For
1197 * more details see https://docs.zephyrproject.org/latest/develop/languages/cpp/
1198 */
1199#if defined(__STDC_VERSION__) && (__STDC_VERSION__) < 201100
1200# define Z_DEVICE_INIT_PM_BASE(pm_) ({ .pm_base = (pm_),},)
1201#else
1202# define Z_DEVICE_INIT_PM_BASE(pm_) (.pm_base = (pm_),)
1203#endif
1204
1211#define Z_DEVICE_SECTION_NAME(level, prio) \
1212 _CONCAT(INIT_LEVEL_ORD(level), _##prio)
1213
1233#define Z_DEVICE_BASE_DEFINE(node_id, dev_id, name, init_fn, deinit_fn, flags, pm, data, config, \
1234 level, prio, api, state, deps) \
1235 COND_CODE_1(DT_NODE_EXISTS(node_id), (), (static)) \
1236 COND_CODE_1(Z_DEVICE_IS_MUTABLE(node_id), (), (const)) \
1237 STRUCT_SECTION_ITERABLE_NAMED_ALTERNATE( \
1238 device, COND_CODE_1(Z_DEVICE_IS_MUTABLE(node_id), (device_mutable), (device)), \
1239 Z_DEVICE_SECTION_NAME(level, prio), DEVICE_NAME_GET(dev_id)) = \
1240 Z_DEVICE_INIT(name, init_fn, deinit_fn, flags, pm, data, config, api, state, deps, \
1241 node_id, dev_id)
1242
1248#define Z_DEVICE_CHECK_INIT_LEVEL(level) \
1249 COND_CASE_1(Z_INIT_PRE_KERNEL_1_##level, (), \
1250 Z_INIT_PRE_KERNEL_2_##level, (), \
1251 Z_INIT_POST_KERNEL_##level, (), \
1252 (ZERO_OR_COMPILE_ERROR(0)))
1253
1263#define Z_DEVICE_INIT_ENTRY_DEFINE(node_id, dev_id, level, prio) \
1264 Z_DEVICE_CHECK_INIT_LEVEL(level) \
1265 \
1266 static const Z_DECL_ALIGN(struct init_entry) __used __noasan Z_INIT_ENTRY_SECTION( \
1267 level, prio, Z_DEVICE_INIT_SUB_PRIO(node_id)) \
1268 Z_INIT_ENTRY_NAME(DEVICE_NAME_GET(dev_id)) = { \
1269 .init_fn = NULL, \
1270 .dev = (const struct device *)&DEVICE_NAME_GET(dev_id), \
1271 }
1272
1295#define Z_DEVICE_DEFINE(node_id, dev_id, name, init_fn, deinit_fn, flags, pm, \
1296 data, config, level, prio, api, state, ...) \
1297 Z_DEVICE_NAME_CHECK(name); \
1298 \
1299 IF_ENABLED(CONFIG_DEVICE_DEPS, \
1300 (Z_DEVICE_DEPS_DEFINE(node_id, dev_id, __VA_ARGS__);)) \
1301 \
1302 IF_ENABLED(CONFIG_DEVICE_DT_METADATA, \
1303 (IF_ENABLED(DT_NODE_EXISTS(node_id), \
1304 (Z_DEVICE_DT_METADATA_DEFINE(node_id, dev_id);))))\
1305 \
1306 Z_DEVICE_BASE_DEFINE(node_id, dev_id, name, init_fn, deinit_fn, flags, \
1307 pm, data, config, level, prio, api, state, \
1308 Z_DEVICE_DEPS_NAME(dev_id)); \
1309 \
1310 Z_DEVICE_INIT_ENTRY_DEFINE(node_id, dev_id, level, prio); \
1311 \
1312 IF_ENABLED(CONFIG_LLEXT, \
1313 (IF_ENABLED(DT_NODE_EXISTS(node_id), \
1314 (Z_DEVICE_EXPORT(node_id);))))
1315
1326#define Z_MAYBE_DEVICE_DECLARE_INTERNAL(node_id) \
1327 extern COND_CODE_1(Z_DEVICE_IS_MUTABLE(node_id), (), \
1328 (const)) struct device DEVICE_DT_NAME_GET(node_id);
1329
1330DT_FOREACH_STATUS_OKAY_NODE(Z_MAYBE_DEVICE_DECLARE_INTERNAL)
1331
1332
1333#define Z_DEVICE_API_TYPE(_class) _CONCAT(_class, _driver_api)
1334
1336
1343#define DEVICE_API(_class, _name) const STRUCT_SECTION_ITERABLE(Z_DEVICE_API_TYPE(_class), _name)
1344
1353#define DEVICE_API_GET(_class, _dev) ((const struct Z_DEVICE_API_TYPE(_class) *)_dev->api)
1354
1365#define DEVICE_API_IS(_class, _dev) \
1366 ({ \
1367 STRUCT_SECTION_START_EXTERN(Z_DEVICE_API_TYPE(_class)); \
1368 STRUCT_SECTION_END_EXTERN(Z_DEVICE_API_TYPE(_class)); \
1369 (DEVICE_API_GET(_class, _dev) < STRUCT_SECTION_END(Z_DEVICE_API_TYPE(_class)) && \
1370 DEVICE_API_GET(_class, _dev) >= STRUCT_SECTION_START(Z_DEVICE_API_TYPE(_class))); \
1371 })
1372
1373#ifdef __cplusplus
1374}
1375#endif
1376
1377#include <zephyr/syscalls/device.h>
1378
1379#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:644
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:724
static device_handle_t device_handle_get(const struct device *dev)
Get the handle for a given device.
Definition device.h:563
#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:587
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:622
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:488
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:680
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:3048
#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:501
int(* init)(const struct device *dev)
Initialization function.
Definition device.h:503
Runtime device dynamic structure (in RAM) per driver instance.
Definition device.h:458
bool initialized
Indicates the device initialization function has been invoked.
Definition device.h:471
uint8_t init_res
Device initialization return code (positive errno value).
Definition device.h:466
Runtime device structure (in ROM) per driver instance.
Definition device.h:513
struct pm_device_base * pm_base
Definition device.h:545
const device_handle_t * deps
Optional pointer to dependencies associated with the device.
Definition device.h:537
struct pm_device_isr * pm_isr
Definition device.h:547
const char * name
Name of the device instance.
Definition device.h:515
struct pm_device * pm
Definition device.h:546
void * data
Address of the device instance private data.
Definition device.h:523
const void * api
Address of the API structure exposed by the device instance.
Definition device.h:519
device_flags_t flags
Device flags.
Definition device.h:527
struct device_ops ops
Device operations.
Definition device.h:525
struct device_state * state
Address of the common device state.
Definition device.h:521
const void * config
Address of device instance config information.
Definition device.h:517
const struct device_dt_metadata * dt_meta
Definition device.h:551
Device PM info.
Definition device.h:193
Runtime PM info for device with synchronous PM.
Definition device.h:241
Runtime PM info for device with generic PM.
Definition device.h:217
Linkable loadable extension symbol definitions.
Misc utilities.
Macros to abstract toolchain specific capabilities.