Intel® FPGA University Program
University Program Material, Education Boards, and Laboratory Exercises
1221 Discussions

WORKING: DE2-115 Simple Socket Server

Altera_Forum
Honored Contributor II
14,505 Views

Hi, 

 

It seems difficult to get help on these forums so I want to pass on what i learnt for others. I've struggled to learn FPGAs over the past few weeks and I have finally got a simple socket server working for the DE2-115. I'll quickly post my findings so someone else can take this and learn from it and not have to struggle on their own as i did. 

 

procedure 

 

 

I'll make this brief:
  1. I used updated versions for everything as of 4/4/11. 10.1 Sp1. 

  2. Download and install the Knowledge base update to prevent nios from crashing. 

    http://www.altera.com/support/kdb/solutions/rd12222010_317.html 

  3. Take the Quartus DE2_115 webserver example for Enet0 RGMII that comes on the CD and use quartus flash programmer to program. 

  4. Get this PDF and follow its instructions "http://www.altera.com/literature/tt/tt_nios2_tcpip.pdf?gsa_pos=1&wt.oss_r=1&wt.oss=simple socket server example nios edition socket server example nios edition" NOTE it includes the spaces (wierd). do everything the same except the part mentioned in my next step. 

  5. Instead of copying the files from the tutorial.zip; copy the ones that i have attached to this post. (the .c and .h files including the eeprom folder) 

  6. This example will now work as explained in the pdf. 

explanation 

  • The original example code in the tutorial does not have the correct method for gettig the MAC address on the DE2-115. I have deleted the majority of the original MAC code and replaced it with code i got from the DE2-115 webserver example. This includes the flashgetoffset function. 

  • The LED_PIO_BASE in the original is an invalid for the DE2-115. I replaced it with the LEDG (green leds), you could replace it with red if you wished. This has been done by modifying the led.c file. 

Sorry for the quick rush post, but i truly hope this helps someone. We should all try to help each other and I hope over the coming months that someone does the same for me with any problems i get in the future. 

 

Any questions just ask
(Virus scan in progress ...)
0 Kudos
66 Replies
Altera_Forum
Honored Contributor II
2,196 Views

Great work on converting the example. Can you please post it up so I can update this thread.  

 

In regards to your question re external access and IPs. I imagine you have to use features of your router to enable external access. I'm not knowledgable here at all so i suggest you google abouthome webserving. But I suppose you could use a port forward on your router. So your IP given to you by your ISP would be the IP and then the port your design uses would go with that. So you set your router to forward anything on that port to your boards local address. I have no idea if that would work, perhaps being a webpage you may not be able to select port. Again I obviously have no idea, sorry.
0 Kudos
Altera_Forum
Honored Contributor II
2,196 Views

 

--- Quote Start ---  

Hello, I managed to run the web server example and it works! However, I need to ask you if there is any way that I can send from FPGA to the webpage. In fact, using the webpage, I can write on the LCD, or light the leds ... What i need is the other way around, from fpga to the webpage..  

--- Quote End ---  

 

 

Congratulations on getting the Web Server running! That's a BIG step in the right direction.  

 

I presume when you ask about sending data from the FPGA to the Web page that you are talking about dynamic data, or perhaps local variables such as IP address, etc. Sending HTML pages is nothing more than sending text, it just includes HTML code as part of the text string. 

 

The trick is inserting dynamic (variable) data into the text stream on-the-fly. I'm using the C programming sprintf() function to replace format "wildcards" in a text string with program variables. If you're not familiar with it, sprintf() is just like printf() except that instead of printing to a screen or terminal, it prints to a buffer. 

 

To demonstrate this, include the attached ip_config.c and ip_config.h files into your webserver project, and add the following code segment (between the 'Fred's') to http.c http_find_file() function: 

 

/* Try to open the file */ 

printf("\nFetching file: %s.\n\n", filename ); 

/***** Added by Fred *****/ 

if (!strcmp(IP_CONFIG_FILE,conn->uri)) 

Get_IP_Config(sendbuff); // Call routine to update IP and Host information in HTML format 

send(conn->fd,(void*)sendbuff,strlen(sendbuff),0); // Send Status XML page 

conn->state = RESET; // Then reset the connection 

return -1; // and bail out fo this process 

/***** End Fred *****/ 

conn->file_handle = fopen(filename, "r"); 

 

 

You will also need to include ip_config.h in your http.c file. 

 

The way this works is by hijacking the http.c http_find_file() function to look for 'ip.html' after the IP address before it tries to find any of the files in the ro_zipfs.zip that are hard-coded and cannot be changed on-the-fly. 

 

You may need to change some of the variable names in the attached files to match your BSP, but it should work. (I'll be eagerly waiting to hear.) 

 

(please note that i am not an experienced "c" programmer, so there may be more elegant ways of doing this. this will get you started, then you can experiment from there.) 

 

 

--- Quote Start ---  

And another thing is that the IP address assigned to the board and used to control the board remotely is local and I can only access it if I am within the domain of my router. What are my options if I want someone outside my router to have access to the board other than getting a real IP? 

 

--- Quote End ---  

 

 

AsValdr is on the right track. Most routers have a default IP Address of 192.168.1.1 that will call up a web page in your browser for setting the configuration. You want to configure http port forwarding for the MAC address of your system. You can also assign FTP and telnet to your system this way. Each requires a separate port-forwarding assignment. Check your router documentation for the specifics. I have a couple systems set up that way and they work great.
(Virus scan in progress ...)
0 Kudos
Altera_Forum
Honored Contributor II
2,196 Views

Hello, thank you for your fast reply... 

 

I'm trying to learn more about port forwarding and concerning the code that you gave me, what is sendbuff.. It is generating an error during compilation! I am new to C programming so I would really appreciate your help.. 

 

Thank you!
0 Kudos
Altera_Forum
Honored Contributor II
2,196 Views

 

--- Quote Start ---  

 

I'm trying to learn more about port forwarding and concerning the code that you gave me, what is sendbuff.. It is generating an error during compilation! I am new to C programming so I would really appreciate your help.. 

 

--- Quote End ---  

 

 

'sendbuff' is a variable that needs to be declared within the http.c file - something I forgot to mention in my description. Insert this code segment char sendbuff[768]; just below the two existing variable declarations in the http_find_file() function so that it looks like this: 

 

 

int http_find_file(http_conn* conn) 

printf( "I'm at http_find_file...\n\n" ); 

 

alt_u8 filename[256]; 

int ret_code = 0; 

char sendbuff[768]; 

 

 

What you are doing here is reserving 768 bytes of memory that becomes the buffer that sprintf() puts the HTML formatted text string into. We use sprintf() as a convenient way to pick up the variables we want to include in the HTML text. Then the send() function pushes the string out through the socket connection to the requesting HTTP client, as in the following line: 

 

send(conn->fd,(void*)sendbuff,strlen(sendbuff),0); // send ip config html page 

 

The conn->fd is the socket connection, sendbuff is our buffer which now contains the HTML text string, strlen(sendbuff) returns the size of the string in the buffer so send() knows when to quit, and 0 is the offset from the beginning of the buffer where we begin sending. 

 

There's nothing magical about this number 768, I just kept increasing the buffer size until it was big enough to hold my HTML code. If you want to send more HTML code than fits in this buffer, just increase its size. 

 

I have only been studying C programming for about three months, so you are not far behind. It's terribly confusing at first, but it gradually falls into place. Trying to figure out existing code that you know works is a good way to reinforce your leaning.
0 Kudos
Altera_Forum
Honored Contributor II
2,196 Views

Hello, 

 

I am using NIOS II 10.0 IDE. When I perform some changes to the C code, it compiles and generates no error. But the problem is that when I try to run the webserver, the changes are not observed as if the program is running according to the previous code without the changes. I tried to use Nios II 10.0 Software Build Tools for Eclipse but it is generating errors because of the "include" files ("unresolved inclusion"). Any help please?! 

 

Thank you!
0 Kudos
Altera_Forum
Honored Contributor II
2,196 Views

 

--- Quote Start ---  

Hello, 

 

I am using NIOS II 10.0 IDE. When I perform some changes to the C code, it compiles and generates no error. But the problem is that when I try to run the webserver, the changes are not observed as if the program is running according to the previous code without the changes. I tried to use Nios II 10.0 Software Build Tools for Eclipse but it is generating errors because of the "include" files ("unresolved inclusion"). Any help please?! 

 

Thank you! 

--- Quote End ---  

 

 

It sounds a bit silly, but try creating a new project and copy and paste the error free code into it. Generally when I find something is trying to run older versions of code, this fixes it.
0 Kudos
Altera_Forum
Honored Contributor II
2,196 Views

Well, I tried to create a new project! And the result is that I have errors, for example: 

 

(SEVERE) generate: java.lang.IllegalStateException: java.lang.IllegalStateException: java.lang.NumberFormatException: empty String 

make[1]: *** [system_description/../obj/system.h-t] Error 1 

make: *** [system_project] Error 2 

 

or: 

 

5 [main] ? (428) c:\altera\10.0\quartus\bin\cygwin\bin\make.exe: *** fatal error - couldn't allocate heap, Win32 error 487, base 0x930000, top 0xA00000, reserve_size 847872, allocsize 851968, page_const 4096 

3 [main] make 2992 fork: child -1 - died waiting for longjmp before initialization, retry 0, exit code 0x100, errno 11 

make: C:/altera/10.0/nios2eds/components/altera_hal/build/system_rules.mk:106: fork: Resource temporarily unavailable 

/bin/sh: /cygdrive/c/altera/10.0/nios2eds/components/altera_hal: is a directory 

10 [main] ? (2716) c:\altera\10.0\quartus\bin\cygwin\bin\make.exe: *** fatal error - couldn't allocate heap, Win32 error 487, base 0x930000, top 0xA20000, reserve_size 978944, allocsize 983040, page_const 4096 

15839448 [main] make 2992 fork: child -1 - died waiting for longjmp before initialization, retry 0, exit code 0x100, errno 11 

make: vfork: Resource temporarily unavailable 

7 [main] ? (3300) c:\altera\10.0\quartus\bin\cygwin\bin\make.exe: *** fatal error - couldn't allocate heap, Win32 error 487, base 0x930000, top 0xA20000, reserve_size 978944, allocsize 983040, page_const 4096 

19049540 [main] make 2992 fork: child -1 - died waiting for longjmp before initialization, retry 0, exit code 0x100, errno 11 

make: vfork: Resource temporarily unavailable 

6 [main] ? (3988) c:\altera\10.0\quartus\bin\cygwin\bin\make.exe: *** fatal error - couldn't allocate heap, Win32 error 487, base 0x930000, top 0xA20000, reserve_size 978944, allocsize 983040, page_const 4096 

24311990 [main] make 2992 fork: child -1 - died waiting for longjmp before initialization, retry 0, exit code 0x100, errno 11 

make: vfork: Resource temporarily unavailable 

6 [main] ? (428) c:\altera\10.0\quartus\bin\cygwin\bin\make.exe: *** fatal error - couldn't allocate heap, Win32 error 487, base 0x930000, top 0xA20000, reserve_size 978944, allocsize 983040, page_const 4096 

27505975 [main] make 2992 fork: child -1 - died waiting for longjmp before initialization, retry 0, exit code 0x100, errno 11 

make: vfork: Resource temporarily unavailable 

Creating generated.sh... 

6 [main] ? (592) c:\altera\10.0\quartus\bin\cygwin\bin\make.exe: *** fatal error - couldn't allocate heap, Win32 error 487, base 0x930000, top 0xA20000, reserve_size 978944, allocsize 983040, page_const 4096 

30345606 [main] make 2992 fork: child -1 - died waiting for longjmp before initialization, retry 0, exit code 0x100, errno 11 

make: vfork: Resource temporarily unavailable 

6 [main] ? (3032) c:\altera\10.0\quartus\bin\cygwin\bin\make.exe: *** fatal error - couldn't allocate heap, Win32 error 487, base 0x930000, top 0xA20000, reserve_size 978944, allocsize 983040, page_const 4096 

32702017 [main] make 2992 fork: child -1 - died waiting for longjmp before initialization, retry 0, exit code 0x100, errno 11 

make: vfork: Resource temporarily unavailable 

Creating generated.x... 

6 [main] ? (3872) c:\altera\10.0\quartus\bin\cygwin\bin\make.exe: *** fatal error - couldn't allocate heap, Win32 error 487, base 0x930000, top 0xA20000, reserve_size 978944, allocsize 983040, page_const 4096 

37521586 [main] make 2992 fork: child -1 - died waiting for longjmp before initialization, retry 0, exit code 0x100, errno 11 

make: vfork: Resource temporarily unavailable 

6 [main] ? (2008) c:\altera\10.0\quartus\bin\cygwin\bin\make.exe: *** fatal error - couldn't allocate heap, Win32 error 487, base 0x930000, top 0xA20000, reserve_size 978944, allocsize 983040, page_const 4096 

42000515 [main] make 2992 fork: child -1 - died waiting for longjmp before initialization, retry 0, exit code 0x100, errno 11 

make: makefile:73: fork: Resource temporarily unavailable 

7 [main] ? (2292) c:\altera\10.0\quartus\bin\cygwin\bin\make.exe: *** fatal error - couldn't allocate heap, Win32 error 487, base 0x930000, top 0xA20000, reserve_size 978944, allocsize 983040, page_const 4096 

44203642 [main] make 2992 fork: child -1 - died waiting for longjmp before initialization, retry 0, exit code 0x100, errno 11 

make: makefile:73: fork: Resource temporarily unavailable 

6 [main] ? (3216) c:\altera\10.0\quartus\bin\cygwin\bin\make.exe: *** fatal error - couldn't allocate heap, Win32 error 487, base 0x930000, top 0xA20000, reserve_size 978944, allocsize 983040, page_const 4096 

46395488 [main] make 2992 fork: child -1 - died waiting for longjmp before initialization, retry 0, exit code 0x100, errno 11 

make: makefile:73: fork: Resource temporarily unavailable 

7 [main] ? (3800) c:\altera\10.0\quartus\bin\cygwin\bin\make.exe: *** fatal error - couldn't allocate heap, Win32 error 487, base 0x930000, top 0xA40000, reserve_size 1110016, allocsize 1114112, page_const 4096 

52057925 [main] make 2992 fork: child -1 - died waiting for longjmp before initialization, retry 0, exit code 0x100, errno 11 

make: vfork: Resource temporarily unavailable 

Build completed in 253.497 seconds 

 

What can i do to solve these? Any help please!!! I have read many threads with the following problem but there is no solution! 

 

Thank you!
0 Kudos
Altera_Forum
Honored Contributor II
2,196 Views

Problem Solved!!!

0 Kudos
Altera_Forum
Honored Contributor II
2,196 Views

 

--- Quote Start ---  

Thanks! 

Now the telnet server works. I am using a cross over cable and set the ip address, the subnet mask, and the gateway in windows manually. For the subnet mask and gateway, I used the values specified in the file simple_socket_server.h.  

I also had to turn off enable_dhcp_client as described in the file that you uploaded. 

So it was, as you said, a connection problem on the cable/computer side. 

 

The simple socket server is running on both evaluation boards, DE2 and DE4. 

 

Now I can start changing the socket server task to transfer data. 

--- Quote End ---  

 

Dear David, 

I met the same problem,as follows:# ################################### 

IP address of et1 : 192.168.10.234 

Created "Inet main" task (Prio: 2) 

Created "clock tick" task (Prio: 3) 

DHCP timed out, going back to default IP address(es) 

Simple Socket Server starting up 

[sss_task] Simple Socket Server listening on port 30 

Created "simple socket server" task (Prio: 4)# ##################################### 

 

You said it's connection problem on the cable/computer side,can you tell me how to solve this problem. 

Looking forward to your reply and english isn't my native language, so I am sorry for some unclear sentence.
0 Kudos
Altera_Forum
Honored Contributor II
2,196 Views

I used a cross-over cable and set the computer's IP address to 192.168.10.235, and the subnet mask and the gateway to the same value as the socket server. 

Then, if you ping the Board's IP address 192.168.10.234, it should be successful. 

 

Where do you have troubles?
0 Kudos
Altera_Forum
Honored Contributor II
2,196 Views

 

--- Quote Start ---  

I used a cross-over cable and set the computer's IP address to 192.168.10.235, and the subnet mask and the gateway to the same value as the socket server. 

Then, if you ping the Board's IP address 192.168.10.234, it should be successful. 

 

Where do you have troubles? 

--- Quote End ---  

 

Thanks for your reply,I have do the job as you say,but ping meet the problems as follows: 

************************************************* 

Pinging 192.168.10.234 with 32 bytes of data: 

reply from 192.168.10.235 :Can not access the target host 

reply from 192.168.10.235 :Can not access the target host 

reply from 192.168.10.235 :Can not access the target host 

reply from 192.168.10.235 :Can not access the target host 

 

Ping statistics for 192.168.10.234 : 

Packets :Sent = 4, Received = 4, Lost = 0(0% loss), 

 

************************************************* 

at the same time, telnet still failed at the port 30. 

Have you ever change the code in simple_socket_server.c or something else(especially the code about DHCP)?
0 Kudos
Altera_Forum
Honored Contributor II
2,196 Views

Can you post the full output of NIOS? Does it say: "Auto-negotiation Failed" or "...Passed"?

0 Kudos
Altera_Forum
Honored Contributor II
2,196 Views

I changed the http_send_file() function and I added the code that you gave me,however when I open the webpage it is generating the following error on the console: Error_handle_receive: error preparing response and on the webpage it is giving me:  

error 324 (net::err_empty_response): the server closed the connection without sending any data. 

And one more question please: why did the following statement generate error on tse (undefined variable): 

strncpy(IP_Stat.MAC_Address,sprint_macaddr(macaddress),IP_ADDR_SIZE); 

 

Thank you so much for your help!
0 Kudos
Altera_Forum
Honored Contributor II
2,196 Views

 

--- Quote Start ---  

Can you post the full output of NIOS? Does it say: "Auto-negotiation Failed" or "...Passed"? 

--- Quote End ---  

 

The output of NIOS II is: 

*************************************************************** 

InterNiche Portable TCP/IP, v3.1  

 

Copyright 1996-2008 by InterNiche Technologies. All rights reserved.  

prep_tse_mac 0 

Your Ethernet MAC address is 00:07:ed:ff:61:06 

Static IP Address is 192.168.10.234 

prepped 1 interface, initializing... 

[tse_mac_init] 

INFO : TSE MAC 0 found at address 0x0b442000 

INFO : PHY Marvell 88E1111 found at PHY address 0x10 of MAC Group[0] 

INFO : PHY[0.0] - Automatically mapped to tse_mac_device[0] 

INFO : PHY[0.0] - Restart Auto-Negotiation, checking PHY link... 

INFO : PHY[0.0] - Auto-Negotiation PASSED 

MARVELL : Mode changed to RGMII/Modified MII to Copper mode 

MARVELL : Enable RGMII Timing Control 

MARVELL : PHY reset 

INFO : PHY[0.0] - Checking link... 

INFO : PHY[0.0] - Link not yet established, restart auto-negotiation... 

INFO : PHY[0.0] - Restart Auto-Negotiation, checking PHY link... 

INFO : PHY[0.0] - Auto-Negotiation PASSED 

INFO : PHY[0.0] - Link established 

INFO : PHY[0.0] - Speed = 1000, Duplex = Full 

OK, x=0, CMD_CONFIG=0x00000000 

 

MAC post-initialization: CMD_CONFIG=0x0400020b 

[tse_sgdma_read_init] RX descriptor chain desc (1 depth) created 

mctest init called 

IP address of et1 : 192.168.10.234 

Created "Inet main" task (Prio: 2) 

Created "clock tick" task (Prio: 3) 

 

Simple Socket Server starting up 

[sss_task] Simple Socket Server listening on port 30 

Created "simple socket server" task (Prio: 4) 

******************************************************** 

It seems that it should work, but the ping & telnet can't work, and the error i have show you previously.
0 Kudos
Altera_Forum
Honored Contributor II
2,196 Views

 

--- Quote Start ---  

Can you post the full output of NIOS? Does it say: "Auto-negotiation Failed" or "...Passed"? 

--- Quote End ---  

 

Dear David, the ping and telnet are succeed when I use the DHCP server, but when I connect the board and PC with a cross-over cable, I failed. 

 

DHCP in the BSPEditor is diabled, and I change some codes in Quartus II,as follows: 

*********************************** 

// ===== SOPC control signal defing 

assign set_1000_to_the_tse_mac = 1'b1; 

assign set_10_to_the_tse_mac = 1'b0; 

*********************************** 

hope for your reply.
0 Kudos
Altera_Forum
Honored Contributor II
2,196 Views

I don't know what's going on. I think best would be, if you opened a new thread.

0 Kudos
Altera_Forum
Honored Contributor II
2,196 Views

 

--- Quote Start ---  

I don't know what's going on. I think best would be, if you opened a new thread. 

--- Quote End ---  

 

Hi,David 

I open a new thread, and I meet the same problem. I can send words or command via Telnet or Ping, when I use a router. However, I always failed when I directly connect the board and PC with a cross-over cable. I am really confused, I hope that you could help me.  

Can you send your software project to my email, then I can compare our code. My email --- sxxhh18@163.com 

Have a good day!
0 Kudos
Altera_Forum
Honored Contributor II
2,196 Views

 

--- Quote Start ---  

Thanks for posting your design. I cannot get your design running. 

When I implement your design, I get the error: 

undefined reference to 'tse_mac_device' 

Specifically, the error lies in these two lines of code are indicated in the file altera_avalon_tse.c: 

if(tse_mac_device.tse_mac_base == p_driver_data->hw_mac_base_addr) { 

psys_info = &tse_mac_device

 

Does anyone know how I can handle this error? 

 

I can't see how I should build my own socket server, when the examples are not working. I can also use the DE4 board if that is easier. 

 

Thanks 

--- Quote End ---  

 

 

 

--- Quote Start ---  

Hi,David 

I open a new thread, and I meet the same problem. I can send words or command via Telnet or Ping, when I use a router. However, I always failed when I directly connect the board and PC with a cross-over cable. I am really confused, I hope that you could help me.  

 

Have a good day! 

--- Quote End ---  

 

 

Hi, David and bjtuxuxu, 

 

I'm facing the same problem now and really confused about how to make the telnet client access the cable connected to the board. My program just keeps listening but nerver get the request...... Could you please give me some suggestions about how to solve the problem ? 

 

Really thanks for your help!!
0 Kudos
Altera_Forum
Honored Contributor II
2,196 Views

You should set your PC to 1000Mbps full duplex. 

And if you failed at ethernet0, then try ethernet1. 

Good luck !
0 Kudos
Altera_Forum
Honored Contributor II
2,199 Views

Hi all  

 

after 2 weeks I can run the SSS application  

thanks for providing the modified version for DE2-115  

and thanks for all post , it was very helpful for me especially is my first nios II application ! 

 

but I cant only run the application with the DHCP  

if I disable DHCP I get the following errors and the application won't build  

 

1- void SSSInitialTask(void *task_data) 

INT8U error_code; 

 

system_dhcp_hostname = "NEEK_1"; 

 

wait_on_phy(); 

 

/* 

* Register new DHCP "IP attained" callback function. 

* If DHCP is acquired, ws_ipset will be called instead of dhc_main_ipset(). 

*/ 

dhc_set_callback( 0, ws_ipset ); // error  

 

2- void SSSMonitorPhyTask(void *task_data) 

// 

 

// 

// 

dhc_set_state( 0, dhcs_initreboot );// error  

 

any idea how to fix these 2 errors to connect FPGA directly to my PC  

 

many thanks in advance
0 Kudos
Altera_Forum
Honored Contributor II
2,199 Views

When you disable DHCP. 

Just use a cross-over cable and set the computer's IP address to 192.168.10.235, set the IP in simple_socket_server.h to 192.168.10.234. 

And you should set you PC to 1000Mbps or 100Mbps instead of Auto-negotiation. 

Good luck to you!
0 Kudos
Reply