Zephyr API Documentation 4.0.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
device.h File Reference
#include <stdint.h>
#include <zephyr/devicetree.h>
#include <zephyr/init.h>
#include <zephyr/linker/sections.h>
#include <zephyr/pm/state.h>
#include <zephyr/sys/device_mmio.h>
#include <zephyr/sys/iterable_sections.h>
#include <zephyr/sys/util.h>
#include <zephyr/toolchain.h>
#include <zephyr/syscalls/device.h>

Go to the source code of this file.

Data Structures

struct  device_state
 Runtime device dynamic structure (in RAM) per driver instance. More...
 
struct  device
 Runtime device structure (in ROM) per driver instance. More...
 

Macros

#define DEVICE_HANDLE_NULL   0
 Flag value used to identify an unknown device.
 
#define DEVICE_NAME_GET(dev_id)
 Expands to the name of a global device object.
 
#define DEVICE_DEFINE(dev_id, name, init_fn, pm, data, config, level, prio, api)
 Create a device object and set it up for boot time initialization.
 
#define DEVICE_DT_NAME(node_id)
 Return a string name for a devicetree node.
 
#define DEVICE_DT_DEFER(node_id)
 Determine if a devicetree node initialization should be deferred.
 
#define DEVICE_DT_DEFINE(node_id, init_fn, pm, data, config, level, prio, api, ...)
 Create a device object from a devicetree node identifier and set it up for boot time initialization.
 
#define DEVICE_DT_INST_DEFINE(inst, ...)
 Like DEVICE_DT_DEFINE(), but uses an instance of a DT_DRV_COMPAT compatible instead of a node identifier.
 
#define DEVICE_DT_NAME_GET(node_id)
 The name of the global device object for node_id.
 
#define DEVICE_DT_GET(node_id)
 Get a device reference from a devicetree node identifier.
 
#define DEVICE_DT_INST_GET(inst)
 Get a device reference for an instance of a DT_DRV_COMPAT compatible.
 
#define DEVICE_DT_GET_ANY(compat)
 Get a device reference from a devicetree compatible.
 
#define DEVICE_DT_GET_ONE(compat)
 Get a device reference from a devicetree compatible.
 
#define DEVICE_DT_GET_OR_NULL(node_id)
 Utility macro to obtain an optional reference to a device.
 
#define DEVICE_GET(dev_id)
 Obtain a pointer to a device object by name.
 
#define DEVICE_DECLARE(dev_id)
 Declare a static device object.
 
#define DEVICE_INIT_DT_GET(node_id)
 Get a init_entry reference from a devicetree node.
 
#define DEVICE_INIT_GET(dev_id)
 Get a init_entry reference from a device identifier.
 
#define DEVICE_API(_class, _name)
 Wrapper macro for declaring device API structs inside iterable sections.
 
#define DEVICE_API_GET(_class, _dev)
 Expands to the pointer of a device's API for a given class.
 
#define DEVICE_API_IS(_class, _dev)
 Macro that evaluates to a boolean that can be used to check if a device is of a particular class.
 

Typedefs

typedef int16_t device_handle_t
 Type used to represent a "handle" for a device.
 
typedef int(* device_visitor_callback_t) (const struct device *dev, void *context)
 Prototype for functions used when iterating over a set of devices.
 

Functions

static device_handle_t device_handle_get (const struct device *dev)
 Get the handle for a given device.
 
static const struct devicedevice_from_handle (device_handle_t dev_handle)
 Get the device corresponding to a handle.
 
static const device_handle_tdevice_required_handles_get (const struct device *dev, size_t *count)
 Get the device handles for devicetree dependencies of this device.
 
static const device_handle_tdevice_injected_handles_get (const struct device *dev, size_t *count)
 Get the device handles for injected dependencies of this device.
 
static const device_handle_tdevice_supported_handles_get (const struct device *dev, size_t *count)
 Get the set of handles that this device supports.
 
int device_required_foreach (const struct device *dev, device_visitor_callback_t visitor_cb, void *context)
 Visit every device that dev directly requires.
 
int device_supported_foreach (const struct device *dev, device_visitor_callback_t visitor_cb, void *context)
 Visit every device that dev directly supports.
 
const struct devicedevice_get_binding (const char *name)
 Get a device reference from its device::name field.
 
bool device_is_ready (const struct device *dev)
 Verify that a device is ready for use.
 
int device_init (const struct device *dev)
 Initialize a device.
 

Macro Definition Documentation

◆ DEVICE_API

#define DEVICE_API ( _class,
_name )
Value:
const STRUCT_SECTION_ITERABLE(Z_DEVICE_API_TYPE(_class), _name)
#define STRUCT_SECTION_ITERABLE(struct_type, varname)
Defines a new element for an iterable section.
Definition iterable_sections.h:216

Wrapper macro for declaring device API structs inside iterable sections.

Parameters
_classThe device API class.
_nameThe API instance name.

◆ DEVICE_API_GET

#define DEVICE_API_GET ( _class,
_dev )
Value:
((const struct Z_DEVICE_API_TYPE(_class) *)_dev->api)

Expands to the pointer of a device's API for a given class.

Parameters
_classThe device API class.
_devThe device instance pointer.
Returns
the pointer to the device API.

◆ DEVICE_API_IS

#define DEVICE_API_IS ( _class,
_dev )
Value:
({ \
STRUCT_SECTION_START_EXTERN(Z_DEVICE_API_TYPE(_class)); \
STRUCT_SECTION_END_EXTERN(Z_DEVICE_API_TYPE(_class)); \
(DEVICE_API_GET(_class, _dev) < STRUCT_SECTION_END(Z_DEVICE_API_TYPE(_class)) && \
DEVICE_API_GET(_class, _dev) >= STRUCT_SECTION_START(Z_DEVICE_API_TYPE(_class))); \
})
#define DEVICE_API_GET(_class, _dev)
Expands to the pointer of a device's API for a given class.
Definition device.h:1221
#define STRUCT_SECTION_END(struct_type)
iterable section end symbol for a struct type
Definition iterable_sections.h:167
#define STRUCT_SECTION_START(struct_type)
iterable section start symbol for a struct type
Definition iterable_sections.h:149

Macro that evaluates to a boolean that can be used to check if a device is of a particular class.

Parameters
_classThe device API class.
_devThe device instance pointer.
Return values
trueIf the device is of the given class
falseIf the device is not of the given class