Forum Discussion
DE2_UDP example for download here free (feedbacks are wellcomed)
Hi all.
My goal is to get about 3Mbytes/sec data transfer rate from my DE2 board to PC. Here in this example I get about 1.2 Mbytes/sec. I'll accept comments about, how to speed up this, as well as suggests to improve the code, and some feedback from people that have interest in this theme. Could be in this thread or private. You can download the full project from: http://www.btxsistemas.com.ar/net2.zip I've used Quartus II 7.2 full suite. And the Wireshark software (http://www.wireshark.org/) like a net sniffer, but also, I've included in the main project folder, a UDP reciever to test the comunication between the DE2 board and the PC, if you wont to download the wireshark. Don't forget to specify your IP address and your MAC address in the NIOS hello_word "C" code to get it work properly. The main project is a modification of the DE2_NET demostration code that comes with the DE2 board. Have fun, and I'll be waiting for some comments.94 Replies
- Altera_Forum
Honored Contributor
Hi cafukarfoo.
I haven't any idea why data is corrupt, are you completely sure of that ? Did you write correctly your IP in hex in the code ? or, are you sure wirreshark is getting data only from DE2 ? Is the MAC address correct ? Sorry if the tips I suggest you are so simple, but there are no reason to get that results. Try to avoid the router to let you know all recieved is from DE2 board, I can imagine you try with differents net cables. Cheers. Alberto. - Altera_Forum
Honored Contributor
That's all I need to learn about UDP on DE2-70 board, if not a problem, can I ask you if I have some mistaken it.
- Altera_Forum
Honored Contributor
--- Quote Start --- That's all I need to learn about UDP on DE2-70 board, if not a problem, can I ask you if I have some mistaken it. --- Quote End --- It's ok. Cheers Alberto. - Altera_Forum
Honored Contributor
hi, I modified your project for DE2-70 Board, but since nothing come in and out on the board, I could not make the connection between the board and my PC.
Please help me (Urgent) Here I attached my project. http://cid-70829448936b989b.office.live.com/embedicon.aspx/Public/NET^_PART.zip http://cid-70829448936b989b.office.live.com/self.aspx/public/net%5e_part.zip - Altera_Forum
Honored Contributor
Hi friends,
I got it work, but do you know how to capture those packets at PC side. I wrote simple UDP program in JAVA to listen on the IP Address 192.168.0.30 (DE2 IP Address) and port 1024 (get the port number by observe the packet in Ethereal). But I have not received any thing. And I would to do the receive function as well. Anyone give me an advise how to do it? - Altera_Forum
Honored Contributor
Hi btxsistemas,
I would like to modified your code to send and receive a string data but I am not successes, would you please show me how to do it? Since I am using your code and I receive very weird data on my PC side. Please help me. Thanks! - Altera_Forum
Honored Contributor
--- Quote Start --- Hi btxsistemas, I would like to modified your code to send and receive a string data but I am not successes, would you please show me how to do it? Since I am using your code and I receive very weird data on my PC side. Please help me. Thanks! --- Quote End --- Sorry I leave that project a long time ago, I never did the recieve part in the DE2. Try with the recieve example code that comes with the board. Cheers. Aberto. - Altera_Forum
Honored Contributor
Hi,
I was success to make it transfer a character from DE2 board to PC, and I got correct a character on PC side. But when I transferred the character back from PC to DE2 board, I could not make it correctly. I always got the same data for different character data. Could anyone please help me with my code Here is my files/* * network.h * */ # ifndef NETWORK_H_ # define NETWORK_H_ /* Assign IP: 192.168.1.44 IP Address for the DE2 */ # define Src_IP1 0xC0 # define Src_IP2 0xA8 # define Src_IP3 0x01 # define Src_IP4 0x2C /* Assign IP: 192.168.1.30 IP Address for the PC */ # define Dest_IP1 0xC0 # define Dest_IP2 0xA8 # define Dest_IP3 0x01 # define Dest_IP4 0x1E /* DE2 MAC Address */ # define Src_MAC1 0x01 # define Src_MAC2 0x60 # define Src_MAC3 0x6E # define Src_MAC4 0x11 # define Src_MAC5 0x02 # define Src_MAC6 0x0F /* PC MAC Address */ # define Dest_MAC1 0x00 # define Dest_MAC2 0x16 # define Dest_MAC3 0xD4 # define Dest_MAC4 0xBB # define Dest_MAC5 0xCA # define Dest_MAC6 0x91 # define payload 1 /* Send and receive one character */ /* Total Packet Length * Frame Header, IP Header, UDP Header, Payload * */ # define Packet_Len (payload + 0x2B) # define UDP_Len (payload + 8) # define UDP_Len_H ((UDP_Len & 0xFF00)>>8) # define UDP_Len_L (UDP_Len & 0x00FF) # define IP_Len (payload + 8 + 20) # define IP_Len_H ((IP_Len & 0xFF00)>>8) # define IP_Len_L (IP_Len & 0x00FF) # define IP_Csum1 (0x0000C511 + (Src_IP1<<8)+Src_IP2+(Src_IP3<<8)+Src_IP4+(Dest_IP1<<8)+Dest_IP2+(Dest_IP3<<8)+(Dest_IP4)+(IP_Len_H<<8) + IP_Len_L) # define IP_Csum2 ((IP_Csum1&0x0000FFFF)+(IP_Csum1>>16)) # define IP_Csum3 (0x0000FFFF - IP_Csum2) # define IP_Csum4 ((IP_Csum3 & 0xFF00)>>8) # define IP_Csum5 ((IP_Csum3 & 0x00FF)) # endif /* NETWORK_H_ */
Here is my receiving data (always the same for different character data) Receive Packet Length = 64 0x01,0x60,0x6E,0x11,0x02,0x0F,0x00,0x16, 0xD4,0xBB,0xCA,0x91,0x08,0x00,0x45,0x00, 0x00,0x2D,0x10,0xC7,0x00,0x00,0x80,0x11, 0xA6,0x5E,0xC0,0xA8,0x01,0x1E,0xC0,0xA8, 0x01,0x2C,0x04,0x00,0x04,0x00,0x00,0x19, 0x88,0xAE,0x2F,0x31,0x39,0x32,0x2E,0x31, 0x36,0x38,0x2E,0x31,0x2E,0x34,0x34,0x20, 0x3A,0x20,0x54,0x00,0x2A,0x58,0x79,0x24, Receive message: //* * main.c * */ # include "basic_io.h" # include "network.h" # include "LCD.h" # include "DM9000A.C" # include "DM9000A.H" # include <string.h> # include <ctype.h> unsigned char PC_MAC_ADDR = { 0x00, 0x16, 0xD4, 0xBB, 0xCA, 0x91 }; unsigned char DE2_MAC_ADDR = { 0x01, 0x60, 0x6E, 0x11, 0x02, 0x0F }; unsigned int receive_status, receive_len, i, packet_num; unsigned char receive_buffer; # define UDP_PACKET_PAYLOAD_OFFSET 42 unsigned char ARP_Packet = { /* Ethernet MAC header 14 bytes, * first 6 bytes for Destination MAC address * second 6 bytes for SOURCE MAC address * last 2 bytes for Ethernet types (ARP = 0806) */ Dest_MAC1, Dest_MAC2, Dest_MAC3, Dest_MAC4, Dest_MAC5, Dest_MAC6, Src_MAC1, Src_MAC2, Src_MAC3, Src_MAC4, Src_MAC5, Src_MAC6, 0x08, 0x06, /* ARP Header, * */ 0x00, 0x01, // Hardware Ethernet 0x0001 0x08, 0x00, // Protocol IP 0x0800 0x06, // Hardware size 6 0x04, // Protocol size 4 0x00, 0x02, // Reply Src_MAC1, Src_MAC2, Src_MAC3, Src_MAC4, Src_MAC5, Src_MAC6, Src_IP1, Src_IP2, Src_IP3, Src_IP4, Dest_MAC1, Dest_MAC2, Dest_MAC3, Dest_MAC4, Dest_MAC5, Dest_MAC6, Dest_IP1, Dest_IP2, Dest_IP3, Dest_IP4 }; unsigned char UDP_Packet = { /* Ethernet MAC header 14 bytes, * first 6 bytes for Destination MAC address * second 6 bytes for SOURCE MAC address * last 2 bytes for Ethernet types (IP = 0800) */ Dest_MAC1, Dest_MAC2, Dest_MAC3, Dest_MAC4, Dest_MAC5, Dest_MAC6, Src_MAC1, Src_MAC2, Src_MAC3, Src_MAC4, Src_MAC5, Src_MAC6, 0x08, 0x00, /* IP Header, 20 bytes * 4 bits for version * 4 bits for header length * 8 bits for type of service * 16 bits for total length of packet * 16 bits for identification * 3 bits for flag, 13 bits for fragment offset * 8 bits for time to live * 8 bit for protocol * 16 bit for header checksum * 32 bits for source IP * 32 bits for destination IP */ 0x45, 0x00, IP_Len_H, IP_Len_L, 0x00, 0x00, 0x00, 0x00, 0x80, 0x11, // UDP Type IP_Csum4, IP_Csum5, Src_IP1, Src_IP2, Src_IP3, Src_IP4, Dest_IP1, Dest_IP2, Dest_IP3, Dest_IP4, 0x04, 0x00, 0x04, 0x00, // Port 1024 UDP_Len_H, UDP_Len_L, 0x00, 0x00, /* UDP data, * Data take one byte. */ 0x41 // Character A }; void ethernet_interrupt_handler() { int i = 0; unsigned char mac_addr; receive_status = ReceivePacket(receive_buffer, &receive_len); if (receive_status == DMFE_SUCCESS) { /* Display the whole packet receive */ printf("\n\nReceive Packet Length = %d", receive_len); for(i = 0; i < receive_len;i++) { if (i%8==0) printf("\n"); printf("0x%.2X,", receive_buffer); } printf("\n"); /* Get the source address from the packet */ for(i = 6 ; i < 12; i++) { mac_addr = receive_buffer; } /* Compare the mac address to the PC MAC address */ if (memcmp(mac_addr, PC_MAC_ADDR, 6) == 0) { if (receive_len >= 14) { // A real Ethernet packet if (receive_buffer == 8 && receive_buffer == 6){ // An ARP Packet TransmitPacket(ARP_Packet, sizeof(ARP_Packet)); /* Clear the DM9000A ISR: PRS, PTS, ROS, ROOS 4 bits, by RW/C1 */ iow(ISR, 0x3F); /* Re-enable DM9000A interrupts */ iow(IMR, INTR_set); //DM9000_init(SRC_MAC_ADDR); } else { if (receive_buffer == 8 && receive_buffer == 0 && receive_len >= 34) { // An IP packet if (receive_buffer == 0x11) { // A UDP packet if (receive_len >= UDP_PACKET_PAYLOAD_OFFSET) { char request = (receive_buffer + UDP_PACKET_PAYLOAD_OFFSET); printf("Receive message: %c\n",request); } } else { printf("Received non-UDP packet\n"); } } else { printf("Received non-IP packet\n"); } } } else { printf("Malformed Ethernet packet\n"); } } } else { printf("Error receiving packet\n"); } /* Clear the DM9000A ISR: PRS, PTS, ROS, ROOS 4 bits, by RW/C1 */ iow(ISR, 0x3F); /* Re-enable DM9000A interrupts */ iow(IMR, INTR_set); //DM9000_init(SRC_MAC_ADDR); } int main() { LCD_Init(); LCD_Show_Text("TEAM-SYNTHESIS"); LCD_Line2(); LCD_Show_Text("Ethernet Testing"); printf("Network Transfer: Team-Synthesis (c) 2011.\n"); DM9000_init(); // Initialize the DM9000A. alt_irq_register( DM9000A_IRQ, NULL, (void*)ethernet_interrupt_handler ); while (1) { TransmitPacket(UDP_Packet,sizeof(UDP_Packet)); usleep(500000); } return 0; } - Altera_Forum
Honored Contributor
hi, I got it work, but somehow there is some delay between the character send. Can anyone give me advise?
- Altera_Forum
Honored Contributor
If anyone can give me any advice it would be greatly appreciated. I'm trying to implement this on a DE2-115 with the Cyclone IV, however whenever I try to change the derice in the programmer it says the replacement is incompatible. How can I make it compatible or allow it to still be used? When I compiled the code I did choose the correct Device which I assumed would make it compile for the CIV, but it seemed not to.