Ethernet in its most basic form

As a hobby project, I want to create a two-port router, and I want to do it from as low as level as possible. I want to program it in C.

Ethernet cables consist of 8 pairs of wires, and from what I know, only 4 of the pairs are used.

So let's say I approached this project form the very most fundamental level, let's say I decided to use a run-of-the-mill microcontroller such as a PIC that has 8 IO pins. Would this be an absolute mammoth of a task to do? Would I go insane trying to synchronise start and stop bits, reading frame check sums, sending Manchester-encoded data? Something tells me I'd be biting off a bit more than I can chew.

So what would be just up from that? Well how about if I had some sort of "callback function" that was magically invoked whenever a frame was received, something like:

void ProcessFrame(char unsigned const *data) { char unsigned mac_dest[6], mac_src[6];

memcpy(mac_dest,data,sizeof mac_dest);

data += 6;

memcpy(mac_src,data,sizeof mac_src);

/* I increment the pointer taking the data I need from the frame. */ }

That's pretty much all the functionality I would need. I'd write the network protocol stack myself.

I've heard about things like the "rabbit embedded ethernet" but it sounds way too advanced for what I want; it'd take all of the fun out of the project. Plus it's expensive.

Looking at other more basic devices though, I was very interested when I read the following article:

formatting link

It involves using the ENC28J60 chip, but as far as I know it can only do 10 Mbps. That's great and all, but since this is my own little hobby project I see no reason why I can't opt for 100 Mbps or perhaps even gigabit (depending on the price of the chip!).

Anyone got any suggestions for what chip(s) I should use? Basically I just need the following functionality:

1) Analyse frames when they're received 2) Send out my own frames

Of course, all the stuff like CDMA/CD would be handled under the hood and I wouldn't have to bother with it.

Also, as far as is possible, I like to program in Standard C (particularly to the 1989 standard), sot it'd be helpful if there was a pretty standard-compliant compiler for the chip.

Reply to
Tomás Ó hÉilidhe
Loading thread data ...

There are a million microcontrollers with embedded Ethernet, including a bunch of PICs. There are also a dedicated million Ethernet controllers out there.

If you really want to implement an Ethernet controller, you'll need a bunch of external hardware, and you'll want to look at the specs for Ethernet, although you'll be able to put much of the logic on a FPGA. This is far from a trivial task, and further, you seem to imply that you *don't* want to do this when you expect someone else to take care of CSMA/CD and stuff like that. And FWIW, bit-banging a 10Mb Ethernet link is simply not going to be possible on a PIC.

If what you're wanting to do is implement the protocol stack, then you definitely want to use a canned Ethernet controller. And that will give you exactly what you want. You hand it a frame, and it sends it, and it will let you know when it's received one. Just pick one that easy to interface with the CPU of your choice.

Reply to
robertwessel2

No way.

Erm, no. It's 8 wires, not 8 pairs. And in the current technology (GBit Ethernet), they are all used.

That would be putting it mildly. I think "completely impossible" would be a good deal closer to the truth.

Start with: how many microcontrollers do you know that have enough horsepower to not just bit-bang, but also _receive_ signals at 10 millions steps a second? 100 million? And still have any left to significantly process the data?

At the very minimum, you need a serious FPGA or pre-made Ethernet MAC/PHY circuit to handle all the bit stuff, and leaves only the upper protocol levels to the microcontroller.

Certainly. Well, if you're not already insane that is...

Not on anything remotely resembling a PIC you can't.

Reply to
Hans-Bernhard Bröker

This is exactly what I'm looking for, a microcontroller that sends frames when I tell it to, and also hands frames to me when they're received. I want to write all the protocol stuff myself.

You say "pick one that's easy to interface with the CPU of your choice"; I thought that these devices were fully-fledged microcontrollers and so I wouldn't have the option of mix-matching CPU's.. ? Do I misunderstand?

Can anyone suggest a very simple Ethernet micrcontroller that will do what I want? I've considering going with the ENC28J60 which can do 10 Mbps, but I just want to check first to see if there's anything that does 100 Mbps or maybe even gigabit.

Reply to
Tomás Ó hÉilidhe

Microcontrollers vary greatly in how they can interface to external devices. For example, you might find one with two Ethernet controllers on the chip, and you're all set. I don't happen to know of a PIC like that, but don't take that to mean anything in particular. Other controller families *do* have products with multiple Ethernet interfaces built in, although typically in higher end parts.

Or you might have enough I/O pins on your microcontroller to interface a traditional Ethernet controller chip, or your controller might actually support a PCI interface, and then any of the current PCI compatible chips will work for you.

Or you might have a CAN or SPI (or other) local bus interface on your controller, and you can get a Ethernet controller with a matching interface (for example, many PICs have SPI, and you can get a ENC28J60 to attach to that).

For your project, you might well end up with a combination of a controller with an integrated Ethernet controller, and then a second external Ethernet controller attached via SPI, or something like that.

Reply to
robertwessel2

No way, no how, are you going to bit-bang a protocol whose baud rate is equal to the MIPS of your processor.

Perhaps you could do it with an FPGA and a microprocessor helping, but the task would be huge.

Most sane folks do this by using a chip that has built-in Ethernet hardware.

--
Tim Wescott
Control systems and communications consulting
 Click to see the full signature
Reply to
Tim Wescott

For 10BASE-T and 100BASE-TX, there are four pairs, of which two are used. For 1000BASE-T, all four pairs are used.

A bit more than most microcontrollers can chew.

Using hardware to actually receive the frame? In other words, an Ethernet MAC/PHY?

There are microcontrollers with one or more Ethernet MACs built in, and even a few that have the PHY built in.

Reply to
Eric Smith

Have a look at

formatting link

Reply to
Murray R. Van Luyn

one of many solutions here may suit you:

formatting link

Cheers Don...

--
Don McKenzie

Site Map:            http://www.dontronics.com/sitemap
 Click to see the full signature
Reply to
Don McKenzie

Thanks for all the replies.

I see now that there's two ways of going about this:

1) Getting an independant ethernet controller that will connect to my separate microcontroller 2) Getting a micrcontroller that has built-in Ethernet

I definitely want to go with the built-in Ethernet!

I was thinking to myself that it would be cool get a chip that can do gigabit, but I've been googling and I haven't found one.

So far, I've looked at these two chips:

1) PIC18F97J60 : It can only do 10 Mbps and its core is 8-Bit. 2) MCF5223x : It can do 100 Mbps and its core is 32-Bit.

My own electronics provider lists them at the around about the same price for a single unit: $10.

So far I'm thinking of going with the MCF5223X. I'll have to find out if I can get a handy little kit for programming it that will connect to my PC via USB.

There's a complication in my two-port router project, namely that I'll have two ethernet ports. I wonder will I end up needing two separate ethernet microcontrollers that will communicate with each other? Or perhaps even four microcontrollers?

Reply to
Tomás Ó hÉilidhe

I suggest getting one controller with ethernet, and making a simple project where some hardware can be controlled over an ethernet connection.

Making your own router is a complex project for a beginner, and not very useful. Routers can be obtained in any PC store for less than you'd need for the parts.

Reply to
Arlet

Do either of these parts include the PHY? One part that I know of which does is the Luminary Micro LM3S6xxx or LM3S8xxx part. Both of these include an Ethernet MAC and PHY for 10 or 100 Mbit/s operation, along with a lot of other peripherals. They have an eval board for around $50, IIRC. The Motorola parts tend to have expensive boards and the LM parts run a lot faster than the PICs.

If you want to know cost effective ways of building a router, you could buy one and open it up. In fact, if you dig around, many routers have been hacked and info is available for booting them with Linux. That would be the ultimate inexpensive development system!

Reply to
rickman

If you google Fred Eady (Circuit Cellar), you'll find a bunch of his projects that deal w/ ethernet at a basic level where you can learn quite a bit w/o going nuts... Your basic chips are the ENC28J60,

18F67J60, the Realtek 8019as, National 83848i, and the Cirrus CS8900. I'm sure there are others but these are the ones I've played with, & there is plenty you can do w/ these w/o dropping big $$$.

Don't forget, you still need a PHY+magnetics.

Best, Tom

Reply to
Blip

I just want to run a design past you. I only thought of it a few minutes ago so I'm not certain if it'll work.

A normal ethernet-capable microcontroller works with only one Ethernet port, but of course I'll want it to work with two ports if I'm to have a two-port router.

My two-port router will have very basic functionality. A packet that's received on port 1 will be forwarded out on port 2 (but with a altered target MAC address of course). Also, a packet that's received on port

2 will be forwarded out on port 1 (again with an altered target MAC address).

Now how about this:

Let's say I get two ethernet microcontrollers, uc1 and uc2. And let's say I get two ethernet ports, p1 and p2.

Now let's say I use uc1 to recieve data from p1, and to send data out on p2. In the same fashion, I'd use uc2 to receive data from p2 and send data out on p1.

I'd do this simply by connecting one wire pair of p1 to uc1, and the other pair to uc2. Similarly I'd attach one wire pair of p2 to uc1, and the other to uc2.

Now the first thing that comes to mind is how I'd deal with colissions, but I don't think this is of concern if I use Full Duplex mode.

Is this go-er, do you think?

Reply to
Tomás Ó hÉilidhe

Ah crap I just realised I'd have no way of replying to ARP requests for the router ports.

How else could I go about operating two separate ethernet ports?

Reply to
Tomás Ó hÉilidhe

There are a couple MCF5223X kits available from Freescale. They cost $100 and $300 if I remember correctly. They both come with a USB base programming solution.

formatting link

formatting link

Most developers use CodeWarrior, but I've been using the GNU tools under Linux distributed by Codesourcery:

formatting link

Petter

--
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
 Click to see the full signature
Reply to
Petter Gustad

There's no point at all for most of these chips to support Gb-E, since there's no possible way they could come anywhere remotely close to driving that kind of bandwidth. And since your typical switch will happily connect to any of those, it make no difference there either.

But if you can't find a controller with two built in ports, you'll want to pick a controller that makes it easy to add an external controller (up thread I mentioned a SPI Ethernet chip from Microchip which you can add to any PIC with an SPI port). You don't really want to have two separate controllers, since that just adds the issue of how the two chips then exchange information (like the packets you're hoping to forward).

Anyway, you'll probably want to start by supporting static routes only (which is trivial to program), just blindly forwarding packets is going to make a mess.

But if I may suggest - get yourself and old PC, and a couple of simple to program Ethernet cards (NE2000 compatibles are very simple), and then write your router software to run under DOS. If you get a motherboard with actual ISA slots, you can even avoid the minor issue of having to track down the PCI address assignments. Your development and testing environment will be much better, and certainly a lot more understood and well documented. Although you might have to get a floppy drive for your development PC.

Reply to
robertwessel2

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.