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.
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.
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]
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.
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
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.
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.
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]
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.
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
Previous article:Using Flash-based MCUs to store user data
Next article:The internal memory of MPC5554 is accessed by the external bus
- Popular Resources
- Popular amplifiers
Recommended Content
Latest Microcontroller Articles
He Limin Column
Microcontroller and Embedded Systems Bible
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
MoreSelected Circuit Diagrams
MorePopular Articles
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
MoreDaily News
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
Guess you like
- Establishment of RF chip/modem chip design team
- F28335 uses external SRAM for program simulation
- Looking for experts in Helmholtz coil magnetic field
- How to use the VGA_SYNC_N signal in the VGA of DE1-SOC?
- CCS Tips: Remove the prompt when burning DSP/BIOS
- SEED-DEC6416 is available for purchase, second-hand is also acceptable
- Calculation of stack usage in C2000 DSP
- IRLR024 Output Current
- Bidirectional thyristor circuit wiring problem
- "Goodbye 2019, Hello 2020" + The wind and clouds are free and happy