Abstract: an embedded operating system is the core of embedded system applications. This article compares two typical open-source embedded operating systems, analyzes and summarizes several issues in embedded operating system applications, and summarizes the basis for selecting embedded operating systems.
Introduction
With the rapid development of modern computer technology and the wide application of Internet technology, the transition from the PC era to the 3C (computer, communication, and consumer electronics) era, represented by personal digital assistants, handheld PCs, and Information appliances. In the post-PC era, embedded systems play an increasingly important role and are widely used in Information appliances, mobile computer devices, network devices, industrial control simulation, and other fields. The development of embedded systems has also become a hot technology in the IT industry in recent years.
Embedded Systems that complete simple functions generally do not require an operating system. For example, a small system consisting of many M cs51 series single-chip microcomputer only uses software to implement a simple control loop. However, with the advent of the Post-PC era, embedded system design becomes increasingly complex and embedded operating systems are essential.
Generally speaking, an embedded operating system is different from a general computer operating system. It has the characteristics of low space occupation, high execution efficiency, convenient customization, and fixed storage required by software.
Since 1980s, some IT organizations and companies have started to develop commercial embedded systems and specialized operating systems. Some well-known embedded systems have emerged, such as Microsoft's wince and windriversystem's VxWorks, which represent non-real-time and real-time embedded operating systems. However, the cost of commercial products is very expensive. for general purposes, the cost of commercial products will be increased and the competitiveness will be lost.
The uC/OS and uClinux operating systems are two free embedded operating systems with excellent performance and open source code, which can be used as a model for studying real-time operating systems and non-real-time operating systems. This article compares uC/OS with uCLinux, analyzes and summarizes several important issues in embedded operating system applications, and summarizes the basis for selecting Operating Systems in embedded system development.
Introduction to two Open Source Embedded Operating Systems
The uC/OS and uClinux operating systems are currently widely used two Free and Open Source Embedded operating systems. UC/OS is suitable for small-sized control systems. It features high execution efficiency, small space occupation, excellent real-time performance, and high scalability. The minimum kernel can be translated to 2 K. UClinux is an operating system that inherits the excellent features of standard Linux and is designed based on the characteristics of embedded processors. It has embedded network protocols and supports multiple file systems, developers can take advantage of the prior knowledge of standard Linux. After compilation, the target file can be controlled to hundreds of kb.
UC/OS is a real-time operating system with free open source code, small structure, and real-time kernel deprivation. Its Kernel provides functions such as task scheduling and management, time management, synchronization and communication between tasks, memory management, and service interruption.
UClinux is an excellent embedded Linux version. UClinux is short for micro-conrol-Linux. Compared with standard Linux, it integrates the stability of standard Linux operating systems, powerful network functions, and excellent file systems. However, since there is no MMU (Memory Management Unit), the implementation of its multi-task requires some skills.
Comparison of the main performance of the two Embedded Operating Systems
The embedded operating system is the control center of the hardware and software resources of the embedded system. It organizes multiple users to share the various resources of the embedded system as reasonably and effectively as possible. The user refers to all the software above the system program. A reasonable and effective method refers to how the operating system coordinates and makes full use of hardware resources to achieve multi-task. Complex Operating Systems Support file systems to facilitate file organization and standardization.
Another feature of the embedded operating system is that the system is not directly available for different platforms. Generally, the operating system needs to be transplanted to the specialized platform to work normally.
Process scheduling, file system support, and system migration are the most common problems in the practical application of embedded operating systems. The following describes the analysis and comparison of uC/OS and uClinux.
Process Scheduling
Task Scheduling is used to coordinate the competition for resources (such as memory, I/O devices, and CPUs) in computer systems. Process Scheduling is also known as CPU scheduling. Its fundamental task is to allocate CPU to a ready process according to some principle. Because the memory and I/O devices in the embedded system generally belong to a process at the same time as the CPU, the concept of task scheduling is similar to that of process scheduling, which is not distinguished in many cases, the task mentioned below is actually a process concept.
Process Scheduling can be divided into two basic methods: "Deprivation-type scheduling" and "non-deprivation-type scheduling. The so-called "non-deprivation-type scheduling" means that once a process is scheduled for execution, the process continues until the process ends, or for some reason, the CPU is automatically abandoned and enters the waiting state, to re-allocate the CPU to other processes. The so-called "Deprivation-type scheduling" means that once a process with a higher priority appears in the ready state, or the running process has used the specified time slice, immediately deprive the current process of running (put it back to the ready state ),
Allocate the CPU to other processes.
As a real-time operating system, uC/OS uses a real-time, multi-task kernel that is denied. The deprived real-time kernel is running at any time with the highest priority. In uC/OS, a maximum of 64 tasks are supported, corresponding to priority 0 ~ 63, where 0 is the highest priority. Scheduling can be divided into two parts: finding the highest priority task and switching the task.
The most important task is to create a ready task table. Each task in UC/OS has an independent stack space and a data structure called task control block (TCB, the first member variable is the saved Task Stack pointer. The task scheduling module first uses the variable ostcbhighrdy to record the TCB address of the current most advanced ready task, and then calls the OS _task_sw () function to switch the task.
The process scheduling in uClinux follows the tradition of Linux. The system suspends the process at a certain time, and the system generates fast and periodic clock interruptions, and uses the scheduling function (timer processing function) determines when a process has its time slice. Then perform the relevant process switchover, which is achieved by the parent process calling the fork function to generate sub-processes. After the fork call in uClinux is complete, either the child process is executed in place of the parent process (at this time, the parent process has sleep) until the child process calls exit to exit, or the exec is called to execute a new process, at this time, an executable file is generated. Even if the process is only a copy of the parent process, this process is inevitable. After the child process executes exit or exec, the child process uses wakeup to wake up the parent process so that the parent process continues to run.
Since uClinux does not have MMU to manage memory, its access to memory is direct, and the addresses accessed in all programs are actually physical addresses. The operating system team's memory space is not protected, and each process actually shares a runtime space. This requires data protection when multiple processes are implemented, and the space used by the user program may occupy the system kernel space. Pay more attention to these problems during programming, otherwise, the system may crash.
The above analysis shows that the uC/OS kernel is designed and implemented based on the requirements of real-time systems, which is relatively simple and can meet high real-time requirements. UClinux inherits the standard Linux multi-task implementation mode in terms of structure and only improves the features of embedded processors. To achieve real-time performance, the system must run under the control of the real-time kernel. RT-Linux is a real-time kernel that can implement this function.
File System
The so-called file system refers to the organization responsible for accessing and managing file information, it can also be said that it is the software part responsible for file establishment, revocation, organization, read/write, modification, replication, and management of the resources required for file management (such as Directory tables and storage media.
UC/OS is intended for small and medium-sized embedded systems. If it contains all the functions (semaphores, message mailboxes, message queues, and related functions), the compiled uC/OS kernel is only 6 ~ 10 KB, so the system itself does not support the file system. However, uC/OS has excellent scalability. You can add the content of the file system as needed.
UClinux inherits the complete file system performance of Linux. It uses the romfs file system, which requires less space than the general ext2 file system. Space saving comes from two aspects. First, the kernel supports romfs file systems and requires less code than ext2 file systems. Secondly, the romfs file system is relatively simple) requires less storage space. The romfs file system does not support dynamic write/write operations. The system uses the virtual ramdisk method to process the data to be dynamically saved (the ramdisk uses the ext2 File System ).
UClinux also inherits the advantages of the Linux network operating system, which can easily support the Network File System and embed the TCP/IP protocol, which facilitates the development of network access devices in uClinux.
According to the support of the two operating systems for the file system, uClinux is a good choice in complicated embedded systems that require more file processing. However, uC/OS is mainly suitable for some control systems.
Port Operating System
The purpose of porting an embedded operating system is to instruct the operating system to run on a microprocessor or microcontroller. Both uC/OS and uClinux are open source code operating systems, and their structured design is easy to separate the processor-related parts. Therefore, it is possible to be transplanted to a new processor.
The transplantation of the two systems is described below.
(1) transplantation of uC/OS
To transplant uC/OS, the target processor must meet the following requirements;
· The C compiler of the processor can generate reusable code and enable and disable interruptions in C language;
· The processor supports interruption and can generate scheduled interruption;
· The processor supports enough RAM (several K bytes) as a task stack in a multi-task environment;
· The processor reads and stores the stack pointer and other CPU registers into the stack or memory.
After understanding the technical details of the processor and C compiler, you only need to modify the processor-related code for porting uC/OS. The specific content is as follows:
· In OS _ CPU. H, you need to set a constant to identify the growth direction of the stack;
· In OS _ CPU. H, several macros need to be declared for switching interruptions and task switching;
· In OS _ CPU. H, you need to redefine a series of data types based on the processor's word length;
· OS _ cpu_a.asm needs to rewrite functions in four assembly languages;
· OS _ cpu_c.c requires six simple functions written in C language;
· Modify the main header file include. h and add the preceding three files and other header files.
(2) porting uClinux
Since uClinux is actually a kind of improvement for Linux for embedded systems, its structure is complicated, and the transplantation of uClinux is much more complicated than that of uC/OS. In general, to transplant uClinux, the target processor must not only meet the preceding uC/OS requirements, but also have sufficient capacity (hundreds of kb or more) External ROM and ram.
The transplantation of uClinux can be divided into three levels:
· Structure-level transplantation: if the structure of the processor to be transplanted is different from that of any supported processor, You need to modify the file of the processor structure under the Linux/arch directory. Although most of the uClinux kernel code is independent of the processor and its architecture, its lowest-level code is also specific to various systems. This is mainly manifested in their Interrupt Processing context, memory ing maintenance, task context and initialization process are all unique. These routines are located in the Linux/ARCH/directory. Linux supports a wide variety of architecture, so for a new system, its low-level routines can imitate similar system routines.
· Platform-level transplantation: If the processor to be transplanted is a branch processor of a certain uClinux support system, you need to create a directory under the relevant architecture directory and write the relevant code. For example, mc68ez328 is based on the m68k kernel without MMU. In this case, you need to create the Linux/ARCH/m68knommu/platform/mc68ez328 directory and write the tracking program under it (to implement the functions such as the interface from the user program to the kernel function) interrupt control scheduler and vector initialization program.
· Board-level porting: If your processor is supported by uClinux, you only need to port it. Board-level porting requires Linux/ARCH /? Create a directory for the corresponding board in platform/, and then create the corresponding startup code crt0_rom.s or crt0_ram.s and the Link Description file Rom. LD or ram. lD. Board-level porting also includes writing drivers and setting environment variables.
Conclusion
By comparing the uC/OS and uClinux, we can see that the two operating systems have their own advantages and disadvantages in application. UC/OS occupies less space, has high execution efficiency, excellent real-time performance, and is relatively simple for porting new processors. UClinux occupies a relatively large amount of space, and its real-time performance is average. Porting new processors is relatively complicated. However, uClinux has the ability to support a variety of file systems, embedded with the TCP/IP protocol, can learn from the rich resources of Linux, for some complex applications, uClinux has a considerable advantage. For example, Cisco 2500/3000/4000 routers are developed based on the uCLinux operating system. In short, the choice of the operating system is determined by the requirements of the embedded system. Simply put, a small control system can take full advantage of the small and real-time uC/OS advantages. If you develop complicated systems such as PDA and Internet connection terminals, uClinux is a good choice.