Skip to content

Commit 2d53ce6

Browse files
keith-zephyrstephanosio
authored andcommitted
emul: add stub driver for emulators
Not all emulators correspond to a real driver. Notably some tests don't require a real driver. Provide a macro that initializes a stub driver. Signed-off-by: Keith Short <[email protected]>
1 parent 500809f commit 2d53ce6

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright 2023 Google LLC
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#ifndef ZEPHYR_INCLUDE_EMUL_STUB_DEVICE_H_
8+
#define ZEPHYR_INCLUDE_EMUL_STUB_DEVICE_H_
9+
10+
#include <zephyr/device.h>
11+
#include <zephyr/devicetree.h>
12+
13+
/*
14+
* Needed for emulators without corresponding DEVICE_DT_DEFINE drivers
15+
*/
16+
17+
struct emul_stub_dev_data {
18+
/* Stub */
19+
};
20+
struct emul_stub_dev_config {
21+
/* Stub */
22+
};
23+
struct emul_stub_dev_api {
24+
/* Stub */
25+
};
26+
27+
/* For every instance of a DT_DRV_COMPAT stub out a device for that instance */
28+
#define EMUL_STUB_DEVICE(n) \
29+
__maybe_unused static int emul_init_stub_##n(const struct device *dev) \
30+
{ \
31+
ARG_UNUSED(dev); \
32+
return 0; \
33+
} \
34+
\
35+
static struct emul_stub_dev_data stub_data_##n; \
36+
static struct emul_stub_dev_config stub_config_##n; \
37+
static struct emul_stub_dev_api stub_api_##n; \
38+
DEVICE_DT_INST_DEFINE(n, &emul_init_stub_##n, NULL, &stub_data_##n, &stub_config_##n, \
39+
POST_KERNEL, 1, &stub_api_##n);
40+
41+
#endif /* ZEPHYR_INCLUDE_EMUL_STUB_DEVICE_H_ */

0 commit comments

Comments
 (0)