Forum Discussion
DE2 Ethernet Primitive Solution
With the DE2 board, the Ethernet controller does not seem to work in Quartus II 8.0 or 8.1. There are several problems with the DE2_NET demonstration; it was built pre-7.1, the software driver does not work, the support is for crap, nobody seems to post anything useful on this topic etc. So here is the answer I would have killed for a month ago; in the DM9000A ISR, re-initialize the DM9000A and set a flag. In the main program loop, register the ISR again and clear the flag.
Sample code: //--------------------------------------------------------------# include "basic_io.h"# include "test.h"# include "LCD.h"# include "DM9000A.C" # define DE2_8_7Segs_BASE 0x01901028 unsigned int aaa,rx_len,i,packet_num; unsigned char RXT[68]; unsigned int EnetReceive; void ethernet_interrupts() { packet_num++; aaa=ReceivePacket (RXT,&rx_len); //Do your processing here. //Reinitialize the DM9000A and set the flag to setup the //ISR pointer. DM9000_init(); EnetReceive = TRUE; } int main(void) { unsigned int Success; unsigned char TXT[] = { 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, 0x01,0x60,0x6E,0x11,0x02,0x0F, 0x08,0x00,0x11,0x22,0x33,0x44, 0x55,0x66,0x77,0x88,0x99,0xAA, 0x55,0x66,0x77,0x88,0x99,0xAA, 0x55,0x66,0x77,0x88,0x99,0xAA, 0x55,0x66,0x77,0x88,0x99,0xAA, 0x55,0x66,0x77,0x88,0x99,0xAA, 0x55,0x66,0x77,0x88,0x99,0xAA, 0x55,0x66,0x77,0x88,0x99,0xAA, 0x00,0x00,0x00,0x20 }; //Initialize the LCD. LCD_Init(); //Test the LCD. Success = DM9000_init(); LCD_Show_Text(""); if (Success == DMFE_SUCCESS) { //Tell the user if the DM9000A initialize or failed. LCD_Show_Text("DM9000A"); LCD_Line2(); LCD_Show_Text("Initialized."); alt_irq_register( DM9000A_IRQ, NULL, (void*)ethernet_interrupts ); } else { LCD_Show_Text("DM9000 Failed."); } packet_num=0; EnetReceive = FALSE; //Main loop. while (Success == 0) { //Register the ISR again after the ISR has fired and the device has been //re-initialized. if (EnetReceive == TRUE) { alt_irq_register( DM9000A_IRQ, NULL, (void*)ethernet_interrupts ); EnetReceive = FALSE; } Success = TransmitPacket(TXT,0x40); msleep(500); outport(DE2_8_7SEGS_BASE ,packet_num); } LCD_Show_Text("TX Failed."); return 0; } //------------------------------------------------------------------------- /* To get a full grasp of why this works read ·http://www.altera.com/literature/hb/nios2/n2sw_nii52006.pdf If you are doing this as a continuing project, become very familiar with the ISO-OSI 7 model and device networking. Note: Currently this code is very sloppy and needs revision. The true event in the init function needs to be determined. The only reason I posted this "as-is" was because of the crazy ammount of time I spent on this problem and the elation which comes with success. */21 Replies
- Altera_Forum
Honored Contributor
now another problem is that when you ISR read a packet from DM9000A, maybe another packet is coming, but it doesn't produce interrupt signal,so after you read a packet,you need read the next status word to check if there is another packet is in the buffer, when your ISR finish, you should make sure that there is no packet in the buffer.
good luck! - Altera_Forum
Honored Contributor
Better solution than my solution: unloading and reloading the ISR.
Soap Box: That makes sense. I can't confirm this with any hard evidence; but every time I ran code on a NIOS II, it seemed as though the ISR automatically created a critical section without any extra effort on the programmer's part. I can't believe Terasic and Altera can get away with this MSDN setup for embedded development. It is possible they expected user's to us MicroLinux and not really care about how things where cobbled together. Looks like Cornell does Junior Projects for Master's Degrees; however, the report is well formatted. This may help some people: http://instruct1.cit.cornell.edu/courses/ece576/finalprojects/f2007/mjk64_hmm32_jdp45/mjk64_hmm32_jdp45/index.html - Altera_Forum
Honored Contributor
--- Quote Start --- That's fantastic! I chewed through that example so many times it drove me nuts. Plus the DM900A thing was about 1/8th of my project. Thanks, Adam F. --- Quote End --- I have try to send a udp packets to de2, but it can only received a arp request packet, which tell who's the 192.168.0.55, tell the host. so I make a arp reply packet manually ,and send it back to the host pc, after that, I can't receive any udp packet more. appreciate your help! - Altera_Forum
Honored Contributor
I will need some specifics on the setup, but I can give some broad suggestions. For anything which helps you get to the solution faster, I need to know the basics of what you are trying to do.
If you are manually handling ARP, a number of things can go wrong. The address is taken or incorrect, the HW type could be incorrect, or (likely), it sounds like DHCP could be assigning an IP, the reply is not what it should bind to. First, if there is only one PC in the loop, why bother with ARP? It makes the system more robust and it will play nicely with a router, but it doesn't provide a lot of utility unless the end goal is a server. Second, the more a network can be simplified, the faster a problem can be diagnosed. In this situation, use a hub between the PC and DE2. Have the PC bind to one port, the DE2 another. If microLinux is used, more complexity is added to the system. A problem above the hardware layer is a discussion of RFCs. - Altera_Forum
Honored Contributor
thanks for your reply.
My goal is using the pc to transfer the video streams to DE2, and to make some video proccess, such as decode, enhance. I need to make a rate controller in pc to controller it , like a video player, vlc, the rate is about 3m/s. - Altera_Forum
Honored Contributor
The best advice I can give is to put a hub between the PC and the DE2 and use a sniffer for DE2 packets while going through the NIOS debugger. If the system is going down after an ARP, best guess is you are sending an ARP packet which something on the network is unhappy about.
If the hub doesn't get you any farther, check the OS requirements for the DE2. Using a switch, and not sending ARP, with just a PC and DE2 connected should tell you if that is the problem. Routers usually require a bit of work to shut off enough functionality to turn it into a switch. If the DE2 dies after the first packet sent, there is likely an issue with the DM9000 registers. Sending broadcasts will tell if that's the issue. One thing that is strange, if you only have the one DE2, then you only have to worry about a MAC address. Tell me how things go with the DE2 and a PC connected via switch. - Altera_Forum
Honored Contributor
Thanks for your advice.
I have added the codes , Tmp = ior(0xF5); Tmp = ior(0xF4); into ReceivePacket function. It works! I can receive continuous data from pc. It seems to reset the DM9000A memory data address to 0x0c00. In the read memory operation, when the bit 7 of IMR is set, the memory address increment will wrap to location 0x0c00. - Altera_Forum
Honored Contributor
--- Quote Start --- Thanks for your advice. I have added the codes , Tmp = ior(0xF5); Tmp = ior(0xF4); into ReceivePacket function. It works! I can receive continuous data from pc. It seems to reset the DM9000A memory data address to 0x0c00. In the read memory operation, when the bit 7 of IMR is set, the memory address increment will wrap to location 0x0c00. --- Quote End --- to Li.Huiliang, you did it successfully,while i'll do the same thing with you with a DE2 ,but i don't know how to start it ,can you give me the code that you just succeed.please send to [email protected] ,i'll be very thankful! - Altera_Forum
Honored Contributor
Is there any special software to send packets to the FPGA board
- Altera_Forum
Honored Contributor
--- Quote Start --- to Li.Huiliang, you did it successfully,while i'll do the same thing with you with a DE2 ,but i don't know how to start it ,can you give me the code that you just succeed.please send to [email protected] ,i'll be very thankful! --- Quote End --- can plzzz send me that code also thnkyou [email protected]