Realize wireless remote IAP function based on GPRS
[Copy link]
Abstract: Introduce IAP function and its related applications, as well as the practical significance of using GPRS to remotely implement IAP function; Combined with a groundwater remote monitoring system in a certain area, focus on the idea and implementation method of using GPRS network to remotely execute IAP upgrade system, as well as some key technologies that should be paid attention to in the application; Discuss the method of designing a simple and practical application layer protocol using GPRS communication, with emphasis on the checksum and retransmission mechanism in communication; Discuss some factors that affect the reliability of remote IAP upgrade of this system and the targeted solutions adopted.Keywords: GPRS IAP remote upgrade online programming remote monitoring Introduction
This system is designed to monitor the water use of agricultural wells in response to the problem that groundwater resources have been seriously overdrawn and water resources have been seriously damaged. The purpose is to monitor the water use of agricultural wells. Agricultural wells are widely distributed at sites, with distances between sites ranging from tens of meters to one or two hundred kilometers. Using manual meter reading to monitor will waste a lot of manpower and material resources, and the real-time performance is poor. In the past , the GSM method also had the problems of poor real-time performance and difficult control.
At present, the reliable and practical solution to such problems is to connect the field equipment to the server on the Internet to achieve real-time monitoring and management at the upper layer; but there are no special Internet access points and equipment on site. Using GPRS to access the Internet for remote data transmission has been a hot topic for enterprises, research institutes and other scientific research institutions in the past two years. With the increasing maturity of GPRS technology, GPRS has been successfully applied to remote meter reading, night lighting, oil field monitoring, automatic measurement, intelligent instruments and other remote data transmission systems that are inconvenient or even impossible to operate manually. Therefore, this system uses a mixed working mode of GPRS and GSM: use the GPRS working mode when the network is unobstructed; otherwise, it can switch to the GSM working mode. Each site data transmission terminal logs in to GPRS regularly, accesses the host server on the Internet, and downloads the collected data and site status to the server hard disk; the upper layer uses B/S browser mode for different levels such as prefecture level, district level, and city level to set permissions for browsing; at the same time, the real-time status of the site can be monitored at any time, the real-time on-site conditions can be reported, and the system historical data information can be called.
Market opportunities and the maturity of application technology are often a pair of contradictions. Especially for new technologies such as GPRS, it is usually necessary to develop the market while improving the technology. However, practice is the only criterion for testing the truth. After the system is handed over for use, users give feedback on some suggestions for improving functions. In addition, after long-term use, the "bugs" hidden in the terminal program may also surface. This requires upgrading the program of the data transmission terminal. However, imagine that if 200 sites are put into use, even if ISP on-site online programming is used, the staff will go to each site to update the program. Not only will a lot of manpower and material resources be wasted, but the opportunity to open up the market will be directly missed, and the consequences for the enterprise may be fatal.
This design scheme is applied to this type of GPRS remote monitoring system, integrating GPRS network communication technology to solve the problem of data transmission terminal program upgrade.
1 Introduction to IAP Function and System Application
IAP (In-Application Programming) is a programming mode applied to Flash program memory. Simply put, it is to read, erase, and write a certain storage space of the program under the control of the application program. It is very similar to the operation of ISP (In-System Programming). It is not necessary to remove the chip from the circuit board, burn it with a programmer, and then install it to run the new program, that is, it has the function of online programming. However, they have their differences: ISP usually erases and programs the entire chip, and downloads the program to Flash through the PC serial port under manual operation, which requires simple hardware resources-serial port RX, TX and RS232 driver chip; while IAP is to read and write another program Flash under the control of a certain program, and can control the read and write operations of a certain segment, a certain page, or even a certain byte. According to the functional characteristics of IAP, simulation software can be made to replace the emulator function. Making a simple interface application on the PC can directly realize the online simulation of the user program: setting breakpoints, single-step running, changing the running results and debugging, etc. In the same way, according to the functional characteristics of ISP, the programmer can be replaced. This system integrates the IAP mode into the GPRS communication system and uses GPRS to remotely upgrade the software of the specified target chip.
2 IAP function system architecture
The IAP function system architecture is shown in Figure 1. Figure 1 System architecture (only the parts related to the IAP function are marked)
P89LPC936 is a highly stable and multifunctional 51-core MCU launched by Philips; it integrates the I2C bus, and the read and write operation of the I2C device FM24C256 is fast and stable; the enhanced UART has powerful serial communication functions such as frame error detection, frame interval detection, optional double buffering, optional separation of receiving and sending interrupts, etc., which enhances the reliability of serial communication with the GPRS module; built-in AD/DA converter; 16 KB Flash access memory, support ISP and IAP; using TSSOP28 or HWQFN28 low-cost packaging. The peripheral circuit of the design system can be reduced to a minimum, which not only improves the performance of the system, but also can upgrade some terminal functions by IAP without changing the peripheral hardware circuit.
FM24C256, 256 Kb FRAM (Ferroelectric Memory), has the power-off data retention characteristics of ROM and the read and write speed and times of RAM, the read and write times can reach 100 billion times, it uses I2C bus read and write operations, it is stable and reliable to use; it uses 8-pin SOIC package, the interface circuit with MCU is simple, and the communication is reliable. The communication rate is adjustable from 0 to 400 kHz. The values of the two SFRs I2SCLH and I2SCLL of P89LPC936 determine the duty cycle of the serial clock generator. This system selects a 7.372 8 MHz crystal oscillator, I2SCLH=I2SCLL=75, and the I2C rate is 25 Kbps.
The GPRS module uses Q2406B produced by WAVECOM, a dual-band GPRS/GSM module (EGSM900/1 800 MHz or EGSM900/1 900 MHz), with built-in TCP/IP, which is fully compatible with standard AT commands; its design and development complies with the ETSI GSM Phase 2+ standard. This system module uses a baud rate of 9.6 kbps, while the module's factory baud rate is 115 200 bps. When initializing the module with a serial terminal, special attention should be paid to this.
Figure 2 IAP function implementation working status 3 IAP function software programming
3.1 System working status analysis
① User program working status. In the remote data transmission system, the user program completes normal user functions such as data acquisition, storage, and transmission, system monitoring, alarm, and receiving and executing host computer settings and control commands.
② IAP working status, as shown in Figure 2. The host computer sends an upgrade program signaling. After the data transmission terminal receives and replies to the confirmation message, it begins to wait for the download signaling; after receiving the correct download signaling, it begins to download the code to FM24C256 for temporary storage. Send and receive data according to the frame sequence number, check the correctness of the frame, and use the handshake data stream to ensure that each frame is completely correctly received and stored. After the code is sent, send the download completion signal, including the total length of the code and the block check code; each stage adopts delay processing: when the delay time is up, continue the retransmission process three times, and report the error message if it is not received, force it to go offline, and switch to the user program to be upgraded. If the communication is normal, enter the most critical step - Flash erasing and programming.
Philips solidifies a 256-byte boot ROM in the space of P89LPC936 address FF00H~FFFFH. All MCU operations on the internal Flash can be completed by calling this subroutine. When using the IAP function, provide the entry parameters of this subroutine (refer to Philips' data manual), and then call the entry address FF00H of the program to read, write, and erase Flash. When erasing and programming Flash, all interrupts need to be turned off. The same Flash cannot be erased and programmed at the same time, and the sector must be cleared before programming. The program list for erasing the Flash sector (entry parameters A, R7, R4 and R5, return parameters (F0(C), R7) are as follows: ERASE_FLASH: MOVA, #04H; A is the operation type (A = 04H, telling IAP that an erase operation is being performed) MOVR7,#01H; R7 delete operation mode (00H means delete page; 01H means delete sector) MOVR4,#HIGH; The high 8 bits of the Flash address to be operated MOVR5,#LOW; The low 8 bits of the Flash address to be operated LCALLFF00H JCERASE_FLASH; F0(C): 0 means erasing success, 1 means erasing failure
3.2 IAP function system SFR configuration
(1) User confidentiality sector setting MOVSEC6,#04H; prohibit erasing Flash sector 6 MOVSEC7,#04H; prohibit erasing Flash sector 7 The codes of sector 6 and sector 7 are used to control erasing and programming Flash. To ensure that there is no misoperation, erasing is only allowed with a special programmer at the factory.
(2) IAP privilege key value setting To execute the IAP function of erasing or writing Flash, it is necessary to write 96H to the RAM unit FFH to set the privilege key value before calling the IAP function program. The program code is as follows: MOVR0, #0FFH MOV@R0, #96 After the IAP program processes the function call, the authorization key value is cleared. Therefore, the authorization key value must be set before each call to the IAP function program. 3.3IAP function implementation process
The IAP function implementation process is shown in Figure 3 and Figure 4. flagIAP is the flag for preparing to erase the Flash after the download program is completed and the checksum is confirmed. It is very important to open up the unit storage function in FM24C256: when an exception occurs in the program erasure, such as power-off reset, you can start the program and confirm the erasure with the host computer to continue to complete the upgrade task. The number of bytes programmed each time is consistent with the number of code bytes in 1 frame of data transmitted by the host computer. The frame number indicates how many frames the program is divided into for transmission and how many programming operations.
3.4 Protocol design
The theoretical speed of the GPRS network is 117 kbps, but it is far from reaching it in reality; after the GPRS is connected to the Internet, it enters the data transparent transmission stage. This system designs the user application layer protocol based on the perfect TCP/IP mechanism. In order to realize the system software upgrade of a terminal in the system, the program code to be upgraded can be converted into system signaling through the coding software, connected to the Internet to the GPRS network, and transparently transmitted and downloaded to the target data transmission terminal. The signaling format of this system adopts the following code frame format: Figure 3 Main Program
The code data segments of the start signaling frame and the end signaling frame are both FFH. The synchronization code is set to AAH, 55H; the byte length (1B) indicates the number of bytes of code data contained in this data frame, which is usually less than 64; the download target address (5B) is set to the factory ID number, which is given a specific code meaning. Only after the ID number is verified to be correct can the data transmission terminal receive the command, and it is a unique identifier and cannot be changed; from the perspective of security, this system is set to a combination of the factory date and number: 0501160000 indicates the first product shipped on January 16, 2005. The frame sequence number (1B) indicates the number of transmission frames divided into this upgrade program. During the command transmission process, this field is 00H. The control field (1B) indicates whether the transmission is an operation command or data. The end code is set to 55H, AAH. The uplink and downlink data formats of the data transmission terminal are exactly the same. Except for the code data segment, the other fields of the uplink response data are copies of the downlink control data to achieve data flow control.
4 Discussion on IAP Function Reliability
The system upgrade process is inevitably disturbed by the environment, such as system power failure or network communication blockage, failure and other accidents, which may lead to IAP upgrade failure. Therefore, there must be a set of reliable software and hardware mechanisms to ensure the complete normal operation of IAP. The following introduces some measures taken by this system:
① Power failure handling. The power grid fluctuations in the on-site environment are quite large, and power failures occur frequently, which even affect the normal operation of the system. It can be powered by batteries to provide a stable and reliable working power supply; plus a charging board circuit, it can directly charge the circuit when there is power. In addition, the software has also made a perfect handshake mechanism, and the signaling sets the receipt to ensure that the communication is correct and there will be no misoperation; the download and erase Flash parts are isolated in timing, and the impact of network communication performance and power failure anomalies on the normal operation of the system is minimized. Figure 4 Interrupt program ② Errors generated during data transmission. The general and effective solution is to use CRC cyclic redundancy check and retransmission mechanism. After the data check code is correct, it is stored in FM24C256. If there is an error or timeout, the frame sequence number is sent to request retransmission until the end frame is detected. 3823 If the data length of the last frame is not enough, fill it with FFH to send a full frame.
③ Handle the large delay or blocking during data transmission. Data transmission adopts timeout processing, and if the three-way handshake fails, an exception handling mechanism is used. This technical solution fundamentally solves the problem of difficult on-site upgrades of this system, greatly improves the maintainability of the system, accelerates the time to market of new products, can provide faster and more perfect user services, and enhance the market competitiveness of products. Using the GPRS network as a carrier, this technology provides a solution in the vast monitoring sites or rural areas where it is difficult to access the Internet.
|