File tree Expand file tree Collapse file tree 2 files changed +65
-1
lines changed
libraries/tests/mbed/can_loopback Expand file tree Collapse file tree 2 files changed +65
-1
lines changed Original file line number Diff line number Diff line change
1
+ #include " mbed.h"
2
+ #include " test_env.h"
3
+
4
+ #if defined(TARGET_LPC1549)
5
+ CAN can1 (D9, D8);
6
+ #elif defined(TARGET_LPC1768) || defined(TARGET_LPC4088)
7
+ CAN can1 (p9, p10);
8
+ #endif
9
+
10
+ #define TEST_ITERATIONS 127
11
+
12
+ int main () {
13
+ MBED_HOSTTEST_TIMEOUT (20 );
14
+ MBED_HOSTTEST_SELECT (dev_null);
15
+ MBED_HOSTTEST_DESCRIPTION (CAN Loopback);
16
+ MBED_HOSTTEST_START (" MBED_A27" );
17
+
18
+ can1.mode (CAN::Reset);
19
+
20
+ if (!can1.mode (CAN::LocalTest)) {
21
+ printf (" Mode change failed\n " );
22
+ }
23
+
24
+ char success_count = 0 ;
25
+ for (char i=0 ; i < TEST_ITERATIONS; i++) {
26
+ unsigned int id = 1337 ;
27
+ CANMessage tx_msg (id, &i, sizeof (i));
28
+ bool sent = false ;
29
+ if (can1.write (tx_msg)) {
30
+ printf (" Sent %u: %d\n " , id, i);
31
+ sent = true ;
32
+ }
33
+ wait_ms (50 );
34
+
35
+ bool read = false ;
36
+ CANMessage rx_msg;
37
+ if (can1.read (rx_msg)) {
38
+ printf (" Read %u: %d\n " , rx_msg.id , rx_msg.data [0 ]);
39
+ read = (rx_msg.id == id) && (rx_msg.data [0 ] == i);
40
+ }
41
+
42
+ bool success = sent && read;
43
+
44
+ if (success) {
45
+ success_count++;
46
+ }
47
+ }
48
+
49
+ MBED_HOSTTEST_RESULT (success_count == TEST_ITERATIONS);
50
+ }
Original file line number Diff line number Diff line change 80
80
* i2c_eeprom:
81
81
* LPC1*: (SDA=p28 , SCL=p27)
82
82
* KL25Z: (SDA=PTE0, SCL=PTE1)
83
-
83
+
84
+ * can_transceiver:
85
+ * LPC1768: (RX=p9, TX=p10)
86
+ * LPC1549: (RX=D9, TX=D8)
87
+ * LPC4088: (RX=p9, TX=p10)
88
+
84
89
"""
85
90
TESTS = [
86
91
# Automated MBED tests
270
275
"automated" : True ,
271
276
"duration" : 10 ,
272
277
},
278
+ {
279
+ "id" : "MBED_A27" , "description" : "CAN loopback test" ,
280
+ "source_dir" : join (TEST_DIR , "mbed" , "can_loopback" ),
281
+ "dependencies" : [MBED_LIBRARIES , TEST_MBED_LIB ],
282
+ "automated" : True ,
283
+ "duration" : 20 ,
284
+ "peripherals" : ["can_transceiver" ],
285
+ "mcu" : ["LPC1549" , "LPC1768" ],
286
+ },
273
287
{
274
288
"id" : "MBED_BLINKY" , "description" : "Blinky" ,
275
289
"source_dir" : join (TEST_DIR , "mbed" , "blinky" ),
You can’t perform that action at this time.
0 commit comments