diff --git a/drivers/can/CMakeLists.txt b/drivers/can/CMakeLists.txt index 775ca34eb2b..b5fc723590c 100644 --- a/drivers/can/CMakeLists.txt +++ b/drivers/can/CMakeLists.txt @@ -4,6 +4,7 @@ zephyr_library() zephyr_sources_ifdef(CONFIG_CAN_MCUX_MCAN can_mcux_mcan.c) zephyr_library_sources_ifdef(CONFIG_CAN can_common.c) +zephyr_library_sources_ifdef(CONFIG_CAN_FAKE can_fake.c) zephyr_library_sources_ifdef(CONFIG_CAN_LOOPBACK can_loopback.c) zephyr_library_sources_ifdef(CONFIG_CAN_MCAN can_mcan.c) zephyr_library_sources_ifdef(CONFIG_CAN_MCP2515 can_mcp2515.c) diff --git a/drivers/can/Kconfig b/drivers/can/Kconfig index e2faa0d3c50..c8164ec550b 100644 --- a/drivers/can/Kconfig +++ b/drivers/can/Kconfig @@ -111,6 +111,7 @@ source "drivers/can/Kconfig.native_posix_linux" source "drivers/can/Kconfig.sja1000" source "drivers/can/Kconfig.esp32" source "drivers/can/Kconfig.kvaser" +source "drivers/can/Kconfig.fake" source "drivers/can/transceiver/Kconfig" diff --git a/drivers/can/Kconfig.fake b/drivers/can/Kconfig.fake new file mode 100644 index 00000000000..7a76ac2bb81 --- /dev/null +++ b/drivers/can/Kconfig.fake @@ -0,0 +1,13 @@ +# Fake CAN configuration options + +# Copyright (c) 2022 Vestas Wind Systems A/S +# SPDX-License-Identifier: Apache-2.0 + +config CAN_FAKE + bool "Fake CAN driver" + default y + depends on DT_HAS_ZEPHYR_FAKE_CAN_ENABLED + select CAN_HAS_CANFD + select CAN_HAS_RX_TIMESTAMP + help + Enable support for the FFF-based fake CAN driver. diff --git a/tests/drivers/can/shell/src/fake_can.c b/drivers/can/can_fake.c similarity index 98% rename from tests/drivers/can/shell/src/fake_can.c rename to drivers/can/can_fake.c index c4aa9703d82..fd700bb542f 100644 --- a/tests/drivers/can/shell/src/fake_can.c +++ b/drivers/can/can_fake.c @@ -6,15 +6,14 @@ #include #include +#include #include #ifdef CONFIG_ZTEST_NEW_API #include #endif /* CONFIG_ZTEST_NEW_API */ -#include "fake_can.h" - -#define DT_DRV_COMPAT test_fake_can +#define DT_DRV_COMPAT zephyr_fake_can DEFINE_FAKE_VALUE_FUNC(int, fake_can_start, const struct device *); diff --git a/dts/bindings/can/zephyr,fake-can.yaml b/dts/bindings/can/zephyr,fake-can.yaml new file mode 100644 index 00000000000..c84eacfcd6d --- /dev/null +++ b/dts/bindings/can/zephyr,fake-can.yaml @@ -0,0 +1,10 @@ +# Copyright (c) 2022 Vestas Wind Systems A/S +# SPDX-License-Identifier: Apache-2.0 + +description: | + This binding provides a fake CAN controller for use as either a stub or a mock in Zephyr + testing. + +compatible: "zephyr,fake-can" + +include: can-fd-controller.yaml diff --git a/tests/drivers/can/shell/src/fake_can.h b/include/zephyr/drivers/can/can_fake.h similarity index 100% rename from tests/drivers/can/shell/src/fake_can.h rename to include/zephyr/drivers/can/can_fake.h diff --git a/tests/drivers/can/shell/Kconfig b/tests/drivers/can/shell/Kconfig deleted file mode 100644 index e3abac21339..00000000000 --- a/tests/drivers/can/shell/Kconfig +++ /dev/null @@ -1,13 +0,0 @@ -# Copyright (c) 2022 Vestas Wind Systems A/S -# SPDX-License-Identifier: Apache-2.0 - -config TEST_FAKE_CAN - bool - default y - depends on DT_HAS_TEST_FAKE_CAN_ENABLED - select CAN_HAS_RX_TIMESTAMP - select CAN_HAS_CANFD - help - Enable support for the fake CAN driver. - -source "Kconfig.zephyr" diff --git a/tests/drivers/can/shell/app.overlay b/tests/drivers/can/shell/app.overlay index 1e7d0fb5621..60366fc3a52 100644 --- a/tests/drivers/can/shell/app.overlay +++ b/tests/drivers/can/shell/app.overlay @@ -6,7 +6,7 @@ /{ fake_can: fake_can { - compatible = "test-fake-can"; + compatible = "zephyr,fake-can"; status = "okay"; sjw = <1>; sample-point = <875>; diff --git a/tests/drivers/can/shell/dts/bindings/test-fake-can.yaml b/tests/drivers/can/shell/dts/bindings/test-fake-can.yaml deleted file mode 100644 index 2964bf8864a..00000000000 --- a/tests/drivers/can/shell/dts/bindings/test-fake-can.yaml +++ /dev/null @@ -1,10 +0,0 @@ -# Copyright (c) 2022 Vestas Wind Systems A/S -# SPDX-License-Identifier: Apache-2.0 - -description: | - This binding provides resources required to build and run the - tests/drivers/can/shell test in Zephyr. - -compatible: "test-fake-can" - -include: can-fd-controller.yaml diff --git a/tests/drivers/can/shell/src/main.c b/tests/drivers/can/shell/src/main.c index ce3f38019d4..cf2f5cc348c 100644 --- a/tests/drivers/can/shell/src/main.c +++ b/tests/drivers/can/shell/src/main.c @@ -4,11 +4,10 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include "fake_can.h" - #include #include +#include #include #include #include