-
Notifications
You must be signed in to change notification settings - Fork 8.3k
drivers: can: CANBUS driver for native_posix board #37124
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
drivers: can: CANBUS driver for native_posix board #37124
Conversation
This initial version supports SocketCAN. The driver passes CANBUS data between Linux vcan virtual CAN driver and Zephyr. You also need to use can-setup.sh script from the net-tools project in order to make communication work with Linux vcan driver. Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Add native_posix board support to socket-can sample application. Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
…2.6.0 Update file name canbus_native_posix_xx.x to can_native_posix_xx.x to keep consistent with can driver for other platforms. Update implementation to work with the current state of zephyr and update samples/net/sockets/can/boards/native_posix.conf. Replace deprecated DEVICE_AND_API_INIT() with DEVICE_DT_INST_DEFINE() and add can_1 and can_2 in native_posix.dts. Signed-off-by: Ruixiang Du <ruixiang.du@westonrobot.com>
Move struct socket_can_context to socket_can_context.h to ensure struct socket_can_context can be included without replying on socket_can_generic.h. Change rx thread of canbus to be preemptive to avoid can frame loss. Update naming of _ENABLE to _ENABLED to follow convention in Kconfig.native_posix. Signed-off-by: Pin Loon Lee <pinloon.lee@westonrobot.com>
|
@cfriedt I'm not a CAN maintainer, I think it should rather be assigned to @alexanderwachter. |
| zephyr_sources_ifdef(CONFIG_CAN_SHELL can_shell.c) | ||
| zephyr_sources_ifdef(CONFIG_CAN_NET can_net.c) | ||
|
|
||
| if(CONFIG_CAN_NATIVE_POSIX) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a quick comment: socket CAN is only available on Linux, so I think a name other than "native_posix" should be used. The build should only be available on Linux hosts actually (maybe CMAKE_HOST_SYSTEM_NAME can be useful here?)
| config CAN_NATIVE_POSIX_INTERFACE_1_NAME | ||
| string "CANBUS interface 1 name on Linux side" | ||
| depends on CAN_NATIVE_POSIX_INTERFACE_1_ENABLED | ||
| default "vcan0" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DeviceTree can likely be used for that
|
SocketCAN was written mainly maintained by @jukkar. I'm not very familiar with SocketCAN, but I can comment on the API later this week. |
|
@pllee4-weston: This now has a git conflict, please rebase. |
|
@alexanderwachter on Jul 26:
It still would be nice to get a review from you, as you're the CAN guy ;-). |
|
|
||
| #define DT_DRV_COMPAT zephyr_native_posix_can | ||
|
|
||
| #define LOG_MODULE_NAME canbus_posix |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These can go to the registration in line 20
| } | ||
| } | ||
|
|
||
| k_sleep(K_MSEC(10)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is there a sleep? Do you need to poll for the interface up?
| int ret = -ENODEV; | ||
|
|
||
| ARG_UNUSED(timeout); | ||
| ARG_UNUSED(callback_isr); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would rather return an error in case someone pass a callback.
Since callbacks are not supported, this driver may not work with other CAN subsys like ISO-TP or canopen.
| return ret < 0 ? ret : 0; | ||
| } | ||
|
|
||
| static int canbus_np_attach_isr(const struct device *dev, can_rx_callback_t isr, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do you want to receive any frame if this function is empty?
Seems that you only want to support socketCAN. If so, please remove the z_can API
|
|
||
| ctx->dev_fd = canbus_np_iface_open(ctx->if_name); | ||
| if (ctx->dev_fd < 0) { | ||
| LOG_ERR("Cannot open %s (%d)", ctx->if_name, ctx->dev_fd); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Return an error?
| #define LOG_LEVEL CONFIG_CAN_LOG_LEVEL | ||
|
|
||
| #include <logging/log.h> | ||
| LOG_MODULE_REGISTER(LOG_MODULE_NAME); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above, move the name and level as arguments to this macro
| ret = -errno; | ||
| close(fd); | ||
| return ret; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| ret = -errno; | |
| close(fd); | |
| return ret; | |
| close(fd); | |
| return -errno; |
|
Since this PR only supports socketCAN, why don't you use a socket with PF_CAN directly instead? |
|
This pull request has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this pull request will automatically be closed in 14 days. Note, that you can always re-open a closed pull request at any time. |
jukkar#21
#14196
@jukkar it would be great if you can help to review as well