All of lore.kernel.org
 help / color / mirror / Atom feed
From: Oliver Hartkopp <socketcan@hartkopp.net>
To: "Matthias Weißer" <m.weisser.m@gmail.com>, linux-can@vger.kernel.org
Subject: Re: sjw in can_calc_bittiming
Date: Tue, 2 Nov 2021 16:36:05 +0100	[thread overview]
Message-ID: <0a539c49-b92e-892e-5848-613ff745c283@hartkopp.net> (raw)
In-Reply-To: <CAO8h3eEcK7c6M5T88K0MO6eQk64DY+85Mzsi5zdT9tV9mxiMfw@mail.gmail.com>

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
> 

  reply	other threads:[~2021-11-02 15:36 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-02 15:03 sjw in can_calc_bittiming Matthias Weißer
2021-11-02 15:36 ` Oliver Hartkopp [this message]
2021-11-02 15:59   ` Wolfgang Grandegger
2021-11-03  7:12   ` Matthias Weißer
2021-11-05 12:07 ` Marc Kleine-Budde

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=0a539c49-b92e-892e-5848-613ff745c283@hartkopp.net \
    --to=socketcan@hartkopp.net \
    --cc=linux-can@vger.kernel.org \
    --cc=m.weisser.m@gmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.