Losing CAN messages with socket-CAN
Hi Marc,
Thanks for the fast response. I've collected answers to your questions and pasted them below.
Best Regards,
Jeroen Lammertink
--------------------------------------------------------------------------
<> We are sending batches of 80 CAN messages using socket CAN to transfer an <> image for download. After the 80 messages we wait for a response
<Are you evaluating the return value of the write() or sendmsg() systemcall?
We do evaluate the write call to the socket with an assert. I’ve included the code below. (See CCanPort::Write()). I’ve also included the code in which the socket is created, just to be complete. When the problem (of losing CAN messages) happens, the Assert is not triggered. So I deduce that the socket remains unaware of the losing of messages.
<> consisting of a single CAN message. Within the messages we have coded a <> sequence number, so that we can detect lost messages. Besides the CAN <> device that is subject of download, we have also a (hardware) CAN sniffer <> on the CAN bus. We typically log CAN messages when we put them in the <> socket. With this set-up we typically detect losing a short series of <> (mostly 5) CAN messages, somewhere halfway the batch of 80. No other <> devices are present on the CAN bus.
<> I've dumped below some version and set-up info of Ubuntu, socket-can and <> ifconfig.
<> Is this problem known?
<> May this problem be related to using an old version of socket can?
< This is either a userspace problem or a buggy driver. The driver problem < may have been fixed in the meantime.
<> How can I upgrade Ubuntu to the latest versions of socket-can?
< First we have to figure out what's broken.
<> -------------------------------------------------------------------------- <> bmterra@q7buntu:~/user/jla$ uname -a
<> Linux q7buntu 3.5.0-26-generic #42~precise1-Ubuntu SMP Mon Mar 11 22:19:42 <> UTC 2013 i686 i686 i386 GNU/Linux
<> bmterra@q7buntu:~/user/jla$ cat /proc/net/can/version
<> rev 20090105 abi 8
<> bmterra@q7buntu:~/user/jla$ ifconfig can0
<> can0 Link encap:UNSPEC HWaddr
<> 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
<> UP RUNNING NOARP MTU:16 Metric:1 <> RX packets:1128 errors:0 dropped:0 overruns:0 frame:0 <> TX packets:4400 errors:0 dropped:0 overruns:0 carrier:0 <> collisions:0 txqueuelen:1024 <> RX bytes:9024 (9.0 KB) TX bytes:34176 (34.1 KB) <> Interrupt:18
<> --------------------------------------------------------------------------
< Which CAN hardware are you using?
Qseven module PQ7-M105IT
with Intel Platform Controller HUB EG20T IOH
with a “BOSCH CAN Protocol Version 2.0B Active
(ISO 11519, ISO 11898, and SAEJ2411)” CAN controller
This CAN controller identifies itself (according to data sheet) as follows:
Vendor Identification Register 8086h
Device Identification Register 8818h
Revision Identification Register 00h
Class Code Register 0C0900h--------------------------------------------------------------------------
size_t CCanPort::Write(can_frame *pFrame)
{
ssize_t ret = write(m_Sock, pFrame, sizeof(*pFrame));
ASSERT(ret == sizeof(*pFrame));
return ret;
}CCanPort::CCanPort()
{
int rcvbuf_size = BUFFER_SIZE;
m_Sock = socket( PF_CAN, SOCK_RAW, CAN_RAW );
struct ifreq ifr;
strcpy(ifr.ifr_name, "can0");
ioctl(m_Sock, SIOCGIFINDEX, &ifr);
struct sockaddr_can addr;
addr.can_family = AF_CAN;
addr.can_ifindex = ifr.ifr_ifindex;
// Set receive buffer size
setsockopt(m_Sock, SOL_SOCKET, SO_RCVBUF, &rcvbuf_size, sizeof(rcvbuf_size));
// Bind
bind( m_Sock, (struct sockaddr*)&addr, sizeof(addr) );
}Quoted 58 lines · j.p.lammertink
Hi Marc,
Thanks for the fast response. I've collected answers to your questions and pasted them below.
Best Regards,
Jeroen Lammertink
--------------------------------------------------------------------------
<> We are sending batches of 80 CAN messages using socket CAN to transfer an <> image for download. After the 80 messages we wait for a response
<Are you evaluating the return value of the
write()orsendmsg()systemcall?We do evaluate the write call to the socket with an assert. I’ve included the code below. (See
CCanPort::Write()). I’ve also included the code in which the socket is created, just to be complete. When the problem (of losing CAN messages) happens, the Assert is not triggered. So I deduce that the socket remains unaware of the losing of messages.<> consisting of a single CAN message. Within the messages we have coded a <> sequence number, so that we can detect lost messages. Besides the CAN <> device that is subject of download, we have also a (hardware) CAN sniffer <> on the CAN bus. We typically log CAN messages when we put them in the <> socket. With this set-up we typically detect losing a short series of <> (mostly 5) CAN messages, somewhere halfway the batch of 80. No other <> devices are present on the CAN bus.
<> I've dumped below some version and set-up info of Ubuntu, socket-can and <> ifconfig.
<> Is this problem known?
<> May this problem be related to using an old version of socket can?< This is either a userspace problem or a buggy driver. The driver problem < may have been fixed in the meantime.
<> How can I upgrade Ubuntu to the latest versions of socket-can?
< First we have to figure out what's broken.
<> -------------------------------------------------------------------------- <> bmterra@q7buntu:~/user/jla$ uname -a
<> Linux q7buntu 3.5.0-26-generic #42~precise1-Ubuntu SMP Mon Mar 11 22:19:42 <> UTC 2013 i686 i686 i386 GNU/Linux
<> bmterra@q7buntu:~/user/jla$ cat/proc/net/can/version
<> rev 20090105 abi 8
<> bmterra@q7buntu:~/user/jla$ ifconfig can0
<> can0 Link encap:UNSPEC HWaddr
<> 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00<> UP RUNNING NOARP MTU:16 Metric:1 <> RX packets:1128 errors:0 dropped:0 overruns:0 frame:0 <> TX packets:4400 errors:0 dropped:0 overruns:0 carrier:0 <> collisions:0 txqueuelen:1024 <> RX bytes:9024 (9.0 KB) TX bytes:34176 (34.1 KB) <> Interrupt:18
Quoted 8 lines
<> --------------------------------------------------------------------------
< Which CAN hardware are you using?
Qseven module PQ7-M105IT
with Intel Platform Controller HUB EG20T IOH
with a “BOSCH CAN Protocol Version 2.0B Active(ISO 11519, ISO 11898, and SAEJ2411)” CAN controller
Which driver do you use? (check "ip -d -s link show can0").
Quoted 5 lines
This CAN controller identifies itself (according to data sheet) as follows:
Vendor Identification Register 8086h Device Identification Register 8818h Revision Identification Register 00h Class Code Register 0C0900h
Ah, the "pch_can" driver does have known issues. End of last year I sent some patches to improve the "pch_can" or, even better, make the "c_can" driver work on the EG20T as well. See:
http://marc.info/?l=linux-can&m=135531975013055&w=2
Are you able to build and use a recent mainline kernel? I need to figure out how to help you best.
Wolfgang.