Re: [PATCH v5 4/7] can: dev: add can_tdc_get_relative_tdco() helper function

From: Marc Kleine-Budde
Date: Mon Aug 16 2021 - 07:27:13 EST


On 15.08.2021 12:32:45, Vincent Mailhol wrote:
> struct can_tdc::tdco represents the absolute offset from TDCV. Some
> controllers use instead an offset relative to the Sample Point (SP)
> such that:
> | SSP = TDCV + absolute TDCO
> | = TDCV + SP + relative TDCO
>
> Consequently:
> | relative TDCO = absolute TDCO - SP
>
> The function can_tdc_get_relative_tdco() allow to retrieve this
> relative TDCO value.
>
> CC: Stefan Mätje <Stefan.Maetje@xxxxxx>
> Signed-off-by: Vincent Mailhol <mailhol.vincent@xxxxxxxxxx>
> ---
> include/linux/can/dev.h | 29 +++++++++++++++++++++++++++++
> 1 file changed, 29 insertions(+)
>
> diff --git a/include/linux/can/dev.h b/include/linux/can/dev.h
> index 0be982fd22fb..fa75e29182a3 100644
> --- a/include/linux/can/dev.h
> +++ b/include/linux/can/dev.h
> @@ -93,6 +93,35 @@ static inline bool can_tdc_is_enabled(const struct can_priv *priv)
> return !!(priv->ctrlmode & CAN_CTRLMODE_TDC_MASK);
> }
>
> +/*
> + * can_get_relative_tdco() - TDCO relative to the sample point
> + *
> + * struct can_tdc::tdco represents the absolute offset from TDCV. Some
> + * controllers use instead an offset relative to the Sample Point (SP)
> + * such that:
> + *
> + * SSP = TDCV + absolute TDCO
> + * = TDCV + SP + relative TDCO
> + *
> + * -+----------- one bit ----------+-- TX pin
> + * |<--- Sample Point --->|
> + *
> + * --+----------- one bit ----------+-- RX pin
> + * |<-------- TDCV -------->|
> + * |<------------------------>| absolute TDCO
> + * |<--- Sample Point --->|
> + * | |<->| relative TDCO
> + * |<------------- Secondary Sample Point ------------>|
> + */
> +static inline s32 can_get_relative_tdco(const struct can_priv *priv)
> +{
> + const struct can_bittiming *dbt = &priv->data_bittiming;
> + s32 sample_point_in_tc = (CAN_SYNC_SEG + dbt->prop_seg +
^^

Only one space. I'll fix the while applying.

> + dbt->phase_seg1) * dbt->brp;
> +
> + return (s32)priv->tdc.tdco - sample_point_in_tc;
> +}
> +
> /* helper to define static CAN controller features at device creation time */
> static inline void can_set_static_ctrlmode(struct net_device *dev,
> u32 static_mode)

Marc

--
Pengutronix e.K. | Marc Kleine-Budde |
Embedded Linux | https://www.pengutronix.de |
Vertretung West/Dortmund | Phone: +49-231-2826-924 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |

Attachment: signature.asc
Description: PGP signature