What I understand

Source: Internet
Author: User

 

What I understand:

Protocols, protocols, and Protocols are dizzy...

 

Recently, I am working on the network port. I have a terrible headache. I finally got a little eye on it.

 

My system uses the UCOS operating system, so I use tasks ).

First, write the driver (this task has been completed by someone, and I will not write it), and then start to work.

 

1. Create a task accepted by the network port and a task sent by the network port in task _ start (task for task creation) during hardware startup. Call task_net_rx and task_net_tx respectively.

2. call the net_init () function in the initialization function sys_init (function for power-on Initialization) to set the IP address, gateway, subnet mask, MAC address, and other information of the network port, and start the gateway.

3. First, you need to create a sending and receiving circular buffer. I have created it here. Let's simply pick up the implementation of the task_net_tx function: Wait for the receiving function to send a semaphore net_sem. If yes, net_tx_num takes the number from the ring buffer and sends it according to the length of the sent data.

4. Then the focus is to accept the function: the accept function needs to parse what protocol is used to send the content, which indicates what the meaning is, and how to handle the received information in the future, so it is complicated. To achieve communication, you must first implement the ARP Protocol to ensure the basis of communication, and then implement the TCP and UDP protocols as the main communication path. Implement the Ping function to ensure the basis of the test communication. Because it is not a complete TCP/IP protocol stack, to reduce the amount of code, write your own code to implement this function. As a carrier, TCP and UDP data packets contain data information and also implement protocols in data information, for example, Modbus protocol, 104 communication protocol, DNP protocol, custom protocol, and so on. In each specific protocol implementation, how to parse and process data is another layer of processing. This mainly reflects the thought of hierarchy.

 

From the perspective of hierarchy, I can divide this process into several layers.

Lowest layer:

Task_net_rx

{

If (ARP) arp_ack ();

Else if (UDP) udp_ack ();

...

Save the returned data to the ring buffer and set the semaphore.

}

The last layer is the implementation of these protocols. Here we provide interfaces for the last layer of protocols:

Udp_ack ()

{

...

If (Modbus) n = modbus_ack ();

Else if (DNP) n = dnp_ack ();

...

...

}

In the same way.

 

In this way, the entire network processing structure is ready.

 

Due to limited time, I have no time to go to the detailed code of LWIP and read its instructions. By the way, my understanding is as follows:

1. LWIP implements detailed layers. My code is layered according to my own understanding, not so strict.

2. LWIP has a dedicated caching and data management mechanism. I don't have this.

3. LWIP is not fully layered, and resources are wasted to reduce data copying between layers. My code is completely a global variable and does not copy data.

4. The LWIP is customized, the code can be increased or decreased, and the socket interface is implemented. My code can also be deleted, but it is relatively simple.

 

Take a good look at the code of these experts for a long time!

So far, over!

 

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.