@@ -36,6 +36,7 @@ enum emul_bus_type {
36
36
EMUL_BUS_TYPE_I2C ,
37
37
EMUL_BUS_TYPE_ESPI ,
38
38
EMUL_BUS_TYPE_SPI ,
39
+ EMUL_BUS_TYPE_NONE ,
39
40
};
40
41
41
42
/**
@@ -62,6 +63,14 @@ struct emul_list_for_bus {
62
63
*/
63
64
typedef int (* emul_init_t )(const struct emul * emul , const struct device * parent );
64
65
66
+ /**
67
+ * Emulator API stub when an emulator is not actually placed on a bus.
68
+ */
69
+ struct no_bus_emul {
70
+ void * api ;
71
+ uint16_t addr ;
72
+ };
73
+
65
74
/** An emulator instance - represents the *target* emulated device/peripheral that is
66
75
* interacted with through an emulated bus. Instances of emulated bus nodes (e.g. i2c_emul)
67
76
* and emulators (i.e. struct emul) are exactly 1..1
@@ -82,6 +91,7 @@ struct emul {
82
91
struct i2c_emul * i2c ;
83
92
struct espi_emul * espi ;
84
93
struct spi_emul * spi ;
94
+ struct no_bus_emul * none ;
85
95
} bus ;
86
96
/** Address of the API structure exposed by the emulator instance */
87
97
const void * backend_api ;
@@ -101,10 +111,10 @@ struct emul {
101
111
#define Z_EMUL_REG_BUS_IDENTIFIER (_dev_node_id ) (_CONCAT(_CONCAT(__emulreg_, _dev_node_id), _bus))
102
112
103
113
/* Conditionally places text based on what bus _dev_node_id is on. */
104
- #define Z_EMUL_BUS (_dev_node_id , _i2c , _espi , _spi ) \
114
+ #define Z_EMUL_BUS (_dev_node_id , _i2c , _espi , _spi , _none ) \
105
115
COND_CODE_1(DT_ON_BUS(_dev_node_id, i2c), (_i2c), \
106
116
(COND_CODE_1(DT_ON_BUS(_dev_node_id, espi), (_espi), \
107
- (COND_CODE_1(DT_ON_BUS(_dev_node_id, spi), (_spi), (-EINVAL ))))))
117
+ (COND_CODE_1(DT_ON_BUS(_dev_node_id, spi), (_spi), (_none ))))))
108
118
/**
109
119
* @brief Define a new emulator
110
120
*
@@ -120,10 +130,10 @@ struct emul {
120
130
* @param _backend_api emulator-specific backend api
121
131
*/
122
132
#define EMUL_DT_DEFINE (node_id , init_fn , data_ptr , cfg_ptr , bus_api , _backend_api ) \
123
- static struct Z_EMUL_BUS(node_id, i2c_emul, espi_emul, spi_emul) \
133
+ static struct Z_EMUL_BUS(node_id, i2c_emul, espi_emul, spi_emul, no_bus_emul) \
124
134
Z_EMUL_REG_BUS_IDENTIFIER(node_id) = { \
125
135
.api = bus_api, \
126
- .Z_EMUL_BUS(node_id, addr, chipsel, chipsel) = DT_REG_ADDR(node_id), \
136
+ .Z_EMUL_BUS(node_id, addr, chipsel, chipsel, addr ) = DT_REG_ADDR(node_id), \
127
137
}; \
128
138
const STRUCT_SECTION_ITERABLE(emul, EMUL_DT_NAME_GET(node_id)) \
129
139
__used = { \
@@ -132,8 +142,8 @@ struct emul {
132
142
.cfg = (cfg_ptr), \
133
143
.data = (data_ptr), \
134
144
.bus_type = Z_EMUL_BUS(node_id, EMUL_BUS_TYPE_I2C, EMUL_BUS_TYPE_ESPI, \
135
- EMUL_BUS_TYPE_SPI), \
136
- .bus = {.Z_EMUL_BUS(node_id, i2c, espi, spi) = \
145
+ EMUL_BUS_TYPE_SPI, EMUL_BUS_TYPE_NONE), \
146
+ .bus = {.Z_EMUL_BUS(node_id, i2c, espi, spi, none ) = \
137
147
&(Z_EMUL_REG_BUS_IDENTIFIER(node_id))}, \
138
148
.backend_api = (_backend_api), \
139
149
};
0 commit comments