Commit 39f66c9e authored by Vincent Mailhol's avatar Vincent Mailhol Committed by Marc Kleine-Budde

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.frSuggested-by: default avatarStefan Mätje <Stefan.Maetje@esd.eu>
Signed-off-by: default avatarVincent Mailhol <mailhol.vincent@wanadoo.fr>
Signed-off-by: default avatarMarc Kleine-Budde <mkl@pengutronix.de>
parent 63dfe070
...@@ -193,12 +193,13 @@ void can_calc_tdco(struct net_device *dev) ...@@ -193,12 +193,13 @@ void can_calc_tdco(struct net_device *dev)
* one or two. * one or two.
*/ */
if (dbt->brp == 1 || dbt->brp == 2) { if (dbt->brp == 1 || dbt->brp == 2) {
/* Reuse "normal" sample point and convert it to time quanta */ /* Sample point in clock periods */
u32 sample_point_in_tq = can_bit_time(dbt) * dbt->sample_point / 1000; 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; 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; priv->ctrlmode |= CAN_CTRLMODE_TDC_AUTO;
} }
} }
......
...@@ -31,8 +31,8 @@ ...@@ -31,8 +31,8 @@
* *
* To solve this issue, ISO 11898-1 introduces in section 11.3.3 * To solve this issue, ISO 11898-1 introduces in section 11.3.3
* "Transmitter delay compensation" a SSP (Secondary Sample Point) * "Transmitter delay compensation" a SSP (Secondary Sample Point)
* equal to the distance, in time quanta, from the start of the bit * equal to the distance from the start of the bit time on the TX pin
* time on the TX pin to the actual measurement on the RX pin. * to the actual measurement on the RX pin.
* *
* This structure contains the parameters to calculate that SSP. * This structure contains the parameters to calculate that SSP.
* *
...@@ -44,8 +44,13 @@ ...@@ -44,8 +44,13 @@
* |<------- TDCO ------->| * |<------- TDCO ------->|
* |<----------- Secondary Sample Point ---------->| * |<----------- Secondary Sample Point ---------->|
* *
* To increase precision, contrary to the other bittiming parameters
* which are measured in time quanta, the TDC parameters are measured
* in clock periods (also referred as "minimum time quantum" in ISO
* 11898-1).
*
* @tdcv: Transmitter Delay Compensation Value. The time needed for * @tdcv: Transmitter Delay Compensation Value. The time needed for
* the signal to propagate, i.e. the distance, in time quanta, * the signal to propagate, i.e. the distance, in clock periods,
* from the start of the bit on the TX pin to when it is received * from the start of the bit on the TX pin to when it is received
* on the RX pin. @tdcv depends on the controller modes: * on the RX pin. @tdcv depends on the controller modes:
* *
...@@ -62,17 +67,18 @@ ...@@ -62,17 +67,18 @@
* TDC is disabled and all the values of this structure should be * TDC is disabled and all the values of this structure should be
* ignored. * ignored.
* *
* @tdco: Transmitter Delay Compensation Offset. Offset value, in time * @tdco: Transmitter Delay Compensation Offset. Offset value, in
* quanta, defining the distance between the start of the bit * clock periods, defining the distance between the start of the
* reception on the RX pin of the transceiver and the SSP * bit reception on the RX pin of the transceiver and the SSP
* position such that SSP = @tdcv + @tdco. * position such that SSP = @tdcv + @tdco.
* *
* @tdcf: Transmitter Delay Compensation Filter window. Defines the * @tdcf: Transmitter Delay Compensation Filter window. Defines the
* minimum value for the SSP position in time quanta. If the SSP * minimum value for the SSP position in clock periods. If the
* position is less than @tdcf, then no delay compensations occur * SSP position is less than @tdcf, then no delay compensations
* and the normal sampling point is used instead. The feature is * occur and the normal sampling point is used instead. The
* enabled if and only if @tdcv is set to zero (automatic mode) * feature is enabled if and only if @tdcv is set to zero
* and @tdcf is configured to a value greater than @tdco. * (automatic mode) and @tdcf is configured to a value greater
* than @tdco.
*/ */
struct can_tdc { struct can_tdc {
u32 tdcv; u32 tdcv;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment