All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net-next] candev: allow SJW user setting for bittiming calculation
@ 2011-09-22 10:24 Oliver Hartkopp
       [not found] ` <4E7B0CE4.3070402-fJ+pQTUTwRTk1uMJSBkQmQ@public.gmane.org>
  0 siblings, 1 reply; 2+ messages in thread
From: Oliver Hartkopp @ 2011-09-22 10:24 UTC (permalink / raw)
  To: David Miller
  Cc: SocketCAN Core Mailing List, Linux Netdev List,
	Pavel-XecQL68PM4x789tOGE2Ojw, Píša,
	Wolfgang Grandegger

This patch adds support for SJW user settings to not set the synchronization
jump width (SJW) to 1 in any case when using the in-kernel bittiming
calculation.

The ip-tool from iproute2 already supports to pass the user defined SJW
value. The given SJW value is sanitized with the controller specific sjw_max
and the calculated tseg2 value. As the SJW can have values up to 4 providing
this value will lead to the maximum possible SJW automatically. A higher SJW
allows higher controller oscillator tolerances.

Signed-off-by: Oliver Hartkopp <socketcan-fJ+pQTUTwRTk1uMJSBkQmQ@public.gmane.org>

---

diff --git a/drivers/net/can/dev.c b/drivers/net/can/dev.c
index 9bf1116..25695bd 100644
--- a/drivers/net/can/dev.c
+++ b/drivers/net/can/dev.c
@@ -150,7 +150,19 @@ static int can_calc_bittiming(struct net_device *dev, struct can_bittiming *bt)
 	bt->prop_seg = tseg1 / 2;
 	bt->phase_seg1 = tseg1 - bt->prop_seg;
 	bt->phase_seg2 = tseg2;
-	bt->sjw = 1;
+
+	/* check for sjw user settings */
+	if (!bt->sjw || !btc->sjw_max)
+		bt->sjw = 1;
+	else {
+		/* bt->sjw is at least 1 -> sanitize upper bound to sjw_max */
+		if (bt->sjw > btc->sjw_max)
+			bt->sjw = btc->sjw_max;
+		/* bt->sjw must not be higher than tseg2 */
+		if (tseg2 < bt->sjw)
+			bt->sjw = tseg2;
+	}
+
 	bt->brp = best_brp;
 	/* real bit-rate */
 	bt->bitrate = priv->clock.freq / (bt->brp * (tseg1 + tseg2 + 1));

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH net-next] candev: allow SJW user setting for bittiming calculation
       [not found] ` <4E7B0CE4.3070402-fJ+pQTUTwRTk1uMJSBkQmQ@public.gmane.org>
@ 2011-09-22 11:00   ` Wolfgang Grandegger
  0 siblings, 0 replies; 2+ messages in thread
From: Wolfgang Grandegger @ 2011-09-22 11:00 UTC (permalink / raw)
  To: Oliver Hartkopp
  Cc: SocketCAN Core Mailing List, Linux Netdev List, Píša,
	David Miller, Pavel-XecQL68PM4x789tOGE2Ojw

Hi Oliver,

On 09/22/2011 12:24 PM, Oliver Hartkopp wrote:
> This patch adds support for SJW user settings to not set the synchronization
> jump width (SJW) to 1 in any case when using the in-kernel bittiming
> calculation.
> 
> The ip-tool from iproute2 already supports to pass the user defined SJW
> value. The given SJW value is sanitized with the controller specific sjw_max
> and the calculated tseg2 value. As the SJW can have values up to 4 providing
> this value will lead to the maximum possible SJW automatically. A higher SJW
> allows higher controller oscillator tolerances.
> 
> Signed-off-by: Oliver Hartkopp <socketcan-fJ+pQTUTwRTk1uMJSBkQmQ@public.gmane.org>
> 
> ---
> 
> diff --git a/drivers/net/can/dev.c b/drivers/net/can/dev.c
> index 9bf1116..25695bd 100644
> --- a/drivers/net/can/dev.c
> +++ b/drivers/net/can/dev.c
> @@ -150,7 +150,19 @@ static int can_calc_bittiming(struct net_device *dev, struct can_bittiming *bt)
>  	bt->prop_seg = tseg1 / 2;
>  	bt->phase_seg1 = tseg1 - bt->prop_seg;
>  	bt->phase_seg2 = tseg2;
> -	bt->sjw = 1;
> +
> +	/* check for sjw user settings */
> +	if (!bt->sjw || !btc->sjw_max)
> +		bt->sjw = 1;
> +	else {
> +		/* bt->sjw is at least 1 -> sanitize upper bound to sjw_max */
> +		if (bt->sjw > btc->sjw_max)
> +			bt->sjw = btc->sjw_max;
> +		/* bt->sjw must not be higher than tseg2 */
> +		if (tseg2 < bt->sjw)
> +			bt->sjw = tseg2;
> +	}
> +


Hm, bt->sjw is always 0 when can_calc_bittiming() is called!? Or have I
missed something.

Wolfgang,

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2011-09-22 11:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-09-22 10:24 [PATCH net-next] candev: allow SJW user setting for bittiming calculation Oliver Hartkopp
     [not found] ` <4E7B0CE4.3070402-fJ+pQTUTwRTk1uMJSBkQmQ@public.gmane.org>
2011-09-22 11:00   ` Wolfgang Grandegger

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.