summaryrefslogtreecommitdiff
path: root/drivers/net/can
diff options
context:
space:
mode:
authorVincent Mailhol <mailhol.vincent@wanadoo.fr>2021-09-18 18:56:33 +0900
committerMarc Kleine-Budde <mkl@pengutronix.de>2021-10-24 16:24:28 +0200
commit39f66c9e229797a58a12ea78388cbbad1f81aec9 (patch)
treea5e6dd1c3c0ec977737dff8c9e04aea72cae6ae4 /drivers/net/can
parent63dfe0709643528290c8a6825f278eda0e3f3c2e (diff)
can: bittiming: change unit of TDC parameters to clock periods
In the current implementation, all Transmission Delay Compensation (TDC) parameters are expressed in time quantum. However, ISO 11898-1 actually specifies that these should be expressed in *minimum* time quantum. Furthermore, the minimum time quantum is specified to be "one node clock period long" (c.f. paragraph 11.3.1.1 "Bit time"). For sake of simplicity, we prefer to use the "clock period" term instead of "minimum time quantum" because we believe that it is more broadly understood. This patch fixes that discrepancy by updating the documentation and the formula for TDCO calculation. N.B. In can_calc_tdco(), the sample point (in time quantum) was calculated using a division, thus introducing a risk of rounding and truncation errors. On top of changing the unit to clock period, we also modified the formula to use only additions. Link: https://lore.kernel.org/all/20210918095637.20108-3-mailhol.vincent@wanadoo.fr Suggested-by: Stefan Mätje <Stefan.Maetje@esd.eu> Signed-off-by: Vincent Mailhol <mailhol.vincent@wanadoo.fr> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
Diffstat (limited to 'drivers/net/can')
-rw-r--r--drivers/net/can/dev/bittiming.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/drivers/net/can/dev/bittiming.c b/drivers/net/can/dev/bittiming.c
index 9dda44c0ae9d..0ccf982ca301 100644
--- a/drivers/net/can/dev/bittiming.c
+++ b/drivers/net/can/dev/bittiming.c
@@ -193,12 +193,13 @@ void can_calc_tdco(struct net_device *dev)
* one or two.
*/
if (dbt->brp == 1 || dbt->brp == 2) {
- /* Reuse "normal" sample point and convert it to time quanta */
- u32 sample_point_in_tq = can_bit_time(dbt) * dbt->sample_point / 1000;
+ /* Sample point in clock periods */
+ u32 sample_point_in_tc = (CAN_SYNC_SEG + dbt->prop_seg +
+ dbt->phase_seg1) * dbt->brp;
- if (sample_point_in_tq < tdc_const->tdco_min)
+ if (sample_point_in_tc < tdc_const->tdco_min)
return;
- tdc->tdco = min(sample_point_in_tq, tdc_const->tdco_max);
+ tdc->tdco = min(sample_point_in_tc, tdc_const->tdco_max);
priv->ctrlmode |= CAN_CTRLMODE_TDC_AUTO;
}
}