Research on transplanting μC/OS-II on ARM platform

Publisher:虚拟现实迷Latest update time:2012-01-16 Keywords:μCOS-II Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

The transplantation of μC/OS-II on the ARM platform is an important learning process, which helps to improve the knowledge and understanding of RTOS, thereby improving the theoretical and technical level of embedded workers. μC/OS-II is a small real-time kernel with open source code and detailed explanations. It is precisely because of its small kernel that it is easy to study, understand and master. In addition, referring to the TCP/IP protocol, standards and some public books, it is also very convenient to add the TCP/IP protocol stack, Bluetooth communication software and infrared communication protocol to μC/OS-II, and its commercial value has been recognized.

With the development of science and technology, the complexity of embedded applications is getting higher and higher. At the same time, the price of ARM system processors is getting lower and lower. The use of ARM platform + real-time operating system architecture will become more and more widespread. In view of this, this paper conducts an in-depth discussion on the transplantation of μC/OS-II on the ARM platform.

1 Introduction to μC/OS-II operating system and S3C2410 development platform

1.1 Introduction to μC/OS-II

μC/OS was first published in 1992 by Jean J.Labrosse, an American embedded system expert, in a series of articles published in the May and June issues of the magazine "Embedded System Programming". The source code of μC/OS was also published on the magazine's BBS. μC/OS-II is the latest version.

μC/OS-II is specially designed for embedded computer applications, and most of the code is written in C language. The relevant parts of the CPU are written in assembly language, and the total number of assembly language, about 200 lines, is compressed to a minimum, in order to facilitate porting to any other CPU. μC/OS-II has the characteristics of high execution efficiency, small footprint, excellent real-time performance, and scalability. The minimum kernel can be compiled to 2 KB. μC/OS-II can be ported to almost all well-known CPUs.

1.2 Composition of μC/OS-II

Strictly speaking, μC/OS-II is just a real-time operating system kernel, which only includes basic functions such as task scheduling, task management, time management, memory management, and communication and synchronization between tasks. No additional services such as input and output management, file system, network communication, etc. are proposed. However, due to the good scalability and open source code of μC/OS-II, these non-essential functions can be implemented by users according to their own needs.

μC/OS-II can be roughly divided into five parts: core, task processing, time processing, task synchronization and communication, and CPU porting [1].

(1) Core part (OSCore.c): The processing core of the operating system, including operating system initialization, operating system operation, interrupt in and out preamble, clock beats, task scheduling, event processing, etc.

(2) Task processing part (OSTask.c): The part closely related to task operation, including task creation, deletion, suspension, and resumption, etc.

(3) Clock part (OSTime.c): The smallest clock unit in μC/OS-II is timetick (clock beat). Task delay and other operations are completed here.

(4) Task synchronization and communication part: It is the event processing part, including semaphores, mailboxes, mailbox queues, event flags, etc., which are mainly used for the mutual connection between tasks and the access to critical resources.

(5) The interface with the CPU: This refers to the part of μC/OS-II that needs to be rewritten for the CPU used. Since μC/OS-II is a general-purpose operating system, its open source code is written based on the X86 kernel as an example. When applied to other processor platforms, this part of the code must be changed accordingly.

1.3 Introduction to ARM Hardware Development Platform

The hardware development platform used for debugging is a development platform based on Samsung S3C2410A chip. The S3C2410 development board is a general ARM9 development board. Its basic configuration uses Samsung's S3C2410 ARM920T chip with a main frequency of 203 MHz. It integrates SDRAM controller, NAND Flash controller, SD card reader, USB Host and USB Device controller, LCD controller, I2C bus controller, SPI bus interface, etc. The Flash space on the development board is 32 MB, and the SDRAM capacity is 128 MB.

2 S3C2410 bootloader

The original bootloader of the development board was provided by VIVI, and its operation process is divided into two stages. The code of the first stage is programmed in assembly language, and mainly completes the following tasks: (1) Initialize the CPU speed, memory, memory configuration registers, and hardware resources such as serial ports; (2) Establish a mapping map of the memory space to bring the system's software and hardware environment to a suitable state, preparing for the final call to the operating system kernel; (3) Load the operating system image into the memory; (4) Set up relevant registers and resources, jump to the main() function, and enter the second stage.

The second stage of the code is written in C language, starting from the main() function. The main tasks include: initializing the external interface of the development board (I/O interface, UART interface, LCD interface, etc.), initializing the memory mapping and memory management unit, and finally starting the Linux kernel. There are a large number of articles that have made detailed analysis of the boot program of this development board [3]. This article will not repeat them here. The focus of this article is to integrate the boot program with the μC/OS-II operating system. It not only utilizes the UART port, LCD and touch screen interface programs provided by the development board source code; the rich driver programs and interface programs such as clock and memory management, but also successfully completes the transplantation and integration of the μC/OS-II real-time operating system. [page]

3 Transplantation Tips

The kernel of μC/OS-II is divided into two parts, the code that is not related to the processor and the code that is related to the processor. During the transplantation process, three files need to be rewritten according to the characteristics of the S3C2410 processor and the ADSV1.2 development platform (here the factor of the compilation platform is specially emphasized, mainly considering that the understanding of the data format of each compilation platform is slightly different). They are OS_CPU.H and OS_CPU_C.C written in C language and OS_CPU_A.ASM written in assembly language. In addition, to integrate the S3C2410 development board boot program and the μC/OS-II kernel program, their respective main() functions must also be integrated.

3.1 Porting of OS_CPU.H

The OS_CPU.H code in the μC/OS-II kernel is written based on the X86 kernel, and the data format definition is not completely consistent with the ARM9 kernel and the ADSv1.2 development platform. The transplantation of OS_CPU.H is divided into the following 4 parts:

(1) Data type definition: During debugging, it was found that although no error was reported during compilation when defining 8-bit or 16-bit data types, these variables were not initialized or assigned values ​​correctly as required, and errors often occurred during operation. Therefore, when rewriting the OS_CPU.H code, all variables were defined as 32-bit or 64-bit;

(2) Stack growth direction definition: ARM's stack grows from top to bottom, and OS_STK_GROWTH is defined as 1;

(3) Macro definition of switch interrupt: implemented using the assembly function of switch interrupt and placed in the OS_CPU_A.ASM file.

(4) Macro definition OS_TASK_SW(): This macro definition is the code called when μC/OS-II switches from a low priority task to a high priority task outside of ARM interrupt processing. It is always called in task-level code. In some materials, OS_TASK_SW() and OSIntCtxSw() are equated, which is not possible in the ARM kernel because the latter is the task switching function of the ARM kernel in interrupt mode, and the register groups of the processor in different modes are different, and the register contents to be protected are also different. After debugging, it is found that the following code can achieve the purpose.

OS_TASK_SW    
    stmfd sp!, {lr}; PC is pushed into the stack, lr is actually the return address of the task,
    stmfd sp!, {r0-r12, lr}
    mrs r4, cpsr
    stmfd sp!, {r4} ; finally save CPSR ldr r4, =OSTCBCur
    ldr r5, [r4]
    str sp, [r5] ;Save SP in the control block of the current task ldr r5, =OSTCBHighRdy
    ldr r5, [r5]
    str r5, [r4] ;OSTCBCur = OSTCBHighRdy ldr r6, =OSPrioHighRdy
    ldr r6, [r6]
    ldr r4, =OSPrioCur
    str r6, [r4] ;OSPrioCur = OSPrioHighRdy
    ldr sp, [r5] ; get the stack pointer of the new task
    ldr r4, [sp], #4        
    msr cpsr_cxsf, r4 ; restore CPSR first
    ldmfd sp!, {r0-r12, lr, pc}

3.2 Porting of OS_CPU_C.CH

In OS_CPU_C.C, the most important function is OSTaskStkInit(), which is used to initialize the task stack structure when the task is created. The other hook functions can be left unchanged. The code of this function is relatively simple [2]. It should be noted that in the system described in this article, the user task runs in SVC mode and the SPSR register is not saved.

3.3 Porting of OS_CPU_A.ASM

The assembler of the OS_CPU_A.ASM file is the key and difficulty of the μC/OS-II transplantation project. It usually includes OSStartHighRdy(), OSIntCtxSw(), OSTickISR() and switch interrupt code. Among them, the main work of OSStartHighRdy() is to restore all registers corresponding to the highest priority task from the task stack in order, and its code is simple. For the switch interrupt function, the code used during debugging is as follows:

EnterCritical   
    mrs r1, cpsr
    str r1, [r0]
    orr r1, r1, #NOINT
    msr cpsr_cxsf, r1        
    mov pc, lr    
ExitCritical
    ldr r1, [r0]
    msr cpsr_cxsf, r1    
    mov pc, lr    

Keywords:μCOS-II Reference address:Research on transplanting μC/OS-II on ARM platform

Previous article:Analysis of ARM-based infrared light vehicle speed management system
Next article:Embedded brain blood oxygen parameter monitor based on ARM processor

Recommended ReadingLatest update time:2024-11-16 21:54

Design of CAN Node Based on S3C44B0 and μCOS-II
introduction As systems become more and more complex and powerful, the use of real-time multitasking operating systems in the design of embedded systems has become the mainstream of embedded application design. μCOS-II is an open source embedded real-time operating system (RTOS), which has been successfully por
[Microcontroller]
Design of CAN Node Based on S3C44B0 and μCOS-II
μC/OS-II Porting Notes 1 (FreeScale 68HCS12 Core MCU)
μC/OS-II porting notes 1 (ported to FreeScale 68HCS12 core microcontroller, Small Memory Model) Recently, I spent some time in my spare time to study how to port μC/OS-II to the FreeScale 68HCS12 core microcontroller. In fact, I did this work once two years ago. At that time, I found similar porting codes (68HC11 cor
[Microcontroller]
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号