Skip to content

Commit 299b560

Browse files
committed
[utest][can] Add CAN send and receive tests
1 parent 0a5a829 commit 299b560

5 files changed

Lines changed: 1773 additions & 0 deletions

File tree

components/drivers/can/SConscript

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import os
12
from building import *
23

34
cwd = GetCurrentDir()
@@ -9,4 +10,9 @@ if not GetDepend('RT_USING_DM'):
910

1011
group = DefineGroup('DeviceDrivers', src, depend = ['RT_USING_CAN'], CPPPATH = CPPPATH)
1112

13+
list = os.listdir(cwd)
14+
for item in list:
15+
if os.path.isfile(os.path.join(cwd, item, 'SConscript')):
16+
group = group + SConscript(os.path.join(item, 'SConscript'))
17+
1218
Return('group')
Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
menu "CAN Test"
2+
3+
config RT_UTEST_CAN
4+
bool "CAN Send and Receive Test"
5+
default n
6+
select RT_USING_CAN
7+
8+
if RT_UTEST_CAN
9+
10+
choice
11+
prompt "CAN Test Topology"
12+
default RT_CAN_TC_USING_SELF_LOOPBACK
13+
14+
config RT_CAN_TC_USING_SELF_LOOPBACK
15+
bool "Single CAN Self Loopback"
16+
help
17+
Use one CAN controller to send and receive its own frame. This
18+
mode uses CAN loopback configuration and is suitable for boards
19+
that support controller loopback or TX/RX self-loop wiring.
20+
21+
config RT_CAN_TC_USING_EXTERNAL_DEVICE
22+
bool "Single CAN with External CAN Device"
23+
help
24+
Use one CAN controller connected through a CAN transceiver to an
25+
external CAN node. The external node must follow the configured
26+
transmit and receive frame agreement.
27+
28+
config RT_CAN_TC_USING_DUAL_DEVICE
29+
bool "Two Connected CAN Devices"
30+
help
31+
Use two CAN controllers connected to the same CAN bus and verify
32+
frame transfer in both directions.
33+
34+
endchoice
35+
36+
config RT_CAN_TC_DEVICE_NAME
37+
string "Device Name for Single CAN Test"
38+
default "can1"
39+
depends on RT_CAN_TC_USING_SELF_LOOPBACK || RT_CAN_TC_USING_EXTERNAL_DEVICE
40+
41+
config RT_CAN_TC_TX_DEVICE_NAME
42+
string "TX Device Name for Two CAN Test"
43+
default "can1"
44+
depends on RT_CAN_TC_USING_DUAL_DEVICE
45+
46+
config RT_CAN_TC_RX_DEVICE_NAME
47+
string "RX Device Name for Two CAN Test"
48+
default "can2"
49+
depends on RT_CAN_TC_USING_DUAL_DEVICE
50+
51+
config RT_CAN_TC_EXTERNAL_USING_SEND_TEST
52+
bool "Enable External Device Send Test"
53+
default y
54+
depends on RT_CAN_TC_USING_EXTERNAL_DEVICE
55+
help
56+
Send one standard data frame to the external CAN node. The external
57+
node should receive standard ID RT_CAN_TC_TX_FRAME_ID with DLC 8 and
58+
payload 0x10, 0x11, ..., 0x17.
59+
60+
config RT_CAN_TC_EXTERNAL_USING_RECEIVE_TEST
61+
bool "Enable External Device Receive Test"
62+
default y
63+
depends on RT_CAN_TC_USING_EXTERNAL_DEVICE
64+
help
65+
Wait for one standard data frame from the external CAN node. The
66+
external node should send standard ID RT_CAN_TC_RX_FRAME_ID with DLC
67+
8 and payload 0x20, 0x21, ..., 0x27.
68+
69+
config RT_CAN_TC_USING_NONBLOCKING_SEND_TEST
70+
bool "Enable Nonblocking Send Test"
71+
default n
72+
help
73+
Send one standard data frame with rt_can_msg.nonblocking set to 1.
74+
Self-loopback and dual-device tests verify the frame end to end.
75+
The external-device test only verifies that the frame is accepted or
76+
queued because the common CAN API has no TX-complete wait interface.
77+
Enable this only when the CAN driver implements sendmsg_nonblocking.
78+
79+
config RT_CAN_TC_TX_FRAME_ID
80+
hex "External Device TX Frame ID"
81+
range 0 0x7FF
82+
default 0x321
83+
depends on RT_CAN_TC_USING_EXTERNAL_DEVICE
84+
85+
config RT_CAN_TC_RX_FRAME_ID
86+
hex "External Device RX Frame ID"
87+
range 0 0x7FF
88+
default 0x322
89+
depends on RT_CAN_TC_USING_EXTERNAL_DEVICE
90+
91+
config RT_CAN_TC_NONBLOCKING_TX_FRAME_ID
92+
hex "Nonblocking TX Frame ID"
93+
range 0 0x7FF
94+
default 0x323
95+
depends on RT_CAN_TC_USING_NONBLOCKING_SEND_TEST
96+
97+
config RT_CAN_TC_BAUD_RATE
98+
int "Primary Arbitration Baud Rate for CAN Test"
99+
range 10000 1000000
100+
default 500000
101+
help
102+
Select one of the standard CAN rates: 10000, 20000, 50000, 100000,
103+
125000, 250000, 500000, 800000, or 1000000 bit/s. This rate is
104+
always tested. Self-loopback and dual-device tests can select
105+
additional rates. The external-device topology uses only this rate
106+
because the peer cannot be switched automatically.
107+
108+
menu "Additional Arbitration Baud Rates"
109+
depends on RT_CAN_TC_USING_SELF_LOOPBACK || RT_CAN_TC_USING_DUAL_DEVICE
110+
111+
config RT_CAN_TC_TEST_BAUD_RATE_10K
112+
bool "Test 10 kbit/s"
113+
default n
114+
115+
config RT_CAN_TC_TEST_BAUD_RATE_20K
116+
bool "Test 20 kbit/s"
117+
default n
118+
119+
config RT_CAN_TC_TEST_BAUD_RATE_50K
120+
bool "Test 50 kbit/s"
121+
default n
122+
123+
config RT_CAN_TC_TEST_BAUD_RATE_100K
124+
bool "Test 100 kbit/s"
125+
default n
126+
127+
config RT_CAN_TC_TEST_BAUD_RATE_125K
128+
bool "Test 125 kbit/s"
129+
default n
130+
131+
config RT_CAN_TC_TEST_BAUD_RATE_250K
132+
bool "Test 250 kbit/s"
133+
default n
134+
135+
config RT_CAN_TC_TEST_BAUD_RATE_500K
136+
bool "Test 500 kbit/s"
137+
default n
138+
139+
config RT_CAN_TC_TEST_BAUD_RATE_800K
140+
bool "Test 800 kbit/s"
141+
default n
142+
143+
config RT_CAN_TC_TEST_BAUD_RATE_1M
144+
bool "Test 1 Mbit/s"
145+
default n
146+
147+
comment "The primary arbitration rate is always tested"
148+
149+
endmenu
150+
151+
config RT_CAN_TC_USING_CANFD
152+
bool "Enable CAN FD Test"
153+
depends on RT_CAN_USING_CANFD
154+
default n
155+
help
156+
In addition to classic CAN frames, verify CAN FD frames with an
157+
extended payload. This is an explicit per-device capability test;
158+
enable it only for CAN FD capable controllers and drivers. CAN FD
159+
frames are tested only at the primary arbitration rate.
160+
161+
config RT_CAN_TC_CANFD_DATA_BAUD_RATE
162+
int "CAN FD Data Phase Baud Rate"
163+
range 10000 10000000
164+
default 2000000
165+
depends on RT_CAN_TC_USING_CANFD
166+
help
167+
The data phase may use the same rate as the arbitration phase.
168+
Select a higher rate when testing effective bit-rate switching.
169+
170+
config RT_CAN_TC_CANFD_DATA_LENGTH
171+
int "Maximum CAN FD Payload Length"
172+
range 12 64
173+
default 16
174+
depends on RT_CAN_TC_USING_CANFD
175+
help
176+
Valid CAN FD payload lengths are 12, 16, 20, 24, 32, 48, and 64
177+
bytes. Other values in the numeric range are rejected at runtime.
178+
179+
config RT_CAN_TC_CANFD_BRS
180+
bool "Enable CAN FD Bit Rate Switching"
181+
default y
182+
depends on RT_CAN_TC_USING_CANFD
183+
184+
config RT_CAN_TC_EXTERNAL_READY_DELAY_MS
185+
int "External Node Ready Delay in Milliseconds"
186+
range 0 60000
187+
default 1000
188+
depends on RT_CAN_TC_USING_EXTERNAL_DEVICE
189+
help
190+
Delay after the DUT is configured and prints the frame agreement.
191+
This gives the external node time to start its ordered frame sequence.
192+
193+
config RT_CAN_TC_TIMEOUT_MS
194+
int "RX Timeout in Milliseconds"
195+
range 1000 60000
196+
default 10000
197+
198+
endif
199+
200+
endmenu
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Import('rtconfig')
2+
from building import *
3+
4+
cwd = GetCurrentDir()
5+
src = []
6+
CPPPATH = [cwd, cwd + '/../../include']
7+
8+
if GetDepend(['RT_UTEST_CAN']):
9+
src += Glob('*.c')
10+
11+
group = DefineGroup('utestcases', src, depend = ['RT_USING_UTESTCASES', 'RT_USING_CAN'], CPPPATH = CPPPATH)
12+
13+
Return('group')

0 commit comments

Comments
 (0)