Skip to contentSkip to conversation

candev: allow SJW user setting for bittiming calculation

PATCH Superseded Oliver Hartkopp 2 participants 2 messages Sep 22, 2011 1 message not in the archive

Subsystems (3)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 candev: allow SJW user setting for bittiming calculation

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.

---

drivers/net/can/dev.c +13 -1
index 9bf1116..25695bd 100644
@@ -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));

A message that is not in the archive (sent off-list or not yet received): [email protected]

#2 lore raw

Hi Oliver,

Quoted 26 lines · Oliver Hartkopp

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.

---

drivers/net/can/dev.c +3 -1
index 9bf1116..25695bd 100644
@@ -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)

drivers/net/can/dev.c static int can_calc_bittiming(struct net_device *dev, struct can_bittiming *bt) · line 165

Quoted 10 lines
drivers/net/can/dev.c +10 -0
+		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,