drivers: can: make the fake CAN driver generally available

Make the fake CAN controller driver available for use in tests outside of
the CAN shell test.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
This commit is contained in:
Henrik Brix Andersen 2022-10-26 12:28:46 +02:00 committed by Marti Bolivar
commit f30a5969d0
10 changed files with 29 additions and 29 deletions

View file

@ -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)

View file

@ -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"

13
drivers/can/Kconfig.fake Normal file
View file

@ -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.

View file

@ -6,15 +6,14 @@
#include <zephyr/device.h>
#include <zephyr/drivers/can.h>
#include <zephyr/drivers/can/can_fake.h>
#include <zephyr/fff.h>
#ifdef CONFIG_ZTEST_NEW_API
#include <zephyr/ztest.h>
#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 *);

View file

@ -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

View file

@ -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"

View file

@ -6,7 +6,7 @@
/{
fake_can: fake_can {
compatible = "test-fake-can";
compatible = "zephyr,fake-can";
status = "okay";
sjw = <1>;
sample-point = <875>;

View file

@ -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

View file

@ -4,11 +4,10 @@
* SPDX-License-Identifier: Apache-2.0
*/
#include "fake_can.h"
#include <string.h>
#include <zephyr/drivers/can.h>
#include <zephyr/drivers/can/can_fake.h>
#include <zephyr/fff.h>
#include <zephyr/shell/shell.h>
#include <zephyr/shell/shell_dummy.h>