Method and system for optimizing multi-engineering algorithm of single-chip microcomputer and related device
By dividing the algorithm space and sharing the algorithm library in the multi-engineering scenarios of microcontrollers, the problems of low algorithm code reuse and large maintenance workload are solved, efficient algorithm code reuse and reduce the coupling degree between engineering and algorithm code.
Patent Information
- Application Number
- CN202411424446.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-12
- Publication Date
- 2025-02-28
AI Technical Summary
In the prior art, in multi-engineering scenarios, the reuse rate of algorithm code of microcontrollers is extremely low, and when the algorithm code changes, it needs to be modified and adjusted separately in each project, which increases the workload of development and maintenance.
By dividing the algorithm space in the linked files of at least two projects of the microcontroller, the algorithm library is stored and shared in the RAM memory area. Compile the algorithm library, get the library file and store it in the Flash storage area. When the first project is run, the library file is loaded into the algorithm space, and the subsequent project runs directly call the library file from the algorithm space.
It improves the reuse rate of algorithm code, reduces the coupling between algorithm code and engineering, reduces the workload of development and maintenance, and improves the flexibility of the system.
Smart Images

Figure CN119536788A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to an optimization method, system and related device for a single-chip microcomputer multi-engineering algorithm. Background Art
[0002] With the continuous development of computer technology, the demand for intelligent and automated control in all walks of life is growing. Embedded systems are special computer systems designed based on specific applications. They integrate computer hardware, software and peripherals, and are embedded in object systems to perform specific tasks. As an important component of embedded systems, single-chip microcomputers play a core role in embedded systems with their small size, low power consumption and high availability, while promoting the development of intelligence and automation.
[0003] In the field of software engineering, especially in scenarios involving multiple projects or engineering, a single chip may contain multiple projects at the same time, and each project may contain the same algorithm code. In the prior art, each project maintains and compiles the algorithm code separately, resulting in a very low code reuse rate. If the algorithm code changes, it needs to be modified and adjusted in each project separately, increasing the workload of development and maintenance. Summary of the invention
[0004] In order to solve the above technical problems, the present application provides a method, system and related devices for optimizing a single-chip microcomputer multi-engineering algorithm.
[0005] The technical solution provided in this application is described below:
[0006] The first aspect of the present application provides a method for optimizing a single-chip microcomputer multi-engineering algorithm, the optimization method comprising:
[0007] Divide the algorithm space in the link files of at least two projects of the single-chip microcomputer, wherein the algorithm space is used to store and share the algorithm library in the RAM memory area, and the algorithm library contains all the algorithm codes in the at least two projects;
[0008] Compile the algorithm library to obtain the library file and store it in the Flash storage area;
[0009] When the first project is running, the library file is loaded from the Flash storage area into the algorithm space to execute the required algorithm code;
[0010] When the subsequent project is running, the library file is called from the algorithm space to execute the required algorithm code.
[0011] Optionally, compiling the algorithm library to obtain a library file includes:
[0012] Obtaining the physical address of the algorithm space specified in the link file;
[0013] The physical address of the algorithm space is written into the algorithm library, and the algorithm library is compiled to obtain a library file.
[0014] Optionally, the step of loading the library file from the Flash storage area into the algorithm space to execute the required algorithm code includes:
[0015] Through the initialization program of the first project, according to the physical address of the algorithm space specified in the link file, the library file is loaded from the Flash storage area into the algorithm space;
[0016] When the first project is running, required algorithm codes are obtained from the algorithm space and executed.
[0017] Optionally, the step of loading the library file from the Flash storage area into the algorithm space to execute the required algorithm code includes:
[0018] Get a function pointer pointing to the physical address of the algorithm space;
[0019] The library file is called from the algorithm space according to the function pointer to execute the required algorithm code.
[0020] Optionally, the method further includes:
[0021] When the subsequent project is running, reallocating the global variables of the subsequent project according to the link file;
[0022] Under the premise of using the same stack, the library file is called from the algorithm space to execute the required algorithm code.
[0023] Optionally, the method further includes:
[0024] When the subsequent project is running, the clearing operation of the algorithm space is skipped.
[0025] Optionally, the clear operation includes clear ZI and clear RW operations.
[0026] A second aspect of the present application provides a single-chip multi-engineering algorithm optimization system, the system comprising:
[0027] A partitioning unit, used to partition an algorithm space in a link file of at least two projects of the single-chip microcomputer, wherein the algorithm space is used to store and share an algorithm library in a RAM memory area, wherein the algorithm library contains all algorithm codes in the at least two projects;
[0028] A compiling unit, used for compiling the algorithm library, obtaining the library file and storing it in the Flash storage area;
[0029] A loading unit, used for loading the library file from the Flash storage area into the algorithm space to execute the required algorithm code when the first project is running;
[0030] The calling unit is used to call the library file from the algorithm space to execute the required algorithm code when the subsequent project is running.
[0031] A third aspect of the present application provides a device for optimizing a single-chip multi-engineering algorithm, the device comprising:
[0032] Processor, memory, input-output unit, and bus;
[0033] The processor is connected to the memory, the input and output unit, and the bus;
[0034] The memory stores a program, and the processor calls the program to execute the first aspect and any optional method in the first aspect.
[0035] A fourth aspect of the present application provides a computer-readable storage medium, on which a program is stored. When the program is executed on a computer, the program executes the first aspect and any optional method in the first aspect.
[0036] It can be seen from the above technical solutions that this application has the following advantages:
[0037] In the link file, the RAM memory area is divided into an algorithm space, and the algorithm codes used by all projects are packaged into an algorithm library, compiled into a library file and stored in the Flash storage area. When the first project is run, the library file will be loaded into the algorithm space, and the library file will not be reloaded when the subsequent projects are run. The first project and the subsequent projects can call the same library file from the algorithm space. At the same time, when the algorithm code needs to be modified, the algorithm library can be modified directly without changing the project, thereby reducing the coupling between the algorithm code and the project and improving the reuse rate of the algorithm code. BRIEF DESCRIPTION OF THE DRAWINGS
[0038] In order to more clearly illustrate the technical solution in the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0039] Figure 1A flow chart of an embodiment of a method for optimizing a single-chip multi-engineering algorithm provided in the present application;
[0040] Figure 2 A schematic diagram of memory partitioning for implementing multi-engineering algorithms in a single chip microcomputer in the prior art;
[0041] Figure 3 A memory partition diagram of the optimization method for the single-chip multi-engineering algorithm provided in this application;
[0042] Figure 4 A flow chart of an embodiment of compiling an algorithm library to obtain a library file in the optimization method of a single-chip multi-engineering algorithm provided in the present application;
[0043] Figure 5 A flow chart of an embodiment of loading a library file into an algorithm space according to a physical address of the algorithm space in a method for optimizing a single-chip multi-engineering algorithm provided by the present application;
[0044] Figure 6 A flow chart of an embodiment of using a function pointer to obtain and execute an algorithm code from an algorithm space in the optimization method of a single-chip multi-engineering algorithm provided by the present application;
[0045] Figure 7 A flow chart of an embodiment of allocating project global variables and stacks for a project initialization program in a single-chip microcomputer multi-project algorithm optimization method provided by the present application;
[0046] Figure 8 A flow chart of another embodiment of the single-chip microcomputer multi-engineering algorithm optimization method provided by the present application;
[0047] Fig. 9 A structural schematic diagram of an embodiment of a single-chip microcomputer multi-engineering algorithm optimization system provided by the present application;
[0048] Fig.10 A schematic structural diagram of an embodiment of a single-chip microcomputer multi-engineering algorithm optimization device provided in the present application. DETAILED DESCRIPTION
[0049] It should be noted that the optimization method, system and related device of a single-chip multi-engineering algorithm provided in this application can be applied to a terminal, a system, or a server. For example, the terminal can be a smart phone or a computer, a tablet computer, a smart TV, a smart watch, a portable computer terminal, or a fixed terminal such as a desktop computer. For the convenience of explanation, this application uses the terminal as an example for the execution subject.
[0050] See also Figure 1The present application first provides an embodiment of a method for optimizing a single-chip multi-engineering algorithm, the optimization method comprising:
[0051] S101, dividing an algorithm space in the link files of at least two projects of the single-chip microcomputer, the algorithm space being used to store and share an algorithm library in a RAM memory area, the algorithm library containing all algorithm codes in at least two projects;
[0052] The link file refers to the SCAT file (Scatter file). The SCAT file is a link script file commonly used in embedded development. It is mainly used to define the layout of different segments (such as code segment, data segment, stack, etc.) in memory.
[0053] In this embodiment, by modifying the link file, an algorithm space is divided in the RAM memory area, and the algorithm space is used to store and share the algorithm library. The algorithm library contains all the algorithm codes in the running project, and the algorithm code of all projects is packaged, and a public interface is set to the outside, and then the algorithm library is obtained by modular sealing. When different projects call the algorithm library, they can call the algorithm library in the algorithm space through the public algorithm interface.
[0054] S102, compile the algorithm library, obtain the library file and store it in the Flash storage area;
[0055] Compiling the algorithm library is to convert the source code of the algorithm library into an executable library file through a compiler. First, confirm the format of the source code in the algorithm library. The source code in the algorithm library is usually saved in the format of C language source file (.c), C++ language source file (.cpp), etc. Then select a suitable compiler according to the format of the source code in the algorithm library, such as GNU ArmEmbedded Toolchain, Arm Compiler, Keil MDK and other compilers, use the compiler to execute compilation instructions on the source code, and compile the source code into a library file. The compiled library file can be directly called and run.
[0056] S103, when the first project is running, the library file is loaded from the Flash storage area into the algorithm space to execute the required algorithm code;
[0057] Flash memory is a non-volatile memory that can save data even when there is no power supply. Embedded systems such as single-chip microcomputers usually divide Flash memory into multiple parts, and the Flash storage area is one of them. The Flash storage area applied to single-chip microcomputers is usually used to store main program code, source code files of various projects, etc., so that the single-chip microcomputer can perform various tasks and logical operations. The library files compiled by the algorithm library are stored in the Flash storage area. When the first project is run, the library files will be loaded from the Flash storage area to the algorithm space of the RAM memory area. The RAM memory area is a part of the RAM storage. The RAM storage is a random access memory with fast read and write speeds. Loading the library files into the algorithm space of the RAM memory area can increase the running speed of the library files.
[0058] S104. When the subsequent project is running, the library file is called from the algorithm space to execute the required algorithm code.
[0059] Since the algorithm library contains the algorithm codes used by all projects, and the compiled library file of the algorithm library has been loaded into the algorithm space of the RAM memory area when the first project is initialized, when subsequent projects are initialized, there is no need to load the library file again, but directly call the library file in the algorithm space of the RAM memory area.
[0060] See also Figure 2 and Figure 3 , Figure 2 The present invention is a schematic diagram of memory partitioning for implementing multi-project algorithms in a single-chip microcomputer in the prior art. In the prior art, when running multiple projects, the single-chip microcomputer needs to store the source code files of the projects in the Flash storage area, and also stores the algorithms in each project. The algorithms used in each project may be different. Each project needs to divide different algorithm spaces for storing algorithms according to the size of the algorithms used by itself, and call the algorithms in the algorithm spaces set by itself when each project is running. The size of the storage area divided for each project in the Flash storage area is limited. If the size of the project changes when modifying the project, the algorithm space in the project needs to be trimmed again. Figure 3The schematic diagram of memory partitioning for the optimization method of multi-project algorithms for single-chip microcomputers in this application. The optimization method of multi-project algorithms for single-chip microcomputers in this application can divide an algorithm space in the RAM memory area, and the algorithm space is used to store all algorithms required for each project. The projects stored in the Flash storage space are no longer divided into separate algorithm spaces. Only the first project stores all algorithms, and then all algorithms are loaded into the algorithm space in the RAM memory area. Regardless of whether the algorithms used by each project are the same, there is no need to write them multiple times and then store them separately. Instead, all algorithms are stored in one algorithm space, and each project only needs to call from this one algorithm space when calling an algorithm.
[0061] In this embodiment, an algorithm space is divided out of the RAM memory area in the link file, and the algorithm codes used by all projects are packaged and encapsulated into an algorithm library, and compiled into a library file and stored in the Flash storage area. When the first project is running, the library file will be loaded into the algorithm space, and the library file will no longer be reloaded when the subsequent projects are running. The first project and the subsequent projects can call the same library file from the algorithm space. At the same time, when the algorithm code needs to be modified, the algorithm library can be modified directly without changing the project, thereby reducing the coupling degree between the algorithm code and the project and improving the reuse rate of the algorithm code.
[0062] See also Figure 4 , Figure 4 It is an embodiment of compiling the algorithm library to obtain the library file, and the embodiment includes:
[0063] S401, obtaining the physical address of the algorithm space specified in the link file;
[0064] When dividing the algorithm space of the RAM memory area in the link file, it is necessary to define the physical address of the algorithm space, that is, the starting address and size of the algorithm space. When obtaining the address specified in the link file, the search target should be confirmed. After setting the algorithm space as the search target, the physical address of the algorithm space is found in the link file, and it is determined whether the algorithm space to be searched is consistent with the search target. If it is consistent with the search target, the physical address of the algorithm space is obtained. When obtaining the physical address of the algorithm space specified in the link file, it is necessary to ensure that the physical address of the algorithm space has not been modified in the linker or compilation to prevent the wrong physical address of the algorithm space from being obtained.
[0065] S402. Write the physical address of the algorithm space into the algorithm library, compile the algorithm library, and obtain a library file.
[0066] A variable or constant that stores the physical address of the algorithm space is defined in the algorithm library. When the physical address belongs to a variable, the physical address of the algorithm space obtained in the link file is used to replace the variable defined in the algorithm library. When the physical address belongs to a constant, the physical address of the algorithm space obtained in the link file is the same as the constant, and then the algorithm library is put into the compiler for compilation to obtain the library file.
[0067] In this embodiment, the physical address of the algorithm space is written into the algorithm library, and then the algorithm library is compiled into a library file. When each project calls the library file, it can also make a directional call according to the physical address of the algorithm space, which provides a basis for each project to call the library file and improves the stability of system operation.
[0068] In the above embodiment, before compiling the algorithm library to obtain the library file, the physical address of the algorithm space is obtained from the link file and written into the algorithm library. Figure 5 , Figure 5 An embodiment of loading a library file into an algorithm space according to a physical address of the algorithm space, the embodiment comprising:
[0069] S501, through the initialization program of the first project, according to the physical address of the algorithm space specified in the link file, the library file is loaded from the Flash storage area into the algorithm space;
[0070] When a project is started, it will be initialized first. The project contains an initialization program, which is responsible for setting the initial state and environment of the project, loading necessary resources, configuring project parameters, and performing hardware detection, etc., to ensure that the project can run under preset conditions, avoid running errors caused by uninitialized variables or resources, and provide a stable foundation for the project execution program. For example, in an embedded system, the initialization program will configure the registers of the microcontroller, set the clock frequency, and ensure the normal operation of the peripherals, so as to achieve normal startup and operation of the system.
[0071] In this embodiment, when the first project is running, the initialization program will load the library file from the Flash storage area to the algorithm space in the RAM memory area according to the physical address of the algorithm space specified in the link file, providing a basis for the project operation.
[0072] S502: When the first project is running, the required algorithm code is obtained from the algorithm space and executed.
[0073] After the first project is initialized, the library file is stored in the algorithm space of the RAM memory area. The first project can call the library file according to the physical address of the algorithm space in the library file. After calling the library file, the algorithm code that needs to be executed in the library file is identified, and the algorithm code in the library file is executed in the RAM memory area to implement specific functions or processing tasks.
[0074] In this embodiment, the first project will load the library file from the Flash storage area to the algorithm space in the RAM memory area according to the physical address of the algorithm space specified in the link file, so that the library file can be called by the project in the RAM memory area, and running the library file in the RAM memory area can improve the efficiency of the entire system operation, while also saving space in the Flash storage area, providing a basis for realizing a shared algorithm space.
[0075] In the above step S502, when the first project is running, the algorithm code is obtained from the algorithm space and executed. Figure 6 , Figure 6 An embodiment of obtaining and executing algorithm code from algorithm space using function pointers includes:
[0076] S601, obtaining a function pointer pointing to the physical address of the algorithm space;
[0077] In this embodiment, the single-chip embedded system uses the ARM architecture, which is a computer architecture based on the principle of reduced instruction computing. It is widely used in various embedded systems and has high energy-efficient computing performance. In the ARM architecture, the function call is performed in a relative addressing manner. When calling a function in the RAM memory area, the sub-function in the Flash storage area cannot be called, and only the function in the RAM memory area can be called. Due to the existence of multiple projects, in the C language, the system will manage the stack uniformly. If a value is temporarily assigned to a local variable, when the program leaves, the system will save the value of the local variable in the stack, and this value will change when entering another program. Using function pointers can make different projects directly specify the physical address of the RAM algorithm space, but will not change the value, so as to realize dynamic calling. The first project will first obtain the function pointer of the physical address of the algorithm space when running, which is used for the project to call the library file.
[0078] S602: Call the library file from the algorithm space according to the function pointer to execute the required algorithm code.
[0079] After obtaining the function pointer, the function pointer points to the physical address of the algorithm space, and the library file in the algorithm space is dynamically called through the function pointer, and the algorithm code is executed. By pointing the function pointer to the library file, the project can flexibly select and call these required functions at runtime without having to determine them at compile time.
[0080] In this embodiment, function pointers are used to implement the project's call to the library file. The function pointer can adapt to the dynamic call of multiple projects without changing the value of local variables. Multiple projects can call the library file in the same algorithm space to achieve sharing, thereby enhancing the flexibility of the system.
[0081] In some other specific embodiments, the initialization procedure of the project will set the initial state and environment of the project, see Figure 7 , Figure 7 An embodiment of allocating project global variables and stacks for the initialization program of the project provided by the present application includes:
[0082] S701, when the subsequent project is running, reallocate the global variables of the subsequent project according to the link file;
[0083] Global variables refer to variables that are globally visible in a program. They are external definitions of all function bodies. Their scope covers the entire program and can be referenced by all objects or functions in the program. The stack is divided into heap area and stack area, which are two data structures. The stack is a data structure in which data items are arranged in order, and data items can only be inserted and deleted at one end, i.e., the top of the stack. In microcontroller applications, the stack is a special storage area whose main function is to temporarily store data and addresses to protect breakpoints and scenes.
[0084] Usually, when a project is running, the initialization program of the project will first set initial values for the global variables of the project and allocate space for global variables and stacks, so as to store data generated during the operation of the project. In this embodiment, there are multiple projects. When the first project is started, the initialization program of the first project will set initial values for the global variables of the project according to the link file and allocate space for global variables and stacks. When subsequent projects are started, the initialization program of the subsequent projects will reset the initial values of global variables and allocate space for corresponding global variables according to the link file, but will no longer reallocate the space for the stack, and the subsequent projects will use the same stack as the first project.
[0085] S702: On the premise of using the same stack, call the library file from the algorithm space to execute the required algorithm code.
[0086] Since the same stack is used, the necessary parameters and data can be directly passed when the subsequent project calls the library file of the algorithm space, and the algorithm code can access the data on the stack and perform calculations. This allows different projects to share and execute the same algorithm code without repeated implementation, optimizing memory usage and execution efficiency.
[0087] In this embodiment, not reallocating the stack space can reduce memory usage and help save resources, especially in resource-constrained embedded systems. Repeated stack allocation may introduce additional overhead, and directly using the allocated stack can improve system performance. Avoiding multiple allocation and release of the stack simplifies the complexity of memory management and reduces potential memory leaks or fragmentation problems.
[0088] This application also provides a preferred implementation, see Figure 8 , Figure 8 This is a flow chart of another embodiment of the optimization method of the single-chip multi-engineering algorithm provided by the present application. The flow chart shows the process of the optimization method of the single-chip multi-engineering algorithm being specifically applied to four projects. The four projects are divided into two parts for specific description below:
[0089] 1. First project: In this embodiment, Project 1 is the first project and is initialized first. The initialization process includes setting global variables, stacks and interrupt vector tables, and allocating corresponding memory according to the link file. Subsequently, the library file is loaded into the algorithm space in the RAM memory area to complete the initialization of Project 1. After that, Project 1 will run various functions, including calling the library file in the algorithm space to execute the algorithm code, thereby achieving the project task.
[0090] 2. Subsequent projects: Project 2, Project 3 and Project 4 will be initialized in sequence as subsequent projects. During the initialization process, global variables, stacks and interrupt vector tables are set up respectively, and corresponding memory is allocated according to the link file, but there is no need to reallocate the stack space. Since the library file has been loaded into the algorithm space of the RAM memory area by Project 1, Project 2, Project 3 and Project 4 can directly carry out the functional items of the project after completing the initialization, including calling the library file in the algorithm space to execute the algorithm code and realize the project task.
[0091] In a specific optional embodiment, when a subsequent project is run, the clearing operation of the algorithm space is skipped.
[0092] In this implementation, the RAM memory area stores the stack and global variables of each project, so that the algorithm space is not cleared. If the algorithm space is cleared, the subsequent call to the library file in the algorithm space will cause a call error. Skipping the clearing operation of the algorithm space can keep the algorithm space in existence while the project is running, so that each project can share the algorithm space.
[0093] In a specific optional embodiment, the clear operation includes clear ZI and clear RW operations.
[0094] See also Fig. 9 , the present application also provides a single-chip multi-engineering algorithm optimization system, including:
[0095] A partitioning unit 901 is used to partition an algorithm space in the link files of at least two projects of the single-chip microcomputer, the algorithm space is used to store and share an algorithm library in a RAM memory area, and the algorithm library contains all algorithm codes in at least two projects;
[0096] Compilation unit 902, used to compile the algorithm library, obtain the library file and store it in the Flash storage area;
[0097] The loading unit 903 is used to load the library file from the Flash storage area into the algorithm space to execute the required algorithm code when the first project is running;
[0098] The calling unit 904 is used to call the library file from the algorithm space to execute the required algorithm code when the subsequent project is running.
[0099] Optionally, the compiling unit 902 is specifically used for:
[0100] Get the physical address of the algorithm space specified in the link file;
[0101] Write the physical address of the algorithm space into the algorithm library, compile the algorithm library, and obtain the library file.
[0102] Optionally, the loading unit 903 is specifically used for:
[0103] Through the initialization program of the first project, the library file is loaded from the Flash storage area to the algorithm space according to the physical address of the algorithm space specified in the link file;
[0104] When the first project is run, the required algorithm code is obtained from the algorithm space and executed.
[0105] Optionally, the calling unit 904 is specifically used for:
[0106] Get the function pointer pointing to the physical address of the algorithm space;
[0107] The library file is called from the algorithm space according to the function pointer to execute the required algorithm code.
[0108] Optionally, the system further includes an allocating unit 905, configured to:
[0109] When the subsequent project is running, the global variables of the subsequent project are reallocated according to the link file;
[0110] Under the premise of using the same stack, the library file is called from the algorithm space to execute the required algorithm code.
[0111] Optionally, skip clearing the algorithm space when subsequent projects are run.
[0112] Optionally, the clear operation includes clear ZI and clear RW operations.
[0113] See also Fig.10 The present application also provides a single-chip multi-engineering algorithm optimization device, including:
[0114] Processor 1001, memory 1002, input and output unit 1003, bus 1004;
[0115] The processor 1001 is connected to the memory 1002, the input and output unit 1003 and the bus 1004;
[0116] The memory 1002 stores a program, and the processor 1001 calls the program to execute any of the above methods.
[0117] The present application also relates to a computer-readable storage medium on which a program is stored, wherein when the program is run on a computer, the computer is caused to execute any of the above methods.
[0118] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.
[0119] In the several embodiments provided in the present application, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of units is only a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces, devices or units, which can be electrical, mechanical or other forms.
[0120] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0121] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0122] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions to enable a computer device (which can be a personal computer, server, or network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, read-only memory), random access memory (RAM, random access memory), disk or optical disk and other media that can store program code.
Claims
1. A method for optimizing a single-chip microcomputer multi-engineering algorithm, characterized in that: The optimization method comprises: Divide the algorithm space in the link files of at least two projects of the single-chip microcomputer, wherein the algorithm space is used to store and share the algorithm library in the RAM memory area, and the algorithm library contains all the algorithm codes in the at least two projects; Compile the algorithm library to obtain the library file and store it in the Flash storage area; When the first project is running, the library file is loaded from the Flash storage area into the algorithm space to execute the required algorithm code; When the subsequent project is running, the library file is called from the algorithm space to execute the required algorithm code.
2. The optimization method according to claim 1, characterized in that: The algorithm library is compiled to obtain a library file, including: Obtaining the physical address of the algorithm space specified in the link file; The physical address of the algorithm space is written into the algorithm library, and the algorithm library is compiled to obtain a library file.
3. The optimization method according to claim 1, characterized in that: The step of loading the library file from the Flash storage area into the algorithm space to execute the required algorithm code comprises: Through the initialization program of the first project, according to the physical address of the algorithm space specified in the link file, the library file is loaded from the Flash storage area into the algorithm space; When the first project is running, required algorithm codes are obtained from the algorithm space and executed.
4. The optimization method according to claim 1, characterized in that: The step of loading the library file from the Flash storage area into the algorithm space to execute the required algorithm code comprises: Get a function pointer pointing to the physical address of the algorithm space; The library file is called from the algorithm space according to the function pointer to execute the required algorithm code.
5. The optimization method according to claim 1, characterized in that: The method further comprises: When the subsequent project is running, reallocating the global variables of the subsequent project according to the link file; Under the premise of using the same stack, the library file is called from the algorithm space to execute the required algorithm code.
6. The optimization method according to any one of claims 1 to 5, characterized in that: The method further comprises: When the subsequent project is running, the clearing operation of the algorithm space is skipped.
7. The optimization method according to claim 6, characterized in that: The clear operation includes clear ZI and clear RW operations.
8. A single-chip multi-engineering algorithm optimization system, characterized in that: The system comprises: A partitioning unit, used to partition an algorithm space in a link file of at least two projects of the single-chip microcomputer, wherein the algorithm space is used to store and share an algorithm library in a RAM memory area, wherein the algorithm library contains all algorithm codes in the at least two projects; A compiling unit, used for compiling the algorithm library, obtaining the library file and storing it in the Flash storage area; A loading unit, used for loading the library file from the Flash storage area into the algorithm space to execute the required algorithm code when the first project is running; The calling unit is used to call the library file from the algorithm space to execute the required algorithm code when the subsequent project is running.
9. A method and device for optimizing a single-chip multi-engineering algorithm, characterized in that: The device comprises: Processor, memory, input-output unit, and bus; The processor is connected to the memory, the input and output unit, and the bus; The memory stores a program, and the processor calls the program to execute the method according to any one of claims 1 to 7.
10. A computer-readable storage medium having a program stored thereon, wherein the program, when executed on a computer, performs the method according to any one of claims 1 to 7.