Data storage method and device in EEPROM
By dividing the primary and spare partitions in the EEPROM and cycling the data to adjacent logical blocks, the problem of bad block failure in frequent data storage is solved, and the service life and storage reliability of the EEPROM are significantly improved.
Patent Information
- Application Number
- CN202011505811.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-12-18
- Publication Date
- 2024-12-13
- Estimated Expiration
- 2040-12-18
AI Technical Summary
Existing EEPROMs are prone to bad block failures when frequently data storage, resulting in shortening of service life and unable to meet certain high-frequency data storage needs.
By dividing the primary and secondary partitions in the EEPROM and saving the data in an adjacent logical block, avoiding repeated storage in the same logical block, thereby delaying the occurrence of bad blocks and improving the service life of the EEPROM.
It effectively extends the service life of EEPROM, avoids bad blocks caused by frequent rewrittening, and ensures the reliability and durability of data storage.
Smart Images

Figure CN112527207B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer storage, and in particular to a data storage method and device in an EEPROM. Background Art
[0002] EEPROM (Electrically Erasable Programmable read only memory) is widely used in embedded systems to store important data that needs to be saved frequently due to its high reliability, ultra-long erase and write times (for example, 1 million times), and data not lost after power failure.
[0003] In the existing usage method, users usually only rely on the characteristics of EEPROM itself to ensure the reliability of data. Under this method, for 1 million times of erasure, there may be no problem for ordinary operations, but it is far from enough for some frequent data. For example, if the mileage of a car is saved once every 0.1 kilometers, then the vehicle has traveled 100,000 kilometers, which means 1 million times, but the vehicle has definitely traveled more than 100,000 kilometers. In the prior art, in this case, the mileage of the car is concentrated in several individual storage blocks in the EEPROM. These storage blocks will soon produce bad block failures due to approaching the limit of erasure times, which greatly affects the service life of the entire EEPROM.
[0004] Therefore, a method is needed to maximize the service life of the EEPROM. Summary of the invention
[0005] In view of this, the purpose of this application is to provide a data storage method, system, device and computer-readable storage medium in EEPROM, which can improve the service life of EEPROM. The specific scheme is as follows:
[0006] A method for storing data in an EEPROM, comprising:
[0007] receiving current real-time data corresponding to the target data type;
[0008] Determine the storage location of the last historical data stored in the EEPROM corresponding to the target data type to obtain a target historical storage location, and determine the logic block corresponding to the target historical storage location as the target logic block;
[0009] The current real-time data is saved in a next logic block adjacent to the target logic block in the EEPROM.
[0010] Optionally, also include:
[0011] Using the storage position of the next logic block of the target logic block and the corresponding relationship with the storage position in the spare partition, the current real-time data is saved in the corresponding spare logic block in the spare partition;
[0012] The storage space in the EEPROM is pre-divided into blocks to obtain a main partition and a standby partition.
[0013] Optionally, the process of using the storage position of the next logic block of the target logic block and the corresponding relationship with the storage position in the spare partition to save the current real-time data to the corresponding spare logic block in the spare partition includes:
[0014] Using the storage location and block length of the next logical block of the target logical block, the current real-time data is saved in the corresponding spare logical block in the spare partition;
[0015] The block length is the number of storage blocks included in each partition, and the block length of the standby partition is the same as that of the primary partition.
[0016] Optionally, after using the storage position of the next logic block of the target logic block and the corresponding relationship with the storage position in the spare partition to save the current real-time data to the corresponding spare logic block in the spare partition, the method further includes:
[0017] Receiving a data reading instruction for reading target storage data corresponding to each other in the main partition and each spare partition in the EEPROM;
[0018] Verifying the target storage data stored in each partition according to the data reading instruction;
[0019] If the target storage data stored in all partitions are verified successfully, reading the target storage data;
[0020] If the target storage data stored in any partition fails to be verified, the storage data stored in the most partitions is read.
[0021] Optionally, the process of determining the storage location of the previous historical data stored in the EEPROM corresponding to the target data type to obtain the target historical storage location includes:
[0022] Determine the storage location of the historical data in advance by using the save counts of the current logic block and the adjacent logic block pointed to for the first time when the EEPROM is initialized, so as to obtain the target historical storage location;
[0023] Wherein, after each data is saved in the EEPROM, the save count is increased by one, and the save count and the saved data are saved in the same logic block.
[0024] Optionally, also include:
[0025] S421: Obtain the first saved count saved in the current logic block;
[0026] S422: Determine a second storage position of a second logic block adjacent to the current logic block by using the number of storage blocks occupied by the current logic block;
[0027] S423: using the second storage location, determining whether valid data is stored in the second logic block;
[0028] S424: If valid data is stored, determining whether the second save count in the second logic block is greater than the first save count;
[0029] S425: if the second save count is greater than the first save count, re-execute steps S421 to S424 with the second logic block as the new current logic block until no valid data is stored in the second logic block or the second save count is less than the first data save count, then the current logic block is identified as the first logic block where data was last saved before the EEPROM was powered on;
[0030] The first current logic block is the logic block that is first pointed to when the EEPROM is initialized, and the number of storage blocks included in the current logic block and the second logic block is the same.
[0031] Optionally, the process of saving the current real-time data to a next logic block adjacent to the target logic block in the EEPROM includes:
[0032] The current real-time data is saved to a next logic block adjacent to the target logic block using the target historical storage position and the number of storage blocks included in the target logic block.
[0033] Optionally, the process of using the target historical storage position and the number of storage blocks included in the target logical block to save the current real-time data to the next logical block adjacent to the target logical block includes:
[0034] Using the target historical storage position and the number of storage blocks included in the target logic block, obtaining a first storage position of a next logic block adjacent to the target logic block;
[0035] The current real-time data is saved to a next logic block adjacent to the target logic block by using the first storage location.
[0036] Optionally, after receiving the current real-time data corresponding to the target data type, the method further includes:
[0037] Obtaining the current operating temperature of the EEPROM;
[0038] Determining whether the current operating temperature of the EEPROM exceeds a preset temperature threshold;
[0039] If it exceeds, determining whether the time interval between the current time and the historical storage time for storing the historical data is less than a preset time threshold;
[0040] If it is less, the current real-time data is stored in the memory buffer.
[0041] The present application also discloses a data storage device in an EEPROM, comprising:
[0042] Memory for storing computer programs;
[0043] A processor is used to execute the computer program to implement the data storage method in the EEPROM as described above.
[0044] In the present application, a method for storing data in an EEPROM includes: receiving current real-time data corresponding to a target data type; determining the storage location of the previous historical data corresponding to the target data type stored in the EEPROM to obtain a target historical storage location, and determining a logic block corresponding to the target historical storage location as a target logic block; and saving the current real-time data to a next logic block in the EEPROM that is adjacent to the target logic block.
[0045] The present application saves new data cyclically to the entire EEPROM instead of repeatedly saving the data to the same logic block, which delays the occurrence of bad blocks in the EEPROM and improves the service life of the EEPROM as a whole. BRIEF DESCRIPTION OF THE DRAWINGS
[0046] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying any creative work.
[0047] Figure 1 A schematic flow chart of a method for storing data in an EEPROM disclosed in an embodiment of the present application;
[0048] Figure 2A schematic flow chart of another method for storing data in an EEPROM disclosed in an embodiment of the present application;
[0049] Figure 3 A schematic flow chart of another method for storing data in an EEPROM disclosed in an embodiment of the present application;
[0050] Figure 4 A schematic flow chart of another method for storing data in an EEPROM disclosed in an embodiment of the present application;
[0051] Figure 5 A schematic flow chart of another method for storing data in an EEPROM disclosed in an embodiment of the present application;
[0052] Figure 6 This is a schematic diagram of the structure of a data storage system in an EEPROM disclosed in an embodiment of the present application. DETAILED DESCRIPTION
[0053] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0054] The present application discloses a method for storing data in an EEPROM. Figure 1 As shown, the method includes:
[0055] S11: receiving current real-time data corresponding to the target data type;
[0056] S12: Determine the storage location of the previous historical data stored in the EEPROM corresponding to the target data type to obtain the target historical storage location, and determine the logic block corresponding to the target historical storage location as the target logic block.
[0057] Specifically, in order to extend the service life of the same data type when it is stored in the EEPROM, after receiving the current real-time data of the corresponding target data type, instead of directly selecting a logic block to store the current real-time data, the storage location of the last historical data stored in the EEPROM corresponding to the target data type is first determined to obtain the target historical storage location. The historical data is the data last stored in the EEPROM, which is the same as the target data type of the current real-time data.
[0058] Specifically, after obtaining the target historical storage location, the specific logical block corresponding to the target historical storage location can be found, and the logical block can be determined as the target logical block. The target logical block is used to store historical data. Each logical block can include one or more physical storage blocks. When saving historical data, it is not necessary to fully occupy the storage space included in the logical block. However, in order to reduce the waste of storage space, one logical block can correspond to the minimum number of storage blocks required. For example, a historical data is 6KB, and the storage space of a storage block is 4KB. Then the logical block that saves one historical data includes at least two storage blocks. One storage block can store 4KB of historical data, and the other storage block can store another 2KB of historical data, thereby saving a complete historical data.
[0059] The storage block is a physical storage block in the EEPROM.
[0060] S13: Save the current real-time data to the next logic block adjacent to the target logic block in the EEPROM.
[0061] Specifically, after determining the target logical block, the current real-time data is saved to the next logical block adjacent to the target logical block, thereby ensuring that the data saved each time will not be repeatedly saved in the same logical block, and will not be repeatedly saved in the storage block corresponding to the logical block. At the same time, the current real-time data is always saved to the next logical block adjacent to the target logical block, which can effectively utilize the storage space in the entire EEPROM as a whole, and will not be repeatedly saved in several logical blocks, but will be saved in each logical block in the EEPROM in sequence, avoiding the situation where individual storage blocks in the EEPROM are repeatedly erased and written when saving data, resulting in the rapid exhaustion of the life of individual storage blocks, thereby extending the overall service life of the EEPROM as much as possible.
[0062] It should be noted that the storage space in the EEPROM can be pre-set to the logical block size required to store the target data type, and the storage space in the EEPROM can be divided into multiple adjacent logical blocks in sequence. The first logical block is used as the next logical block adjacent to the last logical block to form a storage space cycle, so as to realize the cyclic storage of current real-time data in each logical block in the entire EEPROM, thereby extending the service life of a single storage block. For example, each storage block can be erased and written 1 million times. At present, it is necessary to repeatedly save the mileage of the car. If the mileage of the car is saved once every 0.1 kilometers, then after the vehicle has traveled 100,000 kilometers, it has reached 1 million times. At this time, using the existing technology, some storage blocks used to store the mileage of the car will be damaged, resulting in the phenomenon of bad blocks in the entire EEPROM. If the cyclic storage method of the embodiment of the present application is adopted, if the EEPROM includes 50 logical blocks, the number of erases and writes that can be performed before damage occurs becomes 50*1 million times, which obviously greatly delays the time when the bad block appears, and extends the service life of the EEPROM as a whole.
[0063] It can be seen that the embodiment of the present application saves new data cyclically in the entire EEPROM, rather than repeatedly saving the data in the same logic block, which delays the occurrence of bad blocks in the EEPROM and improves the service life of the EEPROM as a whole.
[0064] The embodiment of the present application discloses a specific method for storing data in an EEPROM. Compared with the previous embodiment, this embodiment further illustrates and optimizes the technical solution. Figure 2 As shown, specifically:
[0065] S21: receiving current real-time data corresponding to the target data type;
[0066] S22: determining the storage location of the previous historical data stored in the EEPROM corresponding to the target data type to obtain the target historical storage location, and determining the logic block corresponding to the target historical storage location as the target logic block;
[0067] S23: Save the current real-time data to the next logic block adjacent to the target logic block in the EEPROM;
[0068] S24: using the storage position of the next logic block of the target logic block and the corresponding relationship with the storage position in the spare partition, the current real-time data is saved in the corresponding spare logic block in the spare partition.
[0069] Specifically, since the cyclic saving fully utilizes the overall storage space in the EEPROM, but does not change the actual service life of the EEPROM, a large number of bad blocks are likely to occur when the EEPROM is close to its service life, resulting in data loss. In order to avoid data loss caused by bad blocks, the storage space in the EEPROM can be divided into blocks in advance to obtain a main partition and a spare partition. After the current real-time data is saved to the main partition in S21 to S23, the storage position of the next logical block of the target logical block can continue to be used to find the corresponding storage position in the spare partition.
[0070] Specifically, the backup partition also includes multiple adjacent logical blocks connected in sequence, and the logical blocks of the backup partition and the main partition are also continuous with each other. For example, the EEPROM includes 6 logical blocks, which can be evenly divided into two partitions, each partition includes 3 logical blocks, one partition is the main partition, and the other partition is the backup partition. The logical blocks corresponding to the main partition can be the first logical block to the third logical block in sequence, and the logical blocks corresponding to the backup partition can be the fourth logical block to the sixth logical block in sequence. When data is saved to the first logical block, it can also be saved to the first logical block, i.e., the fourth logical block, in the corresponding backup partition at the same time. And so on. Circular storage is also realized in the backup partition, and data backup is also realized.
[0071] Furthermore, the storage location and block length of the next logical block of the target logical block can be used to save the current real-time data to the corresponding spare logical block in the spare partition; wherein the block length is the number of storage blocks included in each partition, and the block length of the spare partition is the same as that of the main partition.
[0072] For example, the EEPROM includes 6 logic blocks, the logic blocks corresponding to the main partition can be the first logic block to the third logic block in sequence, and the logic blocks corresponding to the backup partition can be the fourth logic block to the sixth logic block in sequence. Each logic block can include 2 storage blocks, and the block length of a partition is 6. The storage position of the first logic block can correspond to the storage position of the first storage block, which is 1. The storage position of the fourth logic block is the storage position of the first logic block plus the block length, which is 7, corresponding to the storage position of the first storage block in the fourth logic block.
[0073] Specifically, even if the number of logical blocks included in the primary partition and the backup partition is different, the block length can be used to achieve it. For example, the primary partition includes the first to third logical blocks, the backup partition includes the fourth and fifth logical blocks, the block length is 3, the storage position of the third logical block is 3, the storage position corresponding to the third logical block is 6, and the storage position of the fifth logical block in the backup partition is 5. At this time, a loop can be performed in the backup partition to let the storage position 6 correspond to the fourth logical block, thereby realizing cyclic storage of data in the backup partition.
[0074] It can be understood that multiple spare partitions can be divided in the EEPROM, for example, one or two. However, dividing too many spare partitions will reduce the number of different data that can be stored in the EEPROM at the same time. For this reason, one main partition and two spare partitions can be set as a preference. The three partitions can evenly divide the storage space in the EEPROM so that the logical blocks between the partitions can correspond one to one. As shown in Table 1, each Page corresponds to a storage block, Page0 to Page17 are 18 consecutive storage blocks in an EEPROM, Page0 to Page5 correspond to the main partition, Page6 to Page11 correspond to the first spare partition, Page12 to Page17 correspond to the third spare partition, and the storage blocks between each partition are aligned.
[0075] Table 1
[0076] Page0 Page1 Page2 Page3 Page4 Page5 Page6 Page7 Page8 Page9 Page10 Page11 Page12 Page13 Page14 Page15 Page16 Page17
[0077] The embodiment of the present application also discloses a specific method for storing data in an EEPROM. Compared with the previous embodiment, this embodiment further illustrates and optimizes the technical solution. Figure 3 As shown, the above embodiment is further improved, and the method includes:
[0078] S31: receiving a data reading instruction for reading corresponding target storage data in the main partition and each spare partition in the EEPROM.
[0079] Specifically, when the target storage data in the primary partition is read, the corresponding target storage data in each backup partition is also read. Under theoretical conditions, the target storage data stored in each partition should be consistent.
[0080] S32: Verify the target storage data stored in each partition according to the data reading instruction.
[0081] Specifically, after storing multiple data in the primary partition and the backup partition, since it is impossible to ensure that any partition is intact, data verification is required when reading data to avoid reading erroneous target storage data due to data loss caused by bad blocks.
[0082] S33: If the target storage data stored in all partitions are verified successfully, the target storage data is read.
[0083] Specifically, the target storage data may be verified using a checksum occupying 1 byte in the target storage data.
[0084] S34: If the verification of the target storage data stored in any partition fails, the storage data stored in the most partitions is read.
[0085] Specifically, if the verification of the target storage data stored in any partition fails, the storage data stored in the largest number of partitions is read. Since data corruption is a low-probability event, reading the storage data with the largest number of storage can ensure that the correct target storage data is read.
[0086] For example, the EEPROM includes three partitions, a main partition, a first spare partition and a second spare partition. The target storage data is A. The storage data corresponding to the target storage data in the first spare partition becomes A1, and the storage data corresponding to the target storage data in the main partition and the second spare partition are the same and exist in two partitions. Compared with A1, which is only stored in one partition, it is the storage data saved in the most partitions, so the storage data in the main partition or the second spare partition is read as the target storage data.
[0087] The embodiment of the present application discloses a specific method for storing data in an EEPROM. Compared with the above embodiment, the present embodiment further illustrates and optimizes the technical solution. Figure 4 As shown, specifically:
[0088] S41: receiving current real-time data corresponding to the target data type;
[0089] S42: Determine the storage location of historical data in advance by using the save counts of the current logic block and adjacent logic blocks first pointed to when the EEPROM is initialized to obtain the target historical storage location, and determine the logic block corresponding to the target historical storage location as the target logic block.
[0090] Specifically, when the EEPROM is powered on for the first time, it needs to be initialized and the target historical storage location of the last saved historical data needs to be re-determined in order to save the latest data. When the EEPROM is initialized, it will first point to the first logic block in the EEPROM, that is, the current logic block, and then determine whether the current logic block is the logic block that last saved data based on the save count recorded in each logic block. By traversing the logic blocks in the EEPROM, the logic block that last saved data can be found, and then the storage location of the historical data can be determined by saving in sequence to obtain the target historical storage location, and the logic block corresponding to the target historical storage location is determined as the target logic block, or the logic block that last saved data is the target logic block.
[0091] Each time data is saved in the EEPROM, the save count is incremented by one, and the save count and the saved data are saved in the same logic block. The save count can be represented by an Index, which is a 4-byte unsigned integer.
[0092] S43: Save the current real-time data to the next logic block adjacent to the target logic block in the EEPROM.
[0093] Furthermore, the EEPROM initialization process mentioned in S42 may specifically include the initialization process of searching for the last saved logic block from S421 to S425; wherein,
[0094] S421: Obtain the first saved count saved in the current logic block.
[0095] Specifically, the first current logic block is the logic block first pointed to when the EEPROM is initialized, usually the first logic block of the EEPROM, and the first saved count saved in the current logic block is obtained for subsequent judgment.
[0096] S422: Determine a second storage position of a second logic block adjacent to the current logic block by using the number of storage blocks occupied by the current logic block.
[0097] Specifically, although the logical blocks are adjacent to each other, the actual storage position of the corresponding storage block is still needed during the actual position search process. Since it has pointed to the current logical block, the storage position of the first storage block under the current logical block can be known, and the number of storage blocks in the current logical block is added to the storage position of the first storage block to obtain the second storage position of the second logical block adjacent to the current logical block.
[0098] For example, the storage position of the first storage block of the current logic block is 1, and the current logic block includes 2 storage blocks, then the second storage position of the adjacent second logic block is 3, which is the storage position of the first storage block in the second logic block.
[0099] S423: Using the second storage location, determine whether valid data is stored in the second logic block.
[0100] Specifically, after obtaining the second storage location, the second logical block is found. Therefore, it can be determined whether valid data is stored in the second logical block, because the second logical block may have never been used and has never stored data. If no data has been stored in the second logical block, then it can be said that the current logical block is the last logical block that saved data.
[0101] S424: If valid data is stored, determine whether the second save count in the second logic block is greater than the first save count.
[0102] Specifically, if valid data is stored in the second logic block, it may be old data stored in the second logic block in the past, that is, the data may have been stored once in all logic blocks in the EEPROM during the last storage, and this is the second storage. Therefore, the second logic block may store old data instead of the latest data. Therefore, it is also necessary to determine whether the second save count in the second logic block is greater than the first save count. If it is less than, it means that the data saved in the second logic block is data saved very early, and the data in the current logic block is the data saved for the last time, because the next adjacent second logic block has not yet saved new data.
[0103] S425: If the second save count is greater than the first save count, steps S421 to S424 are re-executed with the second logic block as the new current logic block until no valid data is stored in the second logic block or the second save count is less than the first data save count, then the current logic block is identified as the first logic block that last saved data before the EEPROM was powered on.
[0104] Specifically, if the second save count is greater than the first save count, it means that the second logic block stores data that is saved later than the current logic block. Therefore, the second logic block is reused as the new current logic block and brought back to S421, and the next adjacent logic block is re-compared until no valid data is stored in the second logic block or the second save count is less than the first data save count, then the current logic block is identified as the first logic block that last saved data before the EEPROM was powered on.
[0105] The current logic block and the second logic block include the same number of storage blocks, the same number of storage blocks are required to save data each time, and the storage space of each logic block is the same, which helps to find the next logic block by using the number of storage blocks and the storage position.
[0106] It should be noted that if the current real-time data is saved for the first time after the EEPROM is initialized, the first logic block finally found after the EEPROM is initialized is the target logic block. If the current real-time data is not the data saved for the first time after the EEPROM is initialized, then in the subsequent data saving process, the first logic block is used as the starting point, and the data is saved until it is saved to the target logic block, and then the current update data is stored according to the target historical storage position of the target logic block.
[0107] The present application also discloses a method for storing data in an EEPROM. Figure 5 As shown, the method includes:
[0108] S51: receiving current real-time data corresponding to the target data type;
[0109] S52: Obtain the current operating temperature of the EEPROM.
[0110] Specifically, the EEPROM will heat up after storing data multiple times. Too high a temperature will cause the EEPROM to store data slowly and may even fail to store data. Therefore, the current operating temperature of the EEPROM is detected so that adjustments can be made according to the current operating temperature of the EEPROM.
[0111] S53: Determine whether the current operating temperature of the EEPROM exceeds a preset temperature threshold;
[0112] S54: If exceeded, determining whether the time interval between the current time and the historical storage time of the historical data is less than a preset time threshold;
[0113] S55: If it is less than, the current real-time data is stored in the memory buffer.
[0114] Specifically, if the current operating temperature of the EEPROM exceeds a preset temperature threshold, it means that the EEPROM has been overheated or is close to an overheating upper limit. At this time, it is determined whether the time interval between the current time and the last saved historical saving time is less than the preset time threshold. If it is less, it means that the saving is too frequent. Continuing to save may cause the EEPROM to continue to heat up, which is not conducive to the stable operation of the EEPROM. Therefore, the current real-time data can be saved to the memory buffer in advance to allow the EEPROM to cool down.
[0115] Specifically, if the temperature of the EEPROM drops, the current real-time data in the memory buffer can be saved back to the EEPROM, and the saving process is the same as S11 to S13.
[0116] S56: If the temperature does not exceed the temperature threshold or is not less than the time threshold, determine the storage location of the previous historical data stored in the EEPROM corresponding to the target data type to obtain the target historical storage location, and determine the logic block corresponding to the target historical storage location as the target logic block;
[0117] S57: Using the target historical storage position and the number of storage blocks included in the target logical block, save the current real-time data to the next logical block adjacent to the target logical block.
[0118] Specifically, by utilizing the target historical storage position and the number of storage blocks included in the target logical block, the first storage position of the next logical block adjacent to the target logical block can be obtained, and then utilizing the first storage position to save the current real-time data to the next logical block adjacent to the target logical block, thereby completing data preservation without the need to perform the process of searching for the last saved first logical block required during initialization.
[0119] It is understandable that, before the EEPROM is powered off, if the memory buffer still stores the current real-time data, the current real-time data can be saved again in the EEPROM according to the process from S11 to S13.
[0120] Correspondingly, the embodiment of the present application also discloses a working process of a data storage method in an EEPROM in a specific application scenario, and the process is as follows:
[0121] Taking the EEPROM that records the car's mileage as an example, the vehicle saves mileage data every 0.1 kilometers it travels, and the current mileage data is saved in the next logical block of the logical block used when the mileage data was saved last time. For example, the current mileage data is 52.3, and the last saved mileage data is 52.2, which was saved in the fifth logical block, then the current mileage data is saved in the sixth logical block.
[0122] At the same time, after the current mileage data is saved in the sixth logical block, the current mileage data can also be saved in the first backup partition and the second backup partition at the same time. The first backup partition is based on the block length 12 of the main partition, that is, each block includes 12 storage blocks, each logical block includes 2 storage blocks, and the mileage data needs to use 2 storage blocks. The first backup partition obtains the storage position 23 according to the storage position 11 of the sixth logical block, corresponding to the twelfth logical block in the first backup partition, and saves the current mileage data to the twelfth logical block. The second backup partition uses the block length 12 of the first backup partition and the storage position 23 of the twelfth logical block to find the storage position 35 of the eighteenth logical block, and the current mileage data is saved to the eighteenth logical block.
[0123] In addition, before saving the current mileage data, the current operating temperature and saving time interval of the EEPROM can also be detected. If the temperature exceeds the temperature and is less than the time interval, the current mileage data will be saved in the memory buffer. When the vehicle stops and is ready to be shut down for power off, all the remaining current mileage data in the memory buffer will be saved in the EEPROM.
[0124] At the same time, when the vehicle is started, the EEPROM is initialized and the first logic block that last saved the history count is determined using the saved count in each logic block.
[0125] Accordingly, the present application also discloses a data storage system in an EEPROM, see Figure 6 As shown, the system includes:
[0126] The data receiving module 11 is used to receive the current real-time data corresponding to the target data type;
[0127] The logic block determination module 12 is used to determine the storage location of the previous historical data stored in the EEPROM corresponding to the target data type to obtain the target historical storage location, and determine the logic block corresponding to the target historical storage location as the target logic block;
[0128] The data storage module 13 is used to store the current real-time data in the next logic block adjacent to the target logic block in the EEPROM.
[0129] It can be seen that the embodiment of the present application saves new data cyclically in the entire EEPROM, rather than repeatedly saving the data in the same logic block, which delays the occurrence of bad blocks in the EEPROM and improves the service life of the EEPROM as a whole.
[0130] Specifically, it also includes a data backup module; wherein,
[0131] A data backup module, used to save the current real-time data to the corresponding spare logic block in the spare partition by using the storage position of the next logic block of the target logic block and the corresponding relationship with the storage position in the spare partition;
[0132] The storage space in the EEPROM is pre-divided into blocks to obtain a main partition and a spare partition.
[0133] Specifically, the data backup module may be specifically used to save the current real-time data to the corresponding spare logic block in the spare partition by using the storage location and block length of the next logic block of the target logic block;
[0134] The block length is the number of storage blocks included in each partition, and the block length of the backup partition is the same as that of the primary partition.
[0135] Specifically, it also includes a read instruction receiving module, a data verification module, a first data reading module and a second data reading module; wherein,
[0136] A read instruction receiving module, used for receiving a data read instruction for reading target storage data corresponding to each other in the main partition and each spare partition in the EEPROM;
[0137] A data verification module is used to verify the target storage data stored in each partition according to the data reading instruction;
[0138] A first data reading module, configured to read the target storage data if the target storage data stored in all partitions are successfully verified;
[0139] The second data reading module is used to read the storage data stored in the most partitions if the target storage data stored in any partition fails to be verified.
[0140] Specifically, the logic block determination module 12 is specifically used to determine the storage location of the historical data in advance by using the saved counts of the current logic block and the adjacent logic blocks pointed to for the first time when the EEPROM is initialized, so as to obtain the target historical storage location;
[0141] Each time data is saved in the EEPROM, the save count is increased by one, and the save count and the saved data are saved in the same logic block.
[0142] Specifically, it also includes a first counting acquisition module, a storage location determination module, a valid data judgment module, a counting judgment module and a logic block determination module 12; wherein,
[0143] A first count acquisition module, used to acquire a first saved count saved in the current logic block;
[0144] A storage position determination module, used to determine a second storage position of a second logic block adjacent to the current logic block by using the number of storage blocks occupied by the current logic block;
[0145] A valid data determination module, used to determine whether valid data is stored in the second logic block by using the second storage location;
[0146] A counting judgment module, used for judging whether the second saved count in the second logic block is greater than the first saved count if valid data is stored;
[0147] The logic block determination module 12 is used to, if the second save count is greater than the first save count, use the second logic block as a new current logic block to re-call the first count acquisition module until no valid data is stored in the second logic block or the second save count is less than the first data save count, then the current logic block is identified as the first logic block that last saved data before the EEPROM was powered on;
[0148] The first current logic block is the logic block that is first pointed to when the EEPROM is initialized, and the number of storage blocks included in the current logic block and the second logic block is the same.
[0149] Specifically, the data storage module 13 is specifically used to save the current real-time data to the next logic block adjacent to the target logic block by using the target historical storage position and the number of storage blocks included in the target logic block.
[0150] Specifically, the data storage module 13 includes a storage location acquisition unit and a data storage unit; wherein,
[0151] A storage position acquisition unit, used to obtain a first storage position of a next logic block adjacent to the target logic block by using the target historical storage position and the number of storage blocks included in the target logic block;
[0152] The data storage unit is used to save the current real-time data to the next logic block adjacent to the target logic block by using the first storage position.
[0153] Specifically, it also includes an operating temperature acquisition module, a temperature judgment module, a time interval judgment module and a memory storage module; wherein,
[0154] The operating temperature acquisition module is used to obtain the current operating temperature of the EEPROM;
[0155] A temperature judgment module is used to judge whether the current operating temperature of the EEPROM exceeds a preset temperature threshold;
[0156] The time interval judgment module is used to judge whether the time interval between the current time and the historical storage time of the historical data is less than a preset time threshold if it exceeds;
[0157] The memory storage module is used to store the current real-time data into the memory buffer if it is less than.
[0158] Specifically, it also includes a power-off saving module; wherein,
[0159] The power-off saving module is used to save the current real-time data to the EEPROM before the EEPROM is powered off if the memory buffer has the current real-time data.
[0160] In addition, the embodiment of the present application also discloses a data storage device in an EEPROM, comprising:
[0161] Memory for storing computer programs;
[0162] The processor is used to execute the computer program to implement the data storage method in the EEPROM as mentioned above.
[0163] Finally, it should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article 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, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the presence of other identical elements in the process, method, article or device including the elements.
[0164] Professionals may further appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in the above description according to function. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians may use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.
[0165] The above is a detailed introduction to the technical content provided by the present application. Specific examples are used in this article to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method of the present application and its core idea. At the same time, for general technical personnel in this field, according to the idea of the present application, there will be changes in the specific implementation methods and application scope. In summary, the content of this specification should not be understood as a limitation on the present application.
Claims
1. A method for storing data in an EEPROM, characterized in that: include: receiving current real-time data corresponding to the target data type; Determine the storage location of the previous historical data stored in the EEPROM corresponding to the target data type to obtain a target historical storage location, and determine the logic block corresponding to the target historical storage location as a target logic block; the data type of the historical data is the same as the target data type of the current real-time data; Saving the current real-time data to a next logic block adjacent to the target logic block in the EEPROM; Among them, it also includes: Using the storage location and block length of the next logical block of the target logical block, the current real-time data is saved in the corresponding spare logical block in the spare partition; The storage space in the EEPROM is pre-divided into blocks to obtain a main partition and a spare partition; the block length is the number of storage blocks included in each partition, and the spare partition has the same block length as the main partition; After the current real-time data is saved to the corresponding spare logic block in the spare partition by using the storage position of the next logic block of the target logic block and the corresponding relationship with the storage position in the spare partition, the method further includes: Receiving a data reading instruction for reading target storage data corresponding to each other in the main partition and each spare partition in the EEPROM; Verifying the target storage data stored in each partition according to the data reading instruction; If the target storage data stored in all partitions are verified successfully, reading the target storage data; If the target storage data stored in any partition fails to be verified, then the storage data stored in the most partitions is read; After receiving the current real-time data corresponding to the target data type, the method further includes: Obtaining the current operating temperature of the EEPROM; Determining whether the current operating temperature of the EEPROM exceeds a preset temperature threshold; If it exceeds, determining whether the time interval between the current time and the historical storage time for storing the historical data is less than a preset time threshold; If it is less than, storing the current real-time data in the memory buffer; The process of determining the storage location of the last historical data stored in the EEPROM corresponding to the target data type to obtain the target historical storage location includes: Determine the storage location of the historical data in advance by using the save counts of the current logic block and the adjacent logic block pointed to for the first time when the EEPROM is initialized, so as to obtain the target historical storage location; Wherein, after each data is saved in the EEPROM, the save count is increased by one, and the save count and the saved data are saved in the same logic block; Also includes: S421: Obtain the first saved count saved in the current logic block; S422: Determine a second storage position of a second logic block adjacent to the current logic block by using the number of storage blocks occupied by the current logic block; S423: using the second storage location, determining whether valid data is stored in the second logic block; S424: If valid data is stored, determining whether the second save count in the second logic block is greater than the first save count; S425: if the second save count is greater than the first save count, re-execute steps S421 to S424 with the second logic block as the new current logic block until no valid data is stored in the second logic block or the second save count is less than the first save count, then the current logic block is identified as the first logic block in which data was last saved before the EEPROM was powered on; The first current logic block is the logic block that is first pointed to when the EEPROM is initialized, and the number of storage blocks included in the current logic block and the second logic block is the same.
2. The method for storing data in an EEPROM according to claim 1, wherein: The process of storing the current real-time data in the next logic block adjacent to the target logic block in the EEPROM includes: The current real-time data is saved to a next logic block adjacent to the target logic block using the target historical storage position and the number of storage blocks included in the target logic block.
3. The method for storing data in an EEPROM according to claim 2, wherein: The process of using the target historical storage position and the number of storage blocks included in the target logic block to save the current real-time data to the next logic block adjacent to the target logic block includes: Using the target historical storage position and the number of storage blocks included in the target logic block, obtaining a first storage position of a next logic block adjacent to the target logic block; The current real-time data is saved to a next logic block adjacent to the target logic block by using the first storage location.
4. A data storage device in an EEPROM, characterized in that: include: Memory for storing computer programs; A processor, configured to execute the computer program to implement the method for storing data in an EEPROM as claimed in any one of claims 1 to 3.
Citation Information
Patent Citations
Data storage and reading method
CN102521084A
Environmental-based device operation
CN103176748A
Data storage method and system
CN103514177A
Automobile mileage access system
CN104484280A
Data storage method and electronic equipment
CN105677257A
