Design Method of Embedded Storage System Based on Virtual Storage

Publisher:静心静气Latest update time:2015-04-15 Source: eechina Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
1 Introduction

Embedded systems consist of embedded hardware and embedded software that is fixed in the hardware platform. In traditional small-scale embedded systems, software mostly adopts the foreground and background method, which is usually used in simple occasions with low real-time requirements; for complex applications, the more common practice is to equip the system with an embedded real-time operating system (RTOS), which not only enables the system to have good real-time performance and reduces the workload of software compilation, but also improves the stability of the entire system. In addition, in order to simplify user programs, the system usually provides some necessary library functions for users to call. Compared with the foreground and background system, this real-time embedded system increases the system storage space overhead. Intel 8051 series and various compatible microcontrollers are widely used in various embedded fields due to their extremely high cost performance, rich library functions and long-term technical accumulation. Due to the limitation of the addressing space of traditional microcontrollers, storage space expansion is often required in embedded applications. This paper draws on the virtual storage technology in traditional computer system design and proposes a method for expanding storage space using page grouping and virtual interface technology using 8051 microcontroller as an example. This method has good compatibility with Keil C compiler.

2 Organization of storage system

2.1 Virtual storage system

Virtual storage technology is often used in computer systems to expand the capacity of storage systems. Paged virtual memory is a common organization method. In this method, the entire virtual address space and main memory space are divided into several pages of equal capacity. The address conversion mechanism (usually a fast address conversion table) establishes a mapping from virtual space to main memory space virtual page to real page. The organization relationship of paged memory is shown in Figure 1.

1.gif 

The virtual memory system uses a set of register stacks in the computer CPU as the page table base register, as shown in Figure 1 (b), which together with the page table gives the user program address. The page-based virtual memory of the actual computer system is much more complicated than this, and it is also necessary to consider the external address conversion and page replacement algorithm when a miss occurs. However, these can be simplified or even omitted in embedded systems.

2.2 Program storage area expansion of microcontroller embedded system

Inspired by the virtual memory system, we made some modifications to the above method to apply it to embedded systems. Since the external program memory capacity selected in the system design is 256k, and the addressing space of general microcontrollers (such as the 8051 series) is 64k, for simplicity, 64k is used as one page, and the 256k virtual address is divided into 4 pages and mapped to the 64k space of the microcontroller. The address conversion mechanism in the embedded system can be simplified: the microcontroller does not have a dedicated page table base register, and different pages can be specified through additional port lines (such as P1.0, P1.1, P1.2, etc.) as the base address, and the page table query can be implemented with a jump table. However, the jump table must be correctly accessed before and after the page switch, so all 64k pages need to have a completely identical code segment to store common resources such as jump tables and interrupt vectors.

To improve memory utilization, the structure shown in Figure 2 can be used, in which the common segment stores the jump table required for mutual calls between the upper 32k segments. Before each segment calls each other, it should jump to the common segment first, and then jump to the entry of the called program after executing the page switch, which realizes the transformation from 18-bit virtual address to 16-bit main memory address. It is advisable to use P1.0, P1.1, and P1.2 as the page base address to specify different pages. The corresponding jump table program structure is as follows:

  ADDR: CLR EA; turn off interrupt
  SETB/CLR P1.0; switch page
  SETB/CLR P1.1
  SETB/CLR P1.2
  SETB EA; turn on interrupt
  JMP REAL_ADDR; jump

The operating system and other library functions provided to users are stored in the common segment (the lower 32k of the 256k memory chip), and the other segments are used to store user programs of the embedded system. The schematic diagram of the interface between the microcontroller and the memory using the structure of Figure 2 is shown in Figure 3. The connection method of the A0~A15 address lines is the same as the ordinary memory expansion method.

2.gif 

The above considerations indicate that the page should be switched to the common code area when resetting.

Keil C51 compiler is a very popular and efficient compiler in microcontroller development applications, which supports the above page grouping technology. [page]

3.gif 

2.3 Data storage area expansion of single-chip embedded system

Introducing an operating system into an embedded system requires a certain amount of data storage overhead. If necessary, paging technology can still be used to expand the data storage area capacity.

After the introduction of the operating system, there are two ways to organize the data area. The simpler method is that the operating system and the user program share a data area, and the compiler compiles the entire program together without distinguishing whether it is a system program or a user program. However, this makes the operating system opaque to the user, and a bad user program may damage the system's data area, causing the entire system to crash.

The corresponding other method is to allocate independent data areas to the operating system and user programs respectively, for example, 64k is allocated to the operating system and user programs respectively for 128k data storage. Unfortunately, when the operating system and user program are compiled together, the compiler will automatically assign different addresses to them. In this way, even if the memory is physically separated, the data area of ​​the operating system and the user program cannot be reused, which greatly wastes the address space; and for traditional single-chip microcomputers, the Keil C compiler only supports a maximum of 64k data area. Fortunately, this contradiction can be solved by using a virtual interface method.

To this end, the program in the common code segment is compiled separately, and when linking and locating the target code, a fixed first address is assigned to each function of the operating system and the common library function within 0x0000~0x7FFFH. In view of the fact that the user program may call these functions, it is necessary to write a pseudo function of the same type and the same name for each of these functions. Each pseudo function only contains a transfer instruction to the real function (the entry address is known), and all these functions are stored in a header file called a virtual interface. The virtual interface file is compiled together with the user program to complete the interface between the user program and the operating system for two compilations. Obviously, this method only occupies a very small amount of code space in the user area, without wasting the user data area at all, and at the same time realizes address reuse.

The special correspondence between the common code segment and the operating system's data area (see Figure 4) can be easily specified through the P2 port line. From the timing of accessing the external program area of ​​the microcontroller (Figure 5), it can be seen that after the rising edge of PSEN, instructions or instruction operands begin to appear on the data bus A0~A7. At this time, the address line A15 indicates whether the current access is the common code segment (corresponding to the upper 64k of the data area) or other program segments (corresponding to the lower 64k of the data area). Therefore, the address line A15 is latched at the rising edge of PSEN, and it can be used to select different data memory spaces.

4.gif 

5.gif 

3 Performance Analysis of Storage System

This paper implements the expansion of large-capacity memory in embedded systems based on the idea of ​​virtual storage system. It is not difficult to see that the expansion space of the system is limited by the port line. Since the structure shown in Figure 2 is constructed in the same chip, one more port line needs to be used. Therefore, for the 8051 series, the entire P1 port can be used to expand the system's program virtual space to 8M bytes. The maximum capacity of the data storage area expansion is also related to the number of blocks into which the program is divided when compiling. The maximum can reach 16M bytes, which is large enough in the single-chip embedded system.

When the program calls functions in different pages, additional software switching cycles are required. Frequent page switching will reduce the performance of the system. Therefore, functions should be carefully selected during compilation, and related functions should be allocated in the same page as much as possible.

Data storage area switching is implemented by hardware, and page switching does not reduce system performance. Since the operating system and the user program data area are independent of each other, the entire 64k space is available to the user, which increases the transparency of the operating system.

4 Conclusion

Due to its specialization and particularity, the system's hardware and software design is different from the traditional computer system design method. However, it is still necessary to learn from the mature design methods of traditional computer system architecture when designing embedded systems, and "tailor" them for my own use. When designing embedded platforms, the author borrowed the traditional computer virtual storage idea to expand the storage system, and applied it in actual projects, proving that this method is very effective.

References

   1. Zheng Weimin, Tang Zhizhong Computer System Architecture 1998
   2. Xu Aijun, Peng Xiuhua Single-Chip Microcomputer High-Level Language C51 Windows Environment Programming and Application 2001
   3. Keil Company Keil C Compiler User Manual 
Reference address:Design Method of Embedded Storage System Based on Virtual Storage

Previous article:Using Flash-based MCUs to store user data
Next article:The internal memory of MPC5554 is accessed by the external bus

Recommended Content
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号