Ok, I've made up an ICMP packet and with reply which toggles the led.
Here is the code.
uint8_t my_ping_data[] = {
0x18,0xdb,0xf2,0x3b,0xc0,0x59,0x11,0x22,0x33,0x44,0x55,0x66,0x08,0x00,0x45,0x00,
0x00,0x3c,0x3a,0x2c,0x00,0x00,0x80,0x01,0x7d,0x2d,0xc0,0xa8,0x01,0x12,0xc0,0xa8,
0x01,0x05,0x08,0x00,0xcd,0x8f,0x00,0x01,0x7f,0xcb,0x61,0x62,0x63,0x64,0x65,0x66,
0x67,0x68,0x69,0x6a,0x6b,0x6c,0x6d,0x6e,0x6f,0x70,0x71,0x72,0x73,0x74,0x75,0x76,
0x77,0x61,0x62,0x63,0x64,0x65,0x66,0x67,0x68,0x69
};
uint16_t length;
void build_ping(uint8_t *data)
{
#if 1
uint8_t dst_mac[6] = { 0x18, 0xdb, 0xf2, 0x3b, 0xc0, 0x59 }; /* MAC address of target */
uint8_t dst_ip[4] = { 0xc0, 0xa8, 0x01, 0x05 }; /* 192.168.1.5 IP of target */
#else
uint8_t dst_mac[6] = { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66 }; /* MAC address of board */
uint8_t dst_ip[4] = { 0xc0, 0xa8, 0x01, 0x12 }; /* 192.168.1.18 IP of board */
#endif
uint8_t src_mac[6] = { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66 }; /* MAC address of board */
uint8_t src_ip[4] = { 0xc0, 0xa8, 0x01, 0x12 }; /* 192.168.1.18 IP of board */
/* MAC and IP addresses */
copy_buff(&data[FRAME_ETH_DEST_MAC_OFFSET], dst_mac, 6);
copy_buff(&data[FRAME_ETH_SRC_MAC_OFFSET], src_mac, 6);
copy_buff(&data[FRAME_IP_DEST_OFFSET], dst_ip, 4);
copy_buff(&data[FRAME_IP_SRC_OFFSET], src_ip, 4);
/* Clear IP and ICMP checksums (to be filled in by the MAC) */
data[FRAME_IP_CHECKSUM_OFFSET] = 0;
data[FRAME_IP_CHECKSUM_OFFSET + 1] = 0;
data[FRAME_ICMP_CHECKSUM_OFFSET] = 0;
data[FRAME_ICMP_CHECKSUM_OFFSET + 1] = 0;
/* Update ICMP type to represent Ping */
data[FRAME_ICMP_TYPE_OFFSET] = FRAME_ICMP_TYPE_ECHO_REQUEST;
}
Add this to rx_callback
else if (buffList[0].data[FRAME_IP_PROTO_OFFSET] == FRAME_IP_PROTO_ICMP &&
buffList[0].data[FRAME_ICMP_TYPE_OFFSET] == FRAME_ICMP_TYPE_ECHO_REPLY){
/* Toggle output value LED1 if we get ping reply*/
SIUL2->GPDO[LED/4] = SIUL2->GPDO[LED/4] ^ (SIUL2_GPDO_PDO_4n_WIDTH << (SIUL2_GPDO_PDO_4n_SHIFT - (8 * (LED & 0x03))));
}
In main add this:
enet_buffer_t buff;
buff.data = my_ping_data;
buff.length = sizeof(my_ping_data);
build_ping(buff.data);
for (;;)
{
/* Send back an ICMP echo reply frame */
ENET_DRV_SendFrame(INST_ETHERNET1, &buff, 1);
/* Insert a small delay to make the blinking visible */
delay(720000);
}
Thanks and Regards,
Tiju