From: Simon Horman <simon.horman@corigine.com>
To: Vincent Mailhol <mailhol.vincent@wanadoo.fr>
Cc: Marc Kleine-Budde <mkl@pengutronix.de>,
linux-can@vger.kernel.org, Thomas.Kopp@microchip.com,
Oliver Hartkopp <socketcan@hartkopp.net>,
netdev@vger.kernel.org, marex@denx.de,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3 3/3] can: length: refactor frame lengths definition to add size in bits
Date: Tue, 30 May 2023 17:51:05 +0200 [thread overview]
Message-ID: <ZHYbaYWeIaDcUhhw@corigine.com> (raw)
In-Reply-To: <20230530144637.4746-4-mailhol.vincent@wanadoo.fr>
On Tue, May 30, 2023 at 11:46:37PM +0900, Vincent Mailhol wrote:
> Introduce a method to calculate the exact size in bits of a CAN(-FD)
> frame with or without dynamic bitsuffing.
>
> These are all the possible combinations taken into account:
>
> - Classical CAN or CAN-FD
> - Standard or Extended frame format
> - CAN-FD CRC17 or CRC21
> - Include or not intermission
>
> Instead of doing several individual macro definitions, declare the
> can_frame_bits() function-like macro. To this extent, do a full
> refactoring of the length definitions.
>
> In addition add the can_frame_bytes(). This function-like macro
> replaces the existing macro:
>
> - CAN_FRAME_OVERHEAD_SFF: can_frame_bytes(false, false, 0)
> - CAN_FRAME_OVERHEAD_EFF: can_frame_bytes(false, true, 0)
> - CANFD_FRAME_OVERHEAD_SFF: can_frame_bytes(true, false, 0)
> - CANFD_FRAME_OVERHEAD_EFF: can_frame_bytes(true, true, 0)
>
> The different maximum frame lengths (maximum data length, including
> intermission) are as follow:
>
> Frame type bits bytes
> -------------------------------------------------------
> Classic CAN SFF no-bitstuffing 111 14
> Classic CAN EFF no-bitstuffing 131 17
> Classic CAN SFF bitstuffing 135 17
> Classic CAN EFF bitstuffing 160 20
> CAN-FD SFF no-bitstuffing 579 73
> CAN-FD EFF no-bitstuffing 598 75
> CAN-FD SFF bitstuffing 712 89
> CAN-FD EFF bitstuffing 736 92
>
> The macro CAN_FRAME_LEN_MAX and CANFD_FRAME_LEN_MAX are kept as an
> alias to, respectively, can_frame_bytes(false, true, CAN_MAX_DLEN) and
> can_frame_bytes(true, true, CANFD_MAX_DLEN).
>
> In addition to the above:
>
> - Use ISO 11898-1:2015 definitions for the name of the CAN frame
> fields.
> - Include linux/bits.h for use of BITS_PER_BYTE.
> - Include linux/math.h for use of mult_frac() and
> DIV_ROUND_UP(). N.B: the use of DIV_ROUND_UP() is not new to this
> patch, but the include was previously omitted.
> - Add copyright 2023 for myself.
>
> Signed-off-by: Vincent Mailhol <mailhol.vincent@wanadoo.fr>
...
> +/**
> + * can_bitstuffing_len() - Calculate the maximum length with bitsuffing
> + * @bitstream_len: length of a destuffed bit stream
Hi Vincent,
it looks like an editing error has crept in here:
s/bitstream_len/destuffed_len/
> + *
> + * The worst bit stuffing case is a sequence in which dominant and
> + * recessive bits alternate every four bits:
> + *
> + * Destuffed: 1 1111 0000 1111 0000 1111
> + * Stuffed: 1 1111o 0000i 1111o 0000i 1111o
> + *
> + * Nomenclature
> + *
> + * - "0": dominant bit
> + * - "o": dominant stuff bit
> + * - "1": recessive bit
> + * - "i": recessive stuff bit
> + *
> + * Aside of the first bit, one stuff bit is added every four bits.
> + *
> + * Return: length of the stuffed bit stream in the worst case scenario.
> + */
> +#define can_bitstuffing_len(destuffed_len) \
> + (destuffed_len + (destuffed_len - 1) / 4)
next prev parent reply other threads:[~2023-05-30 15:52 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-07 15:55 [PATCH] can: length: add definitions for frame lengths in bits Vincent Mailhol
2023-05-08 8:54 ` Thomas.Kopp
2023-05-08 12:14 ` Marc Kleine-Budde
2023-05-09 4:16 ` Vincent MAILHOL
2023-05-09 6:43 ` Marc Kleine-Budde
2023-05-09 8:14 ` Vincent MAILHOL
2023-05-09 6:19 ` Thomas.Kopp
2023-05-08 12:20 ` Marc Kleine-Budde
2023-05-09 4:58 ` Vincent MAILHOL
2023-05-09 7:12 ` Thomas.Kopp
2023-05-09 8:06 ` Vincent MAILHOL
2023-05-23 6:52 ` [PATCH v2 0/3] can: length: fix definitions and add bit length calculation Vincent Mailhol
2023-05-23 6:52 ` [PATCH v2 1/3] can: length: fix bitstuffing count Vincent Mailhol
2023-05-23 6:52 ` [PATCH v2 2/3] can: length: fix description of the RRS field Vincent Mailhol
2023-05-23 6:52 ` [PATCH v2 3/3] can: length: refactor frame lengths definition to add size in bits Vincent Mailhol
2023-05-23 7:13 ` Vincent MAILHOL
2023-05-23 11:14 ` Simon Horman
2023-05-30 14:46 ` [PATCH v3 0/3] can: length: fix definitions and add bit length calculation Vincent Mailhol
2023-05-30 14:46 ` [PATCH v3 1/3] can: length: fix bitstuffing count Vincent Mailhol
2023-05-30 14:46 ` [PATCH v3 2/3] can: length: fix description of the RRS field Vincent Mailhol
2023-05-30 14:46 ` [PATCH v3 3/3] can: length: refactor frame lengths definition to add size in bits Vincent Mailhol
2023-05-30 15:51 ` Simon Horman [this message]
2023-05-30 17:29 ` Vincent MAILHOL
2023-05-30 19:49 ` Simon Horman
2023-05-31 9:45 ` Vincent MAILHOL
2023-06-01 10:31 ` Thomas.Kopp
2023-06-01 11:00 ` Vincent MAILHOL
2023-06-01 11:26 ` Thomas.Kopp
2023-06-01 16:56 ` [PATCH v4 0/3] can: length: fix definitions and add bit length calculation Vincent Mailhol
2023-06-01 16:56 ` [PATCH v4 1/3] can: length: fix bitstuffing count Vincent Mailhol
2023-06-01 16:56 ` [PATCH v4 2/3] can: length: fix description of the RRS field Vincent Mailhol
2023-06-01 16:56 ` [PATCH v4 3/3] can: length: refactor frame lengths definition to add size in bits Vincent Mailhol
2023-06-11 2:57 ` [PATCH v5 0/3] can: length: fix definitions and add bit length calculation Vincent Mailhol
2023-06-11 2:57 ` [PATCH v5 1/3] can: length: fix bitstuffing count Vincent Mailhol
2023-06-11 2:57 ` [PATCH v5 2/3] can: length: fix description of the RRS field Vincent Mailhol
2023-06-11 2:57 ` [PATCH v5 3/3] can: length: refactor frame lengths definition to add size in bits Vincent Mailhol
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ZHYbaYWeIaDcUhhw@corigine.com \
--to=simon.horman@corigine.com \
--cc=Thomas.Kopp@microchip.com \
--cc=linux-can@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mailhol.vincent@wanadoo.fr \
--cc=marex@denx.de \
--cc=mkl@pengutronix.de \
--cc=netdev@vger.kernel.org \
--cc=socketcan@hartkopp.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).