Forum Discussion
Ethernet Interface
Hi,
I have a system (a probe) that is currently sending/receiving data from the PC terminal using a UART(RS232) connection. This was easy to configure/program, and the hardware was also easy to make up. However, I wish to upgrade to an Ethernet Interface to improve the speed of the data transfer. I wish to transmit/receive 16-bits of data in one go, I have already done the Web Server and Simple Socket tutorials, but they are way to complex for my needs....is there no equivalent for printf() / getchar() when uning the Ethernet... Thanks in advance... Kushan.16 Replies
- Altera_Forum
Honored Contributor
Oh just take it. You have to unzip this to c:\altera\72\nios2eds\components .Remember, in order for this to work, you'll have to hand edit the system.stf file for your project. Here is an example:
Jake<sw_component id="INICHE_SL" name="NicheStack TCP/IP Stack" sopc_component_dir="altera_iniche_sl"> <sys_defines> <define name="include_tcp" quote="no" value="1"/> <define name="ip_fragments" quote="no" value="1"/> <define name="dhcp_client" quote="no" value="1"/> <define name="INICHE_TIMERS" quote="no" value="1"/> <define name="MEM_WRAPPERS" quote="no" value="1"/> <define name="TCP_ZEROCOPY" quote="no" value="1"/> <define name="ALT_INICHE_SUPERLOOP" quote="no" value="1"/> <define name="TELNET_SVR" quote="no" value="1"/> <define name="IN_MENUS" quote="no" value="1"/> <!--- <define name="ALT_NUMBIGBUFS" quote="no" value="100"/> --> <!--- <define name="PING_APP" quote="no" value="1"/> <define name="INCLUDE_NVPARMS" quote="no" value="1"/> <define name="NET_STATS" quote="no" value="1"/> <define name="DNS_CLIENT" quote="no" value="1"/> <define name="IP_ROUTING" quote="no" value="1"/> <define name="USE_PROFILER" quote="no" value="1"/> <define name="FTP_SERVER" quote="no" value="1"/> <define name="TFTP_SERVER" quote="no" value="1"/> <define name="FTP_CLIENT" quote="no" value="1"/> <define name="TFTP_CLIENT" quote="no" value="1"/> <define name="SERVER_PUSH" quote="no" value="1"/> <define name="VFS_FILES" quote="no" value="1"/> <define name="WEBPORT" quote="no" value="1"/> <define name="HTML_COMPRESSION" quote="no" value="1"/> <define name="FOREIGN_LANG_SUPPORT" quote="no" value="1"/> --> </sys_defines> </sw_component> - Altera_Forum
Honored Contributor
Okay. Well let me assure you the superloop concept is well proven. The InterNiche stack is designed to work in superloop mode. My company now has two products that employ the InterNiche stack in superloop mode.
However, it is certainly fair to consider that going through this process may be beyond your experience level. If you feel that is the case, then you can certainly decide to use the uC/OSII implementation or an alternative TCP/IP stack. As far as your current problem goes. I don't know that you needed to install all three products (Quartus, Megacore, NIOS). I think the NIOS EDS would have been sufficient. Anyway, did you follow all the instructions in the document. You have to copy the "simple_socket_server_no_rtos" folder to your nios software examples directory. You cannot use the regular simple socket server that's bundled with the NIOS EDS. The reason for this is that your "system.stf" file for your system library has to be hand-edited to include support for the InterNiche stack. Altera has decided not to support the superloop version and that is why you have to jump through all these hoops. Altera's own documentation indicates that the stack can be run in superloop mode and that higher networking performance can be acheived in superloop mode but for some reason (probably some agreement with uC) they've decided only to support the uC/OSII version. Obviously I have a patched copy of the stack. However, I'm typically in the habit of teaching a man to fish rather than giving him the fish. On top of that, I've made some custom modifications to the stack and wouldn't want those to cause you any grief. Jake - Altera_Forum
Honored Contributor
The whole superloop concept isn't giving me any positive vibes...I installed Quartus 7.1, and Megacore IP library 7.1 and Nios 2 EDS 7.1, just to get the superloop socket server example to work. I followed the instructions in the attached word document to the letter. However, when I came to the stage of building the superloop socket server example...I got errors in the network_utilities.c file that it could not find the headers "ipport.h" and "tcpport.h"
not sure whats going on!! - Altera_Forum
Honored Contributor
Okay... it seems you've downloaded the patch from the wiki correct? He's included a document that indicates which files he's modified. So what we actually did was run the patch on a 7.1 installation. Then we compared the modified files between the patched 7.1 version and the 7.2 version to see what changes we needed to make to get the superloop mode working. They were minimal and if I remembered off hand what they were I'd just give them to you. Bare in mind that there was other code that changed between 7.1 and 7.2 so you only want the necessary superloop changes.
However, didn't you look at this thread in the NIOS forum? http://forum.niosforum.com/forum/index.php?showtopic=8747 He's got a 7.2 version ready for download. I haven't used it but you could give it a shot. Jake - Altera_Forum
Honored Contributor
and how did you do that??
- Altera_Forum
Honored Contributor
Yes we had to patch 7.2 manually.
Jake - Altera_Forum
Honored Contributor
Right....I tried the superloop mode...but it doesn;t work. I think it is because my Quartus and SOPC builder are version 7.2, instead of 7.1 as in the instructions I downloaded, and so some of the folders that need changed are either in different locations or altogether missing....
- Altera_Forum
Honored Contributor
The version of the InterNiche TCP/IP stack that Altera ships is designed to work with uC/OSII. As such, if you aren't using uC/OSII for your application, the required source files won't even be found.
The InterNiche TCP/IP stack also supports superloop mode which does not require an OS. All of the designs that we have done using the InterNiche stack use superloop mode and thereby do not require uC/OSII. You have to do some minor modifications to the stack to get it to run in superloop mode. Try these threads for more information: http://forum.niosforum.com/forum/index.php?showtopic=8747 http://nioswiki.jot.com/wikihome/nichestack/%22super%20loop%22%20nichestack Jake - Altera_Forum
Honored Contributor
OK so i tried doing some simple socket programming....however am I right in assuming that I will have to use the MicroC/OS-II structure...
I have tried the following code, but Nios II IDE can't find the ipport.h and tcpport.h files, which contain all the socket programming fucntions... # include "sys/socket.h" # include <unistd.h> # include <string.h> # include <alt_types.h> # include <ctype.h> # include <errno.h> # include <stdio.h> # include <sys/alt_flash.h> # include "includes.h" # include "io.h" # include "ipport.h" # include "tcpport.h" # include "network_utilities.h" # define LOCAL_SERVER_PORT 1500 # define SERVER_PORT 1500 # define MAX_MSG 100 int main (int argc, char *argv[]) { int sd, rc, i; struct sockaddr_in localAddr, servAddr; struct hostent *h; if(argc < 3) { printf("usage: %s <server> <data1> <data2> ... <dataN>\n",argv[0]); exit(1); } h = gethostbyname(argv[1]); if(h==NULL) { printf("%s: unknown host '%s'\n",argv[0],argv[1]); exit(1); } servAddr.sin_family = h->h_addrtype; memcpy((char *) &servAddr.sin_addr.s_addr, h->h_addr_list[0], h->h_length); servAddr.sin_port = htons(SERVER_PORT); /* create socket */ sd = socket(AF_INET, SOCK_STREAM, 0); if(sd<0) { perror("cannot open socket "); exit(1); } /* bind any port number */ localAddr.sin_family = AF_INET; localAddr.sin_addr.s_addr = htonl(INADDR_ANY); localAddr.sin_port = htons(0); rc = bind(sd, (struct sockaddr *) &localAddr, sizeof(localAddr)); if(rc<0) { printf("%s: cannot bind port TCP %u\n",argv[0],SERVER_PORT); perror("error "); exit(1); } /* connect to server */ rc = connect(sd, (struct sockaddr *) &servAddr, sizeof(servAddr)); if(rc<0) { perror("cannot connect "); exit(1); } for(i=2;i<argc;i++) { rc = send(sd, argv, strlen(argv) + 1, 0); if(rc<0) { perror("cannot send data "); close(sd); exit(1); } printf("%s: data%u sent (%s)\n",argv[0],i-1,argv[i]); } return 0; } - Altera_Forum
Honored Contributor
Any BSD socket example can be used. The one indicated by Vizziee is a good start.
Just be careful with the header files to include. You should stick to the ones in the sockets server example, as they are not exactly the same than what you can see in some BSD sockets sample codes.