Skip to content

Conversation

@pllee4-weston
Copy link

@pllee4-weston pllee4-weston commented Jul 22, 2021

  • Rebased jukkar's work for canbus for native_posix board to latest main branch

jukkar#21
#14196

@jukkar it would be great if you can help to review as well

jukkar and others added 4 commits July 22, 2021 08:55
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>
@pllee4-weston pllee4-weston changed the title CANBUS driver for native_posix board drivers: can: CANBUS driver for native_posix board Jul 22, 2021
@rlubos
Copy link
Contributor

rlubos commented Jul 26, 2021

@cfriedt I'm not a CAN maintainer, I think it should rather be assigned to @alexanderwachter.

@rlubos rlubos removed their assignment Jul 26, 2021
zephyr_sources_ifdef(CONFIG_CAN_SHELL can_shell.c)
zephyr_sources_ifdef(CONFIG_CAN_NET can_net.c)

if(CONFIG_CAN_NATIVE_POSIX)
Copy link
Member

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"
Copy link
Member

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

@alexanderwachter
Copy link
Member

SocketCAN was written mainly maintained by @jukkar. I'm not very familiar with SocketCAN, but I can comment on the API later this week.

@henrikbrixandersen henrikbrixandersen self-requested a review August 27, 2021 21:42
@pfalcon pfalcon requested a review from jukkar September 14, 2021 21:04
@pfalcon
Copy link
Contributor

pfalcon commented Sep 14, 2021

@pllee4-weston: This now has a git conflict, please rebase.

@pfalcon
Copy link
Contributor

pfalcon commented Sep 14, 2021

@alexanderwachter on Jul 26:

I'm not very familiar with SocketCAN, but I can comment on the API later this week.

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
Copy link
Member

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));
Copy link
Member

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);
Copy link
Member

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,
Copy link
Member

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);
Copy link
Member

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);
Copy link
Member

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

Comment on lines +65 to +67
ret = -errno;
close(fd);
return ret;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ret = -errno;
close(fd);
return ret;
close(fd);
return -errno;

@alexanderwachter
Copy link
Member

Since this PR only supports socketCAN, why don't you use a socket with PF_CAN directly instead?

@github-actions
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants