The Porting of Real-Time Operating System uC/OS-II
on MCS-51 Series of MCU
Lin Shaofen, Zeng Shengbin School of Marine Engineering, Jimei University Xiamen, China shaofenlin@163.com zengshb@163.com
Jiang Xiaoxia School of Marine Engineering, Jimei University Xiamen, China xmjiangxx@tom.com
AbstractThe powerful C/OS-II is based on the priority preemptive real-time kernel which simultaneously provides task management, time management, memory management and communication between the tasks and functions can be ported and reduced freely. This paper analyzes the structure of C/OS-IIs kernel and its code, and introduces how to porting C/OS-II to MCS-51 Series of MCU by means of establishing working stack, simulation stack, task stack and so on. At last, a test program is provided to prove the success of the porting. Keywords-real time; embedded operating system; C/OS-II; porting I. INTRODUCTION With the increasing complexity of embedded computer systems and the need of real-time multi-tasks, more and more customers choose real-time operating system (RTOS). Unlike most commercial RTOS comparison, the source code resources of C/OS-II real-time operating system are opened to the public. Most of the codes are written with standard ANSI C and the procedures have strong readability and portability which has been certificated and passed the rigorous test by Federal Aviation Administration[1]. More importantly, the refined core of the C/OS-II real-time operating system is an effective control system to overcome the shortage of hardware resources [2]. As a result, it is of great significance to research the development and application of transplantation of C/OS-II in a variety of embedded systems. In recent years, the hot research point of real-time embedded operating system is Linux, VxWorks WinCE and so on, but they take up more memory hardware resources [3]. MCU widely used in a variety of real-time process control systems, such as industrial process control, process monitoring, aerospace, weapons robotic systems and other real-time control system. Processing and controlling real-time data with MCS systems to ensure that the work in the best condition, can improve the efficiency and product quality of the system [4]. Due to limited hardware resources, the device such as MCS-51 STC89C516RD+ porting, which takes a high Cost-effective and is rapidly developed in recent years, is more appropriate to C / OS-II real-time operating system. II. THE PORTING REQUIREMENTS OF UC/OS-II A processor can run C/OS-II if it satisfies the following general requirements: 1) Having a C compiler for the processor and the C compiler must be able to produce reentrant code. 2) Be able to disable and enable interrupts from C. 3) The processor must support interrupts and you need to provide an interrupt that occurs at regular intervals (typically between 10 to 100 Hz). 4) The processor must support a hardware stack, and the processor must be able to store a fair amount of data on the stack (possibly many Kbytes). 5) The processor must have instructions to load and store the stack pointer and other CPU registers either on the stack or in memory. The structured design of C/OS-II facilitates the separation of related codes from the processor. As shown in Figure 1, it is shows C/OS-IIs architecture and its relationship with the hardware. Software system can be divided into 4 parts, the related code to processor OS_CPU.H, OS_CPU_A.ASM, OS_CPU_C.C III. THE PORTING METHOD OF UC/OS-II Designing according to the characteristics of task stack, the kernels combine application system and the underlying hardware into a real-time system; it requires an intermediate layer between the kernels and hardware, for the same kernel can be applied to different hardware system, and this is codes relate to the processor [5]. A. Compile OS-CPU.H Includes the definition of related constants, macro, and type to processor, such as # define. Specifically, the definition of the type of systematic data, the definition of growth direction of the stack, the definition of close and open disruption, and the definition of interruption of the soft systems and so on. #define OS_ENTER_CRITICAL () EA = 0; #define OS_EXIT_CRITICAL () EA = 1;
2009 International Conference on Measuring Technology and Mechatronics Automation 978-0-7695-3583-8/09 $25.00 2009 IEEE DOI 10.1109/ICMTMA.2009.615 418
EA = 0 disable interrupts; EA = 1 close interruptions. To make the definition of the procedure reduces the number of rows, and avoid the computer crashes from closing interruption after reset critical-zone. MCS-51 stack bottom- up growth (1 = down, up = 0) shown in Figure 2, OS_STK_GROWTH should be defined as 0. -d`u OST/SlS" ) OSCtxS )
Because MCS-51 has no interruption of soft commands, to calling the procedure. The two formats have the same stack, RETI instruction interruption reset the system, RET do not. For MCS-51, return stack must call for subroutines, interrupted by the return of the RETI instruction stack is possible, on the other hand, interrupt stack RET is not feasible. In short, for stack, the effect of subroutine calls and interruption calls are the same, you can use both of them. In the absence of suspended event, resetting the system interruption would not affect the normal operation of the system. B. Compile OS-CPU-C.C The C / OS-II definite 10 functions in the document. But the most important is task stack initialization function OSTaskStkInit (). Others are used to expand the kernel of the system. OSTaskStkInit () is the call of system itself, when establishes the task for the application of the tasks to initialize the stack. So that the established stack which is already, now to break the system can keep the same stack structure with its environment variables when they finished the storage. This interruption can be ready to return order to make the task of running together. According to the internal structure of MCS-51 stack and the production method, to get the definition to OSTaskStkInit (). C. Compile OS-CPU-A.ASM The key to port C/OS-II is to rewrite 4 functions OSStartHighRdy (), OSCtxSw (), OSIntCtxSw (), OSTickISR (). ACC B DPH DPL PSW R0 R1 R2 R3 R4 R5 R6 R7 HIGH MEMORY LOW MEMORY Stack Growth Figure 2. MCS-51 Stack frame Application Software Software Hardware C/OS-II (Processor Independent Code) OS_CORE.C OS_FLAG.C OS_MBOX.C OS_MEM.C OS_MUTEX.C OS_Q.C OS_SEM.C OS_TASK.C OS_TIME.C uCOS_II.C uCOS_II.H C/OS-II Configuration (Application Specific)
OS_CFG.H INCLUDES.H C/OS-II Port (Processor Specific Code) OS_CPU.H OS_CPU_A.ASM OS_CPU_C.C CPU Timer Figure !. +C/OS-II Hardware/Software Architecture 419 1) OSStartHi-ghRdy () This function is called by OSStart () to start the highest priority task ready-to-run. 2) OSCtxSw () The sequence of events that leads C/OS-II to vector to OSCtxSw () is as follows. The current task calls a service provided by C/OS-II which causes a higher priority task to be ready-to-run. 3) OSIntCtxSw () It is a function that is called by OSIntExit () to perform a context switch from an ISR. 4) OSTickISR () It provide a periodic time source to keep track of time delays and timeouts. IV. DEBUGGING After amending the related code and configuration process is completed, the C/OS-II core sample is testing. Testing of a C/OS-II real-time multi-core tasks need to carefully consider these tests, from simple to complex, you can add some simple tasks, even in the absence of application of the test. This article has been tested based on STC89C516RD+ single-chip microcontroller as the core hardware platform. Because of the restrictions STC89C516RD+s data memory, data memory expansion is not in the circumstances, C / OS-II into a small Keil C51 model has become the choice. Small mode of C / OS- II transplants is characterized by a small model of speed than a lot of speed and mode of operation, which will help improving the speed of the system [6]. Finally, the actual operation of the system is stable and reliable, thats to say transplantation is successful. Different from a number of other commercial embedded operating system, C / OS-II start-up process is relatively simple. C / OS-II is the core of the application in conjunction with the compiler into a HEX file, so long as flashing into the files of the MCUs ROM, the system runs. V. CONCLUSIONS With the complexity of modern industrial real-time operating system has increased and its stringent requirements of the cost, embedded in a variety of MCU still has a very good competition and prospects for development ,as C/OS-IIs sound real-time features such as open source code, and so on. Based on C/OS-II of the characteristics of the porting and the core structure of the detailed study, the porting of C/OS-II on the MCU has completed, and the test passed. In the port process of C/OS-II, first of all, if the embedded system hardware can meet the requirements of real-time operating system; second, correctly read 4 closely related functions of the porting. The article provided a certain method of universality in the MCS-51 Series of MCU port on C/OS- II to rewrite a function, and can also be used to porting of the others. REFERENCES [1] Wang TianMiao. Embedded Systems Design and Analysis [M].Beijing: Tsinghua University Press, 2003.1-40. [2] Hu DaKe, Li Peihong, Lu FangPing. Based on the 8051 MCU embedded guide the development of [M]. Beijing: Electronics Industry Press, 2003 .246-256. [3] JeanJ.Larbosse,ShaoBeibei translate.C/OS-II, The Real-Time Kernel [M]. Beijing: Beijing University of Aeronautics and Astronautics Press, 2003.73-115. [4] Liang HeQing, Lu JianJing, Yang Bo. From C to the C programming language embedded [M]. Beijing: Beijing University of Aeronautics and Astronautics Press, 2002.27-42. [5] Stoke Sam. Embedded system design for a smart rover [J]. American Society for Engineering.2004, 23 (7):115-125. [6] Tian ZhiXin, Zhang lei, Zhao MingYang. Solution of Key problems in the porting of C / OS-II to MCS-51 MCU [J]. Micro Computer Infor mation, 2007, 23:56-58.
Funded projects: 1) Fujian Province, a major special funding (2006HZ0002-3); 2) Fujian Province, a major special funding (2008HZ02010005-5); 3) Fujian Provincial Office of Education-funded major projects (JA07129); 4) Xiamen, a major science and technology projects funded (3502Z20073017).