Skip to content

Commit 50ef360

Browse files
committed
Support CAN XL payload length and DLC definitions according to ISO 11898-1.
1 parent c2f83ad commit 50ef360

File tree

1 file changed

+47
-1
lines changed

1 file changed

+47
-1
lines changed

examples/csp_server.c

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,71 @@
1313
#include <netinet/in.h>
1414
#include <arpa/inet.h>
1515

16-
#include <linux/can.h>
1716
#include <linux/can/raw.h>
1817

1918
#include <csp/csp.h>
2019
#include <csp/drivers/usart.h>
2120
#include <csp/drivers/can_socketcan.h>
2221
#include <csp/interfaces/csp_if_zmqhub.h>
2322

23+
#ifndef CANXL_XLF
24+
/*
25+
* CAN XL payload length and DLC definitions according to ISO 11898-1
26+
* CAN XL DLC ranges from 0 .. 2047 => data length from 1 .. 2048 byte
27+
*/
28+
#define CANXL_MIN_DLC 0
29+
#define CANXL_MAX_DLC 2047
30+
#define CANXL_MAX_DLC_MASK 0x07FF
31+
#define CANXL_MIN_DLEN 1
32+
#define CANXL_MAX_DLEN 2048
33+
2434
/* valid bits in CAN ID for frame formats */
2535
#define CAN_SFF_MASK 0x000007FFU /* standard frame format (SFF) */
2636
#define CAN_EFF_MASK 0x1FFFFFFFU /* extended frame format (EFF) */
2737
#define CAN_ERR_MASK 0x1FFFFFFFU /* omit EFF, RTR, ERR flags */
2838
#define CANXL_PRIO_MASK CAN_SFF_MASK /* 11 bit priority mask */
2939

40+
/*
41+
* defined bits for canxl_frame.flags
42+
*
43+
* The canxl_frame.flags element contains two bits CANXL_XLF and CANXL_SEC
44+
* and shares the relative position of the struct can[fd]_frame.len element.
45+
* The CANXL_XLF bit ALWAYS needs to be set to indicate a valid CAN XL frame.
46+
* As a side effect setting this bit intentionally breaks the length checks
47+
* for Classical CAN and CAN FD frames.
48+
*
49+
* Undefined bits in canxl_frame.flags are reserved and shall be set to zero.
50+
*/
51+
#define CANXL_XLF 0x80 /* mandatory CAN XL frame flag (must always be set!) */
52+
#define CANXL_SEC 0x01 /* Simple Extended Content (security/segmentation) */
53+
3054
/* the 8-bit VCID is optionally placed in the canxl_frame.prio element */
3155
#define CANXL_VCID_OFFSET 16 /* bit offset of VCID in prio element */
3256
#define CANXL_VCID_VAL_MASK 0xFFUL /* VCID is an 8-bit value */
3357
#define CANXL_VCID_MASK (CANXL_VCID_VAL_MASK << CANXL_VCID_OFFSET)
3458

59+
/**
60+
* struct canxl_frame - CAN with e'X'tended frame 'L'ength frame structure
61+
* @prio: 11 bit arbitration priority with zero'ed CAN_*_FLAG flags / VCID
62+
* @flags: additional flags for CAN XL
63+
* @sdt: SDU (service data unit) type
64+
* @len: frame payload length in byte (CANXL_MIN_DLEN .. CANXL_MAX_DLEN)
65+
* @af: acceptance field
66+
* @data: CAN XL frame payload (CANXL_MIN_DLEN .. CANXL_MAX_DLEN byte)
67+
*
68+
* @prio shares the same position as @can_id from struct can[fd]_frame.
69+
*/
70+
71+
struct canxl_frame {
72+
canid_t prio; /* 11 bit priority for arbitration / 8 bit VCID */
73+
__u8 flags; /* additional flags for CAN XL */
74+
__u8 sdt; /* SDU (service data unit) type */
75+
__u16 len; /* frame payload length in byte */
76+
__u32 af; /* acceptance field */
77+
__u8 data[CANXL_MAX_DLEN];
78+
};
79+
#endif
80+
3581
/* CAN CC/FD/XL frame union */
3682
typedef union {
3783
struct can_frame cc;

0 commit comments

Comments
 (0)