Zephyr Project API  3.2.0
A Scalable Open Source RTOS
Emulator interface

Emulators used to test drivers and higher-level code that uses them. More...

Modules

 I2C Emulation Interface
 I2C Emulation Interface.
 
 SPI Emulation Interface
 SPI Emulation Interface.
 
 eSPI Emulation Interface
 eSPI Emulation Interface
 

Data Structures

struct  emul_link_for_bus
 
struct  emul_list_for_bus
 
struct  emul
 

Macros

#define EMUL_DT_NAME_GET(node_id)   _CONCAT(__emulreg_, node_id)
 Use the devicetree node identifier as a unique name. More...
 
#define EMUL_DT_DEFINE(node_id, init_fn, data_ptr, cfg_ptr, bus_api)
 Define a new emulator. More...
 
#define EMUL_DT_INST_DEFINE(inst, ...)   EMUL_DT_DEFINE(DT_DRV_INST(inst), __VA_ARGS__)
 Like EMUL_DT_DEFINE(), but uses an instance of a DT_DRV_COMPAT compatible instead of a node identifier. More...
 
#define EMUL_DT_GET(node_id)   (&EMUL_DT_NAME_GET(node_id))
 Get a const struct emul* from a devicetree node identifier. More...
 

Typedefs

typedef int(* emul_init_t) (const struct emul *emul, const struct device *parent)
 

Enumerations

enum  emul_bus_type { EMUL_BUS_TYPE_I2C , EMUL_BUS_TYPE_ESPI , EMUL_BUS_TYPE_SPI }
 

Functions

 DT_FOREACH_STATUS_OKAY_NODE (Z_MAYBE_EMUL_DECLARE_INTERNAL)
 
int emul_init_for_bus (const struct device *dev)
 
const struct emulemul_get_binding (const char *name)
 Retrieve the emul structure for an emulator by name. More...
 

Detailed Description

Emulators used to test drivers and higher-level code that uses them.

Macro Definition Documentation

◆ EMUL_DT_DEFINE

#define EMUL_DT_DEFINE (   node_id,
  init_fn,
  data_ptr,
  cfg_ptr,
  bus_api 
)

#include <include/zephyr/drivers/emul.h>

Value:
static struct Z_EMUL_BUS(node_id, i2c_emul, espi_emul, spi_emul) \
Z_EMUL_REG_BUS_IDENTIFIER(node_id) = { \
.api = bus_api, \
.Z_EMUL_BUS(node_id, addr, chipsel, chipsel) = DT_REG_ADDR(node_id), \
}; \
const struct emul EMUL_DT_NAME_GET(node_id) __attribute__((__section__(".emulators"))) \
__used = { \
.init = (init_fn), \
.dev = DEVICE_DT_GET(node_id), \
.cfg = (cfg_ptr), \
.data = (data_ptr), \
.bus_type = Z_EMUL_BUS(node_id, EMUL_BUS_TYPE_I2C, EMUL_BUS_TYPE_ESPI, \
.bus = {.Z_EMUL_BUS(node_id, i2c, espi, spi) = \
&(Z_EMUL_REG_BUS_IDENTIFIER(node_id))}, \
};
#define DEVICE_DT_GET(node_id)
Get a const struct device* from a devicetree node identifier.
Definition: device.h:282
#define DT_REG_ADDR(node_id)
Get a node's (only) register block address.
Definition: devicetree.h:2017
#define EMUL_DT_NAME_GET(node_id)
Use the devicetree node identifier as a unique name.
Definition: emul.h:98
@ EMUL_BUS_TYPE_SPI
Definition: emul.h:36
@ EMUL_BUS_TYPE_I2C
Definition: emul.h:34
@ EMUL_BUS_TYPE_ESPI
Definition: emul.h:35
static int init_fn(const struct device *dev)
Definition: main.c:241
Definition: emul.h:67
const struct device * dev
Definition: emul.h:71
Definition: espi_emul.h:110
Definition: i2c_emul.h:35
Definition: spi_emul.h:36
static fdata_t data[2]
Definition: test_fifo_contexts.c:15

Define a new emulator.

This adds a new struct emul to the linker list of emulations. This is typically used in your emulator's DT_INST_FOREACH_STATUS_OKAY() clause.

Parameters
node_idNode ID of the driver to emulate (e.g. DT_DRV_INST(n)); the node_id MUST have a corresponding DEVICE_DT_DEFINE().
init_fnfunction to call to initialise the emulator (see emul_init typedef)
data_ptremulator-specific data
cfg_ptremulator-specific configuration data
bus_apiemulator-specific bus api

◆ EMUL_DT_GET

#define EMUL_DT_GET (   node_id)    (&EMUL_DT_NAME_GET(node_id))

#include <include/zephyr/drivers/emul.h>

Get a const struct emul* from a devicetree node identifier.

Returns a pointer to an emulator object created from a devicetree node, if any device was allocated by an emulator implementation.

If no such device was allocated, this will fail at linker time. If you get an error that looks like undefined reference to __device_dts_ord_<N>, that is what happened. Check to make sure your emulator implementation is being compiled, usually by enabling the Kconfig options it requires.

Parameters
node_idA devicetree node identifier
Returns
A pointer to the emul object created for that node

◆ EMUL_DT_INST_DEFINE

#define EMUL_DT_INST_DEFINE (   inst,
  ... 
)    EMUL_DT_DEFINE(DT_DRV_INST(inst), __VA_ARGS__)

#include <include/zephyr/drivers/emul.h>

Like EMUL_DT_DEFINE(), but uses an instance of a DT_DRV_COMPAT compatible instead of a node identifier.

Parameters
instinstance number. The node_id argument to EMUL_DT_DEFINE is set to DT_DRV_INST(inst).
...other parameters as expected by EMUL_DT_DEFINE.

◆ EMUL_DT_NAME_GET

#define EMUL_DT_NAME_GET (   node_id)    _CONCAT(__emulreg_, node_id)

#include <include/zephyr/drivers/emul.h>

Use the devicetree node identifier as a unique name.

Parameters
node_idA devicetree node identifier

Typedef Documentation

◆ emul_init_t

typedef int(* emul_init_t) (const struct emul *emul, const struct device *parent)

#include <include/zephyr/drivers/emul.h>

Standard callback for emulator initialisation providing the initialiser record and the device that calls the emulator functions.

Parameters
emulEmulator to init
parentParent device that is using the emulator

Enumeration Type Documentation

◆ emul_bus_type

#include <include/zephyr/drivers/emul.h>

The types of supported buses.

Enumerator
EMUL_BUS_TYPE_I2C 
EMUL_BUS_TYPE_ESPI 
EMUL_BUS_TYPE_SPI 

Function Documentation

◆ DT_FOREACH_STATUS_OKAY_NODE()

DT_FOREACH_STATUS_OKAY_NODE ( Z_MAYBE_EMUL_DECLARE_INTERNAL  )

◆ emul_get_binding()

const struct emul * emul_get_binding ( const char *  name)

#include <include/zephyr/drivers/emul.h>

Retrieve the emul structure for an emulator by name.

Emulator objects are created via the EMUL_DT_DEFINE() macro and placed in memory by the linker. If the emulator structure is needed for custom API calls, it can be retrieved by the name that the emulator exposes to the system (this is the devicetree node's label by default).

Parameters
nameEmulator name to search for. A null pointer, or a pointer to an empty string, will cause NULL to be returned.
Returns
pointer to emulator structure; NULL if not found or cannot be used.

◆ emul_init_for_bus()

int emul_init_for_bus ( const struct device dev)

#include <include/zephyr/drivers/emul.h>

Set up a list of emulators

Parameters
devDevice the emulators are attached to (e.g. an I2C controller)
Returns
0 if OK
negative value on error