canbusload: Add exact CAN frame length calculation (including bitstuffing)

This adds an algorithm for calculating the exact number of bits a CAN
frame occupies on the bus and uses this algorithm in canbusload. It
also moves the other methods for CAN frame length calculation, already
present in canbusload, to the new file.

The added algorithm calculates the exact number of stuffed bit in a
CAN frame. Note that in order to calculate that correctly, we must
also know the frame's CRC. Hence, the algorithm also includes CRC
calculation routine.

The correctness of the algorithm was verified on an oscilloscope for
several different SFF and EFF frames.

Currently only CAN frames are supported. For CANFD frames, a different
algorithm is needed. CANFD uses different CRC polynomials and
calculates the CRC from the staffed bit-stream (CAN calculates CRC
from de-stuffed bit-stream).

Signed-off-by: Michal Sojka <sojkam1@fel.cvut.cz>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
This commit is contained in:
Michal Sojka
2014-01-30 16:23:25 +01:00
committed by Marc Kleine-Budde
parent 4ddde7b966
commit 2206f92de7
5 changed files with 305 additions and 32 deletions
+35
View File
@@ -0,0 +1,35 @@
#ifndef CANFRAMELEN_H
#define CANFRAMELEN_H
#include <linux/can.h>
/**
* Frame length calculation modes.
*
* CFL_WORSTCASE corresponds to Ken Tindells *worst* case calculation
* for stuff-bits (see "Guaranteeing Message Latencies on Controller
* Area Network" 1st ICC'94) the needed bits on the wire can be
* calculated as:
*
* (34 + 8n)/5 + 47 + 8n for SFF frames (11 bit CAN-ID) => (269 + 48n)/5
* (54 + 8n)/5 + 67 + 8n for EFF frames (29 bit CAN-ID) => (389 + 48n)/5
*
* while 'n' is the data length code (number of payload bytes)
*
*/
enum cfl_mode {
CFL_NO_BITSTUFFING, /* plain bit calculation without bitstuffing */
CFL_WORSTCASE, /* with bitstuffing following Tindells estimation */
CFL_EXACT, /* exact calculation of stuffed bits based on frame
* content and CRC */
};
/**
* Calculates the number of bits a frame needs on the wire (including
* inter frame space).
*
* Mode determines how to deal with stuffed bits.
*/
unsigned can_frame_length(struct canfd_frame *frame, enum cfl_mode mode, int mtu);
#endif