Forum Discussion
Altera_Forum
Honored Contributor
15 years agoWORKING: DE2-115 Simple Socket Server
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:- I used updated versions for everything as of 4/4/11. 10.1 Sp1.
- Download and install the Knowledge base update to prevent nios from crashing. http://www.altera.com/support/kdb/solutions/rd12222010_317.html
- Take the Quartus DE2_115 webserver example for Enet0 RGMII that comes on the CD and use quartus flash programmer to program.
- 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.
- 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)
- This example will now work as explained in the pdf.
- 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.
66 Replies
- Altera_Forum
Honored Contributor
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. - Altera_Forum
Honored Contributor
--- 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. - Altera_Forum
Honored Contributor
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! - Altera_Forum
Honored Contributor
--- 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 pageThe 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.
- Altera_Forum
Honored Contributor
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! - Altera_Forum
Honored Contributor
--- 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. - Altera_Forum
Honored Contributor
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! - Altera_Forum
Honored Contributor
Problem Solved!!!
- Altera_Forum
Honored Contributor
--- 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. - Altera_Forum
Honored Contributor
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?