7#ifndef ZEPHYR_INCLUDE_DEVICE_H_ 
    8#define ZEPHYR_INCLUDE_DEVICE_H_ 
   52#define DEVICE_HANDLE_SEP INT16_MIN 
   59#define DEVICE_HANDLE_ENDS INT16_MAX 
   62#define DEVICE_HANDLE_NULL 0 
   64#define Z_DEVICE_MAX_NAME_LEN   48 
   81#define DEVICE_NAME_GET(name) _CONCAT(__device_, name) 
   93#define SYS_DEVICE_DEFINE(drv_name, init_fn, pm_control_fn, level, prio) \ 
   94        DEVICE_DEFINE(Z_SYS_NAME(init_fn), drv_name, init_fn,           \ 
   96                      NULL, NULL, level, prio, NULL) 
  137#define DEVICE_DEFINE(dev_name, drv_name, init_fn, pm_control_fn,       \ 
  138                      data_ptr, cfg_ptr, level, prio, api_ptr)          \ 
  139        Z_DEVICE_DEFINE(DT_INVALID_NODE, dev_name, drv_name, init_fn,   \ 
  141                        data_ptr, cfg_ptr, level, prio, api_ptr) 
  155#define DEVICE_DT_NAME(node_id) \ 
  156        DT_PROP_OR(node_id, label, DT_NODE_FULL_NAME(node_id)) 
  195#define DEVICE_DT_DEFINE(node_id, init_fn, pm_control_fn,               \ 
  196                         data_ptr, cfg_ptr, level, prio,                \ 
  198        Z_DEVICE_DEFINE(node_id, Z_DEVICE_DT_DEV_NAME(node_id),         \ 
  199                        DEVICE_DT_NAME(node_id), init_fn,               \ 
  201                        data_ptr, cfg_ptr, level, prio,                 \ 
  202                        api_ptr, __VA_ARGS__) 
  214#define DEVICE_DT_INST_DEFINE(inst, ...) \ 
  215        DEVICE_DT_DEFINE(DT_DRV_INST(inst), __VA_ARGS__) 
  233#define DEVICE_DT_NAME_GET(node_id) DEVICE_NAME_GET(Z_DEVICE_DT_DEV_NAME(node_id)) 
  247#define DEVICE_DT_GET(node_id) (&DEVICE_DT_NAME_GET(node_id)) 
  256#define DEVICE_DT_INST_GET(inst) DEVICE_DT_GET(DT_DRV_INST(inst)) 
  276#define DEVICE_DT_GET_ANY(compat)                                           \ 
  277        COND_CODE_1(DT_HAS_COMPAT_STATUS_OKAY(compat),                      \ 
  278                    (DEVICE_DT_GET(DT_COMPAT_GET_ANY_STATUS_OKAY(compat))), \ 
  299#define DEVICE_DT_GET_ONE(compat)                                           \ 
  300        COND_CODE_1(DT_HAS_COMPAT_STATUS_OKAY(compat),                      \ 
  301                    (DEVICE_DT_GET(DT_COMPAT_GET_ANY_STATUS_OKAY(compat))), \ 
  302                    (ZERO_OR_COMPILE_ERROR(0))) 
  316#define DEVICE_GET(name) (&DEVICE_NAME_GET(name)) 
  333#define DEVICE_DECLARE(name) static const struct device DEVICE_NAME_GET(name) 
  358#ifdef CONFIG_PM_DEVICE 
  386#ifdef CONFIG_PM_DEVICE 
  406        extern const struct device __device_start[];
 
  426static inline const struct device *
 
  429        extern const struct device __device_start[];
 
  430        extern const struct device __device_end[];
 
  431        const struct device *dev = NULL;
 
  432        size_t numdev = __device_end - __device_start;
 
  434        if ((dev_handle > 0) && ((
size_t)dev_handle <= numdev)) {
 
  435                dev = &__device_start[dev_handle - 1];
 
  516                while (region != 2) {
 
  628size_t z_device_get_all_static(
const struct device * *devices);
 
  636bool z_device_ready(
const struct device *dev);
 
  647static inline int z_device_usable_check(
const struct device *dev)
 
  649        return z_device_ready(dev) ? 0 : -
ENODEV;
 
  665static inline int z_impl_device_usable_check(
const struct device *dev)
 
  667        return z_device_usable_check(dev);
 
  703#define Z_DEVICE_DT_DEV_NAME(node_id) _CONCAT(dts_ord_, DT_DEP_ORD(node_id)) 
  708#define Z_DEVICE_STATE_NAME(dev_name) _CONCAT(__devstate_, dev_name) 
  714#define Z_DEVICE_HANDLE_NAME(node_id, dev_name)                         \ 
  715        _CONCAT(__devicehdl_,                                           \ 
  716                COND_CODE_1(DT_NODE_EXISTS(node_id),                    \ 
  720#define Z_DEVICE_EXTRA_HANDLES(...)                             \ 
  721        FOR_EACH_NONEMPTY_TERM(IDENTITY, (,), __VA_ARGS__) 
  723#ifdef CONFIG_PM_DEVICE 
  724#define Z_DEVICE_STATE_PM_INIT(node_id, dev_name)                       \ 
  725        .pm = Z_PM_DEVICE_INIT(Z_DEVICE_STATE_NAME(dev_name).pm, node_id), 
  727#define Z_DEVICE_STATE_PM_INIT(node_id, dev_name) 
  736#define Z_DEVICE_STATE_DEFINE(node_id, dev_name)                        \ 
  737        static struct device_state Z_DEVICE_STATE_NAME(dev_name)        \ 
  738        __attribute__((__section__(".z_devstate"))) = {                 \
 
  739                Z_DEVICE_STATE_PM_INIT(node_id, dev_name)               \
 
  749#define Z_DEVICE_DEFINE_PM_SLOT(dev_name)                               \ 
  750        static const Z_DECL_ALIGN(struct device *)                      \ 
  751        _CONCAT(__pm_device_slot_, DEVICE_NAME_GET(dev_name)) __used    \ 
  752        __attribute__((__section__(".z_pm_device_slots")));
 
  754#define Z_DEVICE_DEFINE_PM_SLOT(dev_name) 
  760#define Z_DEVICE_DEFINE_PRE(node_id, dev_name, ...)                     \ 
  761        Z_DEVICE_DEFINE_HANDLES(node_id, dev_name, __VA_ARGS__)         \ 
  762        Z_DEVICE_STATE_DEFINE(node_id, dev_name)                        \ 
  763        Z_DEVICE_DEFINE_PM_SLOT(dev_name) 
  805#define Z_DEVICE_DEFINE_HANDLES(node_id, dev_name, ...)                 \ 
  806        extern const device_handle_t                                    \ 
  807                Z_DEVICE_HANDLE_NAME(node_id, dev_name)[];              \ 
  808        const device_handle_t                                           \ 
  809        __aligned(sizeof(device_handle_t))                              \ 
  810        __attribute__((__weak__,                                        \ 
  811                       __section__(".__device_handles_pass1")))         \
 
  812        Z_DEVICE_HANDLE_NAME(node_id, dev_name)[] = {                   \
 
  813        COND_CODE_1(DT_NODE_EXISTS(node_id), (                          \
 
  814                        DT_DEP_ORD(node_id),                            \
 
  815                        DT_REQUIRES_DEP_ORDS(node_id)                   \
 
  817                        DEVICE_HANDLE_NULL,                             \
 
  820                        Z_DEVICE_EXTRA_HANDLES(__VA_ARGS__)             \
 
  822        COND_CODE_1(DT_NODE_EXISTS(node_id),                            \
 
  823                        (DT_SUPPORTS_DEP_ORDS(node_id)), ())            \
 
  826#ifdef CONFIG_PM_DEVICE 
  827#define Z_DEVICE_DEFINE_PM_INIT(dev_name, pm_control_fn)                \ 
  828        .pm_control = (pm_control_fn),                                  \ 
  829        .pm = &Z_DEVICE_STATE_NAME(dev_name).pm, 
  831#define Z_DEVICE_DEFINE_PM_INIT(dev_name, pm_control_fn) 
  834#define Z_DEVICE_DEFINE_INIT(node_id, dev_name, pm_control_fn)          \ 
  835                .handles = Z_DEVICE_HANDLE_NAME(node_id, dev_name),     \ 
  836                Z_DEVICE_DEFINE_PM_INIT(dev_name, pm_control_fn) 
  841#define Z_DEVICE_DEFINE(node_id, dev_name, drv_name, init_fn, pm_control_fn, \ 
  842                        data_ptr, cfg_ptr, level, prio, api_ptr, ...)   \ 
  843        Z_DEVICE_DEFINE_PRE(node_id, dev_name, __VA_ARGS__)             \ 
  844        COND_CODE_1(DT_NODE_EXISTS(node_id), (), (static))              \ 
  845                const Z_DECL_ALIGN(struct device)                       \ 
  846                DEVICE_NAME_GET(dev_name) __used                        \ 
  847        __attribute__((__section__(".z_device_" #level STRINGIFY(prio)"_"))) = { \
 
  849                .config = (cfg_ptr),                                    \
 
  851                .state = &Z_DEVICE_STATE_NAME(dev_name),                \
 
  852                .data = (data_ptr),                                     \
 
  853                Z_DEVICE_DEFINE_INIT(node_id, dev_name, pm_control_fn)  \
 
  855        BUILD_ASSERT(sizeof(Z_STRINGIFY(drv_name)) <= Z_DEVICE_MAX_NAME_LEN, \
 
  856                     Z_STRINGIFY(DEVICE_NAME_GET(drv_name)) " too long"); \
 
  857        Z_INIT_ENTRY_DEFINE(DEVICE_NAME_GET(dev_name), init_fn,         \
 
  858                (&DEVICE_NAME_GET(dev_name)), level, prio)
 
  865#include <device_extern.h> 
  867#include <syscalls/device.h> 
ZTEST_BMEM int count
Definition: main.c:33
 
volatile int rv
Definition: main.c:45
 
const struct device * device_get_binding(const char *name)
Retrieve the device structure for a driver by name.
 
int16_t device_handle_t
Type used to represent devices and functions.
Definition: device.h:45
 
static const device_handle_t * device_required_handles_get(const struct device *dev, size_t *count)
Get the set of handles for devicetree dependencies of this device.
Definition: device.h:474
 
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:507
 
static device_handle_t device_handle_get(const struct device *dev)
Get the handle for a given device.
Definition: device.h:403
 
#define DEVICE_HANDLE_NULL
Flag value used to identify an unknown device.
Definition: device.h:62
 
#define DEVICE_HANDLE_SEP
Flag value used in lists of device handles to separate distinct groups.
Definition: device.h:52
 
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:427
 
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:457
 
#define DEVICE_HANDLE_ENDS
Flag value used in lists of device handles to indicate the end of the list.
Definition: device.h:59
 
int device_usable_check(const struct device *dev)
Determine whether a device is ready for use.
 
static bool device_is_ready(const struct device *dev)
Verify that a device is ready for use.
Definition: device.h:686
 
int device_supported_foreach(const struct device *dev, device_visitor_callback_t visitor_cb, void *context)
Visit every device that dev directly supports.
 
int(* pm_device_control_callback_t)(const struct device *dev, enum pm_device_action action)
Device power management control function callback.
Definition: device.h:139
 
#define ENODEV
Definition: errno.h:58
 
static ZTEST_BMEM volatile int ret
Definition: k_float_disable.c:28
 
Definitions of various linker Sections.
 
__INT16_TYPE__ int16_t
Definition: stdint.h:43
 
Runtime device dynamic structure (in RAM) per driver instance.
Definition: device.h:343
 
bool initialized
Definition: device.h:356
 
unsigned int init_res
Definition: device.h:351
 
Runtime device structure (in ROM) per driver instance.
Definition: device.h:367
 
const char * name
Definition: device.h:369
 
const void * api
Definition: device.h:373
 
struct device_state *const state
Definition: device.h:375
 
const device_handle_t *const handles
Definition: device.h:385
 
void *const data
Definition: device.h:377
 
const void * config
Definition: device.h:371
 
Device PM info.
Definition: device.h:88
 
const struct device * dev
Definition: device.h:90