EmbeddedRelated.com
Forums

Ethernet in its most basic form

Started by Unknown May 2, 2008
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:

http://tuxgraphics.org/electronics/200606/article06061.shtml

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.
On May 2, 5:46=A0pm, Tom=E1s =D3 h=C9ilidhe <t...@lavabit.com> wrote:
> 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) > { > =A0 =A0 char unsigned mac_dest[6], mac_src[6]; > > =A0 =A0 memcpy(mac_dest,data,sizeof mac_dest); > > =A0 =A0 data +=3D 6; > > =A0 =A0 memcpy(mac_src,data,sizeof mac_src); > > =A0 =A0 /* I increment the pointer taking > =A0 =A0 =A0 =A0the 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: > > http://tuxgraphics.org/electronics/200606/article06061.shtml > > 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.
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.
Tom&#4294967295;s &#4294967295; h&#4294967295;ilidhe wrote:
> 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.
No way.
> Ethernet cables consist of 8 pairs of wires, and from what I know, > only 4 of the pairs are used.
Erm, no. It's 8 wires, not 8 pairs. And in the current technology (GBit Ethernet), they are all 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?
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.
> Would I go insane trying to synchronise start and stop > bits, reading frame check sums, sending Manchester-encoded data?
Certainly. Well, if you're not already insane that is...
> 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!).
Not on anything remotely resembling a PIC you can't.
On May 3, 12:17=A0am, "robertwess...@yahoo.com"
<robertwess...@yahoo.com> wrote:

> If what you're wanting to do is implement the protocol stack, then you > definitely want to use a canned Ethernet controller. =A0And that will > give you exactly what you want. =A0You hand it a frame, and it sends it, > and it will let you know when it's received one. =A0Just pick one that > easy to interface with the CPU of your choice.
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.
On May 2, 7:02=A0pm, Tom=E1s =D3 h=C9ilidhe <t...@lavabit.com> wrote:
> On May 3, 12:17=A0am, "robertwess...@yahoo.com" > > <robertwess...@yahoo.com> wrote: > > If what you're wanting to do is implement the protocol stack, then you > > definitely want to use a canned Ethernet controller. =A0And that will > > give you exactly what you want. =A0You hand it a frame, and it sends it,=
> > and it will let you know when it's received one. =A0Just pick one that > > easy to interface with the CPU of your choice. > > 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.
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.
On Fri, 02 May 2008 15:46:31 -0700, Tom&aacute;s &Oacute; h&Eacute;ilidhe wrote:

> 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: > > http://tuxgraphics.org/electronics/200606/article06061.shtml > > 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.
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 http://www.wescottdesign.com Need to learn how to apply control theory in your embedded system? "Applied Control Theory for Embedded Systems" by Tim Wescott Elsevier/Newnes, http://www.wescottdesign.com/actfes/actfes.html
Tom&aacute;s &Oacute; h&Eacute;ilidhe <toe@lavabit.com> writes:
> Ethernet cables consist of 8 pairs of wires, and from what I know, > only 4 of the pairs are used.
For 10BASE-T and 100BASE-TX, there are four pairs, of which two are used. For 1000BASE-T, all four 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.
A bit more than most microcontrollers 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:
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.
"Tom&#4294967295;s &#4294967295; h&#4294967295;ilidhe" <toe@lavabit.com> wrote in message 
news:15fe72e6-3238-4a03-8170-cd0ba37d7fbe@s50g2000hsb.googlegroups.com...
> > 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: > > http://tuxgraphics.org/electronics/200606/article06061.shtml > > 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.
Have a look at http://members.iinet.net.au/~vanluynm/Embedded_8051_TCPIP_Webserver.php
one of many solutions here may suit you:
http://www.dontronics-shop.com/Ethernet-p-1-c-347.html

Cheers Don...



-- 
Don McKenzie

Site Map:            http://www.dontronics.com/sitemap
E-Mail Contact Page: http://www.dontronics.com/email

Intelligent 2.83" AMOLED with touch screen for micros:
http://www.dontronics-shop.com/product.php?productid=16699
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?