Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
16 years ago

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