51 Questions and Tips in Single Chip Operating System Development

xiaoxiao2021-03-06  43

51 Questions and Tips in Single Chip Operating System Development

Author: ■ Donghua Institute of Technology Wu Guangwen Zhou Hangci

Speech

The 51 Series MCU is a high-performance 8-bit microcontroller in 1980 in 1980, which is very wide in our application. Currently, software engineers need software engineers from the bottom floor, and require a lot of repetitive labor in system software design. If you develop a 51-series operating system based on a 51-series single-chip microcomputer, then users only need to write the programs of each task, and do not have to record all the tasks to be run in their hearts, but not only reducing the workload of the program, but also reduces the error. The possibility.

1 Selection and argumentation of development platform

The choice of development platform is crucial, because sometimes it does not only affect the progress, product quality, maintainability, etc., also involves the implementability of the program.

In this system, selecting a 51-series microcontroller as the operating platform of the operating system.

First, the 51-series single-chip application is very wide, and a large batch of 51-compatible microcontrollers are successively launched. Here: Low power consumption, high speed and enhanced Philips company's series of products; a series of ATMEL companies combined with Flash (non-volatile flash technology) EEPROM and 80C51 core; in anti-interference performance, electromagnetic compatibility And the communication control bus function is unique, and its products are commonly used in Working environment harsh SIEMENS company products and some other companies' products. Since the product is so rich, the performance is so superior, then in the system design of multitasking and strict requirements for real-time requirements, in order to fully excavate the potential of the microcontroller (especially in real-time), it is also to simplify the development process, based on the 51 series The demand for the real-time operating system of the single chip microcomputer is very strong. Keil's RTX51 FULL is a real-time operating system with a practical value based on a 51-series microcontroller, but the operating system is a source code that is not open.

Secondly, with the help of the integrated development environment of Keil C51, operating system code applied to the 51 series of microcontrollers can be developed.

Keil C51 software provides a rich library function and powerful Windows interface integration development debugging tool.

In addition, it is important that the target code generated by Keil C51 is very high, and the assembly code generated by most statements is compact and easy to understand. In developing large software, it makes it possible to reflect the advantages of advanced languages. The C compiler produces reusable code and can be opened and closed with C language.

2 Develop 51 MCU operating systems should pay attention to problems

(1) The code of operating system software cannot be too long.

Because the system hardware resources of the 51 series single-chip microcomputer are relatively scarce, if the code of the operating system is larger than the application's code, even make the user's application to consider the resource, such an operating system even if the function is improved, practical. Nowadays, the popular embedded operating system cannot be applied to a 51-series microcontroller because the code is too large. Developing a 5000-row bare-based application is to occupy 7 ~ 8kb ROM space, an operating system uses tens of KB, accounting for space, and the real-time advantage is not there (executing so many instructions. ). Therefore, the author of μCOS does not support the transplantation of his code to the 51 series of microcontrollers, which is not surprising.

(2) Operating system cannot occupy too much in-chip RAM space

The 51 series single-chip only has 128 or 256 bytes of RAM space, and it is used to finish it. If the operating system uses the RAM's RAM, what is the user's application? If the user's program can define the variable in the micro-outer RAM, then the system's hardware stack is placed, well known, 51 The hardware stack of the series of single-chip microcomputer cannot be placed outside the film, so it is necessary to use it on the 51-series single-chip microcomputer. However, it is not possible without using the in-chip RAM, because the operating system also passes the parameters, but also use the stack. The C51 microcontroller C function transfer parameter is through the register and memory, cannot pass the stack. However, it is possible to make the operating system code less in the film by some measures. (3) Resolve the issue of a function of function

Develop real-time occupancy operating systems, the re-enter function is not used. The re-enter function can be called by more than one task without having to worry about data being destroyed. The reusable function can be interrupted at any time, and it can be run after a period of time, and the application data will not be lost. Make the function with reusability must make the function to meet one of the following three conditions:

1 Do not use shared resources;

2 In the use of shared resource time, the interrupt is interrupted after use;

3 Apply for a semaphore when using a shared resource, release the quantity after use.

These conditions are easily implemented in standard C, but it is troublesome in Keil C51. Since the standard C is assigned to the local variable into the user stack (dynamically assigned), the Keil C51 assigns a local variable to the register or memory fixed address (static allocation), and override the analysis by variables, the local variable of multiple functions Use the same memory address to reduce memory occupation. In Keil C51, if local variable is allocated in the register, if local variable is allocated in memory, it is more troublesome.

(4) The allocation problem of stack

The main task of occupying the prior art operating system is the scheduling of the task, through the completion of the system through real-time schedule of the task. During the task scheduling, the inevitable task is a preemption problem of system resources, because the CPU in the system is only one, and each task believes that it is the absolute occupant of the CPU, and each task is a dead cycle. The basis for switching between tasks is the respective priority, and a high priority task can abort the running task by task scheduling function or interrupt exit function or the like. The interrupted task only has its own priority to continue to run from the interruption in the current ready task table. This needs to assign task stacks for each task to save the environment variable of the task. Since each task needs to be saved at different times, the number of environment variables need to be saved is different, the allocation problem of the task stack space is also a question.

3 Some skills to solve problems

(1) Solution to the problem of the problem

The task stack is preferably not placed in the film. If the task stack is placed in the tablets, the resources available to the user application are very limited, and the application's function is limited. That's why some 51-series-based single-chip-based real-time operating system based on the task stack in the tablet can only be used to do some demo experiments, but it is not practical. A real-time operating system with practical value-based 51-series microcontroller must run in a RAM environment above 512 bytes. With the development of integration technology, there have been many 51 series of microcontrollers with auxiliary RAM, which integrates the outer RAM into the chip and uses the MOVX instruction to access these RAMs. If the user does not want to expand the 3rd RAM through the three bus, you can use this microcontroller with auxiliary RAM. In addition, because the operating system uses some global variables, in view of the process of processing, it does not want to put all of them in the film, which can be decided to move to the film according to the frequency of these global variable applications, which In the film. Don't underestimate the savings of these bytes, the effect on the 51 series of microcontrollers will be obvious. The author believes that the highest realm of developing the operating system should be developing a green operating system in this kind of resource relatively scarce machine, and the system resources available when the user can use should be similar to the bare metal programming. (2) Solution to the issue

The parameters of the functions of the entries should be tried to complete through the register, which can be written in a general method so that the function is re-entry. If the register is not enough, you can use the hardware stack to save these local variables.

(3) Solution to the stack allocation problem

Given that each task is different for the requirements of the task stack size, even if the same task is interrupted at different times, it can allocate the task stack multi-byte to the statistical task stack. The number of effects of effective data. In the case of the single-chip microcomputer, the stack is also a logo. When the task is switched, put the current task in the stack of environment variables from the bottom to the bottom of the stack, all copied to the stack of the task, and then will run the task All data in the task stack is restored to the place where the stack flag begins. The data copy between the task stack and the hardware stack is shown in Figure 1.

Where stack (i) and stack (j) are elements in the pointer array stack [max_tasks], Num = SP-STKSTART, the operation steps to be performed in Figure 1 are: 1 put the contents of the system hardware stack in the current In the stack of the task; 2 Move the stack content of the task to be run to the system's hardware stack, and pop the content in the hardware stack to each register. This process completes the switching of the task.

Conclusion

This article describes several issues and their solutions that may be encountered in embedded operating system development based on the 51-series single-chip microcomputer. These ideas are those who have been learned in learning and practice. I believe that they can have a certain inspiration for people who are engaged in the same work.

references

1 Jean J.Labrosse. Live Embedded operating system in source code. Shao Beibei translated. Beijing: China Electric Press, 2001

2 Chen Mingpeng, Zhou Li Gong, et al. Principles and Applications of SMALL RTOS51 in Embedded Real-Time Operating System. Beijing: Beijing University of Aeronautics and Astronautics Press, 2004

3 exploration studio. Embedded system development Bible. Beijing: China Youth Publishing House, 2002

(Received date: 2004-07-14)

转载请注明原文地址:https://www.9cbs.com/read-57686.html

New Post(0)