Thread (5 messages) 5 messages, 4 authors, 2021-11-05

Re: sjw in can_calc_bittiming

From: Oliver Hartkopp <socketcan@hartkopp.net>
Date: 2021-11-02 15:36:12

Hi Matthias,

On 02.11.21 16:03, Matthias Weißer wrote:
we recently had a case here where one member of a CAN bus couldn't receive
frames with data content of only zeros:

$ cansend can0 123#0000000000000000

After some investigation we found the root cause to be a slight difference
(about 1%) in actual bitrates of the two members. The one with showed the
RX errors had a sjw value of 1 and a lot of time quanta (40) due to the 40MHz
CAN clock.

This leads to a build up of phase error (as sjw is not able to compensate for
enough of the bitrate difference) which at some point leads to a framing
error due to missing a stuff bit. Playing around with the sample point can
improve or worsen the behavior.

We can fix this quite easily by specifying a higher sjw value.
You can specify the sjw value with the ip command (for CAN FD there is 
also a dsjw). And IIRC you can set it to the max. value for your CAN 
controller if you define sjw to be 4.

Best regards,
Oliver

$ ip link help can
Usage: ip link set DEVICE type can
	[ bitrate BITRATE [ sample-point SAMPLE-POINT] ] |
	[ tq TQ prop-seg PROP_SEG phase-seg1 PHASE-SEG1
  	  phase-seg2 PHASE-SEG2 [ sjw SJW ] ]

	[ dbitrate BITRATE [ dsample-point SAMPLE-POINT] ] |
	[ dtq TQ dprop-seg PROP_SEG dphase-seg1 PHASE-SEG1
  	  dphase-seg2 PHASE-SEG2 [ dsjw SJW ] ]

	[ loopback { on | off } ]
	[ listen-only { on | off } ]
	[ triple-sampling { on | off } ]
	[ one-shot { on | off } ]
	[ berr-reporting { on | off } ]
	[ fd { on | off } ]
	[ fd-non-iso { on | off } ]
	[ presume-ack { on | off } ]

	[ restart-ms TIME-MS ]
	[ restart ]

	[ termination { 0..65535 } ]

	Where: BITRATE	:= { 1..1000000 }
		  SAMPLE-POINT	:= { 0.000..0.999 }
		  TQ		:= { NUMBER }
		  PROP-SEG	:= { 1..8 }
		  PHASE-SEG1	:= { 1..8 }
		  PHASE-SEG2	:= { 1..8 }
		  SJW		:= { 1..4 }
		  RESTART-MS	:= { 0 | NUMBER }
Question is now:
Wouldn't it make sense to increase sjw in can_calc_bittiming() to something
like 5% of the total time quanta? This may increase the reliability of the CAN
network when there are differences in the bitrates of the single members. Are
there any arguments against such an arbitrary selection of sjw?

If you agree with such a change I can come up with a proper patch. If I wrote
totally nonsense please tell me :-)

Regards

Matthias
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help