Re: Portability: Harmony between PC and microcontroller
- From: Tomás Ó hÉilidhe <toe@xxxxxxxxxxx>
- Date: Mon, 5 May 2008 06:57:18 -0700 (PDT)
Thanks for the reply.
On May 5, 3:42 am, Jack Klein <jackkl...@xxxxxxxxxxx> wrote:
Try doing another embedded project, this time with an ARM. ST just
announced some ARM parts with up to 2MB of flash and 96KB of RAM.
For my next hobby project, I want to make a very simple two-port
router. When the router receives a packet, it will look up the IP
address in its routing table, and then decide what port to forward it
out on and what destination MAC address to use. That's pretty much all
it will do. Of course I'll have to make it do a few other things, like
send and receive ARP requests, but nothing too complicated.
I started throwing some code together in notepad, just to see how I'd
make it work. Now the thing is, I see no reason why I shouldn't be
able to move this code over to a PC. Here's the beginnings of it:
typedef uint_fast32_t IPv4addr;
typedef uint_fast64_t MACaddr;
typedef struct RoutingTableEntry {
IPv4addr addr;
IPv4addr mask;
IPv4addr router_addr;
uint_fast8_t port; /* Here's a great example of where I'd
normally use "unsigned int" */
} RoutingTableEntry;
typedef struct InfoForForwarding {
uint_fast8_t port;
MACaddr dst_mac;
} InfoForForwarding;
#define LEN_ROUTING_TABLE 16u
RoutingTableEntry routing_table[LEN_ROUTING_TABLE]; /* Hold 16
routes max in the table */
#define pend_routing_table (routing_table + LEN_ROUTING_TABLE)
InfoForForwarding GetInfoForForwarding(IPv4addr const dst_ip)
{
InfoForForwarding iff = { 0 };
RoutingTableEntry const *p = routing_table;
do
{
if ((dst_ip & p->mask) == p->addr)
{
iff.port = p->port;
/* Now consult ARP table to get MAC address of router */
iff.dst_mac = GetMACaddr(iff.port,p->router_addr);
return iff;
}
} while (pend_routing_table != ++p);
return iff;
}
As I hope you'll agree from looking at this code, there's nothing
microcontroller-specific or PC-specific about it. There's no reason
why the code couldn't be used to make a PC program that would
implement a "virtual router" between two network cards.
It appears that quite a few people think that PC programming and
embedded programming are quite separate from each other, but I hope my
code example above shows why there's no reason why code can't migrate
and be portable between the two. Many C programmers already are
enthusiastic about their code being portable, but I just hope they'd
consider microcontrollers too.
Slightly off-topically, I don't know if you've been following my
thread entitled "Ethernet in its most basic form". I've been asking
around to see what microcontroller I should use for making my little
two port router. I've been given many suggestions of microcontrollers
that will work with one sole ethernet port, but obviously I'll need a
microcontroller that will work with two. (Or then again I might need
two microcontrollers that will communicate with each other... ?). I
don't suppose you'd have any idea what I should use for that? I want
to work at 100 MBps full-duplex.
.
- Follow-Ups:
- Re: Portability: Harmony between PC and microcontroller
- From: CBFalconer
- Re: Portability: Harmony between PC and microcontroller
- References:
- Portability: Harmony between PC and microcontroller
- From: Tomás Ó hÉilidhe
- Re: Portability: Harmony between PC and microcontroller
- From: Jack Klein
- Portability: Harmony between PC and microcontroller
- Prev by Date: socket creation
- Next by Date: Re: K&R2, exercise 6.4
- Previous by thread: Re: Portability: Harmony between PC and microcontroller
- Next by thread: Re: Portability: Harmony between PC and microcontroller
- Index(es):
Relevant Pages
|
Loading