FPGARelated.com
Forums

Communication between FPGA and PC with ethernet

Started by Roggey February 17, 2006
Hello

I have to make an connection to a FPGA-borad.

http://www.celoxica.com/products/rc300/default.asp

This board only supports ethernet communication with the mac-layer. Now
I have to build an app that can send data(in my case images) to the
board.

My question is now how can i send data using the mac-layer only from a
c++ programm.

I do not think that we are using(or is possible to use) a router/switch
between the pc and the board, we will use an pachted-ethernet-cable.

thanks

I am not certain I entirely understand what you are asking, but it
sounds like you have bits and pieces of various concepts and I think
you need to research the components of your system a bit more.

You will need to start, by examing the protocol (language) that the
device you need to communicate with undestands.  Once you have a clear
understanding of it, which in this case sounds like the MAC layer in a
typical ethernet protocol, you can begin to look at what you will need
to connect to it.

I suspect you are looking for a form of magic bullet, such as conenct
through a router and you will all of a sudden have needed commands at
your figertips. Unfortunately, it probably doesn't exist.

As far as accessing this with a C++ program, being C++ isn't enough.
It will depend on what platform you are using, what tools and libraries
you have available, what "level" you are writing you code for (driver,
application, etc).

 "Roggey" <Roggey@gmail.com> writes:
|> I have to make an connection to a FPGA-borad.
|> 
|> http://www.celoxica.com/products/rc300/default.asp
|> 
|> This board only supports ethernet communication with the mac-layer. Now
|> I have to build an app that can send data(in my case images) to the
|> board.
|> 
|> My question is now how can i send data using the mac-layer only from a
|> c++ programm.

How to sent UDP packets or establish a TCP connection from
C++ depends entirely on your operating system. Under Unix/Linux,
you may want to start on the "man 2 socket" manual page and related
tutorials. On MacOS, it's probably the same.

On the FPGA side:

If you have a way to upload a microcontroller into the FPGA, or
it has already a built-in processor, and you have a C compiler
for it, you can install either a bare-boned TCP/IP stack such as

  http://savannah.nongnu.org/projects/lwip/

which also supports ARP and DHCP, or even a full embedded
operating system such as Linux or Windows CE. Thats the most
flexible and luxurious approach.

If you want to avoid using a processor, then you can probably
forget about using TCP. But decoding UDP packets in hardware
may still be very feasible.

If your Ethernet it is a point-to-point link, you may want to try
sending out UDP packets to IP broadcast addresses. This should be
translated into MAC broadcasts and therefore bypasss the entire
address-resolution protocol (ARP) mechanism in which your
FPGA will not participate. On the decoding end, you will have
to hope that the IP packets arrive unfragmented and with
constant-length headers (i.e., no options), which is normally the
case for UDP packets shorter than ~1.5 kB.

Of course all this is a real hack and may fail as soon as
anything else gets connected to the same network. But as long
as you do not expect Ethernet to run will all the features
with which it is used normally, it can be used almost as
easily as any other type of serial port.

Markus

-- 
Markus Kuhn, Computer Laboratory, University of Cambridge
http://www.cl.cam.ac.uk/~mgk25/ || CB3 0FD, Great Britain
Roggey schrieb:

> My question is now how can i send data using the mac-layer only from a > c++ programm.
That is a good question. I know what you are looking for. Normally people use the IP stack and every OS has its own implementation of that. I would be interested in that too, how to send data over the Ethernet. At least the people who implemented the IP stack had to know how to do it :) Guenter
On 17 Feb 2006 08:05:46 -0800, "GHEDWHCVEAIS@spammotel.com" <GHEDWHCVEAIS@spammotel.com> wrote:

>Roggey schrieb: > >> My question is now how can i send data using the mac-layer only from a >> c++ programm. > >That is a good question. I know what you are looking for. > >Normally people use the IP stack and every OS has its own >implementation of that. > >I would be interested in that too, how to send data over the Ethernet. >At least the people who implemented the IP stack had to know how to do >it :) > >Guenter
I think what you are looking for is a DLL which allows raw ethernet frames to be sent - I'm sure it must be possible, but may need to talk to the card at a low level and may be card-specific. It would also need to fight of Windows' own attempts to use it. This looks promising : http://www.rawether.net/
On 17 Feb 2006 08:05:46 -0800, "GHEDWHCVEAIS@spammotel.com"
<GHEDWHCVEAIS@spammotel.com> wrote:

>Roggey schrieb: > >> My question is now how can i send data using the mac-layer only from a >> c++ programm. > >That is a good question. I know what you are looking for. > >Normally people use the IP stack and every OS has its own >implementation of that. > >I would be interested in that too, how to send data over the Ethernet. >At least the people who implemented the IP stack had to know how to do >it :) > >Guenter
Actually all the source is out there but alas not in a very accessible form. One can go to the linux source and grab the driver for the specific network card in question and also use the linux ethernet driver at the bottom of the ip stack (eth_drv.c I think).
Check out this link for some ideas:
http://www.fpga4fun.com/10BASE-T.html

http://www.rawether.net/  this cost very much like 200/400$ depending
on the type.

I found a solution i think it will work. I will test it int the next
week.

I will use an opsource program http://www.winpcap.org/
This program manage all the stuff like open the networkadapter and
stuff like that.

here is some code i found:

#include <stdlib.h>
#include <stdio.h>
#include <pcap.h>

int main(int argc, char **argv)
{
	pcap_t *fp;
	char errbuf[PCAP_ERRBUF_SIZE];
	u_char packet[100];
	int i;

	/* Check the validity of the command line */
	if (argc != 2)
	{
		printf("usage: %s interface", argv[0]);
		return 1;
	}

	/* Open the adapter */
	if ((fp = pcap_open_live(argv[1],		// name of the device
							 65536,			// portion of the packet to capture. It doesn't matter
in this case
							 1,				// promiscuous mode (nonzero means promiscuous)
							 1000,			// read timeout
							 errbuf			// error buffer
							 )) == NULL)
	{
		fprintf(stderr,"\nUnable to open the adapter. %s is not supported by
WinPcap\n", argv[1]);
		return 2;
	}

	/* Supposing to be on ethernet, set mac destination to 1:1:1:1:1:1 */
	packet[0]=1;
	packet[1]=1;
	packet[2]=1;
	packet[3]=1;
	packet[4]=1;
	packet[5]=1;

	/* set mac source to 2:2:2:2:2:2 */
	packet[6]=2;
	packet[7]=2;
	packet[8]=2;
	packet[9]=2;
	packet[10]=2;
	packet[11]=2;

	/* Fill the rest of the packet */
	for(i=12;i<100;i++)
	{
		packet[i]=i%256;
	}

	/* Send down the packet */
	if (pcap_sendpacket(fp,	// Adapter
		packet,				// buffer with the packet
		100					// size
		) != 0)
	{
		fprintf(stderr,"\nError sending the packet: \n", pcap_geterr(fp));
		return 3;
	}

	pcap_close(fp);
	return 0;
}

The way to find the name of the network-adapter can be found here:
http://www.winpcap.org/docs/docs31/html/group__wpcap__tut1.html

thanks to all of you for the help.

roggey

In article <1140181834.631440.296610@f14g2000cwb.googlegroups.com>,
 "Roggey" <Roggey@gmail.com> writes:
>Hello > >I have to make an connection to a FPGA-borad. > >http://www.celoxica.com/products/rc300/default.asp > >This board only supports ethernet communication with the mac-layer. Now >I have to build an app that can send data(in my case images) to the >board. > >My question is now how can i send data using the mac-layer only from a >c++ programm. > >I do not think that we are using(or is possible to use) a router/switch >between the pc and the board, we will use an pachted-ethernet-cable.
Get help from your local software/network/sysadmin geeks. If I was doing that, I'd send UDP packets, and throw away (skip over) the IP and UDP headers on the receiving side. It's probably simplest if you can get a second ethernet card on your PC. You will probably have to setup routing and/or ARP by hand. -- The suespammers.org mail server is located in California. So are all my other mailboxes. Please do not send unsolicited bulk e-mail or unsolicited commercial e-mail to my suespammers.org address or any of my other addresses. These are my opinions, not necessarily my employer's. I hate spam.