Nios® II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++
Announcements
Intel Support hours are Monday-Fridays, 8am-5pm PST, except Holidays. Thanks to our community members who provide support during our down time or before we get to your questions. We appreciate you!

Need Forum Guidance? Click here
Search our FPGA Knowledge Articles here.
12435 Discussions

Going from DE2 to DE2-115 Ethernet

Altera_Forum
Honored Contributor II
930 Views

So I successfully developed my code on the DE2 board to working, essentially it's a variation on BTXSistemas' DE2_Net to introduce some randomization and other features. However I now need to implement it on the DE2-115 which has a much different Ethernet core. I'm trying to use the Web Server example as a starting point but it's so much higher level than I really need that I'm getting nowhere. Basically what I need is to figure out the equivalent function of  

 

TransmitPacket(TXT,Length) 

 

on the DE2-115. Can anyone help me out here? Thanks in advance and I've included my main code below. 

 

#include "alt_types.h" // alt_u32 # include "altera_avalon_pio_regs.h" //IOWR_ALTERA_AVALON_PIO_DATA # include "sys/alt_irq.h" // interrupt # include <stddef.h> # include "sys/alt_flash.h" # include "sys/alt_flash_types.h" # include "sys/alt_alarm.h" // time tick function (alt_nticks(), alt_ticks_per_second()) # include "sys/alt_timestamp.h" # include "sys/alt_stdio.h" # include <fcntl.h> # include "nios2_ctrl_reg_macros.h" # include <io.h> # include <stdio.h> # include <unistd.h> # include <stdlib.h> # include <string.h> # include "LCD.h" # include "system.h" # include "DM9000A.C" # include "hello_led.h" # include "test.h" unsigned int aaa,rx_len,i,packet_num, times, counter; unsigned char RXT; unsigned char SND; // Payload buffer unsigned int IPsource_1,IPsource_2,IPsource_3,IPsource_4; unsigned int IPdestination_1,IPdestination_2,IPdestination_3,IPdestination_4; unsigned int IPchecksum1,IPchecksum2,IPchecksum3,IPchecksum4,IPchecksum5; unsigned int Mac_source1, Mac_source2, Mac_source3, Mac_source4, Mac_source5, Mac_source6; unsigned int Mac_dest1, Mac_dest2, Mac_dest3, Mac_dest4, Mac_dest5, Mac_dest6; unsigned int times, lenght_h, lenght_l; unsigned int flenght, IPlenght_h, IPlenght_l, data_lenght, IPlenght; unsigned int delay, Mode; int data0, data1, data2, data3, data4, data5, data6, data7; int main(void) { LCD_Test(); IPsource_1 = 0xC0; // Assign ie: 192.168.0.44 IP for the DE2 IPsource_2 = 0xA8; IPsource_3 = 0x00; IPsource_4 = 0x2C; IPdestination_1 = 0x??; // Insert your IP data here IPdestination_2 = 0x??; IPdestination_3 = 0x??; IPdestination_4 = 0x??; Mac_dest1 = 0x00; // Insert your MAC address data here Mac_dest2 = 0x03; Mac_dest3 = 0x25; Mac_dest4 = 0x43; Mac_dest5 = 0x6A; Mac_dest6 = 0x27; Mac_source1 = 0x01; // Assign a MAC address for DE2 Mac_source2 = 0x60; Mac_source3 = 0x6E; Mac_source4 = 0x11; Mac_source5 = 0x02; Mac_source6 = 0x0F; delay = 0; Mode = 0; data_lenght = 1468; // Maximun Data lenght 1468 bytes flenght = data_lenght + 0x2E; //Total packet lenght lenght_h = ((data_lenght+8) & 0xFF00)>>8; // Convert in H byte and L byte lenght_l = ((data_lenght+8) & 0x00FF); IPlenght = data_lenght + 8 + 20; // IP Lenght for IP header IPlenght_h = (IPlenght & 0xFF00)>>8; // Convert in H byte and L byte IPlenght_l = (IPlenght & 0x00FF); // Calculating the IP checksum IPchecksum1 = 0x0000C511 + (IPsource_1<<8)+IPsource_2+(IPsource_3<<8)+IPsource_4+ (IPdestination_1<<8)+IPdestination_2+(IPdestination_3<<8)+(IPdestination_4)+ (IPlenght_h<<8) + IPlenght_l; IPchecksum2 = ((IPchecksum1&0x0000FFFF)+(IPchecksum1>>16)); IPchecksum3 = 0x0000FFFF - IPchecksum2; IPchecksum4 = (IPchecksum3 & 0xFF00)>>8; IPchecksum5 = (IPchecksum3 & 0x00FF); srand ( time(NULL) ); unsigned char TXT = { Mac_dest1,Mac_dest2,Mac_dest3,Mac_dest4,Mac_dest5,Mac_dest6, //Destination MAC Mac_source1,Mac_source2,Mac_source3,Mac_source4,Mac_source5,Mac_source6, //Source MAC 0x08,0x00, //Type 0xFF, // Header Length 0x22, //ECN-CE 0x33,0x44, //total Length 0x55,0x66, //Identification 0x77,0x88, //Fragment Offset 0x99, //Time to Live 0xAA, //Protocol 0x55,0x66, //Checksum IPsource_1,IPsource_2,IPsource_3,IPsource_4, //Source IP //0x77,0x88,0x99,0xAA, //Source IP IPdestination_1,IPdestination_2,IPdestination_3,IPdestination_4, //Destination IP 0x99,0xAA,0x55,0x66,0x77,0x88, //Data 0x55,0x66,0x77,0x88,0x99,0xAA, //Data 0x55,0x66,0x77,0x88,0x99,0xAA, //Data 0x55,0x66,0x77,0x88,0x99,0xAA, //Data 0x00,0x00,0x00,0x20,0x99,0xAA}; //Data unsigned char TXT2 = { Mac_dest1, Mac_dest2, Mac_dest3, Mac_dest4 ,Mac_dest5, Mac_dest6, Mac_source1, Mac_source2, Mac_source3, Mac_source4, Mac_source5, Mac_source6, 0x08, 0x00, 0xFF, 0x22, IPlenght_h, IPlenght_l, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, IPchecksum4, IPchecksum5, IPsource_1, IPsource_2, IPsource_3, IPsource_4, IPdestination_1, IPdestination_2, IPdestination_3, IPdestination_4, 0x04, 0x00, 0x04, 0x00, lenght_h, lenght_l, 0x00, 0x00}; for (i = 0; i < 42; i++) // Load the TXT in the SND (ethernet packet). SND = TXT2; for (i = 42; i < flenght-4; i++) // generating the data to send. SND = i-42; SND = 0x35; // This checksum is not correct, but also the net recieve the packets correctly. SND = 0x15; // To do, calculate checksum. SND = 0xF0; SND = 0x13; DM9000_init(); init_button_irq(); LCD_TestSWNR(); //Add ability to change data rates //Modes, send out data at 34 Mbit/s, send data out in bursts, storing in RAM until full //How to get MAC/IP of other INK Board/s and hard code in or software get while (1) { alt_u8 button; button = IORD_ALTERA_AVALON_PIO_DATA(BUTTON_PIO_BASE); bool bSpeedDown, bSpeedUp, bMode; if(button & 0x08) bSpeedDown = FALSE; else{ LCD_TestDS(); delay += 100; msleep(1000); } if(button & 0x04) bSpeedUp = FALSE; else{ if(delay != 0){ LCD_TestIS(); delay -= 100; } else LCD_TestMax(); msleep(1000); } if(button & 0x02) bMode = FALSE; else{ Mode++; delay = 0; if(Mode == 0) LCD_TestSWNR(); else if(Mode == 1) LCD_TestSWR(); else if(Mode == 2) LCD_TestHWPR(); else if(Mode == 3) LCD_TestHWFR(); else if(Mode == 4) LCD_TestP(); else{ Mode = 0; LCD_TestSWNR(); } msleep(1000); } if(Mode == 0){ //SW Not Random Data Generation TransmitPacket(SND,flenght); // Send repetitively 1468 bytes of data. times++; } else if(Mode == 1){ //SW Random Data Generation for (i = 42; i < flenght-4; i++) // generating the data to send. SND = rand() % 255; TransmitPacket(SND,flenght); // Send repetitively 1468 bytes of data. times++; } else if(Mode == 2){ //HW Repeating Packet Data unsigned int data = IORD_ALTERA_AVALON_PIO_DATA(EXPANSION_JP1_BASE); data0 = data & 0x1; data1 = data & 0x10; data1 >>= 3; data2 = data & 0x100; data2 >>= 6; data3 = data & 0x2000; data3 >>= 10; //Should be 9 data4 = data & 0x20000; data4 >>= 13; //Should be 12 data5 = data & 0x200000; data5 >>= 16; //Should be 15 data6 = data & 0x1000000; data6 >>= 18; data7 = data & 0x10000000; data7 >>= 21; data = data0 | data1 | data2 | data3 | data4 | data5 | data6 | data7; for (i = 42; i < flenght-4; i++) // generating the data to send. SND = data; TransmitPacket(SND,flenght); // Send repetitively 1468 bytes of data. times++; } else if(Mode == 3){ //HW Completely Random for(i=34; i < 64; i++){ unsigned int data = IORD_ALTERA_AVALON_PIO_DATA(EXPANSION_JP1_BASE); data0 = data & 0x1; data1 = data & 0x10; data1 >>= 3; data2 = data & 0x100; data2 >>= 6; data3 = data & 0x2000; data3 >>= 10; //Should be 9 data4 = data & 0x20000; data4 >>= 13; //Should be 12 data5 = data & 0x200000; data5 >>= 16; //Should be 15 data6 = data & 0x1000000; data6 >>= 18; data7 = data & 0x10000000; data7 >>= 21; data = data0 | data1 | data2 | data3 | data4 | data5 | data6 | data7; TXT = data; } TransmitPacket(TXT,0x40); times++; } else if(Mode == 4){ //Pause msleep(10);} IOWR(SEG7_DISPLAY_BASE, 0, times); // Show in hex digits the# of packets sent usleep(delay); } return 0; }
0 Kudos
2 Replies
Altera_Forum
Honored Contributor II
78 Views

Hi driscoll42, 

did you get any result from this project. could you please tell us the out come if there is any.
Altera_Forum
Honored Contributor II
78 Views

No, sorry. I never got it working properly.

Reply