Preliminary main mbed library for nexpaq development

Committer:
nexpaq
Date:
Fri Nov 04 20:54:50 2016 +0000
Revision:
1:d96dbedaebdb
Parent:
0:6c56fb4bc5f0
Removed extra directories for other platforms

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nexpaq 0:6c56fb4bc5f0 1 #include "mbed.h"
nexpaq 0:6c56fb4bc5f0 2 #include "test_env.h"
nexpaq 0:6c56fb4bc5f0 3
nexpaq 0:6c56fb4bc5f0 4 #if !DEVICE_CAN
nexpaq 0:6c56fb4bc5f0 5 #error [NOT_SUPPORTED] CAN not supported
nexpaq 0:6c56fb4bc5f0 6 #endif
nexpaq 0:6c56fb4bc5f0 7
nexpaq 0:6c56fb4bc5f0 8 #if defined(TARGET_LPC1549)
nexpaq 0:6c56fb4bc5f0 9 CAN can1(D9, D8);
nexpaq 0:6c56fb4bc5f0 10 #elif defined(TARGET_LPC1768) || defined(TARGET_LPC4088)
nexpaq 0:6c56fb4bc5f0 11 CAN can1(p9, p10);
nexpaq 0:6c56fb4bc5f0 12 #elif defined(TARGET_B96B_F446VE)
nexpaq 0:6c56fb4bc5f0 13 CAN can1(PD_0, PD_1);
nexpaq 0:6c56fb4bc5f0 14 #elif defined(TARGET_VK_RZ_A1H)
nexpaq 0:6c56fb4bc5f0 15 CAN can1(P5_9, P5_10);
nexpaq 0:6c56fb4bc5f0 16 #elif defined(TARGET_NUCLEO_F091RC) || defined(TARGET_NUCLEO_F072RB) || \
nexpaq 0:6c56fb4bc5f0 17 defined(TARGET_NUCLEO_F042K6) || defined(TARGET_NUCLEO_F334R8) || \
nexpaq 0:6c56fb4bc5f0 18 defined(TARGET_NUCLEO_F303RE) || defined(TARGET_NUCLEO_F303K8) || \
nexpaq 0:6c56fb4bc5f0 19 defined(TARGET_NUCLEO_F302R8) || defined(TARGET_NUCLEO_F446RE) || \
nexpaq 0:6c56fb4bc5f0 20 defined(TARGET_DISCO_F429ZI) || \
nexpaq 0:6c56fb4bc5f0 21 defined(TARGET_NUCLEO_F746ZG) || defined(TARGET_DISCO_L476VG) || \
nexpaq 0:6c56fb4bc5f0 22 defined(TARGET_NUCLEO_L476RG) || defined(TARGET_NUCLEO_L432KC)
nexpaq 0:6c56fb4bc5f0 23 CAN can1(PA_11, PA_12);
nexpaq 0:6c56fb4bc5f0 24 defined(TARGET_NUCLEO_F446ZE) || \
nexpaq 0:6c56fb4bc5f0 25 defined(TARGET_NUCLEO_F103RB) || \
nexpaq 0:6c56fb4bc5f0 26 defined(TARGET_NUCLEO_F207ZG) || \
nexpaq 0:6c56fb4bc5f0 27 defined(TARGET_NUCLEO_F303ZE) || \
nexpaq 0:6c56fb4bc5f0 28 defined(TARGET_DISCO_F769NI)
nexpaq 0:6c56fb4bc5f0 29 CAN can1(PB_8, PB_9);
nexpaq 0:6c56fb4bc5f0 30 #endif
nexpaq 0:6c56fb4bc5f0 31
nexpaq 0:6c56fb4bc5f0 32 #define TEST_ITERATIONS 127
nexpaq 0:6c56fb4bc5f0 33
nexpaq 0:6c56fb4bc5f0 34 int main() {
nexpaq 0:6c56fb4bc5f0 35 MBED_HOSTTEST_TIMEOUT(20);
nexpaq 0:6c56fb4bc5f0 36 MBED_HOSTTEST_SELECT(dev_null);
nexpaq 0:6c56fb4bc5f0 37 MBED_HOSTTEST_DESCRIPTION(CAN Loopback);
nexpaq 0:6c56fb4bc5f0 38 MBED_HOSTTEST_START("MBED_A27");
nexpaq 0:6c56fb4bc5f0 39
nexpaq 0:6c56fb4bc5f0 40 #if !defined(TARGET_VK_RZ_A1H)
nexpaq 0:6c56fb4bc5f0 41 can1.mode(CAN::Reset);
nexpaq 0:6c56fb4bc5f0 42 #endif
nexpaq 0:6c56fb4bc5f0 43
nexpaq 0:6c56fb4bc5f0 44 if (!can1.mode(CAN::LocalTest)) {
nexpaq 0:6c56fb4bc5f0 45 printf("Mode change failed\n");
nexpaq 0:6c56fb4bc5f0 46 }
nexpaq 0:6c56fb4bc5f0 47
nexpaq 0:6c56fb4bc5f0 48 char success_count = 0;
nexpaq 0:6c56fb4bc5f0 49 for (char i=0; i < TEST_ITERATIONS; i++) {
nexpaq 0:6c56fb4bc5f0 50 unsigned int id = 1337;
nexpaq 0:6c56fb4bc5f0 51 CANMessage tx_msg(id, &i, sizeof(i));
nexpaq 0:6c56fb4bc5f0 52 bool sent = false;
nexpaq 0:6c56fb4bc5f0 53 if (can1.write(tx_msg)) {
nexpaq 0:6c56fb4bc5f0 54 printf("Sent %u: %d\n", id, i);
nexpaq 0:6c56fb4bc5f0 55 sent = true;
nexpaq 0:6c56fb4bc5f0 56 }
nexpaq 0:6c56fb4bc5f0 57 wait_ms(50);
nexpaq 0:6c56fb4bc5f0 58
nexpaq 0:6c56fb4bc5f0 59 bool read = false;
nexpaq 0:6c56fb4bc5f0 60 CANMessage rx_msg;
nexpaq 0:6c56fb4bc5f0 61 if (can1.read(rx_msg)) {
nexpaq 0:6c56fb4bc5f0 62 printf("Read %u: %d\n", rx_msg.id, rx_msg.data[0]);
nexpaq 0:6c56fb4bc5f0 63 read = (rx_msg.id == id) && (rx_msg.data[0] == i);
nexpaq 0:6c56fb4bc5f0 64 }
nexpaq 0:6c56fb4bc5f0 65
nexpaq 0:6c56fb4bc5f0 66 bool success = sent && read;
nexpaq 0:6c56fb4bc5f0 67
nexpaq 0:6c56fb4bc5f0 68 if (success) {
nexpaq 0:6c56fb4bc5f0 69 success_count++;
nexpaq 0:6c56fb4bc5f0 70 }
nexpaq 0:6c56fb4bc5f0 71 }
nexpaq 0:6c56fb4bc5f0 72
nexpaq 0:6c56fb4bc5f0 73 MBED_HOSTTEST_RESULT(success_count == TEST_ITERATIONS);
nexpaq 0:6c56fb4bc5f0 74 }