Implementation of GPRS terminal based on 8051 embedded system

Abstract: Introduce data transmission based on GPRS network, embedded real-time operating system u / OS-II and small TCP / IP protocol stack uIP; discuss in depth the realization of GPRS terminal based on 8051 embedded system. Provides a simple, cheap and practical GPRS terminal implementation solution, explains how to transplant uC / OS-II and uIP in 8051.

With the sudden increase in the demand for wireless data transmission and the full operation of China Mobile's GPRS service, the application of wireless data communication is becoming more and more widespread. The GPRS network not only has the advantages of wide coverage, fast data transmission speed, high communication quality, always-on and pay-by-flow, but also is a packet data network in itself, supporting TCP / IP protocol without the need to transfer through PSTN and other networks It can directly communicate with the Internet. Therefore, GPRS business has unparalleled cost-effective advantages in wireless Internet access, environmental monitoring, traffic monitoring, mobile office and other industries.

In order to meet the requirements of low cost, miniaturization and mobile flexibility of GPRS terminals, a single chip microcomputer is now widely used to control GPRS terminals, and an embedded system is introduced to implement the TCP / IP protocol stack. At present, the main difficulty lies in: running TCP / IP protocol has high requirements on computer memory and operation speed, and will occupy a lot of system resources; while embedded systems mostly use 8-bit microcontrollers, the hardware resources are very limited, and support for TCP / IP protocol is very difficult. In this paper, a method of transplanting a small TCP / IP protocol stack uIP in the embedded real-time operating system uC / OS-II is adopted, so that the GPRS terminal based on the 8051 embedded system can perform data transmission in the network; at the same time, the system is improved Performance, improve the reliability of the system, enhance the scalability of the system and the continuity of product development.

figure 1

1 Data transmission based on GPRS network

GPRS is a wireless data transmission system formed by introducing new components such as a packet control unit (PCU), a service support node (SGSN), and a gateway support node (GGSN) on the basis of GSM. Its users can use end-to-end packet mode Send and receive data. The data transmission system based on GPRS network is shown as in Fig. 1. The specific data transmission process is:

· The GPRS terminal takes user data from the client system through the interface;

· After processing, it is sent to GSM base station (BSS) in the form of GPRS packet data;

· Packet data is encapsulated by SGSN and sent to GPRS IP backbone network;

· If the packet data is sent to another GPRS terminal, it will be sent to the destination SGSN first, and then sent to the CPBS terminal via BSS; if the packet data is sent to an external network (such as the Internet), the packet data packet will be converted by GGSN protocol After sending to the external network.

2 Embedded real-time operating system uC / OS-II

uC / OS-II was developed by Jean J. A free, open source real-time operating system written by Mr. Labrosse and now popular. It can be widely used in various types and sizes of embedded systems from 8-bit to 64-bit single-chip. The uC / OS-II source code with detailed annotations is only about 200 pages; about 95% of them are written in C language, and the code related to the MCU type is written in 8088, not more than 200 lines. uC / OS-II not only has the characteristics of small structure, curable, cutable, multi-tasking and deprivable real-time kernel; and its real-time performance and stability skirt reliability have also been widely recognized. The minimum core of uC / OS-II can be compiled to 2KB, and the memory is usually in the order of 10KB, which is suitable for the needs of 8051-based embedded systems. Embedding uC / OS-II in the system can divide the whole program into many tasks, each task is relatively independent, and then set a timeout function in each task. After the time runs out, you must hand over the right to use the MCU. Even if a problem occurs in one task, it will not affect the operation of other tasks. Embedding uC / OS-II in the single-chip system improves the reliability of the system and makes the debugging procedure simple, while also enhancing the scalability of the system and the continuity of product development.

However, uC / OS-II is just a real-time operating system kernel. Compared with commercial real-time operating system software packages, it lacks UTIliTIes, such as file system, remote function call library, and communication software library. Communication software includes: TCP / IP software library, Bluetooth communication software library, IrDA infrared communication software library, etc. There are two ways to solve this type of software: one is to purchase third-party software; the other is to write it yourself. If you only use a single-chip microcomputer to realize some functions in the TCP / IP protocol, you can choose a small TCP / IP protocol stack with free open source code and port it to uC / OS-II. At present, the latest version of uC / OS-II is V2.70, but V2.52 is now widely studied and applied.

3 Small TCP / IP protocol stack uIP

uIP is a small free TCP / IP protocol stack developed by Adam Dunkels of the Swiss Academy of Computer Science and other open source code. It is specially written for 8-bit and 16-bit MCUs. uIP is completely written in C language. On the premise of ensuring a complete TCP / IP stack, it only retains the most necessary series of features, so that its code is minimal and the RAM occupied is minimum; it can only handle a single network interface . The usual TCP / IP stack uses the BSD socket API, which requires support from the underlying multitasking operating system, and task management, context switching, and stack space allocation all take a lot of overhead, exceeding the capabilities of 8-bit computer systems. . uIP uses an event-driven interface to respond to events by calling application programs. The corresponding application is called as a C function. Normally, although the source code of uIP is only a few KB and the RAM occupies only a few hundred bytes, uIP provides the necessary protocols for network communication, including: ARP, SLIP, IP, UDP, ICMP (PINC) and TCP Meet the needs of 8-bit MCU to access TCP / IP network (such as Internet). At present, the latest version of uIP is V0.9, which complies with Internet standards.

4 Working principle and hardware implementation of GPRS terminal

The GPRS terminal is realized by the control module controlling the TCP / IP module and the wireless sending module. Its structural block diagram is shown as in Fig. 2.

4.1 Control module

The main functions of the control module are:

The control module initializes the GPRS wireless module through AT commands, attaches it to the GPRS network, obtains the IP address dynamically assigned by the network operator to the GPRS terminal, and establishes a connection with the destination terminal or server;

The control module sends and receives data or commands to the client system through the RS232 serial port;

The control module sends and receives data to the TCP / IP module through the RS232 serial port;

· The control module takes other actions autonomously or according to remote control instructions.

The MCU of the control module selects Winbond's eight-bit computer WINBOODW77E58. W77E58 is a fast programmable multi-programmable microprocessor produced by Taiwan Winbond, which is compatible with MCS51 series of single-chip microcomputers. It integrates 32KB of reprogrammable Flash ROM, 256 bytes of on-chip memory, and IKB MOVX instruction accesses SRAM, programmable watchdog timer, three 16-bit timers, two enhanced full-duplex serial ports, on-chip RC oscillator, dual 16-bit data pointers and many other functions. In many occasions, it is possible to meet system requirements with almost no expansion of peripheral chips. Because it uses a newly designed microprocessor core, removes redundant clocks and storage cycles, under the same crystal frequency, according to different instruction types, its running speed is generally 1.5 to 3 times faster than the traditional 8051 series. Under normal circumstances, the average can reach more than 2.5 times. In addition, because the W77E58 uses a fully static CMOS design, it can work at a low-speed crystal frequency. Compared with the ordinary 8051, if the W77E58 uses a low-speed operating frequency, the power saving performance of the W77E58 will be greatly improved under the same instruction throughput.

4. 2 TCP / IP module

The TCP / IP module communicates with the GPRS wireless module through the RS232 serial port, providing non-transparent and transparent two-way channels. Correspondingly, the module has two transmission modes: transparent mode and non-transparent mode. Through software switching, when the module is in different transmission modes, the data flow direction is also different. When the AT command set is transmitted, the module enters the transparent mode and can directly access the GPRS wireless module; when the module enters the non-transparent transmission mode, the user data enters the TCP / IP module from the serial port, and then into TCP / IP packets It is sent to the GPRS module via the serial port; the GPRS wireless module encapsulates it into a GPRS packet data packet and transmits it to the GPRS network. The TCP / IP module is realized by the embedded system based on the single chip 8051. Choose WINBOODW77E58 as the microprocessor of the embedded system, the embedded real-time operating system chooses uC / OS-II, then transplant uIP in uC / OS-II to realize TCP / IP protocol stack.

4.3 GPRS wireless module

As a wireless transceiver module of GPRS terminal, the GPRS wireless module performs corresponding protocol processing on the TCP / IP packet received from the TCP / IP module and the GPRS packet data received from the base station before forwarding. GPRS wireless module adopts MC35 GPRS module of SIEMENS company. The MC35 module is mainly composed of a radio frequency antenna, internal Flash, SRAM, GSM baseband processor, matching power supply, and a 40-pin ZIF socket. The GSM baseband processor is the core component, its role is equivalent to a protocol processor, used to process AT commands sent by external systems through the serial port. The RF antenna part mainly implements signal modulation and demodulation, as well as signal conversion between the external RF signal and the internal baseband processor. The matching power supply provides the required power for the processor and the RF part. MC35 GPRS module supports GSM900 and GSMl800 dual-frequency network, the receiving rate can reach 86.20kbps, the sending rate can reach 21.5kbps, and it is easy to integrate. Of course, the maximum data throughput also depends on the support of the GPRS network.

5 TCP / IP module software implementation

5. The transplantation of 1 uC / OS-II on 8051

uC / OS-II is free software, and non-commercial applications such as scientific research and teaching are free. Any user can download the source code from the Internet and transplant it with appropriate modifications to make it meet the needs of their own hardware and system. In order to transplant, you need to understand the overall structure of uC / OS-II operating system first. Figure 3 shows the structure of uC / OS-II and its relationship with the hardware.

The code that has nothing to do with the processor contains the system functions of uC / OS-II. Generally, there is no need to modify this part when the system is transplanted; as long as UCOS-II. The C file is included in your own project, and you can include all the code that is not related to MCU in uC / OS-II into the transplanted code.

The code related to the application is that the user customizes the appropriate kernel service function according to his own application system, which includes two files: OS_CFG. H, INCLUDES. H. Among them OS_CFG. H is used to configure the kernel. The user customizes the kernel according to needs and sets the basic conditions of the system, such as the maximum number of tasks that the system can provide, whether to customize the mailbox service, whether the system needs to provide task suspension function, whether to provide task priority dynamic change Functions etc. And INCLUDES. H is the system header file.

The processor-related code contains support for various types of MCUs, and this part needs to be modified according to your own MCU. According to the technical characteristics of Keil C51 compiler and 8051 chip, the transplantation of uC / OS-â…¡ is related to three files: processor-related C files (OS_CPU.H, OS_CPU_C.C) and assembly files (OS_CPU_A.ASM).

(1) Modify OS_CPU. H

File OS_CPU. H includes processor-defined constants, macros, and types defined with #define statements. The main contents modified during migration are:

· Setting of data types related to the compiler. Refer to the help file C51 in Keil C51 compiler. PDF, the specific path is \ C51 \ HLP \ C51. PDF.

· Two macro switch interrupts are defined with #define statement, the specific implementation is:

#define OS_ENTER_CRITICAL () EA = 0 // Off interrupt

#define OS_EXIT_CRITICAL () EA = 1 // Open interrupt

Define OS_STK_GROWTH according to the direction of the 8051 stack.

#define OS_STK_GROWTH 0 // The 8051 stack increases from bottom to top

Set OS_STK_GROWTH to 0, indicating that the stack increases from the bottom (low address) up (high address); set OS_STK_GROWTH to 1, indicates that the stack decreases from the top (high address) to down (low address).

· UC / OS-II needs to use OS_STK_SW () when switching from low-priority tasks to high-priority tasks, imitating the generation of interrupts by executing OS_STK_SW (). Most CPUs will provide soft interrupts or instruction traps (TRAP) to complete this function. The interrupt vector address of the interrupt service subroutine or instruction trap processing function (also called exception handling function) must point to the assembly language function OSCtxSw (). Because 8051 does not have a soft interrupt instruction, it is replaced with a program call.

#define OS_TASK_SW () OSCtxSw ()

(2) Modify OS_CPU_C. C

The uC / OS-II migration example requires users to write 10 simple C functions, among which OSTaskStklnit () is necessary, and the other 9 functions must be declared, but they do not necessarily contain any code. Because Keil C51 compiles functions into non-reentrant structures by default, and multitasking systems require concurrent operations to cause reentry, it is necessary to mark the reentrant keyword after each C function and its declaration to make the compiler generate The code supports function reentrancy during operation. In addition, "pdata" and "data" are used as formal parameters of some functions in uC / OS-II, but it is also a keyword of Keil C51, which will cause compilation errors. Usually "pdata" can be changed to "ppdala", "data" to "ddata" to solve this problem. The specific modified code is as follows:

void * OSTaskStkInit (void (* task) (void * pd),

void * ppdata,

void * ptos,

INT16U opt) reentrant

In uC / OS-II based on 8051, transplanting uIP does not require any modification to the existing TCP / IP source code, but a driver must be written for network devices (such as network card chip, serial port, etc.). At the same time, the integrated part of the existing system should also be processed accordingly. For example, when data arrives or the periodic timer counts up, the main control system should call the uIP function [Liu. The specific steps of transplantation are as follows:

· Create your own directory under the directory uip-0. 9 /, for example uip-0. 9/8051 /

· Put uip_arch. The c file is copied from the directory uip-0. 9 / unix / to the directory uip-0. 9/8051; it contains the 32-bit addition, checksum algorithm implemented in C language;

· Put uipopt. The h file is copied from the directory uip-0. 9 / unix to the directory uip-0. 9/8051 and modified to meet the needs of the system. uipopt. h is the ulP configuration file, which contains not only the setting options such as the IP address of the uIP network point and the maximum value that can be connected at the same time, but also the special options of the system structure and C compiler;

· Reference example unix / tapdev. c and uip / slipdev. c, write driver program for serial port;

· Reference example unix / main. c. Write your own main control system so that you can call the ulP function when appropriate;

· Compile the source code.

This article describes the implementation of GPRS terminal based on 8051 embedded system, and introduces the transplantation of embedded real-time operating system uC / OS-II based on 8051 and the transplantation of small TCP / IP protocol stack uIP in detail: The Internet can perform data transmission with corresponding GPRS terminals and corresponding Internet terminals. The introduction of the real-time operating system in the TCP / IP module of the GPRS terminal not only improved the performance of the system and the reliability of the system, but also enhanced the scalability of the system and the continuity of product development.

European Extension Sockets

Wall Mounted Plug Socket,Fast Charging Wall Outlet,Remote Control Wall Outlet,Surge Protected Wall Socket

Heikki Technology Co., Ltd. , https://www.heikkipower.com

Posted on