|
13 | 13 | #include <netinet/in.h>
|
14 | 14 | #include <arpa/inet.h>
|
15 | 15 |
|
16 |
| -#include <linux/can.h> |
17 | 16 | #include <linux/can/raw.h>
|
18 | 17 |
|
19 | 18 | #include <csp/csp.h>
|
20 | 19 | #include <csp/drivers/usart.h>
|
21 | 20 | #include <csp/drivers/can_socketcan.h>
|
22 | 21 | #include <csp/interfaces/csp_if_zmqhub.h>
|
23 | 22 |
|
| 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 | + |
24 | 34 | /* valid bits in CAN ID for frame formats */
|
25 | 35 | #define CAN_SFF_MASK 0x000007FFU /* standard frame format (SFF) */
|
26 | 36 | #define CAN_EFF_MASK 0x1FFFFFFFU /* extended frame format (EFF) */
|
27 | 37 | #define CAN_ERR_MASK 0x1FFFFFFFU /* omit EFF, RTR, ERR flags */
|
28 | 38 | #define CANXL_PRIO_MASK CAN_SFF_MASK /* 11 bit priority mask */
|
29 | 39 |
|
| 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 | + |
30 | 54 | /* the 8-bit VCID is optionally placed in the canxl_frame.prio element */
|
31 | 55 | #define CANXL_VCID_OFFSET 16 /* bit offset of VCID in prio element */
|
32 | 56 | #define CANXL_VCID_VAL_MASK 0xFFUL /* VCID is an 8-bit value */
|
33 | 57 | #define CANXL_VCID_MASK (CANXL_VCID_VAL_MASK << CANXL_VCID_OFFSET)
|
34 | 58 |
|
| 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 | + |
35 | 81 | /* CAN CC/FD/XL frame union */
|
36 | 82 | typedef union {
|
37 | 83 | struct can_frame cc;
|
|
0 commit comments