1. Simplex communication:
Simplex communication definition: A working mode in which information can only be sent in one direction between two points. It means: assuming that A and B are communicating, only one party can send data to the other party and cannot receive data from the other party. Just like the earpiece that children play with, tie a line between two cups and tighten it, so that you can speak to the cup and the other side can hear the sound.
2. Half-duplex communication:
Half-duplex communication definition: Information can be sent in two directions between two points, but not at the same time. This means that there is a sequence in sending/receiving data. For example, after A sends a data request to B, A can only receive the return data sent from B. However, after A receives the return data sent from B, it can immediately send a data request to B, and B can also send data to A.
3. Full-duplex communication:
Full-duplex communication definition: Communication allows data to be transmitted in two directions at the same time, and its capabilities are equivalent to the combination of two simplex communication modes. The essential difference between full-duplex communication and half-duplex communication is that half-duplex communication uses only one line to achieve two-way communication, but full-duplex communication uses two lines, one for sending data and the other for receiving data.
2. Inter-chip communication
1. Serial communication:
The communication between hosts is essentially the transmission of data back and forth between two chips.
Serial communication is a bit-by-bit communication through full-duplex communication. Its advantages are that it can transmit data over long distances (the signal will be reduced when passing through a too long data link, but generally we use signal amplification to achieve longer data transmission), and it occupies fewer lines (sending line, receiving line, ground line [mainly for anti-interference]). However, serial communication is slightly slower than parallel communication. Generally, we use the RS-232 transmission standard to regulate data transmission.
Figure 5 Serial port pin sequence diagram
For the DB 9-pin serial port interface definition: Line 2 receives data (RxD), Line 3 sends data (TxD), Line 5 is signal ground (GND) [The purpose is to shield external electromagnetic interference]
*RS-232 protocol design:
Figure 6 Communication between 89S51 series microcontroller and PC
For some chips that do not output RS-232 signals, designers often use MAX 232 (a device that converts the TTL level output of the chip communication to RS-232 signals) to connect the PC and the chip. In Figure 6, 89S51 first sends data to MAX 232 T1IN through TxD, then MAX 232 converts the TTL level signal into RS-232 signal inside it, and finally MAX 232 sends it to the COM interface of the PC through T1OUT. At this time, the PC receives the data we sent (the reverse is receiving data: COM TxD -> R1IN -> R1OUT). Knowledge about single-chip microcomputers can be found at www.51hei.com. It is written to be easier to understand. [page]
Three Communication Protocols
1. Ethernet Transmission Protocol:
Ethernet Definition: A local area network that is currently widely used and uses a shared bus transmission media method. In the past, if multiple computers wanted to use a modem to access the Internet, they needed to add a hub (HUB) To connect these computers in parallel. [PS: Compared with a hub and a switch, a hub will evenly distribute the total network data transmission rate to each computer, but a switch will not, which is related to hardware design]
Figure 7: Actual picture of the hub (it's rare to find a picture without a watermark these days..)
Figure 8 Bus-type data transmission link
The line is shared, but how does a computer in the line know whether the data in the line is sent to itself or to other computers? For this reason, people have developed the Ethernet data transmission protocol. The figure below shows the transmission data structure.
Figure 9 Ethernet data transmission structure
The destination address refers to which computer receives the data. The source address is where the data is sent from. For example, if host A needs to send data to the WAN, the destination address is the address of the hub's network adapter (this address is the MAC address, which is the only address owned by the network adapter). When the hub receives the data and forwards it to host B, all hosts on the bus can receive the data packet. If host A receives the data packet, it will compare the destination address in the data packet with its own network adapter. If they are the same, it means that the data is delivered to me. If they are not the same, the data packet will be discarded. This also explains the principle of monitoring other hosts sending/receiving network information under the same hub bus.
ARP request/reply: Its purpose is to use the address of a certain network adapter to initiate an inquiry in the bus, and then obtain the IP address of the network adapter to be queried. Before the computer needs to rely on a hub, switch or router to transmit a message, it must use an ARP request to tell the hub and other message forwarding hardware the MAC address of the local network adapter [PS: You can also use the RIP (Routing Information Protocol) protocol to obtain the IP address from the message forwarding hardware (send the MAC address of the network adapter to obtain the IP address)]. After receiving this request, the message forwarding hardware will search in the ARP cache table (corresponding to the computer's IP address and the MAC address of the network adapter). If the MAC address is not available, the MAC address will be updated in the ARP cache table, and then an ARP reply packet will be sent. Then, when the message forwarding hardware receives the message, it can find the MAC address in the ARP cache table according to the IP address in the data. The address is then sent on the bus. If the IP address of a received data packet is not found in the ARP cache table, the message forwarding hardware will discard the data packet and send an ICMP data unreachable packet to the source IP address. Note that the message forwarding hardware generally refreshes the ARP cache table every thirty minutes.
RARP request/response: If we only know the IP address of a computer under the same hub and want to send data to it but do not have the MAC address of the network adapter of the computer, what should we do? Then we need to broadcast a RARP (Reverse Address Translation Protocol) request to the bus. At this time, the destination address in the Ethernet data structure is set to FFFFFFFFFFFF (i.e.: -1), and the destination IP address in the RARP data packet structure (see Figure 13) is set to the IP address to be queried. Next, when the network adapter of a computer under the bus receives it, it will compare the IP with its own. If the query is for its own IP address, it will return a RARP response containing the IP address and MAC address of the network adapter. Finally, after the query host receives the data packet, it will update the ARP cache table of the local machine, and then it can send data at the IP layer.
Figure 10 ARP/RARP packet structure
2. IP protocol:
Since the Ethernet protocol is only applicable to local area networks, and Ethernet data cannot be sent across message forwarding hardware, people have developed the IP (Internet Protocol) protocol. With it, as long as the computer is connected to the Internet, it can use the IP address (just like a mobile phone number) to communicate (just like a mobile phone uses the GSM protocol to make calls). The following is the structure of the IP protocol data packet:
Figure 11 IP protocol header data packet structure
The meaning of the source IP address and the destination IP address are the same as the source address and destination address in the Ethernet data packet structure. (Other TCP features are omitted here because they are not related to this article)
Readers first take a look at the following network topology diagram:
Figure 12 Network topology diagram of network access control system
There is a main controller in each access control system. These main controllers use Ethernet to transmit data to the Internet through switches. Since the Ethernet transmission protocol can only be used under the same Ethernet, it is impossible for these data to be transmitted outside this area. You can think of it this way: it is obviously impossible for one of the main controllers of the access control system of the Guangzhou branch to send a message to the management computer and card center host of the Shanghai branch through its Ethernet. The IP protocol is different. The IP (Internet Protocol) protocol is suitable for all hosts that are connected to the Internet and have their own independent IP addresses. Therefore, when one of the access control systems of the Guangzhou branch wants to exchange data with the management computer and card center host of the Shanghai branch, it must know the IP address of the host. With it, the system will fill in the various data of the IP protocol header data packet according to the actual situation, and then send it to the switch through Ethernet. The switch will then forward our data packet to the Internet, and then the data packet will reach the switch of the Shanghai branch, and finally the switch of the Shanghai branch will send the data packet to the management computer and card center host through Ethernet.
3. TCP protocol:
TCP protocol is a widely used protocol now. It has many features that network communication protocols do not have (such as retransmission). TCP protocol is developed based on IP protocol. Let's first discuss the TCP data packet structure:
Figure 13 TCP protocol header data structure
The TCP protocol does not specify the address of the sender/receiver. Because it is based on the IP protocol, the address of the IP protocol can also be said to be the address of the TCP protocol. In the TCP protocol header data structure, there is a new term called "port", which is intended to identify different programs receiving different data packets, such as: port 80 sends/receives HTTP protocol data packets, port 21 implements the TELNET protocol, etc. The transmission mechanism of the TCP protocol is relatively special. It first requires a communication connection to be established between the two hosts before data can be transmitted. Finally, when the data transmission is completed, the connection must be closed. Let's take a look at the following TCP communication flow chart:
Figure 13 TCP protocol communication connection and data packet transmission when the connection is closed (because the source image is drawn with many red circles, there is no way but to save it like this, please forgive LC)
We can analyze the above data packet exchange in two parts: the first three data packets mean to establish a TCP connection, and the last four data packets mean to close the TCP connection.
When TCP establishes a connection, the party that actively establishes the connection will send a SYN_SENT type TCP data packet to the destination host. After the destination host processes the connection request, it will immediately return a SYN_ACK type TCP data packet (Editor's note: Regardless of whether the destination host is willing to establish a connection with it, in order to implement this structure, it is necessary to ignore external influences such as firewalls). Finally, after the party that actively establishes the connection receives the SYN_ACK data packet, it returns an ACK data packet, which means that the TCP connection is truly established successfully. This is the TCP three-way handshake process. [page]
When the data transmission between two hosts is over, the connection must be closed. When one party actively closes the connection, it will send a FIN packet to notify the other party. After receiving the FIN packet, the other party will return a FIN_ACK packet to confirm. (Editor's note: Any host that has actively sent a FIN packet cannot send any data anymore, but can receive data) Only when both parties have completed sending FIN packets, the TCP connection will be closed. This is the TCP four-way handshake process.
Sending data is similar to this. Interested readers can read <
4. Summary:
Is the structure of the data packet messed up? Please look at the figure below..
Figure 14 Network packet structure
Since we use Ethernet protocol to send data under Ethernet, the data to be sent to the destination host is included in the data of Ethernet data packet. For this data, it is actually IP data packet, but the data in IP data packet is actually TCP data packet, and the data in TCP data packet is the information we want to send. Therefore, it is easy for readers to understand the network data packet structure (right) in combination with the above figure.
As for the structure diagram on the left, it means the network model, which represents which protocol is located at which level of the network model layer.
4. Network adapter (network card) principle:
1. What is a network adapter:
The significance of a network adapter is to assist the computer processor to realize data transmission.
The following is a real picture, this network adapter is used for desktop computers.
Figure 15 Network adapter physical picture
Due to the rapid development of modern computers, the data transmission speed of network servers sometimes cannot meet the growing demand. For this reason, dual-port network adapters were born, which means that the same network adapter can connect two network cables. If readers want to learn more, please go to: http://www.doc88.com/p-374664665354.html (HP CN1000E Dual-Port Aggregate Network Adapter - Product Introduction)
Figure 16 Dual-port Converged Network Adapter
*Normal mode and promiscuous mode of network adapter:
Generally, we use the normal mode of network adapter. The so-called normal mode actually allows the network adapter to only receive data packets sent to itself. But the promiscuous mode is the opposite. All data packets received by the network adapter are passed to the processor, regardless of whether the data packet is sent to the host.
*About the promiscuous mode of the network adapter
Since data transmission is based on certain standards, as long as there are multiple hosts in the same Ethernet, one of the hosts can use the promiscuous mode to obtain data packets sent/received by other computers. (Please review: "Figure 8 Bus-type data transmission link", the data transmitted under the bus can be received by each host) So this is the principle of monitoring other computers in the local area network. Similarly, we can also use this principle to steal sensitive information such as user accounts and passwords. But before the theft is successful, there is still a prerequisite: data decryption.
Five Windows driver layers:
1. WinSock function library:
WinSock is a runtime library that comes with Windows to interact with the network. Here, programmers can use some related interfaces to implement port binding, TCP connection, closing, sending, receiving data and other functions. Please note that WinSock is just a network interface, or more precisely, a DLL file (Dynamic Link Library, a file used to store code or resource data, for details, please see: http://baike.baidu.com/view/887.htm?fromId=4373 Dynamic Link Library - Baidu Encyclopedia). So WinSock also writes interfaces by calling drivers (the purpose of drivers is to allow the processor to control peripheral hardware). Next, you will see how many drivers the data received from the network adapter needs to pass through before it can reach WinSock.DLL.
2. The driver that the network adapter needs to pass through to submit data:
Before looking at the kernel network driver structure, we must first know:
1. WinSock.DLL is actually on the TDI (Transport Driver Interface, transmission driver interface. Its purpose is to transfer the driver I/O request data structure from top to bottom/from bottom to top step by step. During the data transfer process, the intermediate driver can filter the data) layer.
2. Protocol Driver, protocol driver. Each protocol driver represents a different network protocol (Editor's note: Winpcap and NDISUIO are not network protocol drivers. The former is the Windows network bottom-level packet capture driver. The latter is the driver that controls the NDIS driver I/O)
3. HAL is the hardware abstraction layer (for details, please see: http://baike.baidu.com/view/1166796.htm HAL - Baidu Encyclopedia). When the driver's I/O request data structure is transmitted to this point, the next step is for the processor to control the peripheral hardware through the bus.
Figure 17: Windows system kernel network driver structure
When a normal program calls WinSock.DLL to send a TCP connection request, WinSock.DLL will automatically fill in the IP and TCP packet header structure of the request packet. Then it will be passed to the lower-level driver until the TCP/IP driver. The TCP/IP driver will then forward it to NDIS (Network Driver Interface Specification, network adapter driver), and finally send the TCP connection request packet from the processor to the network adapter through HAL. Next, the network adapter will send it to the Ethernet through the network cable. The receiving data is the opposite, so it is omitted.
6. The process of system operation in browsing www.baidu.com.
So far, I believe that readers have a certain understanding of data transmission between hardware, network protocols, and the structure of Windows system kernel network drivers. Then LCatro will analyze the process of browsing Baidu homepage with you.
Suppose we have just started the computer and immediately browsed the Baidu homepage. (The purpose of doing this is to provide an environment where the DNS cache table is empty)
Figure 18 Using the program to browse Baidu homepage
When we enter www.baidu.com (Editor's note: www.baidu.com is the domain name of the website) to access the browser, it will first convert the domain name to an IP address (i.e. resolution, implemented using the gethostbyname() function). At this time, WinSock will search for the IP address of www.baidu.com from the local DNS (a protocol for resolving domain names and IP addresses) cache table (a data block in the local computer that specifically stores domain names and corresponding IP addresses). Since the host has just been started, the DNS cache table is still blank. WinSock cannot find the corresponding IP address in the DNS cache table, so it sends a domain name query request to the DNS server (i.e. DNS pointer query). After receiving the request, the DNS server will query the domain name locally. If the DNS server does not have the domain name and the corresponding IP address, then the DNS server will submit a query to a higher-level DNS server until the query result is obtained. If successful, a query success packet is returned. If the query still cannot be found, the DNS server will return a query failure packet. [This process is the conversion of domain names to IP The process, in professional terms, is: domain name resolution process.
With the IP address, the browser sends a TCP connection request to it, and the next step is the three-way handshake process. After the connection is successfully established, the browser will send a request to Baidu's server to obtain the source code of http://www.baidu.com/index.html (Editor's note: www.baidu.com/index.html means the .HTML file (web page code file) of the index page of Baidu's homepage). Subsequently, the Baidu server returns the source code of the index page and actively closes the TCP connection. Finally, the browser displays the source code one by one on the web browsing control of the program according to the source code here.
Thinking questions: Please think carefully about how the system is implemented step by step in connection with the knowledge described in this article?
Related knowledge not related to the topic:
*Program startup process:
When we double-click the program, Explorer.exe will call CreateProcess() to run the program. CreateProcess() immediately reads the PE (PreInstallation Environment) of the program file (ie: .EXE file). This is a program structure unique to Windows, and its purpose is to tell Windows What does the system need to do before running the program? For details, please see: http://baike.baidu.com/view/3326.htm?fromId=8358 Windows PE structure - Baidu Encyclopedia) structure, the Windows system will do some related work according to the needs of .EXE, such as: which memory location does the program need to be loaded into? Where is the entry point of the program code? After the system is loaded, the program file is mapped from the hard disk to the memory (memory mapping). Next, CreateProcess() will allocate a stack for the program, and finally create a thread to execute the program. If we run a .INK file (i.e. shortcut), Explorer.exe will parse the .INK file and obtain the running path of the target program from it.
*VB program running details:
Because VB programs completely avoid developers from using code to create controls one by one when designing window interfaces. Readers can contact the development of Win32 window programs. First, in WinMain() (i.e. Win32 application entry point) When the program starts to register->create a window. After the window is created (note that the window is just blank at this time!), the Windows system will send a WM_PRINT message to the window to notify the window to start drawing controls.
Q: Since the window is blank when it is just created, why don't we see a blank window first and then see the program drawing controls on the window step by step?
A: Because the processor executes the code too fast, it only takes a very short time in the drawing process, so that the human eye cannot receive these images.
* Kernel processing keystroke process:
After we enter the URL and press the Enter key on the keyboard, the keyboard will actively trigger an interrupt event to the processor. Because there are too many types of interrupts in the computer system, and different interrupts have different processing methods, people store the entry addresses of different interrupt handlers in the interrupt program entry table. This is an interrupt caused by the keyboard. When the processor receives this interrupt, it immediately jumps out of the currently running program and runs the keyboard interrupt program instead. When the keyboard interrupt program is executed, the processing will continue to execute the original suspended code.
The pressed key is represented by ASCII in the processor. The code is saved and it is also uploaded from the lowest level driver to the application. The application gets the value of the pressed key through the WM_KEYDOWN message sent by the system.
Previous article:LCD1602 screen driver (custom characters)
Next article:Timer/Counter Usage (Natural Interrupt Priority)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- Automotive Ultrasonic Kick-to-Open Reference Design
- 【Ufan Learning】I received the Ufan but where is the drawing? ? ? ?
- 【TI recommended course】#Lecture on basic knowledge of electronic circuits#
- Summary of GPIO usage
- How to Implement Flexible RF Sampling Architectures Using High-Speed Data Converters
- I'm under a lot of pressure. I have an exam tomorrow.
- Solve the problem of abnormal MCU startup
- STM32F207 Ethernet + LAN8742 transmission server will get stuck
- Urgent help!!!!
- Matter Development Guide (V): Firmware Compilation and Burning