LWIP Dual Network port, LPC2294, transplant summary, cs8900

Source: Internet
Author: User

Space

My company's products are dual network port, the original program is the TCP/IP protocol stack, because it is simple to implement the ARP and TCP, UDP the simplest case, so sometimes on the public network will encounter problems.

Later in the single-network port of the product transplant LWIP, lightweight TCP/IP protocol stack, to a certain extent solved the problem, so the product of the dual network card should also be used LWIP this protocol stack to achieve. The job fell on my head.

Porting of single Nic I don't repeat, only describes the problems and solutions that are encountered during porting from a single NIC to a dual NIC.

First, I looked at the changes made in the next single Nic porting.

Hardware starts with hardware initialization, calls My_lwip_init (), creates tasks in this function, adds NIC configuration.
The setting of the MAC address is set in the Low_level_init () function when the NIC is initialized.
The Low_level_output () function processes the output information.
The Low_level_input () function processes the input information.
The Ethernetif_input () function is to differentiate how packets are handled.
As a result, you know that the main changes I need to make are for these functions and their related functions.

Create more than one netif block, add a netif_add to the Mylwip_init () function during hardware initialization, and call Netif_set_up ().
In Low_level_init (), the MAC address of the two network cards is distinguished and populated into the netif block. [This code is visible, the hardware MAC address modified after the program must reset the Netif list to execute correctly.] ]
In Low_level_output (), the returned data is determined to be sent to which network card, the data is copied to the network card send buffer, and then sent.
In Low_level_input (), determine which NIC received the data, and copy the data from the network card acceptance buffer to the payload data of the NETIF block.
After the completion of these steps, the PING program has been able to pass, but there are some strange phenomenon, the same network port can communicate two IP address content [in a network port ping two network cards can pass], so again in the Ethernetif_input () function in the decision to add the destination address is the network card and then enter the TCP/IP processing. By this time also solved.

Then there is a ridiculous problem, ping net1 ok,ping net 2 ok,tcp net1 error,tcp Net2 OK. And only one NIC, Net1 and Net2 are normal. So the suspect is the route this block out of the question, look at lwIP's document only to find that the Ip_route () function of the rule is the target address in this network card network segment is considered the data of this network card, otherwise go the default route configuration. Because our module is to do data hot standby or multi-communication eloquence set dual network card, so two network card is a network segment configuration, then the Ip_route () function found a default route table in the first route returned directly. Helpless, I wrote Ip_route2 (), to compare the source address of the way to determine which network card to send data.

So far, the test OK, happy, and quickly recorded

My processing is more simple, but also more effective, if there are two network card chip, whether it is the same chip, or not the same chip, directly built two drive files, ETHERNETIF.C, add to the project, of course two filename is not the same, and the function name inside the file if it is an external function, should also have different function names, but my experience is that most of them can be the same, because they are static functions (stctic), there are static variables, these variable names do not have to be modified, it is estimated that only the Ethernetif_init () is modified, Ethernetif_input (), come on, it's easy,
Why would you want to do that? Two reasons, since it is two network cards, then certainly to establish two sets of buffers, two sets of address space, equivalent to each network card allocated two different running space. If hard to put them together, that need to solve the problem of parameter transmission, through parameter passing to determine which network card is operating, I am using interrupts to receive data received by the network card, two network cards are of course two interrupt service function, if the hard to use an interrupt processing function, or the above problem, Also determine which network card is the interrupt generated. Not can not handle, can also handle, is too troublesome, simply do two sets of completely independent system, two files, more effective.
Another reason, if it is a computer, don't say add two network card is three four, the problem is not big, it is how to achieve it. It is estimated that a thread is set up for each NIC, which is dedicated to two processing of the data received and sent by the NIC. This to do is to handle the re-entry of the function, I this embedded program is not long to consider the problem of function re-entry, not to mention I this is still bare run, no system. If that's the case, I'd rather do two full-featured files to drive the same NIC.

Collected in 2013-08-15

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.