225bc09f756dbb744785fc57abcd26a4aabb2660
[profile/ivi/can-utils.git] / canframelen.h
1 #ifndef CANFRAMELEN_H
2 #define CANFRAMELEN_H
3
4 #include <linux/can.h>
5
6 /**
7  * Frame length calculation modes.
8  *
9  * CFL_WORSTCASE corresponds to Ken Tindells *worst* case calculation
10  * for stuff-bits (see "Guaranteeing Message Latencies on Controller
11  * Area Network" 1st ICC'94) the needed bits on the wire can be
12  * calculated as:
13  *
14  * (34 + 8n)/5 + 47 + 8n for SFF frames (11 bit CAN-ID) => (269 + 48n)/5
15  * (54 + 8n)/5 + 67 + 8n for EFF frames (29 bit CAN-ID) => (389 + 48n)/5
16  *
17  * while 'n' is the data length code (number of payload bytes)
18  *
19  */
20 enum cfl_mode {
21         CFL_NO_BITSTUFFING, /* plain bit calculation without bitstuffing */
22         CFL_WORSTCASE, /* with bitstuffing following Tindells estimation */
23         CFL_EXACT, /* exact calculation of stuffed bits based on frame
24                     * content and CRC */
25 };
26
27 /**
28  * Calculates the number of bits a frame needs on the wire (including
29  * inter frame space).
30  *
31  * Mode determines how to deal with stuffed bits.
32  */
33 unsigned can_frame_length(struct canfd_frame *frame, enum cfl_mode mode, int mtu);
34
35 #endif