Skip to content

Commit 77e4c65

Browse files
martinjaegercarlescufi
authored andcommitted
drivers: can: native_posix_linux: initial implementation
This driver provides an interface to SocketCAN interfaces of the Linux system running a Zephyr application with the native_posix board. These interfaces may be virtual or actual CAN buses. Signed-off-by: Martin Jäger <martin@libre.solar>
1 parent fd4d188 commit 77e4c65

File tree

8 files changed

+702
-1
lines changed

8 files changed

+702
-1
lines changed

boards/posix/native_posix/native_posix.dts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,4 +194,16 @@
194194
sample-point = <875>;
195195
bus-speed = <125000>;
196196
};
197+
198+
can0: can {
199+
status = "disabled";
200+
compatible = "zephyr,native-posix-linux-can";
201+
/* adjust zcan0 to desired host interface or create an alternative
202+
* name, e.g.: sudo ip link property add dev vcan0 altname zcan0
203+
*/
204+
host-interface = "zcan0";
205+
sjw = <1>;
206+
sample-point = <875>;
207+
bus-speed = <125000>;
208+
};
197209
};

drivers/can/CMakeLists.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,21 @@ zephyr_library_sources_ifdef(CONFIG_CAN_STM32FD can_stm32fd.c)
1414
zephyr_library_sources_ifdef(CONFIG_CAN_STM32H7 can_stm32h7.c)
1515
zephyr_library_sources_ifdef(CONFIG_CAN_RCAR can_rcar.c)
1616

17+
if(CONFIG_CAN_NATIVE_POSIX_LINUX)
18+
if(${CMAKE_HOST_SYSTEM_NAME} STREQUAL Linux)
19+
zephyr_library_include_directories(${ZEPHYR_BASE}/subsys/net/l2)
20+
zephyr_library_compile_definitions(NO_POSIX_CHEATS)
21+
zephyr_library_compile_definitions(_BSD_SOURCE)
22+
zephyr_library_compile_definitions(_DEFAULT_SOURCE)
23+
zephyr_library_sources(
24+
can_native_posix_linux.c
25+
can_native_posix_linux_socketcan.c
26+
)
27+
else()
28+
message(FATAL_ERROR "CONFIG_CAN_NATIVE_POSIX_LINUX only available on Linux")
29+
endif()
30+
endif()
31+
1732
zephyr_library_sources_ifdef(CONFIG_CAN_SJA1000 can_sja1000.c)
1833
zephyr_library_sources_ifdef(CONFIG_CAN_ESP32_TWAI can_esp32_twai.c)
1934

drivers/can/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ source "drivers/can/Kconfig.mcp2515"
9898
source "drivers/can/Kconfig.mcan"
9999
source "drivers/can/Kconfig.rcar"
100100
source "drivers/can/Kconfig.loopback"
101-
101+
source "drivers/can/Kconfig.native_posix_linux"
102102
source "drivers/can/Kconfig.sja1000"
103103
source "drivers/can/Kconfig.esp32"
104104

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Native Linux SocketCAN configuration options
2+
3+
# Copyright (c) 2022 Martin Jäger <martin@libre.solar>
4+
# SPDX-License-Identifier: Apache-2.0
5+
6+
config CAN_NATIVE_POSIX_LINUX
7+
bool "Native Linux SocketCAN Driver"
8+
default y
9+
depends on DT_HAS_ZEPHYR_NATIVE_POSIX_LINUX_CAN_ENABLED
10+
help
11+
Enable native Linux SocketCAN Driver
12+
13+
if CAN_NATIVE_POSIX_LINUX
14+
15+
config CAN_NATIVE_POSIX_LINUX_RX_THREAD_PRIORITY
16+
int "Priority for internal RX thread"
17+
default 2
18+
help
19+
Priority level of the internal thread which is run for
20+
handling of incoming packets.
21+
22+
config CAN_MAX_FILTER
23+
int "Maximum number of concurrent active filters"
24+
default 5
25+
range 1 32
26+
help
27+
Defines the array size of the callback/msgq pointers.
28+
Must be at least the size of concurrent reads.
29+
30+
endif # CAN_NATIVE_POSIX_LINUX

0 commit comments

Comments
 (0)