SocketCAN recover from Error

This forum covers PCAN-Linux and Linux development issues concerning our products
Post Reply
bennog
Posts: 7
Joined: Tue 24. Feb 2015, 12:04

SocketCAN recover from Error

Post by bennog » Tue 24. Feb 2015, 14:31

I am working on a SocketCAN implementation in C / C++

When the Peak USB CAN dongle is in a error state (BUS-OFF in below example), I can not send messages on the bus anymore.
Receiving of messages is no problem.

Code: Select all

# ifconfig -a
can0      Link encap:UNSPEC  HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
          UP NOARP  MTU:16  Metric:1
          RX packets:44385 errors:0 dropped:0 overruns:0 frame:0
          TX packets:24948 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:10
          RX bytes:326159 (318.5 KiB)  TX bytes:188824 (184.3 KiB)

Code: Select all

# ip -d link show can0
3: can0: <NO-CARRIER,NOARP,UP,ECHO> mtu 16 qdisc pfifo_fast state DOWN mode DEFAULT qlen 10
    link/can
    can state BUS-OFF restart-ms 0
    bitrate 500000 sample-point 0.875
    tq 125 prop-seg 6 phase-seg1 7 phase-seg2 2 sjw 1
    pcan_usb: tseg1 1..16 tseg2 1..8 sjw 1..4 brp 1..64 brp-inc 1
    clock 8000000
Also the corresponding error frame(s) when the dongle switch to error state is not very clear to me:

Code: Select all

error message frame
Can worker iRes(16) 0x04 0x00 0x00 0x20 0x08 0x00 0x00 0x00
CAN id  = 0x20000004
CAN dlc = 0x8
CAN data= 0x00 0x0C 0x00 0x00 0x00 0x00 0x00 0x00

error message frame
Can worker iRes(16) 0x04 0x00 0x00 0x20 0x08 0x00 0x00 0x00
CAN id  = 0x20000004
CAN dlc = 0x8
CAN data= 0x00 0x30 0x00 0x00 0x00 0x00 0x00 0x00

error message frame
Can worker iRes(16) 0x40 0x00 0x00 0x20 0x08 0x00 0x00 0x00
CAN id  = 0x20000040
CAN dlc = 0x8
CAN data= 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
Benno

bennog
Posts: 7
Joined: Tue 24. Feb 2015, 12:04

Re: SocketCAN recover from Error

Post by bennog » Wed 25. Feb 2015, 17:39

As always the solution is simple :D

Code: Select all

ip link set can0 type can restart-ms 100
then the controller auto recovers from bus-off errors.

Benno

Post Reply