Embedded Tutorial_DSP Technology_DSP Experiment Box Operation Tutorial: 2-28 Building a Lightweight WEB Server Experiment
[Copy link]
Purpose
The purpose of this video is to learn the communication principles of the TCP/IP protocol and the working principles of the Wed server, and to build a lightweight Web server.
Experimental Principle
Hardware Schematic
The network port was used during the experiment.
WEB SERVER
(WORLD WIDE WEB, World Wide Web)
The World Wide Web is a multimedia information search tool on the Internet. It is a service that has only been developed in recent years and is the fastest growing and most widely used service. It is precisely because of the WWW tool that the Internet has developed rapidly in recent years and the number of users has increased rapidly.
A web server is a program running on a physical server that permanently waits for a client (mainly a browser, such as Chrome, Firefox, etc.) to send a request. When a request is received, it generates a corresponding response and returns it to the client. A web server communicates with the client via the HTTP protocol, so it is also called an HTTP server.
When we enter a URL in the browser, the browser will first request the DNS server to obtain the IP address of the requested site. Then it will send an HTTP Request to the host with the IP address, and then it will receive the HTTP Response from the server. After rendering, the browser will present it to us with a better effect. In this process, it is the Web server that silently contributes behind the scenes.
The working principle of a web server is not complicated and can generally be divided into the following four steps:
- establish connection
The client establishes a TCP connection to the server through the TCP/IP protocol.
Before HTTP starts working, the web browser must first establish a connection with the web server through the network. This connection is completed through TCP. This protocol and the IP protocol together build the Internet, that is, the famous TCP/IP protocol family. Therefore, the Internet is also called the TCP/IP network. HTTP is a higher-level application layer protocol than TCP. According to the rules, only after the lower-level protocol is established can the higher-level protocol be connected. Therefore, a TCP connection must be established first. Generally, the port number of the TCP connection is 80.
The web browser sends a request command to the web server. Once the TCP connection is established, the web browser sends a request command to the web server.
- Request process
The client sends an HTTP protocol request packet to the server, requesting the resource document in the server.
After the browser sends its request command, it also sends some other information to the Web server in the form of header information. Then the browser sends a blank line to notify the server that it has finished sending the header information.
- Response process
The server sends an HTTP protocol response packet to the client. If the requested resource contains dynamic language content, the server will call the dynamic language interpretation engine to process the "dynamic content" and return the processed data to the client. The client interprets the HTML document and renders the graphic results on the client screen.
(4) Close the connection
The web server closes the TCP connection.
Normally, once the web server sends the request data to the browser, it closes the TCP connection. If the browser or server adds this line of code in its header information: Connection: keep-alive, the TCP connection will remain open after sending, so the browser can continue to send requests through the same connection. Keeping the connection saves the time required to establish a new connection for each request and also saves network bandwidth.
HTTP
(HyperText Transfer Protocol)
HTTP is a transmission protocol used to transfer hypertext from a WWW server to a local browser. It is based on the TCP/IP communication protocol to transfer data (HTML files, image files, query results, etc.). It can make browsers more efficient and reduce network transmission. It not only ensures that computers can correctly and quickly transmit hypertext documents, but also determines which part of the transmitted document and which part of the content is displayed first (such as text before graphics). HTTP is an application layer protocol, consisting of requests and responses. It is always the client that initiates the request and the server sends back the response. It is a standard client-server model. The HTTP protocol works on a client-server architecture. As an HTTP client, the browser sends all requests to the HTTP server, i.e., the WEB server, through the URL. The Web server sends a response message to the client based on the received request.
HTTP is a stateless protocol. There is no corresponding relationship between the current request and the previous request of the same client.
LwIP protocol stack
LwIP is a lightweight TCP/IP protocol stack that can be used in various embedded systems. LwIP protocol is an open source TCP/IP protocol stack for embedded systems. LwIP means light weight IP protocol. It reduces the RAM usage while maintaining the main functions of TCP protocol. Generally, it only needs tens of K of RAM and about 40 K of ROM to run, which makes LwIP protocol stack very suitable for use in low-end embedded systems.
The design of LwIP protocol stack adopts the idea of layered structure. Each protocol is implemented as a module, providing some interface functions with other protocols. All TCP/IP protocol stacks are in one process, so the TCP/IP protocol stack is separated from the operating system kernel. The application can be a separate process or reside in the TCP/IP process, and they communicate with each other using the ICP mechanism. If the application is a separate thread, it can communicate with the protocol stack process through the mailbox, message queue, etc. of the operating system. If the application resides in the protocol stack process, the application can communicate with the protocol stack process through the internal callback function.
EMAC
(Ethernet Media Access Controller)
This paper briefly introduces the functional description of the Ethernet media access controller (EMAC) and physical layer (PHY) device management data input/output (MDIO) modules integrated in the device. The EMAC module is used to move data between the device and other hosts connected to the same network, complying with the Ethernet protocol. The EMAC controls the packet data flow from the system to the PHY. The MDIO module controls the PHY configuration and status monitoring. Both the EMAC and MDIO modules are connected to the system kernel through a custom interface, which allows efficient data transmission and reception. This custom interface is called the EMAC control module and is an indispensable peripheral of the EMAC/MDIO.
The EMAC/MDIO has the following features:
(1) Synchronous 10/100 Mbps operation.
(2) Standard media independent interface (MII) or reduced media independent interface (RMII) to the physical layer device (PHY).
(3) EMAC acts as a DMA master to the internal and external storage space of the device.
Procedure flow chart
Operational phenomenon
hardware equipment
The hardware interface used in this experiment is the network port. The required hardware is the experimental board, emulator, network cable, RS232 cross serial port female bus, USB to RS232 serial port cable and power supply.
Hardware Hookup
(1) Use an Ethernet cable to connect the Ethernet port of the experimental board to the router. The program obtains the IP dynamically by default. If there is no router, use an Ethernet cable to connect the Ethernet port of the experimental board to the Ethernet port of the computer. Please modify the program and set the static IP of the computer according to the experimental manual.
(2) Use the RS232 cross-port female cable and USB to RS232 serial cable to connect the UART2 serial port of the experiment board and the USB port of the computer.
(3) Connect the emulator to the computer's USB port.
(4) Set the dip switch to DEBUG mode 01111, connect the power supply of the experimental box, and turn on the power switch to power on.
Software Operation
(1) First check the serial port number in the device manager;
(2) Set up the serial port debugging tool and set the baud rate to 115200.
After setting up the serial port debugging tool, perform related operations in CCS.
Import the project and select the corresponding project in the Demo folder
Compile project
Connect CCS to the experiment box and load the program
Click to run the program, and the serial terminal will print the automatically acquired IP address of the experimental box.
Enter cmd at the bottom of the Windows Start menu to enter the console window and execute the ping command to confirm that the network part of the experimental box is working properly.
Open the browser and enter the URL http://192.168.0.116 to see the URL content.
After the experiment is over, first click the yellow button to pause the program, then click the red button to exit the connection between CCS and the experimental box, and finally turn off the power of the experimental box.
|