I am trying to find a way to do a loopback test of the ethernet port on our target board. Ideally I would like to do this with just a loopback connector on the ethernet interface, and not require any external active device to be connected.
What I am seeing is that, when running in the simulator, the application can send a broadcast UDP frame, then receive that same frame. But when running on the target board, it definitely sends the frame (I can see it in Ethereal) but does not receive it.
I have the unit send a broadcast UDP frame, using IP address of 255.255.255.255 (using fnAddARP() to add something to the arp cache so the UDP send function does not try to arp it and fail). A UDP receive task is setup to see this frame, and currently, to send a 'response' frame (also a broadcast frame).
Here is the code to send the 'request':
unsigned char ip[4] = {255, 255, 255, 255};
unsigned char mac[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
UDP_MESSAGE udp;
uStrcpy((CHAR *) udp.ucUDP_Message, "Request");
fnAddARP(ip, mac, ARP_FIXED_IP);
fnSendUDP(socket, ip, A32_TEST_SERVER_PORT, (unsigned char *) &udp + 2, uStrlen((CHAR *) udp.ucUDP_Message), OWN_TASK);
And here is the code to receive the 'request' and send a 'response':
extern void test_svr(TTASKTABLE *ptrTaskTable) {
if(!((socket = fnGetUDP_socket(TOS_MINIMISE_DELAY, udp_listener, (UDP_OPT_SEND_CS | UDP_OPT_CHECK_CS))) < 0)) {
fnBindSocket(socket, TEST_SERVER_PORT);
ptrUDP_Frame = uMalloc(sizeof(UDP_MESSAGE));
} else {
return;
}
}
// UDP data server - reception call back function
//
extern int udp_listener(USOCKET SocketNr, unsigned char ucEvent, unsigned char *ucIP, unsigned short usPortNr, unsigned char *data, unsigned short usLength) {
unsigned char new_ip[4] = {255, 255, 255, 255};
unsigned char new_mac[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
switch(ucEvent) {
case UDP_EVENT_RXDATA:
if(uMemcmp(data, "Request", 7) == 0) {
fnAddARP(new_ip, new_mac, ARP_FIXED_IP);
uStrcpy((CHAR *) data, "Response");
usLength = uStrlen((CHAR *) data);
fnSendUDP(socket, new_ip, TEST_SERVER_PORT, (data - sizeof(UDP_HEADER)), usLength, OWN_TASK);
}
break;
}
return 0;
}
This works fine in the simulator; the frame gets sent, and the UDP receiver task sees the frame and then sends a similar but slightly different frame. When I run on the target board, it never sees the 'request' frame that it sent. If I run my target board AND the simulator on the same net, the target board receives the 'response' frame from the simulator, but not from itself; the target board does not see its own 'request' frame.
Maybe this just means the ethernet interface is running in half duplex mode? I'm not sure what determines that; the target and the PC running the simulator are connected to the same hub.
Anyone have any other suggestion for testing the ethernet port with a minimum of external hardware?