Re: Portability: Harmony between PC and microcontroller




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.
.



Relevant Pages

  • Re: Suggestions for bare minimum for microcontroller experiments....
    ... After a few months of reading webpages about microcontrollers, ... I have fairly versed in the C programming language. ... To start with, while I have used AVRs and AVR Studio, I haven't used ... WinAVR or any of the hardware you list, so I might be wrong in saying ...
    (comp.robotics.misc)
  • Re: LED driver type application: want to control Christmas lights
    ... programming, ... microcontrollers, and including the programming of the ... There are kits out there, most most kits seem to teach little more than how ... end up using networks of the SAME microcontroller that's in the kit. ...
    (sci.electronics.basics)
  • Re: microcontroller programming -- how to begin
    ... microcontrollers. ... so programming as such ... it requires getting a working toolchain ... correctly getting the working code onto the chip, ...
    (sci.electronics.design)
  • Re: sensors - pc interface
    ... microcontrollers, and do all the control and processing in the PC. ... I have never programmed a microcontroller, so I feel much more comfortable programming and debugging in my PC. ... But I have just realized that at least I have to use microcontrollers for IR sensors, as I have not found any with I2C output. ... The programming involved is not so much programming as such, but more akin to wiring up devices: setting clock rates, enabling peripherals, and selecting options. ...
    (comp.robotics.misc)

Loading