A variable management method and device

By first running the initialization function assignment and obtaining the structure address when the ECU is powered on, the problem of EEPROM read value coverage and low efficiency of single variable management is solved, efficient management of variables and low error probability are achieved, and the operation process is simplified.

CN112596769BActive Publication Date: 2024-10-22WEICHAI POWER CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202011543213.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-12-21
Publication Date
2024-10-22
Estimated Expiration
2040-12-21

AI Technical Summary

Technical Problem

In automotive electronic control units (ECUs), there is a problem that the EEPROM read value is overwritten during the initialization and assignment of variables, and single variable management is inefficient and error-prone, resulting in high maintenance costs.

Method used

When the ECU is powered on, it first runs the initialization function of the variable to assign the initial value to the variable, obtains the first address and effective length of the structure in the memory, then reads from the EEPROM and assigns the value to the corresponding variable, and manages the variables in the form of a structure. to simplify EEPROM functions and improve operating efficiency.

Benefits of technology

By running the initial value assignment logic first to prevent the EEPROM read value from being overwritten, structure management reduces maintenance costs and error probability, and improves code execution efficiency and ease of operation.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN112596769B_ABST
    Figure CN112596769B_ABST
Patent Text Reader

Abstract

The present invention discloses a variable management method and device, the method comprising: when receiving a power-on instruction, running the initialization function of each variable in the ECU to assign the initial value to the corresponding variable; obtaining the first address and effective length of the structure used to manage each variable in the ECU in the memory; reading the storage value of each variable from the EEPROM according to the first address and effective length and assigning it to the corresponding variable. By managing the initial value at the logic where the variable is located, the function of the EEPROM is simplified, and the initial value assignment logic is run first each time, and then the EEPROM reading logic is run, so as to avoid the problem of the EEPROM reading value being overwritten due to the error code in terms of timing; by managing the variable with the structure, only the first address needs to be maintained, so as to ensure that each member is continuous in address and has a fixed relative relationship with the first address, which can solve the problem that a single variable management needs to maintain multiple mapping relationships with the EEPROM, and reduce the maintenance cost and the probability of error.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of automobile technology, and in particular to a variable management method and device. Background Art

[0002] In the field of automotive electronics, when the ECU (Electronic Control Unit) is powered off, the variable values ​​of the variables in the ECU (such as running time, fuel consumption, DPF (particulate trap) carbon load, etc.) need to be stored in the EEPROM (Programmable Read-Only Memory). When the ECU is powered on again, it needs to read the last stored variable values ​​from the EEPROM first, complete the initialization assignment of the corresponding variables, and then execute the logic of the initialization function where the variable logic is located.

[0003] However, for the order of first executing EEPROM read to complete the variable assignment operation, and then running the variable initialization function, if there is any operation on the variable in the initialization function, it may cause the EEPROM read value to be overwritten by the initial value, and the variables in the ECU are managed as single variables, and each variable has a corresponding EEPROM address in the EEPROM. In this way, when assigning variables, single variables are operated one by one, and the operation efficiency is low. In addition, a single variable needs to maintain more information, which is prone to errors. Summary of the invention

[0004] The purpose of the present invention is to propose a variable management method and device to address the deficiencies of the above-mentioned prior art, and this purpose is achieved through the following technical solutions.

[0005] A first aspect of the present invention provides a variable management method, the method comprising:

[0006] When receiving the power-on command, the initialization function of each variable in the ECU is run to assign the initial value to the corresponding variable;

[0007] Get the first address and effective length of the structure used to manage each variable in the ECU in memory;

[0008] The storage value of each variable is read from the EEPROM according to the first address and the effective length, and the storage value is assigned to the corresponding variable.

[0009] A second aspect of the present invention provides a variable management device, the device comprising:

[0010] The initialization module is used to run the initialization function of each variable in the ECU when receiving the power-on command to assign the initial value to the corresponding variable;

[0011] The acquisition module is used to obtain the first address and effective length of the structure used to manage various variables in the ECU in the memory;

[0012] The reading and assigning module is used to read the storage value of each variable from the EEPROM according to the first address and the effective length, and assign the storage value to the corresponding variable.

[0013] Based on the variable management method and device described in the first and second aspects above, the present invention has the following beneficial effects:

[0014] By managing the default initial value at the logic where the variable is located, the function of the EEPROM is simplified. Each time, the default initial value assignment logic is run first, and then the EEPROM reading logic is run to avoid the problem of the EEPROM reading value being overwritten due to erroneous code in terms of timing. By managing all variables in the form of a structure, only the first address needs to be maintained to ensure that each variable member is continuous in address and has a fixed relative relationship with the first address. This can solve the problem that a single variable management needs to maintain multiple mapping relationships with the EEPROM, reducing maintenance costs and the probability of errors. At the same time, since the structure is continuous in memory and can correspond one-to-one with the EEPROM, it is possible to operate on a section of memory area, simplifying the operation while improving code execution efficiency and reducing the possibility of errors. BRIEF DESCRIPTION OF THE DRAWINGS

[0015] The drawings described herein are used to provide a further understanding of the present invention and constitute a part of the present invention. The exemplary embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute an improper limitation of the present invention. In the drawings:

[0016] Figure 1 This is a flow chart of an embodiment of a variable management method according to an exemplary embodiment of the present invention;

[0017] Figure 2 A hardware structure diagram of an electronic device according to an exemplary embodiment of the present invention;

[0018] Figure 3 It is a schematic structural diagram of a variable management device according to an exemplary embodiment of the present invention. DETAILED DESCRIPTION

[0019] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present invention. Instead, they are merely examples of devices and methods consistent with some aspects of the present invention as detailed in the appended claims.

[0020] The terms used in the present invention are only for the purpose of describing specific embodiments and are not intended to limit the present invention. The singular forms "a", "the" and "the" used in the present invention and the appended claims are also intended to include plural forms unless the context clearly indicates other meanings. It should also be understood that the term "and / or" used herein refers to and includes any or all possible combinations of one or more associated listed items.

[0021] It should be understood that although the terms first, second, third, etc. may be used in the present invention to describe various information, these information should not be limited to these terms. These terms are only used to distinguish the same type of information from each other. For example, without departing from the scope of the present invention, the first information may also be referred to as the second information, and similarly, the second information may also be referred to as the first information. Depending on the context, the word "if" as used herein may be interpreted as "at the time of" or "when" or "in response to determining".

[0022] In the prior art, EEPROM is used to store variables that need to be stored after the ECU is powered off. These variables need to be stored in EEPROM before the ECU is powered off. When the ECU is powered on again, it is necessary to read the last stored value from the EEPROM to complete the initialization assignment of the corresponding variables. In order to better manage these variables, it is necessary to fix the position of the corresponding variables in the EEPROM so that when the program version is updated, the variable values ​​previously stored in the EEPROM can be used normally; and each variable has a fixed default initial value, and is also managed separately on the EEPROM. When there is a problem with the EEPROM reading value, a reasonable initial value can be given to the variable to ensure that the ECU can operate normally.

[0023] However, the prior art has the following problems:

[0024] (1) In the ECU, since the location of each variable in the EEPROM needs to be maintained, the maintenance information is relatively large, and the mapping relationship between variables and EEPROM is manually processed, which is prone to errors;

[0025] (2) When performing variable assignment operations, only individual variables can be operated one by one, which results in low operation efficiency;

[0026] (3) If the variable assignment operation is performed first, and then the initialization function of the logic where the variable is located is run, if there is any operation on the variable in the initialization function, it may cause the initial value read from the EEPROM to be overwritten.

[0027] In order to solve the above technical problems, the present invention proposes an improved variable management method. After the ECU is powered on, the initialization function of the logic where the variable is located is first run to assign the initial value managed by the initialization function to the variable, and then the first address and effective length of the structure used to manage all variables in the memory are obtained, and then the storage value of the variable is read from the EEPROM according to the first address and effective length and assigned to the corresponding variable.

[0028] Based on the above description, it can be known that by managing the default initial value at the logic where the variable is located, the function of the EEPROM is simplified. Each time, the default initial value assignment logic is run first, and then the EEPROM reading logic is run, so as to avoid the problem of the EEPROM reading value being overwritten by the erroneous code in terms of timing; by managing all variables in the form of a structure, only the first address needs to be maintained, so as to ensure that each variable member is continuous in address and has a fixed relative relationship with the first address, which can solve the problem that a single variable management needs to maintain multiple mapping relationships with the EEPROM, reducing maintenance costs and the probability of errors. At the same time, because the structure is continuous in memory and can correspond one-to-one with the EEPROM, it is possible to operate on a section of memory area, simplifying the operation while improving the code execution efficiency and reducing the possibility of errors.

[0029] The variable management method proposed by the present invention is described in detail below with reference to specific embodiments.

[0030] Figure 1 FIG. 1 is a flow chart of an embodiment of a variable management method according to an exemplary embodiment of the present invention. The variable management method can be applied to an electronic device, which can be an ECU of an engine, or can be an electronic device specifically used to implement variable management, such as Figure 1 As shown, the variable management method includes the following steps:

[0031] Step 101: When a power-on command is received, the initialization function of each variable in the ECU is run to assign an initial value to the corresponding variable.

[0032] Among them, the management of initial values ​​is carried out by the logic where the variables are located, and the initial value assignment operation is uniformly placed in the initialization function of the logic where the variables are located to ensure that the ECU can operate normally when the logic is run for the first time and when there is a problem with the EEPROM. Therefore, the EEPROM is only used to store the variable values ​​and variable assignments of the variables, and the initial value management is not performed, which simplifies the function of the EEPROM.

[0033] It should be noted that the stored value in the EEPROM is the variable value stored when the ECU was last powered off, such as running time, fuel consumption, etc. The initial value of the variable is a preset fixed value. When there is a problem with the EEPROM and the stored variable value cannot be read, a reasonable initial value can be given to the variable to ensure the normal operation of the ECU.

[0034] Step 102: Obtain the first address and effective length of the structure used to manage various variables in the ECU in the memory.

[0035] Among them, for the variables that need to be stored in EEPROM, they are managed in the form of a structure. Each member variable in the structure corresponds one-to-one to the corresponding physical EEPROM. In this way, you only need to know the EEPROM address corresponding to the first address of the structure to fix the address of the variable members inside the structure, that is, the address of each variable member is relative to the first address of the structure, and the variable members also exist continuously. In this way, the problem of manual address management of a single variable is avoided from the data structure, which facilitates the management of variables.

[0036] It should be noted that the EEPROM address corresponding to the first address of the structure is the starting address when reading the EEPROM, and the effective length of the structure is the amount read when reading the EEPROM. As shown in Table 1 below, the first column is the physical address in the EEPROM corresponding to each member variable in the structure EE, and the second column is the member variables managed by the structure EE: EE.LENGTH (length is 1 byte), EE.CHECKSUM (length is 4 bytes), EE.A (length is 1 byte), EE.B (length is 4 bytes), EE.C (length is 4 bytes), and the effective length of the structure EE is 14 bytes.

[0037]

[0038] Table 1

[0039] It should be further explained that since the variables in the ECU are managed as structures, the length of the variables can be changed at any time. That is, when an instruction for changing the length of a variable is received, the effective length of the structure and the length corresponding to the variable are updated according to the variable length carried by the instruction.

[0040] Step 103: Read the storage value of each variable from the EEPROM according to the first address and the effective length, and assign the storage value to the corresponding variable.

[0041] In some embodiments, based on the description of step 102 above, for the process of reading the storage value of each variable from the EEPROM according to the starting address and the effective length, the EEPROM address corresponding to the starting address is first obtained, and then in the EEPROM, with the EEPROM address as the starting address, the storage data of the effective length is read, so that the storage value of each variable can be obtained from the storage data according to the position of each variable in the structure and the corresponding length.

[0042] In one example, taking structure EE as an example, the read command for storing data may be Memcpy(&EE,&EEPROM,LENGTH), where LENGTH is the effective length of the structure, &EE is the first address of the structure, and &EEPROM is the EEPROM address corresponding to the first address.

[0043] For example, as shown in Table 1 above, the LENGTH variable is the first member variable of the structure, and the corresponding length is 1 byte, so the first byte of the stored data is obtained as the storage value of the LENGTH variable; the CHECKSUM variable is the second member variable of the structure, and the corresponding length is 4 bytes, so the second byte to the fifth byte of the stored data is obtained as the storage value of the CHECKSUM variable; the A variable is the third member variable of the structure, and the corresponding length is 1 byte, so the sixth byte of the stored data is obtained as the storage value of the A variable; the B variable is the fourth member variable of the structure, and the corresponding length is 4 bytes, so the seventh byte to the tenth byte of the stored data is obtained as the storage value of the B variable; the C variable is the fifth member variable of the structure, and the corresponding length is 4 bytes, so the eleventh byte to the fourteenth byte of the stored data is obtained as the storage value of the C variable.

[0044] It should be noted that after reading the storage value of each variable from the EEPROM according to the starting address and the effective length, the storage value of each variable can also be verified for each variable. If the verification is successful, the step of assigning the storage value to the corresponding variable is executed. If the verification fails, the assignment operation is not performed.

[0045] It is understandable that the process of verifying the stored value is a rationality check, which can be implemented using relevant technologies and is not limited in the present invention.

[0046] For the process from step 101 to step 103 above, assume that the initial value of the EE.A variable is 4, and perform the assignment operation of EE.A=4 in the initialization function. After the ECU is powered on, first execute the initialization function of the logic where the EE.A variable is located, so that EE.A=4, and then perform the EEPROM read assignment operation. For example, the value of the EE.A variable last uploaded and stored is 10. When the EEPROM is read successfully and the verification is successful, perform the operation EE.A=10; if the EEPROM fails to read or verify, no assignment operation is performed on the EEPROM, and the value of the EE.A variable is kept at the default initial value 4.

[0047] It can be seen that the EEPROM is only responsible for reading the stored information, and the initial value when an error occurs is managed in the logic, avoiding the problem of the EEPROM read value being overwritten in the existing solution.

[0048] At this point, the above Figure 1 The process shown, through Figure 1 The process shown simplifies the function of EEPROM by managing the default initial value at the logic where the variable is located. Each time, the default initial value assignment logic is run first, and then the EEPROM reading logic is run to avoid the problem of EEPROM reading value being overwritten due to erroneous code in terms of timing. By managing all variables in the form of a structure, only the first address needs to be maintained, so that each variable member can be guaranteed to be continuous in address and have a fixed relative relationship with the first address. The problem that a single variable management needs to maintain multiple mapping relationships with EEPROM can be solved, reducing maintenance costs and the probability of errors. At the same time, because the structure is continuous in memory and can correspond one-to-one with EEPROM, it is possible to operate on a section of memory area, simplifying the operation while improving code execution efficiency and reducing the possibility of errors.

[0049] Figure 2 This is a hardware structure diagram of an electronic device according to an exemplary embodiment of the present invention, and the electronic device includes: a communication interface 401, a processor 402, a machine-readable storage medium 403, and a bus 404; wherein the communication interface 401, the processor 402, and the machine-readable storage medium 403 communicate with each other through the bus 404. The processor 402 can execute the variable management method described above by reading and executing the machine executable instructions corresponding to the control logic of the variable management method in the machine-readable storage medium 403. The specific content of the method is referred to the above embodiment, and will not be repeated here.

[0050] The machine-readable storage medium 403 mentioned in the present invention can be any electronic, magnetic, optical or other physical storage device, which can contain or store information, such as executable instructions, data, etc. For example, the machine-readable storage medium can be: volatile memory, non-volatile memory or similar storage medium. Specifically, the machine-readable storage medium 403 can be RAM (Random Access Memory), flash memory, storage drive (such as hard disk drive), any type of storage disk (such as optical disk, DVD, etc.), or similar storage medium, or a combination thereof.

[0051] Corresponding to the above-mentioned embodiment of the variable management method, the present invention also provides an embodiment of the variable management device.

[0052] Figure 3 FIG. 1 is a flow chart of an embodiment of a variable management device according to an exemplary embodiment of the present invention. The control device can be applied to electronic devices, such as Figure 3 As shown, the variable management device includes:

[0053] The initialization module 310 is used to run the initialization function of each variable in the ECU to assign the initial value to the corresponding variable when receiving the power-on command;

[0054] An acquisition module 320 is used to acquire the first address and effective length of a structure in memory used to manage various variables in the ECU;

[0055] The reading and assigning module 330 is used to read the storage value of each variable from the EEPROM according to the first address and the effective length, and assign the storage value to the corresponding variable.

[0056] In an optional implementation, the read assignment module 330 is specifically used to obtain the EEPROM address corresponding to the first address during the process of reading the storage value of each variable from the EEPROM according to the first address and the effective length; in the EEPROM, using the EEPROM address as the starting address, read the storage data of the effective length; and obtain the storage value of each variable from the storage data according to the position of each variable in the structure and the corresponding length.

[0057] In an optional implementation, the device further includes ( Figure 3 Not shown):

[0058] The verification module is used to verify the storage value of each variable after the read assignment module 330 reads the storage value of each variable from the EEPROM according to the first address and the effective length; if the verification is successful, the step of assigning the storage value to the corresponding variable is executed.

[0059] In an optional implementation, the device further includes ( Figure 3 Not shown):

[0060] The length changing module is used to update the effective length of the structure and the length corresponding to the variable according to the variable length carried by the instruction when receiving an instruction for changing the length of a variable.

[0061] The implementation process of the functions and effects of each unit in the above-mentioned device is specifically described in the implementation process of the corresponding steps in the above-mentioned method, and will not be repeated here.

[0062] For the device embodiment, since it basically corresponds to the method embodiment, the relevant parts can refer to the partial description of the method embodiment. The device embodiment described above is only schematic, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of the present invention. Ordinary technicians in this field can understand and implement it without paying creative work.

[0063] Those skilled in the art will readily appreciate other embodiments of the present invention after considering the specification and practicing the invention disclosed herein. The present invention is intended to cover any variations, uses or adaptations of the present invention that follow the general principles of the present invention and include common knowledge or customary techniques in the art not disclosed by the present invention. The description and examples are to be regarded as exemplary only, and the true scope and spirit of the present invention is indicated by the following claims.

[0064] It should also be noted that the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, commodity or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, commodity or device. In the absence of more restrictions, the elements defined by the sentence "comprises a ..." do not exclude the existence of other identical elements in the process, method, commodity or device including the elements.

[0065] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present invention should be included in the scope of protection of the present invention.

Claims

1. A variable management method, characterized in that: The method comprises: When receiving a power-on command, an initialization function at the logic location of each variable in the electronic control unit ECU is run to assign an initial value to the corresponding variable, wherein the variable is an ECU variable, and an initial value assignment operation of the corresponding variable is defined in the initialization function; Obtain the first address and effective length of a structure in memory used to manage each variable in the ECU; wherein the structure records the EEPROM address used to store the value of each variable, the EEPROM address stored at the first address of the structure is the starting address when reading the variable value, and the effective length of the structure is the read length; each member variable in the structure corresponds to the corresponding EEPROM one by one; The storage value of each variable is read from the EEPROM according to the first address and the effective length, and the storage value is assigned to the corresponding variable.

2. The method according to claim 1, characterized in that The step of reading the storage value of each variable from the EEPROM according to the first address and the effective length comprises: Obtain the EEPROM address corresponding to the first address; In the EEPROM, taking the EEPROM address as the starting address, reading the stored data of the effective length; According to the position of each variable in the structure and the corresponding length, the storage value of each variable is obtained from the storage data.

3. The method according to claim 1, characterized in that After reading the stored value of each variable from the EEPROM according to the first address and the effective length, the method further comprises: For each variable, verify the stored value of the variable; If the verification is successful, the step of assigning the stored value to the corresponding variable is executed.

4. The method according to claim 1, characterized in that: The method further comprises: When an instruction for changing the length of a variable is received, the effective length of the structure and the length corresponding to the variable are updated according to the variable length carried by the instruction.

5. A variable management device, characterized in that: The device comprises: An initialization module, for running an initialization function at the logic location of each variable in the electronic control unit ECU upon receiving a power-on instruction, so as to assign an initial value to the corresponding variable, wherein the variable is an ECU variable, and an initial value assignment operation of the corresponding variable is defined in the initialization function; An acquisition module is used to acquire the first address and effective length of a structure used to manage various variables in the ECU in the memory; wherein the structure records the EEPROM address used to store the value of each variable, the EEPROM address stored in the first address of the structure is the starting address when reading the variable value, and the effective length of the structure is the read length; each member variable in the structure corresponds to the corresponding EEPROM one by one; The reading and assigning module is used to read the storage value of each variable from the EEPROM according to the first address and the effective length, and assign the storage value to the corresponding variable.

6. The device according to claim 5, characterized in that The reading and assigning module is specifically used to obtain the EEPROM address corresponding to the first address in the process of reading the stored value of each variable from the EEPROM according to the first address and the effective length; in the EEPROM, taking the EEPROM address as the starting address, reading the stored data of the effective length; According to the position of each variable in the structure and the corresponding length, the storage value of each variable is obtained from the storage data.

7. The device according to claim 5, characterized in that The device also includes: The verification module is used to verify the storage value of each variable for each variable after the read assignment module reads the storage value of each variable from the EEPROM according to the first address and the effective length; if the verification is successful, the step of assigning the storage value to the corresponding variable is executed.

8. The device according to claim 5, characterized in that The device also includes: The length changing module is used to update the effective length of the structure and the length corresponding to the variable according to the variable length carried by the instruction when receiving an instruction for changing the length of a variable.