1 Introduction
Embedded monitoring system is one of the hot research topics in the current field of industrial automation monitoring application. The improvement of microelectronics technology and microprocessor manufacturing process and the rapid development of network technology have made it possible to build a Web-based embedded remote monitoring system. Such a remote monitoring system can be directly connected to the Internet through the TCP/IP network protocol to achieve remote monitoring, becoming a remote monitoring system that is truly not limited by time and space.
Since the storage capacity of MCUs newly launched by some semiconductor manufacturers has been greatly improved in recent years, and programs written in C language have the advantages of strong portability and good readability, the monitoring software in this article is written in standard C language and compiled in m6811-elf-gcc. This article will start with the communication basis of the embedded Web monitoring system - the Ethernet interface module, and describe the design and implementation of each functional module.
2 Ethernet interface programming
The Ethernet interface program is closely related to the network control chip in the hardware design. Different network control chips have different Ethernet interface programs, but a complete Ethernet interface program usually includes three parts: hardware module initialization, Ethernet frame sending and Ethernet frame receiving.
1. Hardware module initialization
The Freescale MC9S12NE64 MCU used in this article integrates two hardware sub-modules, EPHY and EMAC. Their initialization must be carried out strictly according to the technical manual to avoid ignoring some details.
2. Sending Ethernet frames
To send an Ethernet frame in NE64, the frame content must be written into the transmit buffer (TX buffer) of the EMAC module, and then sent out through the send command. The following work is completed by the lower-level hardware. The registers related to the sending of Ethernet frames include the transmit buffer frame end pointer register (TXEFP) and the transmit control and status register (TXCTS).
3. Receiving Ethernet frames
There are two methods to determine the reception of Ethernet frames: query method and interrupt method. Since the interrupt method has better execution efficiency, this article uses the interrupt method to receive Ethernet frames. Since NE64 has two receiving buffers A and B, the arriving frames may be stored in buffer A or buffer B, so there are also two interrupt vectors: A buffer reception completion interrupt and B buffer reception completion interrupt, and their vector addresses are $FFB2 and $FFB4 respectively. Whether the data is received in buffer A or buffer B, the processing method is the same, which is to read the received data frame and then perform corresponding processing.
3. Programming of uIP Protocol Implementation
3.1 Implementation of TCP Protocol
The TCP protocol is the core of the embedded Web. It provides a reliable data stream transmission method based on connection and with confirmation, which can enhance the service quality of the network. The mechanism of the TCP protocol is very complex, and its complete implementation requires high storage capacity and computing power of the processor. This is a luxury for embedded systems, so it must be simplified. This paper is going to implement a monitoring system based on an embedded Web server. After careful analysis, this paper obtains a simplified TCP state machine as shown in Figure 1. The disconnection of the connection is actively executed by the server. Through multiple experiments, it is concluded that this method is simpler and more stable in this system than the state machine of the standard TCP protocol that actively disconnects the connection.
Figure 1 Simplified TCP state diagram of the server [page]
In addition, this system can adjust the number of connections supported by TCP according to different application requirements, but usually only supports a single TCP connection at the same time. At the same time, in order to avoid deadlock of the state machine due to the loss of datagrams, this paper uses a simple timing mechanism to reset the TCP state machine after timeout.
The process of establishing a TCP connection is called a "three-way handshake". First, the client makes a connection request to the server. At this time, the client inserts its own ISN in the TCP header and sets the SYN flag to 1, indicating that the sequence number field is legal and needs to be checked. Secondly, after receiving the TCP segment, the server responds with its own ISN and confirms receipt of the client's TCP segment by setting the ACK flag to 1. Finally, the client confirms receipt of the server's ISN and sets the ACK flag to 1. At this point, the complete TCP connection is established and the data transmission process in full-duplex mode begins.
3.2 Implementation of other protocols
On the basis of realizing the Ethernet bottom layer driver, the upper layer protocol for Ethernet communication is realized next. The ARP protocol is a communication protocol for the communicating parties to obtain the MAC address of each other. It is the basis of network communication. This paper realizes the sending and receiving of ARP request messages and the receiving and processing of ARP response messages. In order to facilitate network debugging, the Ping command is implemented in uIP. This part can be omitted when the monitoring device is working normally. SD12-MCS is an embedded Web-based application device, not an embedded gateway or router. Therefore, in order to save embedded system resources, this paper cuts the routing function of the IP protocol, and all routing issues are completed by the default gateway. Although the Web-based SD12-MCS uses the TCP protocol, there are currently some applications based on the UDP protocol. In order to make the system more scalable, this paper also implements the UDP protocol.
4 Design and Implementation of Web Server
The working mode of this monitoring system is embedded Web server mode. Therefore, based on the implementation of uIP protocol, this paper designs and implements the HTTP protocol and CGI processing program of the application layer.
4.1 Design and Implementation of HTTP Protocol
HTTP, the application layer protocol of the Web, is the core of the Web. The client/server model implemented by the HTTP protocol is a request/response structure. Considering the number of connections supported by the embedded TCP protocol and security issues during system implementation, this article adopts the HTTP1.0 protocol, and the Web server disconnects the connection each time it sends a response. The status code has many meanings, and this article uses two types: when the request for a web page is successful, the status code 200 is returned with a reason phrase of OK; when the requested web page does not exist, the status code 404 is returned with a reason phrase of NOT FOUND. The header field name is also an optional part, but this article uses one of the options, Content-Length:, to indicate the number of bytes of the object sent, to facilitate program debugging. The entity part is the specific content of the response, such as an HTML web page or a picture, etc.
The implementation of HTTP protocol static page in this article needs to complete the following contents: first obtain the file name in the URL, then call the https_calculatehash() function according to the file name to obtain the file handle, that is, the hash field value in the file processing entry data structure, find the starting address of the file according to the value, and then load the file into the TCP socket send buffer. When the sent file is too long and larger than the size of the send buffer, the buffer overflow problem will occur. The solution of this article is: first determine the length of the file. When the file is too long, divide the file into multiple segments that are not larger than the size of the send buffer, and then send them out in a loop. The program flow of static page processing in HTTP protocol is shown in Figure 2.
Figure 2 HTTP static page processing flow chart [page]
4.2 Design and Implementation of CGI
In this monitoring system, in addition to supporting static pages, it must also support the processing of dynamic content and dynamic forms, mainly including dynamically generating real-time data collection pages and processing control command forms. In order to achieve this function, this paper designs a CGI interface processing program.
Considering the actual application, this paper does not need to transplant the operating system in NE64, so the standard CGI cannot be copied to create a CGI interface for the Web server. First, the Web server in this paper cannot run multiple applications at the same time. The operation of each application will monopolize the CPU until it is completed. Secondly, this paper does not implement a complex cache mechanism, so repeatedly executing applications is a slow process. Therefore, this paper cuts down the standard CGI and designs an embedded CGI. This method realizes the data collection and monitoring of the embedded Web server. Its work process is shown in Figure 3.
Figure 3 CGI processing flow
5 A/D acquisition subroutine
In order to achieve data acquisition with different precision and more channels, the system uses both the NE64 integrated A/D acquisition module and the dedicated A/D acquisition chip TLC2543 expanded through SPI. Therefore, the A/D acquisition subroutine contains the contents of these two parts. In the specific implementation, this paper uses the variable TLCAD to control which acquisition subroutine to call. When TLCAD=100, the TLC2543 acquisition subroutine is called; when TLCAD=99, the integrated A/D acquisition subroutine is called. When the system is collecting data, the analog input signal is connected in sequence from the smallest channel number. The actual number of analog quantities is determined by the variables NE64ADNmb and TLCADNmb, which respectively represent the number of analog quantities with an acquisition precision of 10 bits and the number of analog quantities with an acquisition precision of 12 bits.
In the process of A/D data acquisition, it is inevitable to be interfered by random noise, which will cause inaccurate data acquisition and lead to wrong conclusions. In order to prevent pulse interference in the system, the author of this article adopts the median filtering method. On the basis of median filtering, in order to ensure the stability of the acquired data, the author of this article adopts the arithmetic mean filtering method.
6 Module Testing
The main functions of the monitoring system software are to realize multi-channel data acquisition, network protocol communication and object control mechanism. The module test part mainly tests the software of each module. Due to space limitations, the following mainly introduces the test part of the data acquisition part. SD12-MCS supports a total of 30 channels of analog data acquisition, of which 8 channels of 10-bit precision AD belong to the NE64 A/D module, and the remaining 22 channels belong to two TLC2543 acquisition chips. In order to verify whether each acquisition program is correct, this paper designs such a test case: first run one of the acquisition programs with one precision separately, send the data collected by all channels, send it to the high-end PC through the serial port, and display it by the test case of the PC. If the displayed data is correct, the program is correct. On this basis, send parameters to determine which subroutine to call, and control the acquisition of multiple analog quantities at the same time. Since the analog quantity acquisition in this paper starts from the 0th channel, and so on, there is no need to set which channel the analog quantity is collected, thereby simplifying the program processing.
The author's innovation points:
This paper mainly introduces the design and implementation of a Web-based embedded monitoring system control strategy. The test of each functional module shows that the monitoring system has good performance and meets the relevant design requirements.
References:
[1] Chen Weigang. Network development of industrial control systems [J]. Industrial Instrumentation and Automation Equipment, 2004 (01): 10
[2] Song Yanzhao. Introduction and selection principles of embedded operating system [J]. Industrial Control Computer, 2005(07):41
[3] Wang Jianxin. Current status and trends of remote monitoring technology [J]. Foreign Electronic Measurement Technology, 2005(04):9
[4] Zhu Huasheng, Feng Xiangsheng. Design and implementation of smart home controller based on ARM[J]. Microcomputer Information, 2007, 1-2: 185-187
Previous article:A brief discussion on orthogonality in embedded software system design
Next article:Embedded Data Acquisition System Based on Linux
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
- What are the basic units of Weber Wb and Tesla T?
- How to add c files in esp32 idf components to compile
- Have you noticed the LPDSP32 audio codec inside RSL10? Does your project use this resource?
- Will the push-pull circuit be straight through?
- Award-winning live broadcast: Third-generation TI C2000 new features resource update
- EEWORLD University - Industrial Internet of Things using CC1310 sub-1 GHz wireless MCU
- A simple way to distinguish between broadband FM and narrowband FM
- Wireless Connectivity Technology Selection Guide
- Learning FPGA Embedded System Design-1
- Qorvo 5 GHz iFEM Helps Accelerate Wi-Fi 6 Home Mesh Networking