Information storage method, device, equipment and storage medium
By adding variable declarations and definitions in the startup file and utilizing the stack address mapping mechanism, the problem of fixed storage address of MCU device information is solved, flexible adaptation of the code on different MCUs is achieved, and portability and efficiency are improved.
Patent Information
- Application Number
- CN202210147902.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-02-17
- Publication Date
- 2025-09-09
- Estimated Expiration
- 2042-02-17
AI Technical Summary
In the prior art, the fixed storage address of the microcontroller device information makes it difficult to transplant the target code. The address of the FLASH memory needs to be reset according to the different microcontrollers, which affects the portability of the code.
Add variable declarations and definitions in the startup file, use the address mapping mechanism in the stack to automatically allocate unoccupied addresses in the microcontroller memory during compilation, and realize the storage of device information.
It improves the code portability of device information storage, simplifies the adaptation process of target code on different microcontrollers, and improves work efficiency and flexibility.
Smart Images

Figure CN114510437B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to an information storage method, apparatus, device and storage medium. Background Art
[0002] Generally, a device containing a microcontroller needs to store its own device information (such as BOOT (startup) version, DOWNLOAD (download) version, DIAG (diagnostic) version, etc.) in the FLASH memory of the microcontroller so that technicians can view this device information.
[0003] In the related art, when developing a microcontroller, a technician adds object code to a link configuration file within the microcontroller's development files. The object code specifies the storage address of device information in the microcontroller's FLASH memory. The development file is then compiled to generate an executable file, which is then burned into the microcontroller. The microcontroller then executes this executable file at startup, storing the device information at the specified storage address in the FLASH memory.
[0004] However, in the above method, the target code specifies the storage address of the device information in the FLASH memory, that is, the target code sets a fixed storage address for storing the device information. In this case, if the target code needs to be ported to the development files of another microcontroller, the storage address for storing the device information in the target code must be re-set according to the unoccupied address in the FLASH memory of the other microcontroller, which requires modifying the target code, which is not conducive to the portability of the target code. Summary of the Invention
[0005] This application provides an information storage method, apparatus, device, and storage medium that can improve the code portability of device information storage. The technical solution is as follows:
[0006] In a first aspect, an information storage method is provided, the method comprising:
[0007] Add a variable declaration for each of n variables in the startup file, wherein the n variables correspond one-to-one to n preset information, and n is a positive integer;
[0008] Storing the n variables one by one in n first addresses of a stack in the startup file, wherein the n first addresses are used to indicate storage locations of the n variables in the stack;
[0009] Adding a variable definition of each of the n variables in the startup file, wherein the variable definition of each variable is used to specify an initial value of each variable as corresponding preset information;
[0010] Among them, the startup file is used to obtain an executable file that can be burned to the microcontroller after compilation. When the startup file is compiled, the n first addresses are mapped one by one to n unoccupied second addresses in the memory of the microcontroller, and the n second addresses are used to indicate the storage location of the n preset information in the memory.
[0011] In the present application, a variable declaration for each of n variables is added to the startup file, and the n variables are stored one by one in the n first addresses in the startup file's stack. A variable definition for each of the n variables is then added to the startup file, with the variable definition for each variable being used to specify the initial value of each variable as the corresponding device information. When the startup file is compiled, the n first addresses are mapped one by one to n unoccupied second addresses in the microcontroller's memory. This allows the preset information corresponding to each of the n first addresses to be stored in the corresponding second address in the microcontroller's memory when the executable file compiled from the startup file is subsequently executed. In this case, the startup file does not specify a fixed storage address in the microcontroller's memory for the preset information. Instead, the preset information is automatically allocated to an unoccupied second address in the microcontroller's memory when the startup file is compiled. This makes the startup file highly portable, meaning that the startup file can be used normally even after being ported to the development files of other microcontrollers.
[0012] Optionally, the stack includes a reserved address, and storing the n variables one by one in the n first addresses of the stack in the startup file includes:
[0013] The n variables are stored one by one in the n first addresses in the reserved addresses of the stack.
[0014] Optionally, after adding the variable definition of each of the n variables in the startup file, the method further includes:
[0015] Compiling the startup file to obtain the executable file;
[0016] During the compilation process, the top address of the stack is obtained; the target address mapped by the top address in the memory is obtained; and according to the top address and the target address, the n first addresses are mapped one by one to the n second addresses.
[0017] Optionally, obtaining a target address mapped in the memory by the top address of the stack includes:
[0018] If there are m consecutive addresses in the memory that are not occupied, then use the first address of the m addresses as the target address of the stack top address mapping, where m is the total number of addresses of the stack, and m is an integer greater than or equal to 2;
[0019] Optionally, mapping the n first addresses to the n second addresses one by one according to the stack top address and the target address includes:
[0020] For each of the n first addresses, the following operations are performed:
[0021] Obtaining an address difference between the first address and the stack top address as a specified address difference;
[0022] An address among the m addresses, the address of which the address difference from the target address is the specified address difference, is used as a second address mapped to the first address.
[0023] Optionally, after compiling the startup file to obtain the executable file, the process further includes:
[0024] Burning the executable file to the single chip microcomputer;
[0025] In which, the executable file is executed when the microcontroller is started, and when the executable file is executed, each of the n preset information is stored in the corresponding second address in the memory, and the second address corresponding to each preset information is the second address mapped to the first address of the variable corresponding to each preset information in the stack.
[0026] Optionally, the single chip microcomputer is used to save the n second addresses to the memory after executing the executable file, and after burning the executable file to the single chip microcomputer, the method further includes:
[0027] Obtaining the n second addresses from the memory;
[0028] Acquire preset information stored at each of the n second addresses in the memory.
[0029] Optionally, the preset information is device information of a device on which the single chip microcomputer is installed.
[0030] In a second aspect, a device information storage apparatus is provided, the apparatus comprising:
[0031] A first adding module adds a variable declaration of each of n variables in the startup file, wherein the n variables correspond one-to-one to n preset information, and n is a positive integer;
[0032] a storage module, storing the n variables one by one in n first addresses of the stack in the startup file, wherein the n first addresses are used to indicate storage locations of the n variables in the stack;
[0033] A second adding module is configured to add a variable definition of each of the n variables to the startup file, wherein the variable definition of each variable is used to specify an initial value of each variable as corresponding preset information;
[0034] Among them, the startup file is used to obtain an executable file that can be burned to the microcontroller after compilation. When the startup file is compiled, the n first addresses are mapped one by one to n unoccupied second addresses in the memory of the microcontroller, and the n second addresses are used to indicate the storage location of the n preset information in the memory.
[0035] Optionally, the stack includes a reserved address, and the storage module is used to:
[0036] The n variables are stored one by one in the n first addresses in the reserved addresses of the stack.
[0037] Optionally, the device further comprises:
[0038] A compiling module, used for compiling the startup file to obtain the executable file;
[0039] A first acquisition module is used to obtain the stack top address of the stack during the compilation process; and obtain the target address mapped by the stack top address in the memory;
[0040] A mapping module is used to map the n first addresses to the n second addresses one by one according to the stack top address and the target address.
[0041] Optionally, the first acquisition module is used to:
[0042] If there are m consecutive addresses in the memory that are not occupied, then use the first address of the m addresses as the target address of the stack top address mapping, where m is the total number of addresses of the stack, and m is an integer greater than or equal to 2;
[0043] Optionally, the mapping module is used to:
[0044] For each of the n first addresses, the following operations are performed:
[0045] Obtaining an address difference between the first address and the stack top address as a specified address difference;
[0046] An address among the m addresses, the address of which the address difference from the target address is the specified address difference, is used as a second address mapped to the first address.
[0047] Optionally, the device further comprises:
[0048] A burning module, used for burning the executable file into the single chip microcomputer;
[0049] In which, the executable file is executed when the microcontroller is started, and when the executable file is executed, each of the n preset information is stored in the corresponding second address in the memory, and the second address corresponding to each preset information is the second address mapped to the first address of the variable corresponding to each preset information in the stack.
[0050] Optionally, the device further comprises:
[0051] A second acquisition module, configured to acquire the n second addresses from the memory;
[0052] The third acquisition module is configured to acquire the preset information stored at each of the n second addresses in the memory.
[0053] Optionally, the preset information is device information of a device on which the single chip microcomputer is installed.
[0054] In a third aspect, a computer device is provided, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program implements the above-mentioned information storage method when executed by the processor.
[0055] In a fourth aspect, a computer-readable storage medium is provided, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the above-mentioned information storage method is implemented.
[0056] In a fifth aspect, a computer program product comprising instructions is provided, which, when executed on a computer, enables the computer to execute the steps of the above-mentioned information storage method.
[0057] It can be understood that the beneficial effects of the second, third, fourth and fifth aspects mentioned above can be found in the relevant description of the first aspect mentioned above, and will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS
[0058] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the following briefly introduces the drawings required for use in the description of the embodiments. 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 any creative work.
[0059] Figure 1 This is a flow chart of an information storage method provided by an embodiment of the present application;
[0060] Figure 2 This is a schematic diagram of a startup file provided in an embodiment of the present application;
[0061] Figure 3 This is a schematic diagram of the structure of a device information storage device provided in an embodiment of the present application;
[0062] Figure 4 It is a structural diagram of a computer device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0063] In order to make the objectives, technical solutions and advantages of this application clearer, the implementation methods of this application will be further described in detail below with reference to the accompanying drawings.
[0064] It should be understood that the “multiple” mentioned in this application refers to two or more. In the description of this application, unless otherwise specified, “ / ” means or, for example, A / B can mean A or B; “and / or” in this article is merely a description of the association relationship of associated objects, indicating that there can be three relationships, for example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone. In addition, in order to facilitate the clear description of the technical solution of this application, words such as “first” and “second” are used to distinguish between identical or similar items with basically the same functions and effects. Those skilled in the art can understand that words such as “first” and “second” do not limit the quantity and execution order, and words such as “first” and “second” do not necessarily limit them to be different.
[0065] Before explaining the embodiments of the present application in detail, the application scenarios of the embodiments of the present application are first explained.
[0066] The information storage method provided in the embodiment of the present application is applied to the scenario of storing information, such as the scenario of storing device information or other fixed information in the memory of a single-chip microcomputer. For example, during the development of a single-chip microcomputer, the information storage method provided in the embodiment of the present application can be used to store device information in the memory of the single-chip microcomputer (such as a FLASH memory, etc.). The device information can be relevant information of the device on which the single-chip microcomputer is to be installed, such as the BOOT (startup) version, DOWNLOAD (download) version, DIGA (diagnostic) version, etc. of the device.
[0067] In the information storage method provided in an embodiment of the present application, a first address is assigned to each of n variables in a startup file stack, and a variable definition for each variable is added to the startup file. Through the variable definition of each variable, the preset information corresponding to each variable can be saved in the startup file. Thus, when the startup file is compiled, the first address of each variable in the startup file stack is mapped to an unoccupied second address in the memory of the microcontroller. The second address is the storage address of the preset information corresponding to each variable in the microcontroller. Subsequently, the preset information corresponding to each variable can be stored at the second address.
[0068] In this case, the startup file does not specify a fixed storage address for the preset information in the MCU's memory. Instead, the first address of the variable corresponding to the preset information in the startup file is mapped to an unoccupied second address in the MCU's memory when the startup file is compiled. In other words, the unoccupied second address in the MCU's memory is automatically allocated to the preset information when the startup file is compiled. This makes the startup file highly portable, meaning that the startup file can be used normally even after being ported to the development files of other MCUs.
[0069] The information storage method provided in the embodiments of the present application is explained in detail below.
[0070] Figure 1 This is a flow chart of an information storage method provided by an embodiment of the present application. Figure 1 , the method includes the following steps.
[0071] Step 101: The terminal adds a variable declaration of each of n variables in a startup file, where the n variables correspond one-to-one to n preset information.
[0072] For example, each of the n variables is used to represent the name of corresponding preset information. The preset information can be pre-set. For example, the preset information can be device information of a device that requires a microcontroller to be installed. The device information may include the device's boot version, download version, DIGA version, etc. n is a positive integer.
[0073] The startup file is a file in the development file of the microcontroller. The startup file is a modifiable file, which is used to initialize the stack pointer and program counter pointer, set the stack size, set the entry address of the exception vector table, etc. when developing the microcontroller.
[0074] For example, if you need to store device information named downloadVersion, productVersion, and diagVersion, add variable declarations for downloadVersion, productVersion, and diagVersion to the startup file. For example, the terminal can add the following statements to the startup file to declare these variables: EXTERN downloadVersion, EXTERN productVersion, EXTERNdiagVersion. The EXTERN modifier modifies the variable declaration. That is, the EXTERN modifier is used before the variable declaration to indicate that the variable is defined elsewhere and is to be referenced here.
[0075] After the terminal adds the variable declaration of each of the n variables in the startup file, it may further allocate storage space for each of the n variables, that is, it may continue to execute the following step 102 .
[0076] Step 102: The terminal stores the n variables one by one in the n first addresses of the stack in the startup file.
[0077] The n first addresses are addresses in the stack, and the n first addresses are used to indicate storage locations of the n variables in the stack. Each of the n first addresses stores one of the n variables.
[0078] In this case, the terminal allocates n first addresses to the n variables in the stack and stores the n variables one by one in the n first addresses, so that each of the n variables has a storage location in the stack.
[0079] Specifically, the stack of the startup file includes reserved addresses, and the operation of step 102 may be: the terminal stores the n variables one by one in n first addresses in the reserved addresses of the stack.
[0080] The reserved address is a fixed address space in the stack, and each address in the reserved address is not allocated, that is, each address in the reserved address does not store data.
[0081] In this case, the terminal can select n addresses from the reserved addresses of the stack as the first addresses, and then store the n variables one by one in the n first addresses in the reserved addresses of the stack. In this way, the n variables can be stored in the stack without affecting other data addresses in the stack.
[0082] For example, if you need to store device information named downloadVersion, after adding the variable declaration of downloadVersion in the startup file, the terminal needs to store the downloadVersion variable in the reserved address of the stack. If the address range of the reserved address of the stack is 32-64, the first address 32 can be allocated to the downloadVersion variable in the reserved address of the stack to store the downloadVersion variable in the first address 32. For example, the terminal can store the downloadVersion variable in the first address 32 by adding the following statement in the first address 32: DCD downloadVersion. DCD is a data definition pseudo-instruction, which is used to allocate a continuous word storage unit and initialize it with specified data.
[0083] Step 103: The terminal adds a variable definition for each of the n variables to the startup file. The variable definition for each of the n variables specifies the initial value of each variable as corresponding preset information. The startup file is compiled to generate an executable file that can be burned into the microcontroller. During compilation, the n first addresses of the startup file are mapped one-to-one to n unoccupied second addresses in the memory of the microcontroller. The n second addresses indicate the storage location of the n preset information in the memory.
[0084] For example, for the downloadVersion variable, the device information corresponding to the downloadVersion variable is the DOWNLOAD version of the device. Assuming that the DOWNLOAD version of the device is V01.02, the terminal can add the variable definition of the downloadVersion variable through the following statement: const unsigned char downloadVersion[] = "V01.02" to specify that the initial value of the downloadVersion variable is V01.02.
[0085] In this case, the terminal adds the variable definition of each of the n variables in the startup file. After mapping the n first addresses to the n second addresses, the initial value (i.e., the corresponding preset information) specified by the variable definition of each of the n variables can be subsequently stored in the n second addresses, that is, the n preset information can be stored one by one in the n second addresses.
[0086] It is worth noting that the terminal can add a code statement for storing preset information to the startup file through the above steps 101 to 103. For example, after adding the code statement for storing preset information, the part of the content in the startup file obtained is as follows: Figure 2shown.
[0087] Figure 2 This is a schematic diagram of the startup file. Figure 2 The structure includes three parts: declaration part 201, stack part 202, and variable definition part 203. Declaration part 201 is used to declare multiple variables; stack part 202 is used to allocate stack addresses for multiple variables, including the variables declared in declaration part 201; and variable definition part 203 is used to define the initial values of the multiple variables declared.
[0088] Figure 2 Module?cstartup is used to mark the beginning of the code, meaning the terminal begins execution from the next code statement after Module?cstartup. In declaration section 201, the terminal adds code statements declaring the downloadVersion, diagVersion, and productVersion variables corresponding to the preset information. In the reserved addresses in stack section 202, the terminal adds code statements allocating stack addresses for the downloadVersion, diagVersion, and productVersion variables: DCD downloadVersion, DCD diagVersion, and DCD productVersion. This means the downloadVersion, diagVersion, and productVersion variables are stored one by one in the reserved addresses on the stack. DCD sfe(CSTACK) is used to indicate the top of the stack. In variable definition section 203, the initial values of the downloadVersion, diagVersion, and productVersion variables are defined, specifying the initial values of the downloadVersion, diagVersion, and productVersion variables to be the corresponding preset information V01.02, V01.01, and device generation 1, respectively.
[0089] Furthermore, after the terminal adds the code statement storing the preset information to the startup file through steps 101 to 103, the startup file is obtained. Thereafter, when the terminal needs to develop a single-chip microcomputer, it can compile the startup file to obtain an executable file. The operation of compiling the startup file can be performed by a compiler in the terminal.
[0090] During the compilation process, the terminal obtains the top address of the stack; obtains the target address mapped by the top address in the memory of the microcontroller; and maps the n first addresses to the n second addresses one by one according to the top address and the target address.
[0091] The stack top address refers to the address of the starting position in the stack. For example, the stack top address is generally 0.
[0092] The target address refers to the address in the memory of the microcontroller to which the terminal maps the top address of the stack when compiling the startup file.
[0093] Among them, the operation of the terminal obtaining the target address mapped by the top of the stack address in the memory can be: if there are m consecutive addresses in the memory that are not occupied, the terminal uses the first address of the m addresses as the target address mapped by the top of the stack address, m is the total number of addresses of the stack, and m is an integer greater than or equal to 2.
[0094] During the compilation process, the terminal searches for m consecutive unoccupied addresses in the memory. If there are m consecutive unoccupied addresses in the memory, it means that the m addresses in the memory can store the data in all addresses in the stack. Therefore, the terminal uses the first address of the m addresses as the target address for mapping the top address of the stack, and thus the data in the stack is stored starting from the first address of the m addresses.
[0095] In this case, the terminal can ensure that the data of all addresses in the stack can be stored in the m addresses by using the first address of m consecutive unoccupied addresses in the memory as the target address, that is, as the target address for mapping the top of the stack address. In this case, the terminal can ensure that the data of all addresses in the stack can be stored in the m addresses, that is, it can ensure that the n variables in the n first addresses in the stack can be stored in n addresses among the m unoccupied addresses.
[0096] Among them, the operation of the terminal mapping n first addresses to n second addresses one by one according to the top address of the stack and the target address can be: for each of the n first addresses, the following operations are performed: the terminal obtains the address difference between a first address and the top address of the stack as the specified address difference; and uses the address among the m addresses whose address difference with the target address is the specified address difference as a second address mapped to this first address.
[0097] In this case, the terminal obtains the address difference between a first address and the stack top address, thereby obtaining the address difference between the variable at the first address in the stack and the data at the stack top address, that is, the specified address difference. The specified address difference is mapped to the address of the memory, and the address difference between the target address and the address mapped to the memory by the first address is equal to the specified address difference. Therefore, the terminal uses the address of the m addresses that has an address difference of the specified address difference with the target address as a second address mapped to the first address, thereby obtaining the storage address of the preset information corresponding to the variable at the first address in the memory.
[0098] In this way, the terminal can obtain the storage addresses of n preset information corresponding to the n variables in the memory by performing the above operation on each of the n first addresses.
[0099] Furthermore, after the terminal compiles the startup file to obtain an executable file, the terminal can also burn the executable file into the single chip microcomputer.
[0100] In this case, the single-chip microcomputer executes the executable file at startup to implement the operations of declaring the n variables and storing the initial value specified in the variable definition of each of the n variables (i.e., the corresponding preset information) in the second address mapped to the first address where each variable is located in the stack. In other words, the single-chip microcomputer executes the executable file at startup, and when executing the executable file, each of the n preset information is stored in the corresponding second address in the memory. The second address corresponding to each preset information is the second address mapped to the first address where the variable corresponding to this preset information is located in the stack.
[0101] Furthermore, after executing the executable file, the single chip microcomputer can also save n second addresses to the memory so that the n preset information can be read accordingly when needed.
[0102] It is worth noting that after the single chip microcomputer is installed in the device, the technician can view the n preset information at any time. Specifically, the terminal obtains n second addresses from the memory of the single chip microcomputer; and obtains the preset information stored at each of the n second addresses in the memory.
[0103] In this way, the terminal can obtain the preset information stored in each of the n second addresses through the n second addresses, and then the terminal displays the obtained n preset information on the display screen for the technician to view.
[0104] It is noteworthy that the information storage method provided by the embodiment of the present application is to realize the storage of preset information by modifying the startup file. Since the code statements in the startup file are relatively simple, it is relatively easy for technical personnel to learn, so it is simpler for technical personnel to modify the startup file than to modify the link configuration file, which can improve work efficiency. In addition, since almost every compiler and every single-chip microcomputer has a startup file, modifying the startup file can be completed within the compiler's project without modifying external files, thereby not only reducing workload and improving work efficiency, but also eliminating the need to change the information storage method provided by the embodiment of the present application after replacing the compiler. In addition, the storage address of the preset information in the memory is not fixed in the method of modifying the startup file. The storage address of the preset information in the memory is automatically allocated according to the unoccupied address in the memory during the compilation process of the startup file, so it can be easily transplanted to the development platform of other single-chip microcomputers. It can be seen from this that the embodiment of the present application uses a simpler, more convenient and more efficient way to store preset information, which is simple to operate, easy to maintain, and can more intuitively view the stored preset information.
[0105] In an embodiment of the present application, the terminal adds a variable declaration for each of the n variables in the startup file, and stores the n variables one by one in the n first addresses in the stack of the startup file, and then adds a variable definition for each of the n variables in the startup file, and the variable definition of each variable is used to specify the initial value of each variable as the corresponding device information. When the startup file is compiled, the n first addresses are mapped one by one to the n unoccupied second addresses in the memory of the microcontroller, so that when the executable file compiled by the startup file is subsequently executed, the preset information corresponding to the variable in each of the n first addresses can be stored in the corresponding second address in the memory of the microcontroller. In this case, the startup file does not specify a fixed storage address for the preset information in the memory of the microcontroller, but the unoccupied second address in the memory of the microcontroller is automatically allocated to the preset information when the startup file is compiled. Therefore, the startup file has good portability, that is, the startup file can be used normally after being transplanted to the development file of other microcontrollers.
[0106] Figure 3 This is a schematic diagram of the structure of a device information storage device provided by an embodiment of the present application. The device information storage device can be implemented as part or all of a computer device by software, hardware, or a combination of both. The computer device can be the following Figure 4 Computer equipment shown. Figure 3 The device includes: a first adding module 301, a storage module 302, and a second adding module 303.
[0107] A first adding module 301 adds a variable declaration of each of n variables in the startup file, wherein the n variables correspond one-to-one to n preset information, and n is a positive integer;
[0108] A storage module 302 stores the n variables one by one in n first addresses of a stack in the startup file, where the n first addresses are used to indicate storage locations of the n variables in the stack;
[0109] A second adding module 303 adds a variable definition of each of the n variables in the startup file, where the variable definition of each variable is used to specify an initial value of each variable as corresponding preset information;
[0110] Among them, the startup file is used to obtain an executable file that can be burned into the microcontroller after compilation. When compiling, the n first addresses of the startup file are mapped one by one to the n unoccupied second addresses in the memory of the microcontroller, and the n second addresses are used to indicate the storage location of the n preset information in the memory.
[0111] Optionally, the stack includes a reserved address, and the storage module 302 is used to:
[0112] The n variables are stored one by one in n first addresses in the reserved addresses of the stack.
[0113] Optionally, the device further comprises:
[0114] A compilation module, used for compiling the startup file to obtain the executable file;
[0115] A first acquisition module is used to obtain the stack top address of the stack during the compilation process; and obtain the target address mapped by the stack top address in the memory;
[0116] A mapping module is used to map the n first addresses to n second addresses one by one according to the stack top address and the target address.
[0117] Optionally, the first acquisition module is used to:
[0118] If there are m consecutive addresses in the memory that are not occupied, then the first address among the m addresses is used as the target address for stack top address mapping, where m is the total number of addresses in the stack and m is an integer greater than or equal to 2;
[0119] Optionally, the mapping module is used to:
[0120] For each of the n first addresses, the following operations are performed:
[0121] Obtaining an address difference between a first address and a stack top address as a specified address difference;
[0122] An address among the m addresses, the address of which the address difference from the target address is a specified address difference, is used as a second address of the first address mapping.
[0123] Optionally, the device further comprises:
[0124] A burning module, used for burning the executable file into the single chip microcomputer;
[0125] Among them, the executable file is executed when the microcontroller is started, and when the executable file is executed, each of the n preset information is stored in the corresponding second address in the memory, and the second address corresponding to each preset information is the second address mapped to the first address of the variable corresponding to each preset information in the stack.
[0126] Optionally, the device further comprises:
[0127] A second acquisition module, configured to acquire n second addresses from the memory;
[0128] The third acquisition module is configured to acquire the preset information stored at each of the n second addresses in the memory.
[0129] Optionally, the preset information is device information of a device on which the single chip microcomputer is installed.
[0130] In an embodiment of the present application, a variable declaration for each of n variables is added to the startup file, and the n variables are stored one by one in the n first addresses in the startup file's stack. A variable definition for each of the n variables is then added to the startup file, and the variable definition for each variable is used to specify the initial value of each variable as the corresponding device information. When the startup file is compiled, the n first addresses are mapped one by one to n unoccupied second addresses in the microcontroller's memory, so that when the executable file compiled from the startup file is subsequently executed, the preset information corresponding to the variable in each of the n first addresses can be stored in the corresponding second address in the microcontroller's memory. In this case, the startup file does not specify a fixed storage address for the preset information in the microcontroller's memory. Instead, the preset information is automatically allocated to an unoccupied second address in the microcontroller's memory when the startup file is compiled. Therefore, the startup file has good portability, meaning that the startup file can be used normally after being ported to the development files of other microcontrollers.
[0131] It should be noted that: when the device information storage device provided in the above embodiment stores preset information, it only uses the division of the above-mentioned functional modules as an example. In actual applications, the above-mentioned functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above.
[0132] The functional units and modules in the above embodiments may be integrated into a single processing unit, or each unit may exist physically separately, or two or more units may be integrated into a single unit. The above integrated units may be implemented in the form of hardware or software functional units. In addition, the specific names of the functional units and modules are only for the purpose of distinguishing them from each other and are not intended to limit the scope of protection of the embodiments of this application.
[0133] The device information storage apparatus and information storage method embodiments provided in the above embodiments belong to the same concept. The specific working processes and technical effects brought about by the units and modules in the above embodiments can be found in the method embodiment part and will not be repeated here.
[0134] Figure 4 This is a schematic diagram of the structure of a computer device provided in an embodiment of the present application. Figure 4 As shown, the computer device 4 includes: a processor 40, a memory 41, and a computer program 42 stored in the memory 41 and executable on the processor 40. When the processor 40 executes the computer program 42, the steps of the information storage method in the above embodiment are implemented.
[0135] The computer device 4 can be a general-purpose computer device or a dedicated computer device. In a specific implementation, the computer device 4 can be a desktop computer, a portable computer, a handheld computer, a tablet computer, etc. The embodiment of the present application does not limit the type of the computer device 4. Those skilled in the art will understand that Figure 4 This is merely an example of the computer device 4 and does not constitute a limitation on the computer device 4 . The computer device 4 may include more or fewer components than shown in the figure, or a combination of certain components, or different components. For example, the computer device 4 may also include input and output devices, network access devices, etc.
[0136] The processor 40 may be a central processing unit (CPU), or may be another general-purpose processor, a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor may be a microprocessor or any conventional processor.
[0137] In some embodiments, the memory 41 may be an internal storage unit of the computer device 4, such as a hard disk or memory of the computer device 4. In other embodiments, the memory 41 may also be an external storage device of the computer device 4, such as a plug-in hard disk, a Smart Media Card (SMC), a Secure Digital (SD) card, a flash memory card, etc. equipped on the computer device 4. Furthermore, the memory 41 may include both an internal storage unit of the computer device 4 and an external storage device. The memory 41 is used to store an operating system, application programs, a boot loader, data, and other programs. The memory 41 may also be used to temporarily store data that has been output or is about to be output.
[0138] An embodiment of the present application also provides a computer device, which includes: at least one processor, a memory, and a computer program stored in the memory and executable on the at least one processor, wherein the processor implements the steps of any of the above-mentioned method embodiments when executing the computer program.
[0139] An embodiment of the present application further provides a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, the steps in the above-mentioned method embodiments can be implemented.
[0140] An embodiment of the present application provides a computer program product, which, when executed on a computer, enables the computer to execute the steps in the above-mentioned various method embodiments.
[0141] If the integrated unit is implemented as a software functional unit and sold or used as a standalone product, it can be stored in a computer-readable storage medium. Based on this understanding, the present application can implement all or part of the processes in the above-mentioned method embodiments by using a computer program to instruct the relevant hardware. The computer program can be stored in a computer-readable storage medium. When executed by a processor, the computer program can implement the steps of each of the above-mentioned method embodiments. The computer program includes computer program code, which can be in source code form, object code form, executable file, or some intermediate form. The computer-readable medium can at least include: any entity or device capable of carrying the computer program code to the camera / terminal device, recording medium, computer memory, ROM (Read-Only Memory), RAM (Random Access Memory), CD-ROM (Compact Disc Read-Only Memory), magnetic tape, floppy disk, and optical data storage device. The computer-readable storage medium mentioned in the present application can be a non-volatile storage medium, in other words, a non-transitory storage medium.
[0142] It should be understood that all or part of the steps for implementing the above embodiments may be implemented using software, hardware, firmware, or any combination thereof. When implemented using software, all or part of the steps may be implemented in the form of a computer program product. The computer program product may include one or more computer instructions. The computer instructions may be stored in the above-mentioned computer-readable storage medium.
[0143] In the above embodiments, the description of each embodiment has its own focus. For parts that are not described or recorded in detail in a certain embodiment, reference can be made to the relevant description of other embodiments.
[0144] Those skilled in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.
[0145] In the embodiments provided in this application, it should be understood that the disclosed apparatus / computer equipment and methods can be implemented in other ways. For example, the apparatus / computer equipment embodiments described above are merely schematic. For example, the division of modules or units is merely a logical function division. In actual implementation, there may be other division methods, such as 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 through some interfaces, indirect coupling or communication connection of the apparatus or unit, which can be electrical, mechanical or other forms.
[0146] Units described as separate components may or may not be physically separate, and components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of these units may be selected to achieve the purpose of this embodiment according to actual needs.
[0147] The above-described embodiments are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. These modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the various embodiments of the present application, and should all be included in the scope of protection of the present application.
Claims
1. An information storage method, characterized in that: The method comprises: Add a variable declaration for each of n variables in the startup file, wherein the n variables correspond one-to-one to n preset information, and n is a positive integer; Storing the n variables one by one in n first addresses of a stack in the startup file, wherein the n first addresses are used to indicate storage locations of the n variables in the stack; Adding a variable definition of each of the n variables in the startup file, wherein the variable definition of each variable is used to specify an initial value of each variable as corresponding preset information; The startup file is used to obtain an executable file that can be burned into the single-chip microcomputer after compilation. When the startup file is compiled, the n first addresses are mapped one by one to n unoccupied second addresses in the memory of the single-chip microcomputer, and the n second addresses are used to indicate the storage location of the n preset information in the memory; The preset information is the device information of the device on which the single chip microcomputer is installed, and the device information includes the startup version, download version, and diagnostic version of the device.
2. The method according to claim 1, wherein The stack includes a reserved address, and the storing of the n variables one by one in the n first addresses of the stack in the startup file includes: The n variables are stored one by one in the n first addresses in the reserved addresses of the stack.
3. The method according to claim 1, wherein After adding the variable definition of each of the n variables in the startup file, the method further includes: Compiling the startup file to obtain the executable file; During the compilation process, the top address of the stack is obtained; the target address mapped by the top address in the memory is obtained; and according to the top address and the target address, the n first addresses are mapped one by one to the n second addresses.
4. The method according to claim 3, wherein The obtaining of a target address mapped in the memory by the stack top address includes: If there are m consecutive addresses in the memory that are not occupied, then use the first address of the m addresses as the target address of the stack top address mapping, where m is the total number of addresses of the stack, and m is an integer greater than or equal to 2; The mapping of the n first addresses to the n second addresses one by one according to the stack top address and the target address includes: For each of the n first addresses, the following operations are performed: Obtaining an address difference between the first address and the stack top address as a specified address difference; An address among the m addresses, the address of which the address difference from the target address is the specified address difference, is used as a second address mapped to the first address.
5. The method according to claim 3, wherein After compiling the startup file to obtain the executable file, the method further includes: Burning the executable file to the single chip microcomputer; In which, the executable file is executed when the microcontroller is started, and when the executable file is executed, each of the n preset information is stored in the corresponding second address in the memory, and the second address corresponding to each preset information is the second address mapped to the first address of the variable corresponding to each preset information in the stack.
6. The method according to claim 5, wherein The single chip microcomputer is used to save the n second addresses to the memory after executing the executable file. After burning the executable file to the single chip microcomputer, the method further includes: Obtaining the n second addresses from the memory; Acquire preset information stored at each of the n second addresses in the memory.
7. A device information storage device, characterized in that: The device comprises: A first adding module adds a variable declaration of each of n variables in the startup file, wherein the n variables correspond one-to-one to n preset information, and n is a positive integer; a storage module, storing the n variables one by one in n first addresses of the stack in the startup file, wherein the n first addresses are used to indicate storage locations of the n variables in the stack; A second adding module is configured to add a variable definition of each of the n variables to the startup file, wherein the variable definition of each variable is used to specify an initial value of each variable as corresponding preset information; The startup file is used to obtain an executable file that can be burned into the single-chip microcomputer after compilation. When the startup file is compiled, the n first addresses are mapped one by one to n unoccupied second addresses in the memory of the single-chip microcomputer, and the n second addresses are used to indicate the storage location of the n preset information in the memory; The preset information is the device information of the device on which the single chip microcomputer is installed, and the device information includes the startup version, download version, and diagnostic version of the device.
8. A computer device, characterized in that: The computer device includes a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program implements the method according to any one of claims 1 to 6 when executed by the processor.
9. A computer-readable storage medium, characterized in that The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method according to any one of claims 1 to 6 is implemented.
Citation Information
Patent Citations
Embedded memory multiplexing method
CN103077017A
Memory executing method for executable file
CN104820612A
A BootLoader code reuse method in embed system and development board
CN108958795A