Design of GPRS Terminal System Based on Real-time Embedded Operating System mC/OS-II

The real-time embedded operating system mC/OS-II is oriented to small and medium-sized embedded applications. The kernel including all functional modules is about 10KB. The application amount of RAM is mainly related to the number of tasks in the system.

Authors: Yang Jinfeng, Ye Dunfan, Yu Yongbao

The real-time embedded operating system mC/OS-II is oriented to small and medium-sized embedded applications. The kernel including all functional modules is about 10KB. The application amount of RAM is mainly related to the number of tasks in the system.

GPRS is a data service developed on the basis of the currently running GSM network, and can use the same modulation technology, frequency, and same TDMA frame structure as GSM. Utilizing the existing base station subsystem (BSS), GPRS can provide comprehensive coverage from the beginning.

The hardware composition of GPRS terminal system

The GPRS terminal system is mainly composed of the control part and the GPRS wireless module, as shown in Figure 1.

Design of GPRS Terminal System Based on Real-time Embedded Operating System mC/OS-II
Figure 1 The hardware composition principle of GPRS terminal

In order to adapt to the application of embedded technology in GPRS communication, the control part of the system adopts S3C44B0x chip.

The S3C44B0x are 16/32-bit RISC microprocessors that provide a cost-effective solution for handheld devices and general applications.

S3C44B0x has abundant on-chip resources, can operate the GPRS module through the serial interface, and the operation command is AT command set.

The GPRS wireless module adopts SIM300, which supports the voice, data and short message functions of GPRS, and has embedded TCP/IP protocol. The module is mainly composed of RF antenna, internal Flash, SRAM, GSM baseband processor, matching power supply and a 60-pin ZIF socket. Among them, the GSM baseband processor is the core component, and its function is equivalent to a protocol processor, which is used to process the AT commands sent by the external system through the serial port. The receiving rate of the GPRS module can reach 86.2kbps and the sending rate can reach 21.5kbps, which is easy to integrate.

Migration of mC/OS-II

mC/OS-II is a highly portable operating system, its source code is divided into hardware-independent and hardware-related two parts, only need to modify the hardware-related part when transplanting. To transplant mC/OS-II to S3C44B0X, the following work needs to be done:

(1) Modify the data type

To maintain platform independence, mC/OS-II uses macro-defined general-purpose types, such as INT16U, to represent 16-bit unsigned numbers. When porting, map them to the correct type.

(2) Entering and exiting the critical section

By closing and opening interrupts, implement the function OS_ENTER_CRITICAL() entering the critical section and the function OS_EX2IT_CRITICAL() exiting the critical section.

(3) Set the stack growth direction

Different processor stacks have different growth directions. For the S3C44B0X, the growth direction can be upward or downward.However, since the compiler ADS only supports stack growth from top to bottom, and it must be a full decrement stack, the actual usage direction to be set here is to grow downward, that is,

#define OS_STR_GROWTH 1;

(4) Task switching and scheduling

There are two ways to switch and schedule tasks. One is that the currently running task actively calls OS_Sched() to determine whether there is a higher priority task to run, and if so, switch it to the ready state, and then call OS_TASK_SW() , a soft interrupt is generated, and the interrupt vector points to the function OSIntCtxSw (), in which the task stack is modified and a new task is run. The second is to call OSIntEx() in the interrupt handler after a hardware interrupt is generated.

In the above process, the code for generating soft interrupt and modifying the task stack is related to the processor. The soft interrupt assembly instruction of S3C44B0X is SWI, and the assembly instructions for pushing and popping the stack are STM and LDM respectively.

(5) Initialization of the stack

When mC/OS-II creates a task, it will call the OSTaskStkInt() function to initialize the task stack. Here, the stack needs to be set to the same form as after the interrupt is generated, generally including the task start address, interrupt return address, CPU registers, etc. . Also, make sure that the task is running in privileged mode, not user mode.

(6) Clock beat interrupt

mC/OS-II uses clock tick interrupts to implement time delay and timeout functions. The timing frequency is generally between 10Hz and 100Hz. The code for setting the timer is related to the CPU, and the interrupt vector must point to the mC/OS-II clock tick interrupt service subroutine OSTickISR ( ).

The composition of the system’s processes and tasks

In this system, first call OSInit() to initialize all the variables and data structures of mC/OS-II, then call ARM_init() to initialize the microcontroller’s timer and serial port and other hardware, and call OSTaskCreate() to create each task in turn , and finally call OSStart() to start the system and start multitasking scheduling. The whole system control program module and process are shown in Figure 2.

Design of GPRS Terminal System Based on Real-time Embedded Operating System mC/OS-II
Figure 2 System control program module and flow

The tasks in the whole system include keyboard scanning of ARM control part, LCD Display task and communication task, short message task of GPRS terminal function, voice call task and so on. Therefore, the tasks in the mC/OS-II system mainly include:

The keyboard scanning task task_sys_key scan() includes the scan identification keyscan() of the 4×4 keyboard part, and the implementation of the corresponding key function code keyscan_code(), etc.

LCD Display task task_sys_ lcddis(), including background content display display_context(), input content display display_input(), output content display display_output(), etc.

The communication task task_sys_communication(), in addition to the function host_msg() that communicates between the system and the host, to implement system operations through the computer, and msg_tasl(), which handles communication between tasks.

Voice call task task_sys_telephone(), including phone call gprs_phone_call(), phone answer gprs_phone_recevie(), etc. In addition, it also includes the task of sending and receiving system short messages.

According to the functional requirements of the system for GPRS short message communication and voice communication, set the priority of each task as shown in Table 1.

Epilogue

The mC/OS-II real-time operating system is an open-source and practically verified software platform, and S3C44BOx has powerful 32-bit RISC performance. The design of the GPRS module based on this software and hardware platform can greatly reduce research and development tasks and improve research and development. speed, and create good conditions for realizing the design of GPRS terminal system in a short time.

The Links:   2MBI150S-120 LQ13X02C CM200DY-12NF