From: Tom Evans <tom_usenet@optusnet.com.au>
To: Mike Purvis <mpurvis@clearpathrobotics.com>, linux-can@vger.kernel.org
Subject: Re: Standard CAN over IP
Date: Thu, 05 Feb 2015 10:43:32 +1100 [thread overview]
Message-ID: <54D2AEA4.30405@optusnet.com.au> (raw)
In-Reply-To: <CACsJT9Nxv2Vuq92nnOw4eN6j-RycpqGRErsjp5R_LiMwdS13aQ@mail.gmail.com>
On 05/02/15 07:27, Mike Purvis wrote:
> Hi all,
>
> I'm interested in providing low-cost CAN connectivity to a standard
> Mini-ITX PC— so USB, Ethernet, RS232, PCIe connectivity is available,
> but not I2C or SPI (at least easily).
The obvious approach is to use a PCAN-USB. I guess you want something cheaper
(these are 195 Euros each). Effectively you're making one of these:
http://www.peak-system.com/PCAN-Ethernet-Gateway-DR.330.0.html?&L=1
So you have the "Mini-ITX" presumably running Linux, and you want to bridge
CAN over Ethernet to a Microcontroller that has one or more physical CAN ports
on it. I would guess the latter doesn't have to run Linux.
I've implemented that sort of thing, but the other way around. We have a micro
not running Linux with two CAN ports on it. It communicates over UDP with a
small embedded Linux system. The latter provides three CAN ports that are
bridged over Ethernet to appear to be "physical" ports on the first one. Two
of those ports are physical ones on the Linux micro, and the third is a
virtual VCAN port.
So the first micro thinks it has 5 CAN ports. The VCAN bus on the Linux micro
allows us to run multiple Linux user programs which can each be configured to
either run on a physical CAN port (for some product configurations) or on the
VCAN bus when they need to be controlled by the other micro over Ethernet.
So then you have the question - which device is now in charge of setting the
baud rate and the time quanta for these bridged ports? In our case we let the
first micro set this up, so there has to be an "Open port and configure it
this way" message in the UDP packets together with the Receive and Transmit
framing of CAN messages.
We also signal CAN error states back over UDP, so we have Open, Close,
Configure, Receive, Transmit and Status messages (and "Transmit Multiple").
You can open one UDP port for all the available CAN buses on a unit, one UDP
port for each separate CAN port or a separate UDP port for each CAN ID on each
bus (which requires setting filters). It all depends on how and where (in
software) you want to demultiplex the CAN IDs to the relevant programs, and
whether you want to pack multiple CAN frames in one UDP packet.
We found it easiest to let VCAN do the demultiplexing, as that's what the
SocketCAN interface is very good at.
So we have a user "Bridge" program that receives the UDP frames, interprets
them and simply receives and sends to the two physical CAN ports and the VCAN
port. The user application programs on the Linux box open connections to the
VCAN bus with the appropriate ID filters.
We open one UDP connection with a "port selector" field in each encapsulated
CAN message in the UDP packet. That allows us to pack multiple CAN messages
for multiple ports in the one UDP packet. It creates too much overhead for
both CPUs to put one 8-bytes-of-data CAN message in a
1500-bytes-available-with-60-bytes-overhead UDP packet.
Another consideration is that at the hardware level, CAN is a reliable
protocol. The message got through or it didn't (unless a software bug or
buffer overflow dropped the packet in the receiving device). UDP is the
UNRELIABLE Datagram Protocol. If this is a problem for your usage you might
want CAN over TCP or you might want to add some error handling or packet retry
layer (in other words, try to reinvent TCP all over again).
Another problem is that transmission and reception on physical CAN ports can
often be timestamped to the microsecond. Some uses of CAN rely on this. When
you bridge over Ethernet (and with all the Linux non-real-time problems) you
get some pretty bad latencies, or at least worse ones than the physical ports
provide.
If you have a very busy 1MBit/sec physical CAN bus and you want to connect
your PC to it over the Ethernet bridge, and the PC program is only sending or
receiving messages at a low rate, then you probably don't want everything on
that busy bus to be dumped onto a VCAN bus inside the PC. In that case you
would want a connection that allows CAN filters on the physical port. How
would you configure that if you needed to?
We're finding that a single 43% busy bridged CAN bus can take up 13% of the
total CPU time on our 800MHz ARM CPU.
> I noticed an interesting past discussion on this topic:
That suggested a user program receiving all packets on VCAN and sending them
over UDP and vice versa. That's pretty much what we have.
Tom
next prev parent reply other threads:[~2015-02-04 23:43 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-02-04 20:27 Standard CAN over IP Mike Purvis
2015-02-04 20:44 ` Armin Burchardt
2015-02-04 21:38 ` Mike Purvis
2015-02-04 22:42 ` Gerhard Bertelsmann
2015-02-05 0:50 ` Tom Evans
2015-02-05 13:15 ` Mike Purvis
2015-02-06 8:33 ` Michal Sojka
2015-02-09 16:00 ` Mike Purvis
2015-02-09 18:32 ` Oliver Hartkopp
2015-02-04 23:43 ` Tom Evans [this message]
2015-02-18 17:57 ` Maximilian Güntner
[not found] ` <CACsJT9M4QbYkDvQkGfhFuwA6haNyV5zesUFtLzB5VEbxP=obBA@mail.gmail.com>
2015-02-19 3:21 ` Mike Purvis
2015-02-19 14:58 ` Maximilian Güntner
2015-02-20 11:43 ` Oliver Hartkopp
2015-02-23 12:25 ` Maximilian Güntner
2015-02-23 13:08 ` Oliver Hartkopp
2015-02-23 14:27 ` Maximilian Güntner
2015-02-23 16:22 ` Oliver Hartkopp
2015-03-20 16:54 ` Maximilian Güntner
2015-03-23 10:28 ` Pankajkumar Misra (RBEI/EEA2)
2015-03-23 13:15 ` Maximilian Güntner
2015-03-23 16:57 ` Pankajkumar Misra (RBEI/EEA2)
2015-03-23 13:23 ` GARNERO, PIERRE (P.)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=54D2AEA4.30405@optusnet.com.au \
--to=tom_usenet@optusnet.com.au \
--cc=linux-can@vger.kernel.org \
--cc=mpurvis@clearpathrobotics.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).