RTEMS 7.0-rc1
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
15/*
16 * Copyright (C) 2023-2024 Michal Lenc <michallenc@seznam.cz>
17 * Copyright (C) 2002-2009 DCE FEE CTU Prague
18 * Copyright (C) 2002-2024 Pavel Pisa <pisa@cmp.felk.cvut.cz>
19 *
20 * Redistribution and use in source and binary forms, with or without
21 * modification, are permitted provided that the following conditions
22 * are met:
23 * 1. Redistributions of source code must retain the above copyright
24 * notice, this list of conditions and the following disclaimer.
25 * 2. Redistributions in binary form must reproduce the above copyright
26 * notice, this list of conditions and the following disclaimer in the
27 * documentation and/or other materials provided with the distribution.
28 *
29 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
30 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
31 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
32 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
33 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
34 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
35 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
36 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
37 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
38 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
39 * POSSIBILITY OF SUCH DAMAGE.
40 */
41
42#ifndef _DEV_CAN_CAN_FRAME_H
43#define _DEV_CAN_CAN_FRAME_H
44
56#define CAN_FRAME_BFF_ID_MASK ( 0x000007ff )
60#define CAN_FRAME_EFF_ID_MASK ( 0x1fffffff )
64#define CAN_FRAME_STANDARD_DLEN ( 8u )
68#define CAN_FRAME_FD_DLEN ( 64u )
72#define CAN_FRAME_MAX_DLEN ( CAN_FRAME_FD_DLEN )
73
93#define CAN_FRAME_IDE ( 1 << 0 )
97#define CAN_FRAME_RTR ( 1 << 1 )
101#define CAN_FRAME_ECHO ( 1 << 2 )
105#define CAN_FRAME_LOCAL ( 1 << 3 )
109#define CAN_FRAME_TXERR ( 1 << 4 )
113#define CAN_FRAME_ERR ( 1 << 5 )
117#define CAN_FRAME_FIFO_OVERFLOW ( 1 << 6 )
121#define CAN_FRAME_FDF ( 1 << 7 )
125#define CAN_FRAME_BRS ( 1 << 8 )
129#define CAN_FRAME_ESI ( 1 << 9 )
130
153#define CAN_ERR_ID_TXTIMEOUT ( 1 << 0 )
158#define CAN_ERR_ID_LOSTARB ( 1 << 1 )
163#define CAN_ERR_ID_CRTL ( 1 << 2 )
169#define CAN_ERR_ID_PROT ( 1 << 3 )
174#define CAN_ERR_ID_TRX ( 1 << 4 )
178#define CAN_ERR_ID_ACK ( 1 << 5 )
182#define CAN_ERR_ID_BUSOFF ( 1 << 6 )
186#define CAN_ERR_ID_BUSERROR ( 1 << 7 )
190#define CAN_ERR_ID_RESTARTED ( 1 << 8 )
195#define CAN_ERR_ID_CNT ( 1 << 9 )
199#define CAN_ERR_ID_INTERNAL ( 1 << 10 )
205#define CAN_ERR_ID_TAG ( 1 << 31 )
206
221#define CAN_ERR_DATA_BYTE_TRX_LOSTARB ( 0 )
225#define CAN_ERR_DATA_BYTE_TRX_CTRL ( 1 )
230#define CAN_ERR_DATA_BYTE_TRX_PROT ( 2 )
235#define CAN_ERR_DATA_BYTE_TRX_PROT_LOC ( 3 )
240#define CAN_ERR_TRX_DATA_BYTE ( 4 )
244#define CAN_ERR_DATA_BYTE_CNT_TX ( 6 )
248#define CAN_ERR_DATA_BYTE_CNT_RX ( 7 )
249
261#define CAN_ERR_LOSTARB_UNSPEC ( 0 )
265#define CAN_ERR_LOSTARB_BIT( n ) ( n )
266
278#define CAN_ERR_CRTL_UNSPEC ( 0 )
282#define CAN_ERR_CRTL_RX_OVERFLOW ( 1 << 0 )
286#define CAN_ERR_CRTL_TX_OVERFLOW ( 1 << 1 )
290#define CAN_ERR_CRTL_RX_WARNING ( 1 << 2 )
294#define CAN_ERR_CRTL_TX_WARNING ( 1 << 3 )
298#define CAN_ERR_CRTL_RX_PASSIVE ( 1 << 4 )
302#define CAN_ERR_CRTL_TX_PASSIVE ( 1 << 5 )
306#define CAN_ERR_CRTL_ACTIVE ( 1 << 6 )
307
319#define CAN_ERR_PROT_UNSPEC ( 0 )
323#define CAN_ERR_PROT_BIT (1 << 0)
327#define CAN_ERR_PROT_FOR (1 << 1)
331#define CAN_ERR_PROT_STUFF (1 << 2)
335#define CAN_ERR_PROT_BIT0 (1 << 3)
339#define CAN_ERR_PROT_BIT1 (1 << 4)
343#define CAN_ERR_PROT_OVERLOAD (1 << 5)
347#define CAN_ERR_PROT_ACTIVE (1 << 6)
351#define CAN_ERR_PROT_TX (1 << 7)
352
364#define CAN_ERR_PROT_LOC_UNSPEC ( 0x00 )
368#define CAN_ERR_PROT_LOC_SOF ( 0x01 )
372#define CAN_ERR_PROT_LOC_ID0 ( 0x02 )
376#define CAN_ERR_PROT_LOC_ID1 ( 0x03 )
380#define CAN_ERR_PROT_LOC_ID2 ( 0x04 )
384#define CAN_ERR_PROT_LOC_ID3 ( 0x05 )
388#define CAN_ERR_PROT_LOC_ID4 ( 0x06 )
392#define CAN_ERR_PROT_LOC_IDE ( 0x07 )
396#define CAN_ERR_PROT_LOC_RTR ( 0x08 )
400#define CAN_ERR_PROT_LOC_SRTR ( 0x09 )
404#define CAN_ERR_PROT_LOC_RES0 ( 0x0a )
408#define CAN_ERR_PROT_LOC_RES1 ( 0x0b )
412#define CAN_ERR_PROT_LOC_DLC ( 0x0c )
416#define CAN_ERR_PROT_LOC_DATA ( 0x0d )
420#define CAN_ERR_PROT_LOC_CRCSEQ ( 0x0e )
424#define CAN_ERR_PROT_LOC_CRCDEL ( 0x0f )
428#define CAN_ERR_PROT_LOC_ACK ( 0x10 )
432#define CAN_ERR_PROT_LOC_ACKDEL ( 0x11 )
436#define CAN_ERR_PROT_LOC_EOF ( 0x12 )
440#define CAN_ERR_PROT_LOC_INTERM ( 0x13 )
441
453#define CAN_ERR_TRX_UNSPEC ( 0x00 )
457#define CAN_ERR_TRX_H_MASK ( 0x0f )
461#define CAN_ERR_TRX_H_NOWIRE ( 0x01 )
465#define CAN_ERR_TRX_H_SHORT2BAT ( 0x02 )
469#define CAN_ERR_TRX_H_SHORT2VCC ( 0x03 )
473#define CAN_ERR_TRX_H_SHORT2GND ( 0x04 )
477#define CAN_ERR_TRX_L_MASK ( 0xf0 )
481#define CAN_ERR_TRX_L_NOWIRE ( 0x10 )
485#define CAN_ERR_TRX_L_SHORT2BAT ( 0x20 )
489#define CAN_ERR_TRX_L_SHORT2VCC ( 0x30 )
493#define CAN_ERR_TRX_L_SHORT2GND ( 0x40 )
497#define CAN_ERR_TRX_L_SHORT2CANH ( 0x50 )
498
510 uint64_t timestamp;
516 uint32_t can_id;
522 uint16_t flags;
527 uint16_t dlen;
528};
529
534struct can_frame {
544};
545
553static inline size_t can_framesize( struct can_frame *frame )
554{
555 return offsetof( struct can_frame, data ) + frame->header.dlen;
556}
557
560#endif /* _DEV_CAN_CAN_FRAME_H */
#define CAN_FRAME_MAX_DLEN
Represents maximum allowed CAN frame data length.
Definition: can-frame.h:72
This structure represents the CAN message header.
Definition: can-frame.h:506
uint64_t timestamp
This member holds the CAN timestamp value.
Definition: can-frame.h:510
uint16_t flags
This member holds the CAN flags. These are used to pass additional information between driver and app...
Definition: can-frame.h:522
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:527
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:516
This structure represents one CAN frame. It consists of CAN header and data.
Definition: can-frame.h:534
struct can_frame_header header
This member stores the structure can_frame_header representing CAN header.
Definition: can-frame.h:539
uint8_t data[CAN_FRAME_MAX_DLEN]
This member stores CAN data.
Definition: can-frame.h:543