]> rtime.felk.cvut.cz Git - can-utils.git/blob - canframelen.h
candump: Enable HW timestamping before using it
[can-utils.git] / canframelen.h
1 /*
2  * canframelen.h
3  *
4  * Copyright (c) 2013, 2014 Czech Technical University in Prague
5  *
6  * Author: Michal Sojka <sojkam1@fel.cvut.cz>
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  * 3. Neither the name of Czech Technical University in Prague nor the
17  *    names of its contributors may be used to endorse or promote
18  *    products derived from this software without specific prior
19  *    written permission.
20  *
21  * Alternatively, provided that this notice is retained in full, this
22  * software may be distributed under the terms of the GNU General
23  * Public License ("GPL") version 2, in which case the provisions of the
24  * GPL apply INSTEAD OF those given above.
25  *
26  * The provided data structures and external interfaces from this code
27  * are not restricted to be used by modules with a GPL compatible license.
28  *
29  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
30  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
31  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
32  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
33  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
34  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
35  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
36  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
37  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
38  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
39  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
40  * DAMAGE.
41  *
42  * Send feedback to <linux-can@vger.kernel.org>
43  *
44  */
45
46 #ifndef CANFRAMELEN_H
47 #define CANFRAMELEN_H
48
49 #include <linux/can.h>
50
51 /**
52  * Frame length calculation modes.
53  *
54  * CFL_WORSTCASE corresponds to *worst* case calculation for
55  * stuff-bits - see (1)-(3) in [1]. The worst case number of bits on
56  * the wire can be calculated as:
57  *
58  * (34 + 8n - 1)/4 + 34 + 8n + 13 for SFF frames (11 bit CAN-ID) => 55 + 10n
59  * (54 + 8n - 1)/4 + 54 + 8n + 13 for EFF frames (29 bit CAN-ID) => 80 + 10n
60  *
61  * while 'n' is the data length code (number of payload bytes)
62  *
63  * [1] "Controller Area Network (CAN) schedulability analysis:
64  *     Refuted, revisited and revised", Real-Time Syst (2007)
65  *     35:239-272.
66  *
67  */
68 enum cfl_mode {
69         CFL_NO_BITSTUFFING, /* plain bit calculation without bitstuffing */
70         CFL_WORSTCASE, /* worst case estimation - see above */
71         CFL_EXACT, /* exact calculation of stuffed bits based on frame
72                     * content and CRC */
73 };
74
75 /**
76  * Calculates the number of bits a frame needs on the wire (including
77  * inter frame space).
78  *
79  * Mode determines how to deal with stuffed bits.
80  */
81 unsigned can_frame_length(struct canfd_frame *frame, enum cfl_mode mode, int mtu);
82
83 #endif