A reliable data read-write method and system using EEPROM
By employing circular storage and data voting mechanisms in EEPROM, the problems of low storage efficiency and poor error recovery capability of EEPROM are solved, resulting in a longer service life and higher data read/write reliability.
Patent Information
- Application Number
- CN202511549509.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-10-28
- Publication Date
- 2026-01-27
- Estimated Expiration
- 2045-10-28
Smart Images

Figure CN121008758B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of data read and write technology, and more specifically, to a reliable data read and write method and system using EEPROM. Background Technology
[0002] EEPROM failures commonly fall into three categories: First, the number of erase / write cycles for a single byte reaches the maximum of 1 million, resulting in abnormal data being read. Second, a power outage occurs during the erase / write process of the EEPROM, leading to data write failure and the read data being abnormal. Third, the EEPROM's ability to trap electrons in the floating gate deteriorates. When the retention time of data in the repeatedly erased / written areas of the EEPROM decreases to within the power outage time, the probability of data failure increases significantly, and the failure probability continues to increase with the number of erase / write cycles.
[0003] Currently, some patents have proposed solutions to the problem of data failure in EEPROM storage. For example, patent application publication number CN113345497A proposes an EEPROM data storage method and system for micro-inverters. The storage area in the EEPROM is divided into N storage units. The power generation data acquired each time is sequentially stored into the storage units, and the storage sequence number corresponding to each storage is stored into the storage unit. When the micro-inverter restarts after a power failure, all storage sequence numbers are read. If there are M consecutive valid storage sequence numbers, the largest valid storage sequence number is obtained as the most recently stored valid storage sequence number, and the power generation data corresponding to this sequence number is the most recently stored data. The next storage unit after the most recently stored storage unit is designated as the current storage unit, and the current power generation data is stored in the current storage unit. The valid storage sequence number of the most recently stored data is incremented by one to obtain the current storage sequence number corresponding to the current storage unit, which is then stored in the current storage unit. This method utilizes the principle of circular storage, extending the usable space of the EEPROM in exchange for its lifespan. It also involves writing data, reading it, and verifying the result. By using circular space, the lifespan of the EEPROM is prolonged, and the read / write verification process ensures data accuracy. However, this method has the following three shortcomings: 1. If the stored sequence number after N writes exceeds the maximum value that the storage cell can store, the stored sequence number will be 0, leading to confusion in later logical judgments. 2. While reading and verifying data after writing accurately determines the validity of the written data, if the data retention time decreases to within the power-off time, the next read will result in an error. 3. After power-on, all data needs to be read and the stored sequence numbers sorted, a complex process.
[0004] Patent application publication number CN113342571A proposes a method for preventing EEPROM data loss during power failure in embedded systems. This method performs three backups on the data, performing differential comparisons on the data corresponding to the addresses to be written to the EEPROM before storage to reduce frequent EEPROM erases and writes. After rereading the first set of data, a CRC-16 check is performed. If the comparison results match, the data is used without further verification of the second and third sets. If the comparison results do not match, the second and even third sets of data are read for verification, and the lost data in the aforementioned EEPROM is rewritten. If it is used for the first time or all three backups are lost, the default safe data is used to ensure normal system operation. This method ensures data correctness through the principle of multiple backups and verification. This method has the following two shortcomings: 1. The data is always processed using three backups, and erases and writes are only performed at three fixed addresses. The information erased and written each time is the same, which is the original data plus a CRC-16 checksum. Performing the same storage operation on the storage unit increases the probability of synchronization failure. 2. If all three data validations fail, the default value can only be used, and the most recent record value cannot be recovered. Summary of the Invention
[0005] To address at least one of the aforementioned technical problems, the present invention aims to provide a reliable data read / write method and system using EEPROM. This invention solves the problems of low storage efficiency and poor error recovery capability in the prior art through cyclic storage and data voting mechanisms, thereby extending the lifespan of EEPROM and improving the reliability of data read / write.
[0006] The first aspect of this invention provides a reliable data read / write method using EEPROM, comprising:
[0007] In the EEPROM, a contiguous N-byte address space is allocated as a data storage area. Within this N-byte data storage area, data is stored... There are 4 data packets, where N is a multiple of 4 and M is a multiple of 4. ;
[0008] Each piece of data that needs to be stored is encapsulated into a complete data packet and stored sequentially in the corresponding storage unit. The storage sequence number in the data packet is incremented continuously. The remainder is used to obtain the final storage sequence number that needs to be stored;
[0009] After the microprocessor restarts, it reads the adjacent memory indices of the N bytes sequentially according to their address order. If the next memory indice read matches the current memory indice... If the remainder is not continuously increasing, then the current data is considered the latest data.
[0010] Use the next storage unit of the data packet corresponding to the current storage sequence number as the address of the next storage sequence number, and increment the value of the current storage sequence number by 1. After taking the remainder, the next storage sequence number value is obtained. The value of the latest sequence number is encapsulated into a data packet that needs to be stored and then written to overwrite the data before that address in the EEPROM.
[0011] The data packet consists of four parts: storage sequence number, original code of data, inverse code of data, and XOR code of data; the data packet is written sequentially into consecutive EEPROM storage areas during the storage process.
[0012] This plan also includes:
[0013] When the microprocessor is powered on for the first time, it calculates the data to be stored and obtains the inverse code and XOR code of the data. Then, it combines the storage sequence number, the original code of the data, the inverse code of the data, and the XOR code of the data into a data packet and writes it into the corresponding physical address of the EEPROM byte by byte.
[0014] This plan also includes:
[0015] When storing data for the second time, increment the storage sequence number from the first time by one, and then... After taking the remainder, the final storage sequence number is obtained. The data to be stored is then calculated using the inverse code and XOR code to obtain the corresponding data. The current data is then grouped into a data packet and written byte by byte to the address following the previous data packet.
[0016] And so on, until the first The data is stored at the following address: The data from the Nth storage unit is stored in storage units with addresses 1 to 4, overwriting the original stored data.
[0017] No. The storage sequence number, for After the modulo operation, the result is 1. At this point, the data packet is stored in memory units 5 to 8, overwriting the original stored data.
[0018] This plan also includes:
[0019] Read the original code A, the inverse code B, and the XOR code C of the data.
[0020] Calculate the inverse code A1 and the XOR code A2 of the value based on the original code A;
[0021] Determine whether A1 is equal to B and whether A2 is equal to C. If they are equal, count the number of equal pairs as n.
[0022] Determine if n is greater than or equal to 1. If n is greater than or equal to 1, then the data was read successfully and the true value of the data is A. Mark the location where the complement or XOR code that is not equal to the original code A is stored once.
[0023] If n is less than 1, then calculate the original code B1 and the XOR code B2 of the value based on the inverse code B;
[0024] Determine if B2 is equal to C. If they are equal, the data read is successful, and the corresponding data true value is the original code of B. Mark the storage location of the original code A once. If they are not equal, the data read fails.
[0025] In this solution, after the data read fails, the following steps are also included:
[0026] Repeatedly read the corresponding data and obtain the number of times the data reading failed;
[0027] If the number of times the data reading fails exceeds the preset threshold, the reading of the corresponding data will be stopped, and the data recovery program will be started to recover the corresponding data.
[0028] In this solution, the step of starting the data recovery program to recover the corresponding data specifically includes:
[0029] Extract the bit values from the original code A, the inverse code B, and the XOR code C of this data respectively;
[0030] Based on the preset weighted voting coefficients, the value of each bit is weighted and voted on to obtain the initial weighted value;
[0031] Based on the same position and the same bit value, the corresponding initial weighted values are accumulated to obtain the weighted value at the corresponding position;
[0032] Determine whether the weighted value at the current position is less than the preset weighted threshold. If so, delete the weighted value at the corresponding position; otherwise, save the weighted value at the corresponding position.
[0033] Determine the bit value at the corresponding position based on the saved weighted value;
[0034] Reassemble the bit values at all positions to construct a recovered data set;
[0035] The data corresponding to the recovered data, original code A, inverse code B, and XOR code C in the recovered data set are sent to the preset terminal for display.
[0036] In this scheme, the steps for obtaining the weighted voting coefficients specifically include:
[0037] Based on a preset sliding time window, obtain the number of times the storage location was marked and the number of times the data was read;
[0038] The probability of an error at the corresponding storage location is obtained by comparing the number of times the storage location was marked with the number of times the data was read.
[0039] Multiply the probability value of the storage location error by the corresponding weight coefficient to obtain the weighted voting coefficient revision value of the corresponding storage location;
[0040] The weighted voting coefficient of a storage location is obtained by subtracting the revised weighted voting coefficient of the corresponding storage location from the initial weighted voting coefficient of the storage location.
[0041] A second aspect of the present invention provides a reliable data read / write system using EEPROM, comprising a memory and a processor. The memory stores a program for a reliable data read / write method using EEPROM. When the processor executes the program for a reliable data read / write method using EEPROM, it performs the following steps:
[0042] In the EEPROM, a contiguous N-byte address space is allocated as a data storage area. Within this N-byte data storage area, data is stored... There are 4 data packets, where N is a multiple of 4 and M is a multiple of 4. ;
[0043] Each piece of data that needs to be stored is encapsulated into a complete data packet and stored sequentially in the corresponding storage unit. The storage sequence number in the data packet is incremented continuously. The remainder is used to obtain the final storage sequence number that needs to be stored;
[0044] After the microprocessor restarts, it reads the adjacent memory indices of the N bytes sequentially according to their address order. If the next memory indice read matches the current memory indice... If the remainder is not continuously increasing, then the current data is considered the latest data.
[0045] Use the next storage unit of the data packet corresponding to the current storage sequence number as the address of the next storage sequence number, and increment the value of the current storage sequence number by 1. After taking the remainder, the next storage sequence number value is obtained. The value of the latest sequence number is encapsulated into a data packet that needs to be stored and then written to overwrite the data before that address in the EEPROM.
[0046] The data packet consists of four parts: storage sequence number, original code of data, inverse code of data, and XOR code of data; the data packet is written sequentially into consecutive EEPROM storage areas during the storage process.
[0047] This plan also includes:
[0048] When the microprocessor is powered on for the first time, it calculates the data to be stored and obtains the inverse code and XOR code of the data. Then, it combines the storage sequence number, the original code of the data, the inverse code of the data, and the XOR code of the data into a data packet and writes it into the corresponding physical address of the EEPROM byte by byte.
[0049] This plan also includes:
[0050] When storing data for the second time, increment the storage sequence number from the first time by one, and then... After taking the remainder, the final storage sequence number is obtained. The data to be stored is then calculated using the inverse code and XOR code to obtain the corresponding data. The current data is then grouped into a data packet and written byte by byte to the address following the previous data packet.
[0051] And so on, until the first The data is stored at the following address: The data from the Nth storage unit is stored in storage units with addresses 1 to 4, overwriting the original stored data.
[0052] No. The storage sequence number, for After the modulo operation, the result is 1. At this point, the data packet is stored in memory units 5 to 8, overwriting the original stored data.
[0053] One or more technical solutions proposed in this application have at least the following technical effects:
[0054] This invention solves the problems of low storage efficiency and poor error recovery capability in the prior art by using circular storage and data voting mechanism, thereby extending the service life of EEPROM and improving the reliability of data reading and writing. Attached Figure Description
[0055] Figure 1 A flowchart illustrating a reliable data read / write method for EEPROM according to the present invention is shown.
[0056] Figure 2 A schematic diagram of the data storage of the present invention is shown;
[0057] Figure 3 A schematic diagram of the terminal data storage of the present invention is shown. Figure 1 ;
[0058] Figure 4 A schematic diagram of the terminal data storage of the present invention is shown. Figure 2 ;
[0059] Figure 5 A schematic diagram of the data voting process of this invention is shown;
[0060] Figure 6A block diagram of a reliable data read / write system using EEPROM according to the present invention is shown. Detailed Implementation
[0061] To better understand the above-mentioned objectives, features, and advantages of the present invention, the present invention will be further described in detail below with reference to the accompanying drawings and specific embodiments. It should be noted that, unless otherwise specified, the embodiments and features described in these embodiments can be combined with each other.
[0062] Many specific details are set forth in the following description in order to provide a full understanding of the invention. However, the invention may also be practiced in other ways different from those described herein, and therefore the scope of protection of the invention is not limited to the specific embodiments disclosed below.
[0063] Figure 1 A flowchart of a reliable data read / write method using EEPROM according to the present invention is shown.
[0064] like Figure 1 As shown, this invention discloses a reliable data read / write method using EEPROM, comprising:
[0065] S101, allocate a contiguous N-byte address space in the EEPROM as a data storage area for data storage. Within this N-byte data storage area, store... There are 4 data packets, where N is a multiple of 4 and M is a multiple of 4. ;
[0066] S102, each piece of data that needs to be stored is encapsulated into a complete data packet, and stored sequentially and cyclically into the corresponding storage unit. The storage sequence number in the data packet is continuously incremented, and the storage sequence number is... The remainder is used to obtain the final storage sequence number that needs to be stored;
[0067] S103, After the microprocessor restarts, it sequentially reads the adjacent memory indices of the N bytes according to address order. If the next memory indices read are different from the current memory indices... If the remainder is not continuously increasing, then the current data is considered the latest data.
[0068] S104, take the next storage unit of the data packet corresponding to the current storage sequence number as the address of the next storage sequence number, and increment the value of the current storage sequence number by 1. After taking the remainder, the next storage sequence number is obtained. The value of the latest sequence number is then encapsulated into a data packet that needs to be stored and written to overwrite the data before that address in the EEPROM.
[0069] According to an embodiment of the present invention, the data packet consists of four parts: storage sequence number, original code, inverse code, and XOR code. The data packet is written sequentially into consecutive EEPROM storage areas during the storage process. The inverse code is the bitwise inversion of the original code; for example, if the original code A is 0x3A (binary 00111010), then the corresponding binary inverse code B is 11000101. The XOR code is obtained by XORing the original code with a value; for example, if the value is 0x55, then the XOR code... ,in This indicates a bitwise XOR operation. For example, if the original code A is 0x3A, then the XOR code is... (Binary 01101111); When encapsulating data, each data packet includes a storage sequence number and data content (signature, complement, and XOR code); furthermore, if data has been previously stored at the storage location, the data with the latest sequence number will be overwritten on top of the previously stored data.
[0070] According to an embodiment of the present invention, it further includes:
[0071] When the microprocessor powers on for the first time, it calculates the first data to be stored, determining the data's complement and XOR code. Then, it combines the storage sequence number, the original data, the complement data, and the XOR code into a data packet, which is written byte-by-byte into the corresponding physical address in the EEPROM. Figure 2 As shown.
[0072] According to an embodiment of the present invention, it further includes:
[0073] When storing data for the second time, increment the storage sequence number from the first time by one, and then... After taking the remainder, the final storage sequence number is obtained. The data to be stored is then calculated using the inverse code and XOR code to obtain the corresponding data. The current data is then grouped into a data packet and written byte by byte to the address following the previous data packet.
[0074] And so on, until the first The data is stored at the following address: The data from the Nth storage unit is stored in storage units with addresses 1 to 4, overwriting the existing data. Figure 3 As shown;
[0075] No. The storage sequence number, for After the modulo operation, the result is 1. At this point, the data packet is stored in memory units 5 to 8, overwriting the original stored data.
[0076] It should be noted that, as Figure 4 As shown, the first The storage sequence number is the storage sequence number of the first iteration in the cycle with M as the reference.
[0077] Figure 5 A schematic diagram of the data voting process of the present invention is shown.
[0078] like Figure 5 As shown, according to an embodiment of the present invention, it further includes:
[0079] Read the original code A, the inverse code B, and the XOR code C of the data.
[0080] Calculate the inverse code A1 and the XOR code A2 of the value based on the original code A;
[0081] Determine whether A1 is equal to B and whether A2 is equal to C. If they are equal, count the number of equal pairs as n.
[0082] Determine if n is greater than or equal to 1. If n is greater than or equal to 1, then the data was read successfully and the true value of the data is A. Mark the location where the complement or XOR code that is not equal to the original code A is stored once.
[0083] If n is less than 1, then calculate the original code B1 and the XOR code B2 of the value based on the inverse code B;
[0084] Determine if B2 is equal to C. If they are equal, the data read is successful, and the corresponding data true value is the original code of B. Mark the storage location of the original code A once. If they are not equal, the data read fails.
[0085] It should be noted that if the original code, inverse code, and XOR code do not correspond, it indicates that the data reading has failed.
[0086] According to an embodiment of the present invention, after the data reading fails, the method further includes:
[0087] Repeatedly read the corresponding data and obtain the number of times the data reading failed;
[0088] If the number of times the data reading fails exceeds the preset threshold, the reading of the corresponding data will be stopped, and the data recovery program will be started to recover the corresponding data.
[0089] It should be noted that if a data reading fails, the data will be read again immediately. If the data is identified in the subsequent repeated reading process, the corresponding data is considered to have been read successfully. If the data reading still fails, the number of times the data reading fails is recorded. For example, if the preset threshold is 4 times, the reading of the corresponding data will stop when the number of times the data reading fails exceeds 4.
[0090] According to an embodiment of the present invention, the step of starting the data recovery program to recover the corresponding data specifically includes:
[0091] Extract the bit values from the original code A, the inverse code B, and the XOR code C of this data respectively;
[0092] Based on the preset weighted voting coefficients, the value of each bit is weighted and voted on to obtain the initial weighted value;
[0093] Based on the same position and the same bit value, the corresponding initial weighted values are accumulated to obtain the weighted value at the corresponding position;
[0094] Determine whether the weighted value at the current position is less than the preset weighted threshold. If so, delete the weighted value at the corresponding position; otherwise, save the weighted value at the corresponding position.
[0095] Determine the bit value at the corresponding position based on the saved weighted value;
[0096] Reassemble the bit values at all positions to construct a recovered data set;
[0097] The data corresponding to the recovered data, original code A, inverse code B, and XOR code C in the recovered data set are sent to the preset terminal for display.
[0098] It should be noted that in actual EEPROM use, due to slight differences in manufacturing processes and uneven wear, the error rates of different storage locations vary significantly. Therefore, different weighted voting coefficients are set for different storage locations to weight the bit values and determine the initial weighting value. For example, if the original code A is determined to be 10110101 (binary), the inverse code B is determined to be 01001010, and the XOR code C is determined to be 11100111, and the weighted voting coefficient for the storage location corresponding to the original code A is 0.9, the weighted voting coefficient for the storage location corresponding to the inverse code B is 1, and the weighted voting coefficient for the storage location corresponding to the XOR code C is 0.9, then the weighting value for the first bit with a value of 1 in the above binary code is 0.9 + 1 = 1.9, and the weighting value for the first bit with a value of 0 is 1. For example, if the preset weighting threshold is 1, then the first bit has two possibilities: 0 and 1. The possible values of each bit are recombined to obtain the binary storage address corresponding to the recovered data.
[0099] According to an embodiment of the present invention, it further includes:
[0100] Extract adjacent data from the storage location of the data that failed to be read;
[0101] The data corresponding to the recovered data, original code A, inverse code B and XOR code C in the recovered data set are compared and analyzed with the adjacent data to obtain the data correlation degree.
[0102] The recovered data, the original code A, the inverse code B, and the XOR code C in the recovered data set are displayed sequentially on the preset terminal in descending order of data correlation.
[0103] It should be noted that when there are two adjacent data corresponding to the failed data, the data correlation between them is taken. For example, if the recovered data a has two adjacent data a1 and a2, and the correlation between the recovered data a and adjacent data a1 is 80%, and the correlation between the recovered data a and adjacent data a2 is 50%, then the data correlation between the recovered data a and adjacent data is set to 80%.
[0104] According to an embodiment of the present invention, the step of obtaining the weighted voting coefficient specifically includes:
[0105] Based on a preset sliding time window, obtain the number of times the storage location was marked and the number of times the data was read;
[0106] The probability of an error at the corresponding storage location is obtained by comparing the number of times the storage location was marked with the number of times the data was read.
[0107] Multiply the probability value of the storage location error by the corresponding weight coefficient to obtain the weighted voting coefficient revision value of the corresponding storage location;
[0108] The weighted voting coefficient of a storage location is obtained by subtracting the revised weighted voting coefficient of the corresponding storage location from the initial weighted voting coefficient of the storage location.
[0109] It should be noted that the weighting coefficient is a value greater than or equal to 1; for example, if the preset sliding time window is 24 hours, then the current time is used as the base point to extract the number of times the storage location is read and marked within 24 hours.
[0110] According to an embodiment of the present invention, it further includes:
[0111] If no data is read from the storage location within the current sliding time window, then extract the historical sliding time window that read the data and the historical weighted voting coefficient of the corresponding historical sliding time window;
[0112] Extract the time difference between the current time point and the last time point in the historical sliding time window;
[0113] Multiply the time difference by a preset time decay coefficient to obtain the first value;
[0114] Subtract the first value from the historical weighted voting coefficient to obtain the weighted voting coefficient at the current time node.
[0115] It should be noted that when there are multiple historical sliding time windows for reading the data, the historical sliding time window closest to the current time is used as the benchmark; when there is no historical sliding time window for reading the data, the weighted voting coefficient of the corresponding storage location at the current time node is obtained by subtracting the first value from the initial weighted voting coefficient of the corresponding storage location; the initial weighted voting coefficient of the storage location is set to 1.
[0116] According to an embodiment of the present invention, it further includes:
[0117] If the weighted voting coefficient of a storage location is less than the preset weighted voting coefficient threshold, then the corresponding storage location is set as a non-storage location, and the number of the non-storage location is extracted.
[0118] Divide the N storage regions into intervals using 4 as a base to obtain numbered intervals;
[0119] The non-storage interval is determined based on the number interval into which the non-storage location's number falls;
[0120] Non-storage areas are sealed to stop storing data.
[0121] It should be noted that, for example, if the weighted voting coefficient of storage location number 5 is less than the preset weighted voting coefficient threshold, then storage location number 5 will be set as a non-storage location. The numbering interval will be divided with 4 as the base, and can be divided into... Then the storage location numbered 5 falls into Numbering range, then numbering range This is a non-storage area.
[0122] According to an embodiment of the present invention, it further includes:
[0123] The number of non-storage intervals is obtained in real time. If there are adjacent non-storage intervals, non-storage interval reconstruction is triggered to optimize storage space.
[0124] The step of triggering non-storage interval reconstruction to optimize storage space specifically includes: extracting the numbers of adjacent non-storage intervals, sorting the numbers from smallest to largest, and reconstructing the storage intervals based on 4.
[0125] It should be noted that non-storage locations are not included in the sorting scope. For example, if there are two non-storage ranges, respectively... and Among them, numbers 5 and 11 are non-storage locations. Deleting the corresponding numbers of these non-storage locations will reconstruct the storage range for numbers 6, 7, 8, 9, 10, and 12. Subsequent storage location numbers will then replace the deleted non-storage location numbers. For example, replacing original number 5 with original number 6, replacing original number 6 with original number 7, and so on, will reconstruct the storage range. If the remaining storage location number is less than 4, it will be left idle.
[0126] Figure 6 A block diagram of a reliable data read / write system using EEPROM according to the present invention is shown.
[0127] like Figure 6 As shown, a second aspect of the present invention provides a reliable EEPROM data read / write system 6, including a memory 61 and a processor 62. The memory stores a program for a reliable EEPROM data read / write method. When the processor executes the program for a reliable EEPROM data read / write method, it performs the following steps:
[0128] In the EEPROM, a contiguous N-byte address space is allocated as a data storage area. Within this N-byte data storage area, data is stored... There are 4 data packets, where N is a multiple of 4 and M is a multiple of 4. ;
[0129] Each piece of data that needs to be stored is encapsulated into a complete data packet and stored sequentially in the corresponding storage unit. The storage sequence number in the data packet is incremented continuously. The remainder is used to obtain the final storage sequence number that needs to be stored;
[0130] After the microprocessor restarts, it reads the adjacent memory indices of the N bytes sequentially according to their address order. If the next memory indice read matches the current memory indice... If the remainder is not continuously increasing, then the current data is considered the latest data.
[0131] Use the next storage unit of the data packet corresponding to the current storage sequence number as the address of the next storage sequence number, and increment the value of the current storage sequence number by 1. After taking the remainder, the next storage sequence number value is obtained. The value of the latest sequence number is encapsulated into a data packet that needs to be stored and then written to overwrite the data before that address in the EEPROM.
[0132] The data packet consists of four parts: storage sequence number, original code of data, inverse code of data, and XOR code of data; the data packet is written sequentially into consecutive EEPROM storage areas during the storage process.
[0133] This plan also includes:
[0134] When the microprocessor is powered on for the first time, it calculates the data to be stored and obtains the inverse code and XOR code of the data. Then, it combines the storage sequence number, the original code of the data, the inverse code of the data, and the XOR code of the data into a data packet and writes it into the corresponding physical address of the EEPROM byte by byte.
[0135] This plan also includes:
[0136] When storing data for the second time, increment the storage sequence number from the first time by one, and then... After taking the remainder, the final storage sequence number is obtained. The data to be stored is then calculated using the inverse code and XOR code to obtain the corresponding data. The current data is then grouped into a data packet and written byte by byte to the address following the previous data packet.
[0137] And so on, until the first The data is stored at the following address: The data from the Nth storage unit is stored in storage units with addresses 1 to 4, overwriting the original stored data.
[0138] No. The storage sequence number, for After the modulo operation, the result is 1. At this point, the data packet is stored in memory units 5 to 8, overwriting the original stored data.
[0139] This invention discloses a reliable data read / write method and system using EEPROM. The invention allocates a contiguous N-byte address space in the EEPROM as a data storage area. Within this N-byte data storage area, (M-1) data packets are stored, where N is a multiple of 4. When reading data, adjacent storage sequence numbers in the N bytes are read sequentially according to address order. If the next storage sequence number read is not continuously increasing after taking the remainder of (M+1) with the current storage sequence number, then the current data is considered the latest data. The true value of the read data is determined using a voting method in the original code, inverse code, and XOR code of the stored data. This invention solves the problems of low storage efficiency and poor error recovery capability in existing technologies through circular storage and data voting mechanisms, extending the lifespan of the EEPROM and improving the reliability of data read / write.
[0140] In the several embodiments provided in this application, it should be understood that the disclosed devices and methods can be implemented in other ways. The device embodiments described above are merely illustrative. For example, the division of units is only a logical functional division, and 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. In addition, the coupling, direct coupling, or communication connection between the various components shown or discussed can be through some interfaces, and the indirect coupling or communication connection between devices or units can be electrical, mechanical, or other forms.
[0141] The units described above as separate components may or may not be physically separate. The components shown as units may or may not be physical units. They may be located in one place or distributed across multiple network units. Some or all of the units may be selected to achieve the purpose of this embodiment according to actual needs.
[0142] In addition, in the various embodiments of the present invention, each functional unit can be integrated into one processing unit, or each unit can be a separate unit, or two or more units can be integrated into one unit; the integrated unit can be implemented in hardware or in the form of hardware plus software functional units.
[0143] Those skilled in the art will understand that all or part of the steps of the above method embodiments can be implemented by hardware related to program instructions. The aforementioned program can be stored in a computer-readable storage medium. When the program is executed, it performs the steps of the above method embodiments. The aforementioned storage medium includes various media capable of storing program code, such as mobile storage devices, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0144] Alternatively, if the integrated units of this invention are implemented as software functional modules and sold or used as independent products, they can also be stored in a computer-readable storage medium. Based on this understanding, the technical solutions of the embodiments of this invention, or the parts that contribute to the prior art, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the methods described in the various embodiments of this invention. The aforementioned storage medium includes various media capable of storing program code, such as mobile storage devices, ROM, RAM, magnetic disks, or optical disks.
Claims
1. A reliable data read / write method using EEPROM, characterized in that, include: In the EEPROM, a contiguous N-byte address space is allocated as a data storage area. Within this N-byte data storage area, data is stored... There are 4 data packets, where N is a multiple of 4 and M is a multiple of 4. ; Each piece of data that needs to be stored is encapsulated into a complete data packet and stored sequentially in the corresponding storage unit. The storage sequence number in the data packet is incremented continuously. The remainder is used to obtain the final storage sequence number that needs to be stored; After the microprocessor restarts, it reads adjacent memory indices from the N bytes sequentially according to their address order. If the next memory indices read match the current memory indices... If the remainder is not continuously increasing, then the current data is considered the latest data. Use the next storage unit of the data packet corresponding to the current storage sequence number as the address of the next storage sequence number, and increment the value of the current storage sequence number by 1. After taking the remainder, the next storage sequence number is obtained. The value stored at the latest sequence number is then encapsulated into a data packet that needs to be stored, and the data before that address in the EEPROM is overwritten. The data packet consists of four parts: storage sequence number, original code of data, inverse code of data, and XOR code of data. Data packets are written sequentially to consecutive EEPROM storage areas during the storage process; Also includes: Read the original code A, the inverse code B, and the XOR code C of the data. Calculate the one's complement A1 and the XOR code A2 of the value based on the original code A; Determine whether A1 is equal to B and whether A2 is equal to C. If they are equal, count the number of equal pairs as n. Determine if n is greater than or equal to 1. If n is greater than or equal to 1, then the data was read successfully and the true value of the data is A. Mark the location where the one's complement or XOR code that is not equal to the original code A is stored once. If n is less than 1, then calculate the original code B1 and the XOR code B2 of the value based on the inverse code B; Determine if B2 is equal to C. If they are equal, the data read is successful, and the corresponding data true value is the original code of B. Mark the storage location of the original code A once. If they are not equal, the data read fails.
2. The reliable data read / write method using EEPROM according to claim 1, characterized in that, Also includes: When the microprocessor is powered on for the first time, it calculates the first data that needs to be stored to obtain the inverse code and XOR code of the data. The storage sequence number, original code of the data, inverse code of the data, and XOR code of the data are combined into a data packet and written byte by byte into the corresponding physical address of the EEPROM.
3. The reliable data read / write method using EEPROM according to claim 2, characterized in that, Also includes: When storing data for the second time, increment the storage sequence number from the first time by one, and then... After taking the remainder, the final storage sequence number is obtained. The data to be stored is then calculated using the inverse code and XOR code to obtain the corresponding data. The current data is then grouped into a data packet and written byte by byte to the address following the previous data packet. And so on, until the first The data is stored at the following address: The data is stored in storage unit N, and the Mth data is stored in storage units with addresses 1 to 4, overwriting the original stored data. No. The next storage sequence number, for The remainder is 1, at which point the data packet is stored in memory units 5 to 8, overwriting the original stored data.
4. The reliable data read / write method using EEPROM according to claim 1, characterized in that, Following the failure of this data retrieval, the following also applies: Repeatedly read the corresponding data and obtain the number of times the data reading failed; If the number of times the data reading fails exceeds the preset threshold, the reading of the corresponding data will be stopped, and the data recovery program will be started to recover the corresponding data.
5. A reliable data read / write method using EEPROM according to claim 4, characterized in that, The step of starting the data recovery program to recover the corresponding data specifically includes: Extract the bit values from the original code A, the inverse code B, and the XOR code C of this data respectively; Based on the preset weighted voting coefficients, the value of each bit is weighted and voted on to obtain the initial weighted value; Based on the same position and the same bit value, the corresponding initial weighted values are accumulated to obtain the weighted value at the corresponding position; Determine whether the weighted value at the current position is less than the preset weighted threshold. If so, delete the weighted value at the corresponding position; otherwise, save the weighted value at the corresponding position. Determine the bit value at the corresponding position based on the saved weighted value; Reassemble the bit values at all positions to construct a recovered data set; The data corresponding to the recovered data, original code A, inverse code B, and XOR code C in the recovered data set are sent to the preset terminal for display.
6. A reliable data read / write method using EEPROM according to claim 5, characterized in that, The steps for obtaining the weighted voting coefficients specifically include: Based on a preset sliding time window, obtain the number of times the storage location was marked and the number of times the data was read; The probability of an error at the corresponding storage location is obtained by comparing the number of times the storage location was marked with the number of times the data was read. Multiply the probability value of the storage location error by the corresponding weight coefficient to obtain the weighted voting coefficient revision value of the corresponding storage location; The weighted voting coefficient of a storage location is obtained by subtracting the revised weighted voting coefficient of the corresponding storage location from the initial weighted voting coefficient of the storage location.
7. A reliable data read / write system using EEPROM, characterized in that, The system includes a memory and a processor. The memory stores a program for a reliable data read / write method using EEPROM. When the processor executes the program for a reliable data read / write method using EEPROM, it performs the following steps: In the EEPROM, a contiguous N-byte address space is allocated as a data storage area. Within this N-byte data storage area, data is stored... There are 4 data packets, where N is a multiple of 4 and M is a multiple of 4. ; Each piece of data that needs to be stored is encapsulated into a complete data packet and stored sequentially in the corresponding storage unit. The storage sequence number in the data packet is incremented continuously. The remainder is used to obtain the final storage sequence number that needs to be stored; After the microprocessor restarts, it reads adjacent memory indices from the N bytes sequentially according to their address order. If the next memory indices read match the current memory indices... If the remainder is not continuously increasing, then the current data is considered the latest data. Use the next storage unit of the data packet corresponding to the current storage sequence number as the address of the next storage sequence number, and increment the value of the current storage sequence number by 1. After taking the remainder, the next storage sequence number is obtained. The value of the latest sequence number is encapsulated into a data packet that needs to be stored and then written to overwrite the data before that address in the EEPROM. The data packet consists of four parts: storage sequence number, original code of data, inverse code of data, and XOR code of data. Data packets are written sequentially to consecutive EEPROM storage areas during the storage process; Also includes: Read the original code A, the inverse code B, and the XOR code C of the data. Calculate the one's complement A1 and the XOR code A2 of the value based on the original code A; Determine whether A1 is equal to B and whether A2 is equal to C. If they are equal, count the number of equal pairs as n. Determine if n is greater than or equal to 1. If n is greater than or equal to 1, then the data was read successfully and the true value of the data is A. Mark the location where the one's complement or XOR code that is not equal to the original code A is stored once. If n is less than 1, then calculate the original code B1 and the XOR code B2 of the value based on the inverse code B; Determine if B2 is equal to C. If they are equal, the data read is successful, and the corresponding data true value is the original code of B. Mark the storage location of the original code A once. If they are not equal, the data read fails.
8. A reliable data read / write system using EEPROM according to claim 7, characterized in that, Also includes: When the microprocessor is powered on for the first time, it calculates the first data that needs to be stored to obtain the inverse code and XOR code of the data. The storage sequence number, original code of the data, inverse code of the data, and XOR code of the data are combined into a data packet and written byte by byte into the corresponding physical address of the EEPROM.
9. A reliable data read / write system using EEPROM according to claim 8, characterized in that, Also includes: When storing data for the second time, increment the storage sequence number from the first time by one, and then... After taking the remainder, the final storage sequence number is obtained. The data to be stored is then calculated using the inverse code and XOR code to obtain the corresponding data. The current data is then grouped into a data packet and written byte by byte to the address following the previous data packet. And so on, until the first The data is stored at the following address: The data is stored in storage unit N, and the Mth data is stored in storage units with addresses 1 to 4, overwriting the original stored data. No. The next storage sequence number, for The remainder is 1, at which point the data packet is stored in memory units 5 to 8, overwriting the original stored data.
Citation Information
Patent Citations
EEPROM data power failure non-loss method applied to embedded system
CN113342571A
EEPROM data storage method and system for micro inverter
CN113345497A
Embedded device program upgrading system and method
CN113741943A