can.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2016 OTA keys S.A.
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser General
5  * Public License v2.1. See the file LICENSE in the top level directory for more
6  * details.
7  */
8 
26 #ifndef CAN_CAN_H
27 #define CAN_CAN_H
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
33 #include <stdint.h>
34 
35 #if defined(__linux__)
36 
37 #include <linux/can.h>
38 #include <libsocketcan.h>
39 
40 #else
41 
45 #define CAN_MAX_DLEN (8)
46 
51 /* special address description flags for the CAN_ID */
52 #define CAN_EFF_FLAG (0x80000000U)
53 #define CAN_RTR_FLAG (0x40000000U)
54 #define CAN_ERR_FLAG (0x20000000U)
56 /* valid bits in CAN ID for frame formats */
57 #define CAN_SFF_MASK (0x000007FFU)
58 #define CAN_EFF_MASK (0x1FFFFFFFU)
59 #define CAN_ERR_MASK (0x1FFFFFFFU)
65  enum can_state {
72  CAN_STATE_MAX
73  };
74 
83 typedef uint32_t canid_t;
84 
88 struct can_frame {
90  uint8_t can_dlc;
91  uint8_t __pad;
92  uint8_t __res0;
93  uint8_t __res1;
95  uint8_t data[CAN_MAX_DLEN] __attribute__((aligned(8)));
96 };
97 
101 struct can_filter {
104 };
105 
114  uint32_t bitrate;
115  uint32_t sample_point;
116  uint32_t tq;
117  uint32_t prop_seg;
118  uint32_t phase_seg1;
119  uint32_t phase_seg2;
120  uint32_t sjw;
121  uint32_t brp;
122 };
123 
130  uint32_t tseg1_min;
131  uint32_t tseg1_max;
132  uint32_t tseg2_min;
133  uint32_t tseg2_max;
134  uint32_t sjw_max;
135  uint32_t brp_min;
136  uint32_t brp_max;
137  uint32_t brp_inc;
138 };
139 
140 #endif /* defined(__linux__) */
141 
142 #ifdef __cplusplus
143 }
144 #endif
145 
146 #endif /* CAN_CAN_H */
147 
canid_t can_mask
Mask.
Definition: can.h:103
uint32_t brp
Bit-rate prescaler.
Definition: can.h:121
CAN hardware-dependent bit-timing constant.
Definition: can.h:129
uint8_t __res1
reserved / padding
Definition: can.h:93
RX/TX error count < 128.
Definition: can.h:67
uint32_t bitrate
Bit-rate in bits/second.
Definition: can.h:114
uint8_t __res0
reserved / padding
Definition: can.h:92
uint32_t canid_t
Controller Area Network Identifier structure.
Definition: can.h:83
uint32_t brp_inc
Bit-rate prescaler, increment.
Definition: can.h:137
Device is stopped.
Definition: can.h:70
uint32_t brp_min
Bit-rate prescaler, min value.
Definition: can.h:135
uint8_t __pad
padding
Definition: can.h:91
uint32_t tseg1_min
Time segment 1 = prop_seg + phase_seg1, min value.
Definition: can.h:130
RX/TX error count < 96.
Definition: can.h:66
uint32_t phase_seg2
Phase buffer segment 2 in TQs.
Definition: can.h:119
RX/TX error count >= 256.
Definition: can.h:69
#define CAN_MAX_DLEN
Max data length for a CAN frame.
Definition: can.h:45
Device is sleeping.
Definition: can.h:71
RX/TX error count < 256.
Definition: can.h:68
Controller Area Network frame.
Definition: can.h:88
uint32_t phase_seg1
Phase buffer segment 1 in TQs.
Definition: can.h:118
uint32_t sjw_max
Synchronisation jump width.
Definition: can.h:134
canid_t can_id
32 bit CAN_ID + EFF/RTR/ERR flags
Definition: can.h:89
uint32_t tseg1_max
Time segment 1, max value.
Definition: can.h:131
uint32_t sample_point
Sample point in one-tenth of a percent.
Definition: can.h:115
Controller Area Network filter.
Definition: can.h:101
uint8_t data[CAN_MAX_DLEN]
Frame data.
Definition: can.h:95
uint32_t sjw
Synchronisation jump width in TQs.
Definition: can.h:120
uint32_t tseg2_min
Time segment 2 = phase_seg2, min value.
Definition: can.h:132
uint32_t tq
Time quanta (TQ) in nanoseconds.
Definition: can.h:116
uint32_t tseg2_max
Time segment 2, max value.
Definition: can.h:133
uint8_t can_dlc
frame payload length in byte (0 .
Definition: can.h:90
uint32_t brp_max
Bit-rate prescaler, max value.
Definition: can.h:136
CAN bit-timing parameters.
Definition: can.h:113
canid_t can_id
CAN ID.
Definition: can.h:102
uint32_t prop_seg
Propagation segment in TQs.
Definition: can.h:117