@@ -24,72 +24,78 @@ SCENARIO("calc_can_bit_timing", "[calc_can_bit_timing]")
24
24
{
25
25
GIVEN (" Santiago" )
26
26
{
27
- static uint32_t const F_CAN_CLK_Hz = 20 *1000 *1000UL ;
28
- static uint32_t const TQ_MIN = 8 ;
29
- static uint32_t const TQ_MAX = 25 ;
30
- static uint32_t const SYNC_JUMP_WIDTH = 4 ;
27
+ static uint32_t const F_CAN_CLK_Hz = 24 *1000 *1000UL ;
28
+ static uint32_t const TQ_MIN = 8 ;
29
+ static uint32_t const TQ_MAX = 25 ;
30
+ static uint32_t const TSEG_1_MIN = 4 ;
31
+ static uint32_t const TSEG_1_MAX = 16 ;
32
+ static uint32_t const TSEG_2_MIN = 2 ;
33
+ static uint32_t const TSEG_2_MAX = 8 ;
31
34
32
35
WHEN (" CanBitRate::BR_125k" )
33
36
{
34
37
auto [is_valid_baudrate, baud_rate_prescaler, time_segment_1, time_segment_2] =
35
- util::calc_can_bit_timing (CanBitRate::BR_125k, F_CAN_CLK_Hz, TQ_MIN, TQ_MAX, SYNC_JUMP_WIDTH );
38
+ util::calc_can_bit_timing (CanBitRate::BR_125k, F_CAN_CLK_Hz, TQ_MIN, TQ_MAX, TSEG_1_MIN, TSEG_1_MAX, TSEG_2_MIN, TSEG_2_MAX );
36
39
THEN (" " )
37
40
{
38
- REQUIRE (is_valid_baudrate == true );
39
- REQUIRE (baud_rate_prescaler == 8 );
40
- REQUIRE (time_segment_1 == 11 );
41
- REQUIRE (time_segment_2 == 4 );
41
+ REQUIRE (is_valid_baudrate == true );
42
+ REQUIRE (baud_rate_prescaler == 12 );
43
+ REQUIRE (time_segment_1 == 11 );
44
+ REQUIRE (time_segment_2 == 4 );
42
45
}
43
46
}
44
47
WHEN (" CanBitRate::BR_250k" )
45
48
{
46
49
auto [is_valid_baudrate, baud_rate_prescaler, time_segment_1, time_segment_2] =
47
- util::calc_can_bit_timing (CanBitRate::BR_250k, F_CAN_CLK_Hz, TQ_MIN, TQ_MAX, SYNC_JUMP_WIDTH );
50
+ util::calc_can_bit_timing (CanBitRate::BR_250k, F_CAN_CLK_Hz, TQ_MIN, TQ_MAX, TSEG_1_MIN, TSEG_1_MAX, TSEG_2_MIN, TSEG_2_MAX );
48
51
THEN (" " )
49
52
{
50
- REQUIRE (is_valid_baudrate == true );
51
- REQUIRE (baud_rate_prescaler == 4 );
52
- REQUIRE (time_segment_1 == 11 );
53
- REQUIRE (time_segment_2 == 4 );
53
+ REQUIRE (is_valid_baudrate == true );
54
+ REQUIRE (baud_rate_prescaler == 6 );
55
+ REQUIRE (time_segment_1 == 11 );
56
+ REQUIRE (time_segment_2 == 4 );
54
57
}
55
58
}
56
59
WHEN (" CanBitRate::BR_500k" )
57
60
{
58
61
auto [is_valid_baudrate, baud_rate_prescaler, time_segment_1, time_segment_2] =
59
- util::calc_can_bit_timing (CanBitRate::BR_500k, F_CAN_CLK_Hz, TQ_MIN, TQ_MAX, SYNC_JUMP_WIDTH );
62
+ util::calc_can_bit_timing (CanBitRate::BR_500k, F_CAN_CLK_Hz, TQ_MIN, TQ_MAX, TSEG_1_MIN, TSEG_1_MAX, TSEG_2_MIN, TSEG_2_MAX );
60
63
THEN (" " )
61
64
{
62
- REQUIRE (is_valid_baudrate == true );
63
- REQUIRE (baud_rate_prescaler == 2 );
64
- REQUIRE (time_segment_1 == 11 );
65
- REQUIRE (time_segment_2 == 4 );
65
+ REQUIRE (is_valid_baudrate == true );
66
+ REQUIRE (baud_rate_prescaler == 3 );
67
+ REQUIRE (time_segment_1 == 11 );
68
+ REQUIRE (time_segment_2 == 4 );
66
69
}
67
70
}
68
71
WHEN (" CanBitRate::BR_1000k" )
69
72
{
70
73
auto [is_valid_baudrate, baud_rate_prescaler, time_segment_1, time_segment_2] =
71
- util::calc_can_bit_timing (CanBitRate::BR_1000k, F_CAN_CLK_Hz, TQ_MIN, TQ_MAX, SYNC_JUMP_WIDTH );
74
+ util::calc_can_bit_timing (CanBitRate::BR_1000k, F_CAN_CLK_Hz, TQ_MIN, TQ_MAX, TSEG_1_MIN, TSEG_1_MAX, TSEG_2_MIN, TSEG_2_MAX );
72
75
THEN (" " )
73
76
{
74
- REQUIRE (is_valid_baudrate == true );
75
- REQUIRE (baud_rate_prescaler == 1 );
76
- REQUIRE (time_segment_1 == 11 );
77
- REQUIRE (time_segment_2 == 4 );
77
+ REQUIRE (is_valid_baudrate == true );
78
+ REQUIRE (baud_rate_prescaler == 2 );
79
+ REQUIRE (time_segment_1 == 8 );
80
+ REQUIRE (time_segment_2 == 3 );
78
81
}
79
82
}
80
83
}
81
84
82
85
GIVEN (" Portenta H33" )
83
86
{
84
87
static uint32_t const F_CAN_CLK_Hz = 24 *1000 *1000UL ;
85
- static uint32_t const TQ_MIN = 5 ;
86
- static uint32_t const TQ_MAX = 49 ;
87
- static uint32_t const SYNC_JUMP_WIDTH = 1 ;
88
+ static uint32_t const TQ_MIN = 5 ;
89
+ static uint32_t const TQ_MAX = 49 ;
90
+ static uint32_t const TSEG_1_MIN = 2 ;
91
+ static uint32_t const TSEG_1_MAX = 39 ;
92
+ static uint32_t const TSEG_2_MIN = 2 ;
93
+ static uint32_t const TSEG_2_MAX = 10 ;
88
94
89
95
WHEN (" CanBitRate::BR_125k" )
90
96
{
91
97
auto [is_valid_baudrate, baud_rate_prescaler, time_segment_1, time_segment_2] =
92
- util::calc_can_bit_timing (CanBitRate::BR_125k, F_CAN_CLK_Hz, TQ_MIN, TQ_MAX, SYNC_JUMP_WIDTH );
98
+ util::calc_can_bit_timing (CanBitRate::BR_125k, F_CAN_CLK_Hz, TQ_MIN, TQ_MAX, TSEG_1_MIN, TSEG_1_MAX, TSEG_2_MIN, TSEG_2_MAX );
93
99
THEN (" " )
94
100
{
95
101
REQUIRE (is_valid_baudrate == true );
@@ -101,19 +107,19 @@ SCENARIO("calc_can_bit_timing", "[calc_can_bit_timing]")
101
107
WHEN (" CanBitRate::BR_250k" )
102
108
{
103
109
auto [is_valid_baudrate, baud_rate_prescaler, time_segment_1, time_segment_2] =
104
- util::calc_can_bit_timing (CanBitRate::BR_250k, F_CAN_CLK_Hz, TQ_MIN, TQ_MAX, SYNC_JUMP_WIDTH );
110
+ util::calc_can_bit_timing (CanBitRate::BR_250k, F_CAN_CLK_Hz, TQ_MIN, TQ_MAX, TSEG_1_MIN, TSEG_1_MAX, TSEG_2_MIN, TSEG_2_MAX );
105
111
THEN (" " )
106
112
{
107
113
REQUIRE (is_valid_baudrate == true );
108
114
REQUIRE (baud_rate_prescaler == 3 );
109
- REQUIRE (time_segment_1 == 28 );
115
+ REQUIRE (time_segment_1 == 23 );
110
116
REQUIRE (time_segment_2 == 8 );
111
117
}
112
118
}
113
119
WHEN (" CanBitRate::BR_500k" )
114
120
{
115
121
auto [is_valid_baudrate, baud_rate_prescaler, time_segment_1, time_segment_2] =
116
- util::calc_can_bit_timing (CanBitRate::BR_500k, F_CAN_CLK_Hz, TQ_MIN, TQ_MAX, SYNC_JUMP_WIDTH );
122
+ util::calc_can_bit_timing (CanBitRate::BR_500k, F_CAN_CLK_Hz, TQ_MIN, TQ_MAX, TSEG_1_MIN, TSEG_1_MAX, TSEG_2_MIN, TSEG_2_MAX );
117
123
THEN (" " )
118
124
{
119
125
REQUIRE (is_valid_baudrate == true );
@@ -125,7 +131,7 @@ SCENARIO("calc_can_bit_timing", "[calc_can_bit_timing]")
125
131
WHEN (" CanBitRate::BR_1000k" )
126
132
{
127
133
auto [is_valid_baudrate, baud_rate_prescaler, time_segment_1, time_segment_2] =
128
- util::calc_can_bit_timing (CanBitRate::BR_1000k, F_CAN_CLK_Hz, TQ_MIN, TQ_MAX, SYNC_JUMP_WIDTH );
134
+ util::calc_can_bit_timing (CanBitRate::BR_1000k, F_CAN_CLK_Hz, TQ_MIN, TQ_MAX, TSEG_1_MIN, TSEG_1_MAX, TSEG_2_MIN, TSEG_2_MAX );
129
135
THEN (" " )
130
136
{
131
137
REQUIRE (is_valid_baudrate == true );
0 commit comments