rsiot/components_config/can_general/can_settings.rs
1// ANCHOR: CanSettings
2/// Конфигурация CAN-протокола
3#[derive(Clone, Debug, Default)]
4pub struct CanSettings {
5 /// Настройка скорости CAN
6 pub bitrate: CanSettingsBitrate,
7
8 /// Настройка скорости CAN-FD
9 pub dbitrate: CanSettingsDbitrate,
10
11 /// Used specially when running more than one application on the same node (host)
12 pub mode_loopback: bool,
13
14 /// Only listen for frames on the bus (no sending)
15 pub mode_listen_only: bool,
16
17 /// Make 3 samples instead of 1 during the bit time (on the 2 TQs before the Sample Point)
18 pub mode_triple_sampling: bool,
19
20 /// Just send the CAN message one time (skip retransmission in case of error)
21 pub mode_one_shot: bool,
22
23 /// Enable/Disable Bit Error reporting
24 pub mode_berr_reporting: bool,
25
26 /// CAN-FD протокол
27 pub mode_fd: bool,
28
29 /// When enabled, acknowledgement absence is ignored
30 pub mode_presume_ack: bool,
31
32 /// Enable non-ISO CAN FD (this is the first specification of CAN FD, called CAN FD 1.0 and it’s
33 /// not compatible with ISO CAN FD)
34 pub mode_fd_non_iso: bool,
35
36 /// DLC remaining seven values from 9 to 15 used for CAN FD should be set to 8 for standard CAN.
37 pub mode_cc_len8_dlc: bool,
38
39 /// Transmitter Delay Compensation Value mode (automatic, manual or disabled - used in CAN FD)
40 pub mode_tdcv_mode: bool,
41
42 /// Automatic restart delay time, the time to wait before restart the CAN controller in case of
43 /// a bus-off condition (a CAN node becomes Bus-Off when the the counter for transmission errors
44 /// becomes greater or equal to 256, so the node is deactivated)
45 pub restart_ms: Option<u32>,
46}
47// ANCHOR: CanSettings
48
49// ANCHOR: CanSettingsBitrate
50/// Настройка скорости передачи CAN
51#[derive(Clone, Debug)]
52pub enum CanSettingsBitrate {
53 /// Обычное задание скорости
54 Standard {
55 /// CAN interface’s bit rate (bps)
56 bitrate: u32,
57
58 /// Point in time period where the bus is read to get the current bit level
59 sample_point: Option<f32>,
60 },
61
62 /// Пользовательская настройка скорости
63 Custom {
64 /// Time Quantum (1 TQ = 1 Clock tick)
65 tq: u8,
66
67 /// Compensates the propagation of physical delays between nodes
68 prop_seg: u8,
69
70 /// Used to compensate errors between signal edges and adjust the length of the bit
71 phase_seg1: u8,
72
73 /// Used to compensate errors between signal edges and adjust the length of the bit
74 phase_seg2: u8,
75
76 /// Synchronization jump width, that’s the maximum time by which the bit sampling period
77 /// might be delayed or shortened during each cycle
78 sjw: Option<u8>,
79 },
80}
81// ANCHOR: CanSettingsBitrate
82impl Default for CanSettingsBitrate {
83 fn default() -> Self {
84 CanSettingsBitrate::Standard {
85 bitrate: 500_000,
86 sample_point: None,
87 }
88 }
89}
90
91/// Настройка скорости передачи CAN-FD
92#[derive(Clone, Debug)]
93pub enum CanSettingsDbitrate {
94 /// Используется классический CAN
95 None,
96
97 /// Обычное задание скорости
98 Standard {
99 /// Data bit rate (used in CAN FD, which supports different bit rates for the arbitration phase
100 /// and the data/payload phase)
101 dbitrate: u32,
102
103 /// Data Time Quantum (used in CAN FD)
104 dsample_point: Option<f32>,
105
106 /// Transmitter Delay Compensation Value (used in CAN FD)
107 tdcv: Option<u8>,
108
109 /// Transmitter Delay Compensation Offset (used in CAN FD)
110 tdco: Option<u8>,
111
112 /// Transmitter Delay Compensation Filter windows value (used in CAN FD)
113 tdcf: Option<u8>,
114 },
115
116 /// Пользовательская настройка скорости
117 Custom {
118 /// Data Time Quantum (used in CAN FD)
119 dtq: u8,
120
121 /// Compensates the propagation of physical delays between nodes
122 dprop_seg: u8,
123
124 /// Used to compensate errors between signal edges and adjust the length of the bit
125 dphase_seg1: u8,
126
127 /// Used to compensate errors between signal edges and adjust the length of the bit
128 dphase_seg2: u8,
129
130 /// Synchronization jump width, that’s the maximum time by which the bit sampling period
131 /// might be delayed or shortened during each cycle
132 dsjw: Option<u8>,
133
134 /// Transmitter Delay Compensation Value (used in CAN FD)
135 tdcv: Option<u8>,
136
137 /// Transmitter Delay Compensation Offset (used in CAN FD)
138 tdco: Option<u8>,
139
140 /// Transmitter Delay Compensation Filter windows value (used in CAN FD)
141 tdcf: Option<u8>,
142 },
143}
144impl Default for CanSettingsDbitrate {
145 fn default() -> Self {
146 CanSettingsDbitrate::Standard {
147 dbitrate: 500_000,
148 dsample_point: None,
149 tdcv: None,
150 tdco: None,
151 tdcf: None,
152 }
153 }
154}