RTEMS CAN/CAN FD Stack
Loading...
Searching...
No Matches
can-frame.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: BSD-2-Clause OR Apache-2.0 OR GPL-2.0-or-later */
2
12/*
13 * Copyright (C) 2023-2024 Michal Lenc <michallenc@seznam.cz>
14 * Implementation is based on original LinCAN - Linux CAN bus driver
15 * Part of OrtCAN project https://ortcan.sourceforge.net/
16 * Copyright (C) 2002-2009 DCE FEE CTU Prague <http://control.fel.cvut.cz>
17 * Copyright (C) 2002-2024 Pavel Pisa <pisa@cmp.felk.cvut.cz>
18 *
19 * Redistribution and use in source and binary forms, with or without
20 * modification, are permitted provided that the following conditions
21 * are met:
22 * 1. Redistributions of source code must retain the above copyright
23 * notice, this list of conditions and the following disclaimer.
24 * 2. Redistributions in binary form must reproduce the above copyright
25 * notice, this list of conditions and the following disclaimer in the
26 * documentation and/or other materials provided with the distribution.
27 *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
29 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
32 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
33 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
34 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
35 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
36 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
37 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38 * POSSIBILITY OF SUCH DAMAGE.
39 */
40
41#ifndef _DEV_CAN_CAN_FRAME_H
42#define _DEV_CAN_CAN_FRAME_H
43
55#define CAN_FRAME_BFF_ID_MASK ( 0x000007ff )
59#define CAN_FRAME_EFF_ID_MASK ( 0x1fffffff )
63#define CAN_FRAME_STANDARD_DLEN ( 8u )
67#define CAN_FRAME_FD_DLEN ( 64u )
71#define CAN_FRAME_MAX_DLEN ( CAN_FRAME_FD_DLEN )
72
92#define CAN_FRAME_IDE ( 1 << 0 )
96#define CAN_FRAME_RTR ( 1 << 1 )
100#define CAN_FRAME_ECHO ( 1 << 2 )
104#define CAN_FRAME_LOCAL ( 1 << 3 )
108#define CAN_FRAME_TXERR ( 1 << 4 )
112#define CAN_FRAME_ERR ( 1 << 5 )
116#define CAN_FRAME_FIFO_OVERFLOW ( 1 << 6 )
120#define CAN_FRAME_FDF ( 1 << 7 )
124#define CAN_FRAME_BRS ( 1 << 8 )
128#define CAN_FRAME_ESI ( 1 << 9 )
129
152#define CAN_ERR_ID_TXTIMEOUT ( 1 << 0 )
157#define CAN_ERR_ID_LOSTARB ( 1 << 1 )
162#define CAN_ERR_ID_CRTL ( 1 << 2 )
168#define CAN_ERR_ID_PROT ( 1 << 3 )
173#define CAN_ERR_ID_TRX ( 1 << 4 )
177#define CAN_ERR_ID_ACK ( 1 << 5 )
181#define CAN_ERR_ID_BUSOFF ( 1 << 6 )
185#define CAN_ERR_ID_BUSERROR ( 1 << 7 )
189#define CAN_ERR_ID_RESTARTED ( 1 << 8 )
194#define CAN_ERR_ID_CNT ( 1 << 9 )
198#define CAN_ERR_ID_INTERNAL ( 1 << 10 )
204#define CAN_ERR_ID_TAG ( 1 << 31 )
205
220#define CAN_ERR_DATA_BYTE_TRX_LOSTARB ( 0 )
224#define CAN_ERR_DATA_BYTE_TRX_CTRL ( 1 )
229#define CAN_ERR_DATA_BYTE_TRX_PROT ( 2 )
234#define CAN_ERR_DATA_BYTE_TRX_PROT_LOC ( 3 )
239#define CAN_ERR_TRX_DATA_BYTE ( 4 )
243#define CAN_ERR_DATA_BYTE_CNT_TX ( 6 )
247#define CAN_ERR_DATA_BYTE_CNT_RX ( 7 )
248
260#define CAN_ERR_LOSTARB_UNSPEC ( 0 )
264#define CAN_ERR_LOSTARB_BIT( n ) ( n )
265
277#define CAN_ERR_CRTL_UNSPEC ( 0 )
281#define CAN_ERR_CRTL_RX_OVERFLOW ( 1 << 0 )
285#define CAN_ERR_CRTL_TX_OVERFLOW ( 1 << 1 )
289#define CAN_ERR_CRTL_RX_WARNING ( 1 << 2 )
293#define CAN_ERR_CRTL_TX_WARNING ( 1 << 3 )
297#define CAN_ERR_CRTL_RX_PASSIVE ( 1 << 4 )
301#define CAN_ERR_CRTL_TX_PASSIVE ( 1 << 5 )
305#define CAN_ERR_CRTL_ACTIVE ( 1 << 6 )
306
318#define CAN_ERR_PROT_UNSPEC ( 0 )
322#define CAN_ERR_PROT_BIT (1 << 0)
326#define CAN_ERR_PROT_FOR (1 << 1)
330#define CAN_ERR_PROT_STUFF (1 << 2)
334#define CAN_ERR_PROT_BIT0 (1 << 3)
338#define CAN_ERR_PROT_BIT1 (1 << 4)
342#define CAN_ERR_PROT_OVERLOAD (1 << 5)
346#define CAN_ERR_PROT_ACTIVE (1 << 6)
350#define CAN_ERR_PROT_TX (1 << 7)
351
363#define CAN_ERR_PROT_LOC_UNSPEC ( 0x00 )
367#define CAN_ERR_PROT_LOC_SOF ( 0x01 )
371#define CAN_ERR_PROT_LOC_ID0 ( 0x02 )
375#define CAN_ERR_PROT_LOC_ID1 ( 0x03 )
379#define CAN_ERR_PROT_LOC_ID2 ( 0x04 )
383#define CAN_ERR_PROT_LOC_ID3 ( 0x05 )
387#define CAN_ERR_PROT_LOC_ID4 ( 0x06 )
391#define CAN_ERR_PROT_LOC_IDE ( 0x07 )
395#define CAN_ERR_PROT_LOC_RTR ( 0x08 )
399#define CAN_ERR_PROT_LOC_SRTR ( 0x09 )
403#define CAN_ERR_PROT_LOC_RES0 ( 0x0a )
407#define CAN_ERR_PROT_LOC_RES1 ( 0x0b )
411#define CAN_ERR_PROT_LOC_DLC ( 0x0c )
415#define CAN_ERR_PROT_LOC_DATA ( 0x0d )
419#define CAN_ERR_PROT_LOC_CRCSEQ ( 0x0e )
423#define CAN_ERR_PROT_LOC_CRCDEL ( 0x0f )
427#define CAN_ERR_PROT_LOC_ACK ( 0x10 )
431#define CAN_ERR_PROT_LOC_ACKDEL ( 0x11 )
435#define CAN_ERR_PROT_LOC_EOF ( 0x12 )
439#define CAN_ERR_PROT_LOC_INTERM ( 0x13 )
440
452#define CAN_ERR_TRX_UNSPEC ( 0x00 )
456#define CAN_ERR_TRX_H_MASK ( 0x0f )
460#define CAN_ERR_TRX_H_NOWIRE ( 0x01 )
464#define CAN_ERR_TRX_H_SHORT2BAT ( 0x02 )
468#define CAN_ERR_TRX_H_SHORT2VCC ( 0x03 )
472#define CAN_ERR_TRX_H_SHORT2GND ( 0x04 )
476#define CAN_ERR_TRX_L_MASK ( 0xf0 )
480#define CAN_ERR_TRX_L_NOWIRE ( 0x10 )
484#define CAN_ERR_TRX_L_SHORT2BAT ( 0x20 )
488#define CAN_ERR_TRX_L_SHORT2VCC ( 0x30 )
492#define CAN_ERR_TRX_L_SHORT2GND ( 0x40 )
496#define CAN_ERR_TRX_L_SHORT2CANH ( 0x50 )
497
509 uint64_t timestamp;
515 uint32_t can_id;
521 uint16_t flags;
526 uint16_t dlen;
527};
528
533struct can_frame {
543};
544
552static inline size_t can_framesize( struct can_frame *frame )
553{
554 return offsetof( struct can_frame, data ) + frame->header.dlen;
555}
556
559#endif /* _DEV_CAN_CAN_FRAME_H */
#define CAN_FRAME_MAX_DLEN
Represents maximum allowed CAN frame data length.
Definition: can-frame.h:71
This structure represents the CAN message header.
Definition: can-frame.h:505
uint64_t timestamp
This member holds the CAN timestamp value.
Definition: can-frame.h:509
uint16_t flags
This member holds the CAN flags. These are used to pass additional information between driver and app...
Definition: can-frame.h:521
uint16_t dlen
This member holds the data length of CAN frame. This length does not include size of the header.
Definition: can-frame.h:526
uint32_t can_id
This member holds the CAN identifier value. Only first 29 bits are be valid for CAN ID....
Definition: can-frame.h:515
This structure represents one CAN frame. It consists of CAN header and data.
Definition: can-frame.h:533
struct can_frame_header header
This member stores the structure can_frame_header representing CAN header.
Definition: can-frame.h:538
uint8_t data[CAN_FRAME_MAX_DLEN]
This member stores CAN data.
Definition: can-frame.h:542