Method, device and equipment for sharing memory of single-chip microcomputer and medium

By dividing parameter address tables and dynamic application of RAM memory in the microcontroller, creating a shared memory parameter address block header list, the naming difficulty, duplicate name and resource waste of global variables when data interaction in the microcontroller is solved, efficient development and maintenance are achieved, and RAM usage is improved.

CN119597499APending Publication Date: 2025-03-11TUOBAO XINNENG (XIAMEN) TECHNOLOGY CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411573042.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-06
Publication Date
2025-03-11

AI Technical Summary

Technical Problem

In a microcontroller environment, using global variables for data interaction has problems such as high difficulty in naming variables, serious variable names, poor maintainability, waste of RAM resources and large programming volume.

Method used

By dividing the parameter address table into different parameter blocks, and dynamically applying for RAM memory, creating a shared memory parameter address block header list to realize the reading or modification of parameter values, variable definition is avoided.

Benefits of technology

Improve development efficiency, reduce maintenance difficulty, facilitate modularization, increase readability, and improve RAM usage.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119597499A_ABST
    Figure CN119597499A_ABST
Patent Text Reader

Abstract

The invention discloses a memory sharing method for a single-chip microcomputer, which comprises the following steps: step 1, a parameter address table is divided and defined into different parameter blocks according to the function of parameters, parameter address codes among the parameter blocks are discontinuous, the parameter address codes in the parameter blocks must be continuous, and the parameter address codes in the parameter address table cannot be repeated; 2, dynamically applying for an RAM (Random Access Memory) from the single-chip microcomputer according to the total size of the parameter address table; step 3, retrieving partitions of the parameter address table, creating a shared memory parameter address block head linked list according to partition conditions, and recording linked list information; and step 4, reading or modifying parameter values according to the linked list information and / or the parameter address codes. According to the method, variable definition is not needed, so that the defects caused by data interaction by using global variables are overcome.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of embedded systems, and in particular to a method, device, equipment and medium for single-chip microcomputer shared memory. Background Art

[0002] In the environment of single-chip microcomputer, C language is mostly used, and its RAM space is limited. It is mostly process-oriented programming, and generally uses global variables to realize data interaction between different threads or tasks. For example, in the energy storage system, EMS needs to obtain PCS, battery and other data, and transmit them to the background monitoring. The data of PCS and battery in the whole process is stored in global variables, which is convenient for updating and obtaining data for downward communication and upward communication tasks.

[0003] Currently, this method of using global variables for data interaction has the following defects: Variable naming is difficult. That is, when using global variables, you need to name the variables first. This step is also the most time-consuming, critical, and troublesome step. In order to better maintain the program, variable names are usually composed of English abbreviations or full spellings. However, in many industries, such as new energy, power electronics, etc., many proper nouns cannot be translated into variable names using abbreviations, but only full spellings, which results in lengthy variable names that are difficult to program and understand.

[0004] The phenomenon of duplicate variable names is serious. Since the variable names are named using the abbreviation + full spelling method, as the functions continue to increase, there will be more and more variables with the same or similar names, which is not friendly to later maintenance personnel and makes it difficult to read the code.

[0005] Poor maintainability. When using global variables for data interaction, if the meaning of the variable changes, not only do you need to modify the variable name to avoid misunderstandings by subsequent maintainers, but you also need to replace all old variable names. If there are multiple levels of pointer calls or duplicate variable names, it will increase the difficulty for maintainers to understand, resulting in poor maintainability.

[0006] Waste of RAM resources. After the program is compiled, global variables will occupy RAM space. Even if they are not used, they will still occupy RAM space, leading to insufficient resources.

[0007] The amount of programming is large. Due to the use of global variables, it is inevitable to assign values ​​to variables one by one during programming. The more global variables there are, the greater the workload. Summary of the invention

[0008] The technical problem to be solved by the present invention is to provide a method, device, equipment and medium for single-chip microcomputer shared memory, which does not require variable definition, thereby overcoming the disadvantages of using global variables for data interaction.

[0009] In a first aspect, the present invention provides a method for single-chip computer shared memory, characterized in that it includes: Step 1: Divide the parameter address table into different parameter blocks according to the function of the parameter. The parameter address codes between parameter blocks are not continuous. The parameter address codes within a parameter block must be continuous, and the parameter address codes in the parameter address table cannot be repeated. Step 2: Dynamically request a RAM memory from the microcontroller based on the total size of the parameter address table; Step 3: Retrieve the partition of the parameter address table, and create a shared memory parameter address block header linked list according to the partition situation, and record the linked list information; Step 4: Read or modify the parameter value according to the linked list information and / or the parameter address code.

[0010] In a second aspect, the present invention provides a device for sharing memory of a single-chip microcomputer, comprising: Parameter block division module: used to divide the parameter address table into different parameter blocks according to the function of the parameter. The parameter address codes between parameter blocks are not continuous. The parameter address codes within a parameter block must be continuous, and the parameter address codes in the parameter address table cannot be repeated. The application module is used to dynamically apply for a RAM memory from the microcontroller according to the total size of the parameter address table; Create a module, retrieve the partition of the parameter address table, and create a shared memory parameter address block header linked list according to the partition situation, and record the linked list information; A reading module is used to read or modify the parameter value according to the linked list information and / or the parameter address code.

[0011] In a third aspect, the present invention provides an electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the method described in the first aspect when executing the program.

[0012] In a fourth aspect, the present invention provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the method described in the first aspect.

[0013] One or more technical solutions provided by the present invention have at least the following technical effects or advantages: (1) Improve development efficiency: There is no need to define variables. Address encoding can be performed directly according to the protocol content, reducing the workload of variable naming and improving development efficiency.

[0014] (2) Reduce maintenance difficulty: If you need to add parameters later, you only need to modify the parameter table. There is no need to modify the variable name or perform global replacement.

[0015] (3) Easy to implement modularization: Since this solution applies for memory based on the device, the subsequent addition or deletion of devices will have little impact on the program, thus reducing the coupling of the program.

[0016] (4) Improve readability: Since shared memory address encoding is used, each parameter is a parameter code, and there is no possibility of duplicate parameter names.

[0017] (5) Improve RAM utilization: Since the shared memory of this solution is created only when it is needed, it will not occupy RAM space all the time, unlike global variables that require memory space regardless of whether they are used. And due to the dynamic creation feature, it can be created in the mode that the device needs to use, and can be released when it is not needed, which increases the RAM space utilization.

[0018] The above description is only an overview of the technical solution of the present invention. In order to more clearly understand the technical means of the present invention, it can be implemented according to the contents of the specification. In order to make the above and other purposes, features and advantages of the present invention more obvious and easy to understand, the specific implementation methods of the present invention are listed below. BRIEF DESCRIPTION OF THE DRAWINGS

[0019] The present invention will be further described below in conjunction with embodiments with reference to the accompanying drawings.

[0020] Figure 1 is a flow chart of the method in Embodiment 1 of the present invention; Figure 2 A schematic diagram of a process of converting a "parameter address table" corresponding to a device into a shared memory in an embodiment of the present invention; Figure 3 Schematic diagram of the correspondence between the parameter address code of the parameter address table and the shared memory address in an embodiment of the present invention; Figure 4 A flowchart of creating a single-chip microcomputer shared memory in the method of embodiment 1 of the present invention; Figure 5 A schematic diagram of the corresponding relationship of the shared memory parameter index linked list and the contents of the linked list in an embodiment of the present invention; Figure 6 This is a flow chart of obtaining or writing to the shared memory of a single-chip microcomputer in an embodiment of the present invention; Figure 7 It is a structural schematic diagram of the device in the second embodiment of the present invention; Figure 8 This is a schematic diagram of the structure of an electronic device in Embodiment 3 of the present invention; Fig. 9 Schematic diagram of the structure of the medium in the fourth embodiment of the present invention. DETAILED DESCRIPTION

[0021] The embodiments of the present application provide a method, apparatus, device and medium for sharing memory of a single-chip microcomputer, which eliminates the need for variable definition and thus overcomes the disadvantages of using global variables for data interaction.

[0022] The technical solution in the embodiment of the present application has the following general idea: first, the parameter address table is divided into several independent parameter blocks according to the function of the parameter, and then, based on the total size of the parameter address table, a RAM memory area of ​​the corresponding size is applied to the single-chip microcomputer as a shared memory area. Subsequently, by traversing the parameter address table, a header linked list of the shared memory parameter address block is created according to the defined parameter block, and the corresponding linked list information is recorded. Finally, the application can read or modify the parameter value by querying the linked list information or directly using a specific parameter address code. There is no need to define variables, and address encoding can be performed directly according to the protocol content, reducing the workload of variable naming, improving development efficiency, and there is no case of parameter duplication; since the scheme applies for memory in units of devices, when adding or deleting devices later, the impact on the program is small, reducing the coupling degree of the program; since the shared memory of the scheme is created only when it is needed, the utilization rate of RAM is greatly improved.

[0023] Embodiment 1 like Figure 1 As shown, this embodiment provides a method for single-chip microcomputer shared memory, including: Step 1: Divide the parameter address table into different parameter blocks according to the function of the parameter. The parameter address codes between parameter blocks are not continuous. The parameter address codes within a parameter block must be continuous, and the parameter address codes in the parameter address table cannot be repeated. The parameter address code is unique. During the retrieval, the unique corresponding shared memory address is found according to the parameter address code.

[0024] Figure 2 In the example, the parameter address table is divided into three areas (the actual address length and partition can be distinguished according to the system situation. This example takes a 32-bit microcontroller as an example, so the address uses a 32-bit data size, which has the highest execution efficiency): Parameter address code 0x00000000-0x000000FF: system information block, used to store system information; Parameter address code 0x00050000-0x0005004F: sampling information block, used to store real-time sampling data such as PCS and battery; Parameter address code 0x000C0000-0x000C0100: Setting parameter block, used to store system setting information.

[0025] Step 2: Dynamically request a RAM memory from the microcontroller based on the total size of the parameter address table; like Figure 3As shown, the total size of the parameters (calculated based on one address representing one U8 data) is: (0x000000FF-0x00000000+1)+(0x0005004F-0x00050000+1)+(0x000C0100-0x000C0000+1)=0x251, so the total memory size requested is 0x251.

[0026] Among them, Figure 4 As shown, the specific process of creating a shared memory parameter address block header linked list is as follows: (1) Start by obtaining the device ID and device parameter table; (2) Create a device list List1 corresponding to the device ID; (3) Traverse the device parameter table, obtain the size of each parameter segment, and record it in the parameter block information list List2; (4) Accumulate the size of each parameter segment and calculate the total size of the device parameter; (5) Apply for memory based on the total size of the parameters and end.

[0027] Step 3: Retrieve the partition of the parameter address table, and create a shared memory parameter address block header linked list according to the partition situation, and record the linked list information; Figure 5 As shown, the linked list information includes: Device ID: Identifies the device to which this shared memory belongs. For example, 0x05 can be used for PCS and 0x06 can be used for battery. However, it can be omitted if there is only one device or you do not want to distinguish by device. RAM memory starting address, used to record the starting address of the RAM memory; such as 0x20001100; The total RAM memory size is used to record the total RAM memory size; The specific parameter table partition code information linked list is used to record the partition information of the parameter address table, and each parameter block corresponds to a linked list information; Figure 1 There are three parameter blocks in total, so there are three linked list information List21~List23. Each linked list information further includes: The parameter block starting parameter address code is used to record the starting parameter code of the parameter block. For example, the starting address of the sampling information block is 0x00050000. The starting RAM memory address of the parameter block is used to record the starting address of the parameter block in the RAM memory. For example, the RAM address corresponding to the sampling information is 0x20001200. The size of the parameter block is used to record the size of the RAM memory space occupied by this parameter block. For example, the RAM size of the sampling information block is 0x50.

[0028] Step 4: Read or modify the parameter value according to the linked list information and / or the parameter address code. Figure 5 As shown, if you want to query the current information of PCS, and the device id corresponding to PCS is 0x05, and the current parameter code is 0x00050010, then find the corresponding "shared memory parameter address block header list" List1 according to the device id 0x05, and then find the parameter information block list List21~23 according to the parameter code 0x00050010, and locate List22. At the same time, according to the starting parameter address code 0x00050000 of List22, the offset address 0x00050010-0x00050000=0x10 is calculated, and the actual current value is stored in the RAM address of "the starting RAM address of this parameter block" + the offset address, that is, the RAM address content of 0x20001200+0x10=0x20001210 is the current value.

[0029] Embodiment 2 Based on the same inventive concept, the present application also provides a device corresponding to the method in Example 1, see Example 2 for details.

[0030] like Figure 6 As shown, in this embodiment, a device for sharing memory of a single-chip microcomputer is provided, comprising: Parameter block division module: used to divide the parameter address table into different parameter blocks according to the function of the parameter. The parameter address codes between parameter blocks are not continuous. The parameter address codes within a parameter block must be continuous, and the parameter address codes in the parameter address table cannot be repeated. The application module is used to dynamically apply for a RAM memory from the microcontroller according to the total size of the parameter address table; Create a module, retrieve the partition of the parameter address table, and create a shared memory parameter address block header linked list according to the partition situation, and record the linked list information; the linked list information includes: Device ID: identifies the device to which this shared memory belongs, but can be omitted if there is only one device or if you do not want to distinguish by device; RAM memory starting address, used to record the starting address of the RAM memory; The total RAM memory size is used to record the total RAM memory size; The specific parameter table partition code information linked list is used to record the partition information of the parameter address table. Each parameter block corresponds to a linked list information; a linked list information further includes: The parameter block start parameter address code is used to record the start parameter code of the parameter block; The starting RAM memory address of the parameter block is used to record the starting address of the parameter block in the RAM memory; The size of the parameter block is used to record the size of the RAM memory space occupied by this parameter block.

[0031] A reading module is used to read or modify the parameter value according to the linked list information and / or the parameter address code.

[0032] Since the device introduced in the second embodiment of the present invention is a device used to implement the method of the first embodiment of the present invention, those skilled in the art can understand the specific structure and deformation of the device based on the method introduced in the first embodiment of the present invention, so it is not described here in detail. All devices used in the method of the first embodiment of the present invention belong to the scope of protection of the present invention.

[0033] Embodiment 3 Based on the same inventive concept, the present application provides an electronic device embodiment corresponding to the first embodiment, see the third embodiment for details. This embodiment provides an electronic device, such as Figure 7 As shown, it includes a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, any implementation method in the first embodiment can be implemented.

[0034] Since the electronic device introduced in this embodiment is a device used to implement the method in the first embodiment of the present application, based on the method introduced in the first embodiment of the present application, a person skilled in the art can understand the specific implementation of the electronic device of the present embodiment and its various variations, so how the electronic device implements the method in the embodiment of the present application is not described in detail here. As long as a person skilled in the art implements the device used by the method in the embodiment of the present application, it belongs to the scope of protection of the present application.

[0035] Embodiment 4 Based on the same inventive concept, this application provides a storage medium corresponding to Embodiment 1, see Embodiment 4 for details. This embodiment provides a computer-readable storage medium, such as Figure 8 As shown, a computer program is stored thereon, and when the computer program is executed by a processor, any implementation method in Example 1 can be implemented.

[0036] The technical solution provided in the embodiment of the present application has at least the following technical effects or advantages: no need to define variables, address encoding can be performed directly according to the content of the protocol, the workload of variable naming can be reduced, and development efficiency can be improved. If parameters need to be added later, only the parameter table needs to be modified, and there is no need to modify the variable name and the work of global replacement, which reduces the difficulty of maintenance. Since the scheme applies for memory in units of devices, it is convenient to realize modularization when adding or deleting devices later, which has little impact on the program and reduces the coupling degree of the program. Due to the use of shared memory address encoding, each parameter is a parameter code, and there is no situation of parameter duplication, which increases readability. Since the shared memory of the scheme is created when it is needed, it will not occupy RAM space all the time, unlike global variables, which require memory space regardless of whether it is used, and improve the utilization rate of RAM. And due to the characteristics of dynamic creation, it can be created in the mode that the device needs to use, and can be released when it is not needed, which increases the utilization rate of RAM space.

[0037] Those skilled in the art will appreciate that embodiments of the present invention may be provided as methods, systems, or computer program products. Therefore, the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0038] The present invention is described with reference to flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0039] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.

[0040] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 A step that specifies a function in one or more boxes.

[0041] Although the specific implementation modes of the present invention are described above, those skilled in the art should understand that the specific implementation modes described are only illustrative and are not intended to limit the scope of the present invention. Equivalent modifications and changes made by those skilled in the art in accordance with the spirit of the present invention should be included in the scope of protection of the claims of the present invention.

Claims

1. A method for single-chip microcomputer shared memory, characterized in that: include: Step 1: Divide the parameter address table into different parameter blocks according to the function of the parameter. The parameter address codes between parameter blocks are not continuous. The parameter address codes within a parameter block must be continuous, and the parameter address codes in the parameter address table cannot be repeated. Step 2: Dynamically request a RAM memory from the microcontroller based on the total size of the parameter address table; Step 3: Retrieve the partition of the parameter address table, and create a shared memory parameter address block header linked list according to the partition situation, and record the linked list information; Step 4: Read or modify the parameter value according to the linked list information and / or the parameter address code.

2. The method for sharing memory of a single chip microcomputer according to claim 1, characterized in that: The linked list information includes: Device ID: identifies the device to which this shared memory belongs, but can be omitted if there is only one device or if you do not want to distinguish by device; RAM memory starting address, used to record the starting address of the RAM memory; The total RAM memory size is used to record the total RAM memory size; The specific parameter table partition code information linked list is used to record the partition information of the parameter address table. Each parameter block corresponds to a linked list information; each linked list information further includes: The parameter block start parameter address code is used to record the start parameter code of the parameter block; The starting RAM memory address of the parameter block is used to record the starting address of the parameter block in the RAM memory; The size of the parameter block is used to record the size of the RAM memory space occupied by this parameter block.

3. A device for sharing memory of a single-chip microcomputer, characterized in that: include: Parameter block division module: used to divide the parameter address table into different parameter blocks according to the function of the parameter. The parameter address codes between parameter blocks are not continuous. The parameter address codes within a parameter block must be continuous, and the parameter address codes in the parameter address table cannot be repeated. The application module is used to dynamically apply for a RAM memory from the microcontroller according to the total size of the parameter address table; Create a module, retrieve the partition of the parameter address table, and create a shared memory parameter address block header linked list according to the partition situation, and record the linked list information; A reading module is used to read or modify the parameter value according to the linked list information and / or the parameter address code.

4. The device for sharing memory of a single chip microcomputer according to claim 3, characterized in that: The linked list information includes: Device ID: identifies the device to which this shared memory belongs, but can be omitted if there is only one device or if you do not want to distinguish by device; RAM memory starting address, used to record the starting address of the RAM memory; The total RAM memory size is used to record the total RAM memory size; The specific parameter table partition code information linked list is used to record the partition information of the parameter address table. Each parameter block corresponds to a linked list information; each linked list information further includes: The parameter block start parameter address code is used to record the start parameter code of the parameter block; The starting RAM memory address of the parameter block is used to record the starting address of the parameter block in the RAM memory; The size of the parameter block is used to record the size of the RAM memory space occupied by this parameter block.

5. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the program, the method according to claim 1 or 2 is implemented.

6. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method according to claim 1 or 2 is implemented.