Data storage method and device, equipment and storage medium
By using RAM as a transit station in an embedded data storage system, the frequent erasing and writing of FLASH is reduced, and the problem of shortening FLASH life is solved, extending its service life and improving data operability.
Patent Information
- Application Number
- CN202411241825.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-05
- Publication Date
- 2024-12-20
AI Technical Summary
In the prior art, FLASH's frequent erase writing operations greatly affect its service life, especially when it is necessary to change data frequently, it is easy to cause full writing and frequent erasing, thereby shortening its service life.
By using random access memory (RAM) as a temporary transit station for data storage in an embedded data storage system, data that needs to be frequently written or updated is directly stored in RAM, reducing frequent erasing and writing to FLASH. And determine the storage location through the virtual address and storage space status to extend the service life of FLASH.
It effectively reduces frequent erase writes to FLASH, extends its service life, and improves data operability, achieving a long-life erase frequency in a smaller FLASH space.
Smart Images

Figure CN119166061A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of embedded data storage, and in particular to a data storage method, device, equipment and storage medium. Background Art
[0002] FLASH is generally erased and written in blocks, and single-byte operations are not allowed. The capacity is generally large, but the lifespan is relatively low. EEPROM can read and write single bytes, and has a relatively long lifespan, but the capacity is generally small. In many application scenarios of embedded products, some key data needs to be stored for a long time or frequently changed. Generally, large blocks of data that are not frequently changed will be stored in FLASH, and frequently changed data will be stored in EEPROM. In some scenarios, only FLASH is used, and EEPROM is not used due to considerations of storage data capacity or cost. For data that needs to be stored in a scattered manner, it is necessary to store it frequently while considering the lifespan of FLASH. At this time, it is necessary to apply FLASH emulation EEPROM technology to extend the service life of FLASH and the operability of data. For example, the Chinese patent publication number is CN116301601A, which discloses a data storage method and device for embedded systems with built-in FLASH emulation EEPROM.
[0003] However, the existing FLASH emulation EEPROM technology has the following shortcomings: when data needs to be changed frequently, the data writing frequency is high, and the FLASH is easily filled up. Each time the FLASH is filled with data, it needs to be erased before it can be written again. This will cause frequent erasing and writing of the FLASH, which will greatly affect the service life of the FLASH. Summary of the invention
[0004] Purpose of the invention: An embodiment of the present application provides a data storage method, aiming to overcome the technical problem in the prior art that frequent erasing and writing of FLASH affects the service life of FLASH; another purpose of an embodiment of the present application is to provide a data storage device; the third purpose of the present application is to provide an electronic device; the fourth purpose of the present application is to provide a computer-readable storage medium.
[0005] Technical solution: A data storage method according to an embodiment of the present application is applied to an embedded data storage system, wherein the embedded data storage system at least comprises: a random access memory;
[0006] The method comprises:
[0007] After obtaining the current data to be stored, obtaining a virtual address of the current data to be stored and a current storage space state of the random access memory;
[0008] Determining a target storage location of the data to be stored currently in the random access memory according to a virtual address of the data to be stored currently and a current storage space state of the random access memory;
[0009] And the current data to be stored is stored in the target storage location.
[0010] In some embodiments, determining a target storage location of the data to be stored in the random access memory according to the virtual address of the data to be stored and the current storage space state of the random access memory includes:
[0011] Determining, according to the virtual address of the current data to be stored, whether there is a first virtual address corresponding to the virtual address of the current data to be stored in the current storage space of the random access memory;
[0012] If the first virtual address exists, determining the first virtual address as the target storage location;
[0013] If the first virtual address does not exist, the target storage location is determined according to a current storage space state of the random access memory.
[0014] In some embodiments, determining the target storage location according to the current storage space state of the random access memory includes:
[0015] Determining whether there is an idle storage location in the current storage space of the random access memory according to the current storage space state of the random access memory;
[0016] If there is an idle storage location, determining the idle storage location as the target storage location;
[0017] If there is no free storage location, obtain the first storage location with the smallest heat and the data corresponding to the first storage location in the current storage space of the random access memory, and determine the target storage location based on the first storage location and the data corresponding to the first storage location.
[0018] In some embodiments, the embedded data storage system further includes: a flash memory; and determining the target storage location according to the first storage location and the data corresponding to the first storage location includes:
[0019] The data corresponding to the first storage location is stored in the flash memory, and the first storage location is determined as the target storage location.
[0020] In some embodiments, the flash memory includes at least a first storage area and a second storage area;
[0021] The storing the data corresponding to the first storage location in the flash memory includes:
[0022] Acquire a current legal slice of the flash memory; wherein the current legal slice is the first storage slice or the second storage slice;
[0023] Determine whether the current zone state of the current legal zone is full;
[0024] If the current slice state of the current legal slice is full, taking the next slice immediately following the current legal slice as the target legal slice, and storing the data corresponding to the first storage position in the target legal slice;
[0025] If the current slice state of the current legal slice is not a full state, the data corresponding to the first storage location is stored in the current legal slice.
[0026] In some embodiments, the step of taking the next parcel immediately following the current legal parcel as the target legal parcel includes:
[0027] Erasing the next slice immediately following the current legal slice, and setting the slice state of the next slice to a receiving state;
[0028] Setting the slice state of the current legal slice to a full state, and storing the last written data in the current legal slice to the next slice;
[0029] The current legal slice is erased, and the next slice is used as the target legal slice.
[0030] In some embodiments, when storing the current data to be stored in the target storage location, the method further includes:
[0031] Calculate the heat value of the current data to be stored in the random access memory; count the number of times the current data to be stored is stored in the random access memory; and record the timestamp of the current data to be stored in the random access memory.
[0032] In some embodiments, the counting of the number of times the current data to be stored is stored in the random access memory includes:
[0033] The number of times the current data to be stored is stored in the random access memory is counted through a global variable.
[0034] In some embodiments, the random access memory includes at least: a real-time clock random access memory.
[0035] Accordingly, a data storage device described in an embodiment of the present application is applied to an embedded data storage system, and the embedded data storage system at least includes: a random access memory;
[0036] The device comprises:
[0037] A first acquisition module, used to acquire the current data to be stored;
[0038] A second acquisition module, used for acquiring the virtual address of the current data to be stored and the current storage space state of the random access memory;
[0039] a target storage location determination module, configured to determine a target storage location of the data to be stored currently in the random access memory according to a virtual address of the data to be stored currently and a current storage space state of the random access memory;
[0040] The data storage module is used to store the current data to be stored in the target storage location.
[0041] Correspondingly, an electronic device described in an embodiment of the present application includes a memory, a processor, and a computer program stored in the memory and executable on the processor, and the processor implements the above-mentioned data storage method when executing the computer program.
[0042] Correspondingly, a computer-readable storage medium described in an embodiment of the present application stores a computer program thereon, and the computer program implements the above-mentioned data storage method when executed by a processor.
[0043] Beneficial effects: Compared with the prior art, the data storage method, device, equipment and storage medium of the embodiment of the present application, the data storage method includes: after obtaining the current data to be stored, obtaining the virtual address of the current data to be stored and the current storage space state of the random access memory; determining the target storage position of the current data to be stored in the random access memory according to the virtual address of the current data to be stored and the current storage space state of the random access memory; and storing the current data to be stored in the target storage position. It can be seen that the method directly stores the data that needs to be written or updated frequently into the random access memory, and reduces the frequent erasing and writing of FLASH by using the random access memory as a temporary transfer station for data storage, which can solve the problem of frequent erasing and writing of FLASH affecting the service life of FLASH in the prior art. And according to the virtual address of the current data to be stored and the current storage space state of the random access memory, the storage position of the current data to be stored in the random access memory can be further determined, so as to save the data that needs to be written or updated frequently in the random access memory, thereby improving the service life of FLASH. BRIEF DESCRIPTION OF THE DRAWINGS
[0044] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For those skilled in the art, other drawings can be obtained based on these drawings without creative work.
[0045] Figure 1 is a flow chart of a data storage method provided in an embodiment of the present application;
[0046] Figure 2 is a flowchart of another data storage method provided in an embodiment of the present application;
[0047] Figure 3 is a flowchart of another data storage method provided in an embodiment of the present application;
[0048] Figure 4 It is a principle structural block diagram of a data storage device provided in an embodiment of the present application;
[0049] Figure 5 It is a schematic diagram of the structure of an electronic device according to an embodiment of the present application.
[0050] Reference numerals:
[0051] 101 - first acquisition module; 102 - second acquisition module; 103 - target storage location determination module; 104 - data storage module; 100 - data storage device. DETAILED DESCRIPTION
[0052] The technical solutions in the embodiments of the present application will be described clearly and completely below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, rather than all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present application.
[0053] It should be understood that although the terms first, second, etc. may be used herein to describe various components, these components should not be limited by these terms. These terms are used to distinguish one component from another component. Therefore, the first component discussed below can be referred to as the second component without departing from the teachings of the concepts of the present application. As used herein, the term "and / or" includes any one of the associated listed items and all combinations of one or more.
[0054] Those skilled in the art will appreciate that the drawings are only schematic diagrams of example embodiments and may not be to scale. The modules or processes in the drawings are not necessarily required to implement the present application and therefore cannot be used to limit the scope of protection of the present application.
[0055] Figure 1 This is a flow chart of a data storage method provided in an embodiment of the present application. The embodiment of the present application can be applied to the process of implementing Flash Memory (FLASH) emulation EEPROM technology in an embedded data storage system, reducing the frequent erasing and writing of FLASH, and improving the service life of FLASH. The method can be executed by a data storage device, which can be implemented by software and / or hardware, and the device can be configured in a processor of an embedded data storage system. Please refer to Figure 1 , the method comprises the following steps:
[0056] Step 110: After the current data to be stored is obtained, the virtual address of the current data to be stored and the current storage space state of the random access memory are obtained.
[0057] Each data to be stored has a corresponding virtual address. Therefore, after the current data to be stored is obtained, the virtual address of the current data to be stored is first obtained to make subsequent judgments on data storage.
[0058] Among them, the current storage space status of the random access memory (RAM) may include information such as the available space status of the storage space, the used space status, the virtual address of each storage location, etc., which can be set according to actual conditions and are not specifically limited here.
[0059] Among them, the storage space of RAM is usually relatively small, and the specific space size can be set according to actual conditions, and no specific limitation is made here.
[0060] Step 120: Determine a target storage location of the data to be stored in the random access memory according to the virtual address of the data to be stored and the current storage space state of the random access memory.
[0061] Specifically, whenever frequent updates or data writing are required, the data is stored in the RAM. The specific implementation process is: after the current data to be stored is obtained, the virtual address of the current data to be stored is obtained, and the current storage space state of the random access memory is obtained, and then the storage location of the current data to be stored in the RAM can be determined according to the virtual address of the current data to be stored and the current storage space state of the random access memory, thereby directly storing the data that needs to be frequently updated or written in the RAM, and using the RAM as a temporary transfer station for data storage, reducing the frequent erasing and writing of the FLASH, which can solve the problem of the frequent erasing and writing of the FLASH affecting the service life of the FLASH in the prior art.
[0062] Step 130: Store the current data to be stored into the target storage location.
[0063] Specifically, after determining the target storage location of the data to be stored in the RAM, the data to be stored is directly stored in the RAM. Compared with the prior art, the frequent erasing and writing of the FLASH can be reduced. By combining the RAM with the FLASH, the FLASH simulates the Electrically Erasable Programmable Read-Only Memory (EEPROM), simulates the write life of the EEPROM, improves the service life of the FLASH and the data operability, and realizes a long-life erasing frequency with a smaller FLASH space.
[0064] In the technical solution of this embodiment, the working principle of the data storage method is as follows: Figure 1 First, after obtaining the current data to be stored, obtain the virtual address of the current data to be stored and the current storage space status of the random access memory. Then, determine the target storage location of the current data to be stored in the random access memory according to the virtual address of the current data to be stored and the current storage space status of the random access memory. Finally, store the current data to be stored in the target storage location. It can be seen that this method directly stores the data that needs to be written or updated frequently into the RAM, and reduces the frequent erasing and writing of the FLASH by using the RAM as a temporary transfer station for data storage, which can solve the problem of the frequent erasing and writing of the FLASH affecting the service life of the FLASH in the prior art. And according to the virtual address of the current data to be stored and the current storage space status of the RAM, the storage location of the current data to be stored in the RAM can be further determined, so as to save the data that needs to be written or updated frequently in the RAM, thereby increasing the service life of the FLASH.
[0065] Based on the above embodiment, optionally, the random access memory may be a random access memory that does not lose power.
[0066] In addition, the random access memory can be kept from losing power by designing a power supply device, such as a battery, a button battery, etc. The specific configuration can be made according to the actual situation and is not specifically limited here.
[0067] Based on the above embodiment, optionally, when storing the current data to be stored in the target storage location, it also includes: calculating the heat value of the current data to be stored in the random access memory; counting the number of times the current data to be stored in the random access memory; and recording the timestamp of the current data to be stored in the random access memory.
[0068] Among them, for each data stored in the RAM, the number of times it is stored or written into the RAM is counted or recorded, the heat value stored in the RAM is calculated, and the timestamp of its storage in the RAM is recorded, so as to manage the stored data and further determine the storage location of the data to be stored in the RAM, realize the update or writing of the data to be stored, especially to realize that the data that is repeatedly updated or written (or, the data with high write frequency or heat, and high update frequency or heat) is always saved in the RAM, thereby reducing the number of erase and write times of FLASH and increasing the service life of FLASH.
[0069] As an implementation mode, optionally, when storing the current data to be stored in the target storage location, first, calculate the heat value of the current data to be stored in the random access memory. Then, count the number of times the current data to be stored in the random access memory is stored. Secondly, record the timestamp of the current data to be stored in the random access memory.
[0070] It should be noted that when managing the stored data and subsequently further determining the storage location of the data to be stored in the RAM, the storage location of the data to be stored in the RAM can be further determined based on at least one of the heat value of the data to be stored in the random access memory, the number of times the data to be stored in the random access memory is stored, and the timestamp of the data to be stored in the random access memory. Which one or a combination of these can be used can be set according to actual conditions and is not specifically limited here.
[0071] Specifically, after determining the target storage location of the current data to be stored in the RAM, the current data to be stored is stored in the target storage location, and the heat value of the current data to be stored in the random access memory is calculated, the number of times the current data to be stored in the RAM is counted, and the timestamp of the current data to be stored in the random access memory is recorded, which is conducive to storing data that needs to be repeatedly updated or written in the RAM, so that data with high writing frequency or heat or repeatedly written data is always saved in the RAM, thereby reducing the number of erase and write times of the FLASH and improving the service life of the FLASH. In addition, it is also conducive to further determining the storage location of each data to be stored in the RAM.
[0072] It should be noted that the embodiments of the present application are applicable to applications where small batches of data need to be frequently updated or written, and are particularly applicable to the storage of data that needs to be frequently and repeatedly written or updated.
[0073] In some embodiments, optionally, the implementation method of calculating the heat value of the current data to be stored in the random access memory may include: calculating the heat value according to indicators such as the number of accesses to the local data to be stored, the access time interval, and the access duration. Exemplarily, the heat value of the current data to be stored may be calculated by dividing the number of accesses to the current data to be stored in the current RAM by the ratio of the total number of accesses to all data in the current RAM. Alternatively, the heat value of the current data to be stored may be calculated based on the difference between the last access time and the current time.
[0074] In some embodiments, optionally, counting the number of times the current data to be stored is stored in the random access memory includes: counting the number of times the current data to be stored is stored in the random access memory through a global variable.
[0075] Exemplarily, the implementation process of counting the number of times the current data to be stored is stored in the random access memory through a global variable can be: first, define a global variable to record the number of times each current data to be stored is stored or written in the RAM. When writing the current data to be stored into the RAM, first check the count of the data in the global variable. If the data already exists in the global variable, add 1 to its corresponding count. If the data does not exist in the global variable, add it to the global variable and initialize the count to 1. Among them, the global variable can be an array, a hash table or other suitable data structure, which can be set according to the actual situation, and no specific limitation is made here.
[0076] In some embodiments, optionally, the implementation process of recording the timestamp of the current data to be stored in the random access memory can be: first, record the timestamp, and add a timestamp field in each storage location in the current RAM to record the storage time of the data. Then, update the timestamp, and whenever data is stored in a storage location in the RAM, record the current timestamp in the timestamp field of the storage location. Finally, the survival time of the current data to be stored in the current RAM can be calculated based on the timestamp. Among them, the longer the survival time, the higher the popularity of the data.
[0077] The timestamp may use a specific time format, such as a date and time format, etc. The specific time format may be set according to actual conditions, and no specific limitation is made here.
[0078] Exemplarily, when data needs to be read, first, traverse the data from the RAM to find out whether there is data corresponding to the virtual address of the data to be read in the RAM. If so, read the corresponding data. If not, it means that the data to be read does not exist in the RAM, then traverse the legal area in the FLASH, and search from the back to the front to see whether there is data corresponding to the virtual address of the data to be read. If so, it means that the data to be read is found, and read the corresponding data. Otherwise, it means that the data to be read is not found, and the data reading fails.
[0079] Figure 2 is a flowchart of another data storage method provided in an embodiment of the present application. Based on the above embodiment, optionally, refer to Figure 2 , the method comprises the following steps:
[0080] Step 210: After the current data to be stored is obtained, the virtual address of the current data to be stored and the current storage space state of the random access memory are obtained.
[0081] Step 220: Determine a target storage location of the data to be stored in the random access memory according to the virtual address of the data to be stored and the current storage space state of the random access memory.
[0082] Step 230: Determine whether the current storage space of the random access memory has a first virtual address corresponding to the virtual address of the current data to be stored according to the virtual address of the current data to be stored. If so, execute step 231; otherwise, execute step 232.
[0083] Specifically, after obtaining the current data to be stored and its corresponding virtual address, traverse the data in the RAM to determine whether there is a virtual address corresponding to the virtual address of the current data to be stored in the current storage space of the RAM, and record it as the first virtual address. If it exists, store the current data to be stored according to step 231, calculate the heat value of the current data to be stored in the RAM, count the number of times the current data to be stored is stored or written in the RAM, and record the timestamp of the current data to be stored in the RAM. Otherwise, store the current data to be stored according to step 232, calculate the heat value of the current data to be stored in the RAM, count the number of times the current data to be stored is stored or written in the RAM, and record the timestamp of the current data to be stored in the RAM. Therefore, by determining whether there is a virtual address corresponding to the virtual address of the current data to be stored in the current storage space of the RAM, it is possible to realize that the data that needs to be repeatedly written or repeatedly updated is always stored in the RAM, thereby reducing the frequent erasing and writing of FLASH, and improving the service life of FLASH and the operability of data.
[0084] Exemplarily, whether there is a virtual address corresponding to the virtual address of the data to be currently stored in the current storage space of the RAM refers to: whether there is a virtual address that is the same as the virtual address of the data to be currently stored.
[0085] Step 231: If the first virtual address exists, determine the first virtual address as the target storage location.
[0086] Specifically, after obtaining the current data to be stored, first traverse the RAM to find whether there is a first virtual address that is the same as the virtual address of the data to be stored. If so, the current data to be stored is stored in the first virtual address. In this way, data that is frequently updated or written can be stored in the RAM and always kept in the RAM, thereby reducing the erasing and writing of FLASH and improving the service life of FLASH and the operability of data.
[0087] Step 232: If the first virtual address does not exist, determine the target storage location according to the current storage space state of the random access memory.
[0088] Specifically, after obtaining the current data to be stored, first traverse the RAM to find whether there is a first virtual address that is the same as the virtual address of the data to be stored. If not, further determine the storage location of the current data to be stored in the RAM according to the current storage space status of the RAM, thereby storing the data to be stored in the RAM and using the RAM as a temporary transit station for data storage, thereby reducing the number of erase and write times of the FLASH and improving the service life of the FLASH and the operability of the data.
[0089] Step 240: Store the current data to be stored into the target storage location.
[0090] In the technical solution of this embodiment, the working principle of the data storage method is as follows: Figure 2 First, after obtaining the current data to be stored, obtain the virtual address of the current data to be stored and the current storage space state of the random access memory. Then, determine the target storage position of the current data to be stored in the random access memory according to the virtual address of the current data to be stored and the current storage space state of the random access memory. Secondly, determine whether there is a first virtual address corresponding to the virtual address of the current data to be stored in the current storage space of the random access memory according to the virtual address of the current data to be stored. If there is, the first virtual address is determined as the target storage position. Otherwise, the target storage position is determined according to the current storage space state of the random access memory. Finally, store the current data to be stored in the target storage position. In this way, it is possible to save the data that needs to be frequently updated or written in the RAM, reduce the frequent erasing and writing of the FLASH, and improve the service life of the FLASH. In addition, after obtaining the current data to be stored, firstly by judging whether there is a virtual address corresponding to the virtual address of the current data to be stored in the current storage space of the RAM, it is possible to save the data that needs to be repeatedly written or repeatedly updated in the RAM all the time, thereby reducing the frequent erasing and writing of the FLASH, and improving the service life of the FLASH and the operability of the data. This method can realize direct storage of data that needs to be frequently written or updated in RAM, and use RAM as a temporary transfer station for data storage, thereby reducing the frequent erasing and writing of FLASH, and can solve the problem in the prior art that frequent erasing and writing of FLASH affects the service life of FLASH.
[0091] Figure 3 is a flowchart of another data storage method provided in an embodiment of the present application. Based on the above embodiment, optionally, refer to Figure 3 , the method comprises the following steps:
[0092] Step 310: After the current data to be stored is obtained, the virtual address of the current data to be stored and the current storage space state of the random access memory are obtained.
[0093] Step 320: Determine the target storage location of the data to be stored in the random access memory according to the virtual address of the data to be stored and the current storage space state of the random access memory.
[0094] Step 330: Determine, based on the virtual address of the current data to be stored, whether there is a first virtual address corresponding to the virtual address of the current data to be stored in the current storage space of the random access memory.
[0095] Step 331: If the first virtual address exists, determine the first virtual address as the target storage location.
[0096] Step 332: If the first virtual address does not exist, determine whether there is a free storage location in the current storage space of the random access memory according to the current storage space state of the random access memory.
[0097] Specifically, after obtaining the current data to be stored, first traverse the RAM to find whether there is a first virtual address that is the same as the virtual address of the data to be stored. If not, further determine whether there is free storage space in the current storage space of the RAM. If so, store the current data to be stored in accordance with step 341, calculate the heat value of the current data to be stored in the RAM, count the number of times the current data to be stored is stored or written in the RAM, and record the timestamp of the current data to be stored in the RAM. Otherwise, store the current data to be stored in accordance with step 342, calculate the heat value of the current data to be stored in the RAM, count the number of times the current data to be stored is stored or written in the RAM, and record the timestamp of the current data to be stored in the RAM. Therefore, after obtaining the current data to be stored, it is first determined whether there is a virtual address in the RAM that is the same as the virtual address of the current data to be stored. If so, store the address directly. If it does not exist, it is further determined whether there is a free location in the RAM. This allows the data to be stored in the RAM, especially the data that needs to be repeatedly written or updated to always be kept in the RAM, thereby reducing the frequent erasing and writing of FLASH and improving the service life of FLASH and the operability of the data.
[0098] Step 341: If there is an idle storage location, the idle storage location is determined as the target storage location.
[0099] Specifically, after obtaining the current data to be stored, first traverse the RAM to find whether there is a first virtual address that is the same as the virtual address of the data to be stored. If not, further determine whether there is a free storage location in the current storage space of the RAM. If there is a free storage location, directly store the current data to be stored in the free storage location of the RAM, and store the data to be stored in the RAM, thereby reducing the frequent erasing and writing of FLASH and improving the service life of FLASH and the operability of data.
[0100] It should be noted that the number of current free storage locations of the RAM may be one, two or more, which is subject to the actual operation situation and is not specifically limited here. Exemplarily, when the number of current free storage locations of the RAM is greater than one, they can be stored in sequence according to the order of the storage locations, or they can be set in other ways, which are not specifically limited here.
[0101] Step 342: If there is no free storage location, obtain the first storage location with the smallest heat and the data corresponding to the first storage location in the current storage space of the random access memory, and determine the target storage location based on the first storage location and the data corresponding to the first storage location.
[0102] Specifically, after obtaining the current data to be stored, first traverse the RAM to find whether there is a first virtual address that is the same as the virtual address of the data to be stored. If not, further determine whether there is free storage space in the current storage space of the RAM. If there is no free storage location, the data corresponding to the storage location with the lowest heat currently stored in the RAM (recorded as the first storage location) is removed and transferred to the FLASH, so that the current input to be stored is stored in the RAM, thereby realizing that data that needs to be frequently updated or written is saved in the RAM, thereby minimizing the increase in erase and write of the FLASH due to the need to frequently write or update data, thereby improving the service life of the FLASH and the operability of the data.
[0103] It should be noted that the method for determining the storage location with the lowest heat currently stored in the RAM can be: judging based on at least one of the following: the heat value of the data to be stored in the random access memory is the lowest, the number of times the data to be stored in the random access memory is the least, and the survival time of the data to be stored in the random access memory is the shortest. Which one or a combination of these can be used can be set according to actual conditions, and no specific limitation is made here.
[0104] In some embodiments, optionally, determining the target storage location based on the first storage location and the data corresponding to the first storage location includes: storing the data corresponding to the first storage location in a flash memory, and determining the first storage location as the target storage location.
[0105] Specifically, after obtaining the current data to be stored, first traverse the RAM to find whether there is a first virtual address that is the same as the virtual address of the data to be stored. If not, further determine whether there is free storage space in the current storage space of the RAM. If there is no free storage location, the data corresponding to the storage location with the lowest heat currently stored in the RAM (recorded as the first storage location) is removed and transferred to the FLASH, and the current input to be stored is stored in the first storage location in the RAM, thereby storing the current data to be stored in the RAM.
[0106] In some embodiments, optionally, the flash memory includes at least a first storage area and a second storage area; storing the data corresponding to the first storage location in the flash memory includes: obtaining the current legal area of the flash memory; wherein the current legal area is the first storage area or the second storage area; determining whether the current area status of the current legal area is a full state; if the current area status of the current legal area is a full state, taking the next area following the current legal area as the target legal area, and storing the data corresponding to the first storage location in the target legal area; if the current area status of the current legal area is not a full state, storing the data corresponding to the first storage location in the current legal area.
[0107] Exemplarily, two areas are divided in FLASH, namely the first storage area and the second storage area. When there is no free storage location in RAM, the data corresponding to the storage location with the lowest heat (recorded as the first storage location) currently stored in RAM is removed and transferred to FLASH. The implementation process is as follows: First, obtain the current legal area of FLASH (assuming it is the second storage area), and determine whether the current area status of the current legal area is full. If the current area status of the current legal area is not full, search from front to back in the legal area of FLASH (i.e., the second storage area) for storage space that has not been written (for example, 4 consecutive bytes are all 0XFF, which is free space), and remove the data corresponding to the first storage location in RAM and transfer it to the current legal area (i.e., the second storage area). If the current slice state of the current legal slice is full, the next slice (i.e., the first storage slice) following the current legal slice is used as the target legal slice, and the data corresponding to the first storage position in the RAM is removed and transferred to the target legal slice (i.e., the first storage slice) in the FLASH. The FLASH slice data can be transferred in a manner of: starting from the data slice to be transferred, traversing from back to front, and transferring each virtual address data found first to the beginning of another slice.
[0108] The traversal method of the FLASH area data may be: traversing from the last address in the area from the back to the front.
[0109] In some embodiments, optionally, the next slice following the current legal slice is used as the target legal slice, including: erasing the next slice following the current legal slice, and setting the slice status of the next slice to a receiving state; setting the slice status of the current legal slice to a full state, and storing the last written data in the current legal slice to the next slice; erasing the current legal slice, and using the next slice as the target legal slice.
[0110] Exemplarily, first, obtain the current legal area of FLASH (assuming it is the second storage area), and determine whether the current area state of the current legal area is full. If the current area state of the current legal area is full, then erase the next area (i.e., the first storage area) immediately following the current legal area, and set the area state of the next area (i.e., the first storage area) to the receiving state; set the area state of the current legal area (i.e., the second storage area) to the full state, and store the last written data in the current legal area (i.e., the second storage area) to the next area (i.e., the first storage area), so that when storing data in the next area (i.e., the first storage area), the updated or written data can be queried in time. Erase the current legal area (i.e., the second storage area), and use the next area (i.e., the first storage area) as the target legal area, thereby eliminating the data corresponding to the storage location (recorded as the first storage location) with the lowest heat currently stored in the RAM and transferring it to the FLASH.
[0111] In addition, the data storage method of the embodiment of the present application also includes the initialization of FLASH. When powered on, if the zone state of the current zone is the erase state, and the zone state of another zone is also the erase state, the current zone is set to a legal zone. If the zone state of the current zone is the receiving state, and the zone state of another zone is the full state, the data of the other zone is transferred to the current zone. Otherwise, if the zone state of the current zone is the receiving state, and the other zone is not full, the zone whose zone state is the receiving state of the current zone is set to a legal zone. If the current zone is a legal zone and the zone state of another zone is other states, the other zone is erased. If the zone state of the current zone (assuming it is the first storage zone) is the full state, the other zone (i.e., the second storage zone) is erased, and the data of the current zone (i.e., the first storage zone) is transferred to the erased zone (i.e., the second storage zone).
[0112] Step 350: Store the current data to be stored into the target storage location.
[0113] In the technical solution of this embodiment, the implementation process of the data storage method is: Figure 3First, after obtaining the current data to be stored, obtain the virtual address of the current data to be stored and the current storage space state of the random access memory. Then, determine the target storage position of the current data to be stored in the random access memory according to the virtual address of the current data to be stored and the current storage space state of the random access memory. Secondly, determine whether there is a first virtual address corresponding to the virtual address of the current data to be stored in the current storage space of the random access memory according to the virtual address of the current data to be stored. If the first virtual address exists, determine the first virtual address as the target storage position. If the first virtual address does not exist, determine whether there is an idle storage position in the current storage space of the random access memory according to the current storage space state of the random access memory. If there is an idle storage position, determine the idle storage position as the target storage position. If there is no idle storage position, obtain the first storage position with the smallest heat stored in the current storage space of the random access memory and the data corresponding to the first storage position, and determine the target storage position according to the first storage position and the data corresponding to the first storage position. Finally, store the current data to be stored in the target storage position. Thus, the data that needs to be frequently updated or written can be stored in the RAM, the frequent erasing and writing of the FLASH can be reduced, and the service life of the FLASH can be improved. Moreover, after the current data to be stored is obtained, firstly, by judging whether there is a virtual address corresponding to the virtual address of the current data to be stored in the current storage space of the RAM, the data that needs to be repeatedly written or repeatedly updated can be always stored in the RAM, thereby reducing the frequent erasing and writing of the FLASH, and improving the service life of the FLASH and the operability of the data. In addition, when the virtual address that is the same as the current data to be stored is not currently queried in the RAM, it is further judged whether there is an idle storage location in the RAM, so that the data to be stored can be stored in the RAM, and when there is no idle storage location in the RAM, the data with the smallest number of storage times in the RAM is preferentially transferred so as to store the current data to be stored, thereby realizing that the data that needs to be updated or written is stored in the RAM, and the RAM is used as a temporary transfer station for data storage, and the frequent erasing and writing of the FLASH is reduced, which can solve the problem that the frequent erasing and writing of the FLASH in the prior art affects the service life of the FLASH.
[0114] In some embodiments, optionally, the random access memory includes at least: a real-time clock random access memory (RTC RAM).
[0115] The RTC RAM may be a non-power-off RTC RAM.
[0116] The size of the RTC RAM space can be set according to actual conditions and is not specifically limited here.
[0117] Exemplarily, RTC RAM is only one implementation of the RAM of the present application. In addition, it can also be any other RAM, which can be specifically set according to actual conditions and is not specifically limited here.
[0118] For example, take a non-power-off RTC chip with 31 bytes of RAM available space as an example, and use it as temporary intermediate data storage, using 28 bytes of it, and a total of 7 data can be stored. Each data occupies 4 bytes, of which the first two bytes are used as the virtual address of the data, and the last two bytes are used as the data content. The FLASH is divided into two sections, and the first 12 bytes of each section represent the section status of the section. For example, the section status of the section is shown in Table 1.
[0119] Table 1. Area status of the area
[0120] Status Definition Erase Status Receiving status Legal status Full status BYTE0-3 FFFFFFFF 5555AAAA 5555AAAA 5555AAAA BYTE4-7 FFFFFFFF FFFFFFFF 5555AAAA 5555AAAA BYTE8-11 FFFFFFFF FFFFFFFF FFFFFFFF 5555AAAA
[0121] For example, referring to Table 1, it is assumed that 16K of FLASH space is allocated for the use of the simulated EEPROM, divided into two sections, each section occupies 8K. Among them, the first 12 bytes of each section represent the status of the section. The status of the section includes erase status, receiving status, legal status and full status. Among them, the erase status indicates that the content of the block (BLOCKZ) is all FF, and the receiving status indicates that the current BLOCK is receiving the content of the previous BLOCK. The legal status indicates that all current reads and writes are performed in this BLOCK. The full status indicates that the current BLOCK data is full and no more data can be written. Among them, the first 12 bytes of each BLOCK are used as status definition bits: every four bytes are either 0XFFFFFFFF or 0X5555AAAA. Among them, the data is defined as: the first two bytes are used as the virtual address of the data, and the last two bytes are used as the data content.
[0122] Correspondingly, an embodiment of the present application also provides a data storage device. Figure 4 This is a principle structure block diagram of a data storage device provided in an embodiment of the present application. Figure 4, the data storage device 100 includes: a first acquisition module 101, used to acquire the current data to be stored; a second acquisition module 102, used to acquire the virtual address of the current data to be stored and the current storage space state of the random access memory; a target storage position determination module 103, used to determine the target storage position of the current data to be stored in the random access memory according to the virtual address of the current data to be stored and the current storage space state of the random access memory; a data storage module 104, used to store the current data to be stored in the target storage position. It can be seen that the device directly stores the data that needs to be written or updated frequently into the random access memory, and reduces the frequent erasing and writing of FLASH by using the random access memory as a temporary transfer station for data storage, which can solve the problem of frequent erasing and writing of FLASH affecting the service life of FLASH in the prior art. And according to the virtual address of the current data to be stored and the current storage space state of the random access memory, the storage position of the current data to be stored in the random access memory can be further determined, so as to save the data that needs to be written or updated frequently in the random access memory, thereby improving the service life of FLASH.
[0123] In some embodiments, the target storage location determination module 103 includes: a judgment unit, configured to judge whether there is a first virtual address corresponding to the virtual address of the current data to be stored in the current storage space of the random access memory according to the virtual address of the current data to be stored. A target storage location determination unit, configured to determine the first virtual address as the target storage location if there is the first virtual address; and to determine the target storage location according to the current storage space state of the random access memory if there is no first virtual address.
[0124] In some embodiments, the target storage location determination unit is also used to: determine whether there is a free storage location in the current storage space of the random access memory according to the current storage space status of the random access memory; if there is a free storage location, determine the free storage location as the target storage location; if there is no free storage location, obtain the first storage location with the smallest heat stored in the current storage space of the random access memory and the data corresponding to the first storage location, and determine the target storage location according to the first storage location and the data corresponding to the first storage location.
[0125] In some embodiments, the target storage location determination unit is further used to: store data corresponding to the first storage location in the flash memory, and determine the first storage location as the target storage location.
[0126] In some embodiments, the flash memory includes at least a first storage area and a second storage area; storing data corresponding to the first storage location in the flash memory includes: obtaining a current legal area of the flash memory; wherein the current legal area is the first storage area or the second storage area; determining whether a current area status of the current legal area is a full state; if the current area status of the current legal area is a full state, taking the next area following the current legal area as the target legal area, and storing the data corresponding to the first storage location in the target legal area; if the current area status of the current legal area is not a full state, storing the data corresponding to the first storage location in the current legal area.
[0127] In some embodiments, the next slice following the current legal slice is used as the target legal slice, including: erasing the next slice following the current legal slice, and setting the slice status of the next slice to a receiving state; setting the slice status of the current legal slice to a full state, and storing the last written data in the current legal slice to the next slice; erasing the current legal slice, and using the next slice as the target legal slice.
[0128] In some embodiments, when the current data to be stored is stored in the target storage location, it also includes: counting the number of times the current data to be stored is stored in the random access memory.
[0129] In some embodiments, counting the number of times the current data to be stored is stored in the random access memory includes: counting the number of times the current data to be stored is stored in the random access memory through a global variable.
[0130] In some embodiments, the random access memory includes at least: a real-time clock random access memory that does not lose power.
[0131] Accordingly, the present application also provides an electronic device, see Figure 5 , Figure 5 The structure diagram of the electronic device of the embodiment of the present application is illustrated. The electronic device includes a memory, a processor, and a computer program stored in the memory and executable on the processor, and the steps of the above data storage method are implemented when the processor executes the computer program. Since the data storage method is described in detail above, it will not be repeated here.
[0132] Accordingly, the embodiment of the present application further provides a computer-readable storage medium on which a computer program is stored, and when the computer program is executed by a processor, the steps of the above data storage method are implemented. Since the data storage method is described in detail above, it will not be repeated here.
[0133] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0134] The data storage method, device, equipment and storage medium provided in the embodiments of the present application are introduced in detail above, and the principles and implementation methods of the present application are explained by using specific examples. The description of the above embodiments is only used to help understand the technical solution and its core idea of the present application; ordinary technicians in this field should understand that they can still modify the technical solutions recorded in the aforementioned embodiments, or replace some of the technical features therein with equivalents; and these modifications or replacements do not make the essence of the corresponding technical solution deviate from the scope of the technical solution of the embodiments of the present application.
Claims
1. A data storage method, It is characterized in that Applied to an embedded data storage system, the embedded data storage system at least comprises: a random access memory; The method comprises: After obtaining the current data to be stored, obtaining a virtual address of the current data to be stored and a current storage space state of the random access memory; Determining a target storage location of the data to be stored currently in the random access memory according to a virtual address of the data to be stored currently and a current storage space state of the random access memory; And the current data to be stored is stored in the target storage location.
2. The data storage method according to claim 1, It is characterized in that The step of determining a target storage location of the data to be stored in the random access memory according to the virtual address of the data to be stored and the current storage space state of the random access memory includes: Determining, according to the virtual address of the current data to be stored, whether there is a first virtual address corresponding to the virtual address of the current data to be stored in the current storage space of the random access memory; If the first virtual address exists, determining the first virtual address as the target storage location; If the first virtual address does not exist, the target storage location is determined according to a current storage space state of the random access memory.
3. The data storage method according to claim 2, It is characterized in that The determining the target storage location according to the current storage space state of the random access memory includes: Determining whether there is a free storage location in the current storage space of the random access memory according to the current storage space state of the random access memory; If there is an idle storage location, determining the idle storage location as the target storage location; If there is no free storage location, obtain the first storage location with the smallest heat and the data corresponding to the first storage location in the current storage space of the random access memory, and determine the target storage location based on the first storage location and the data corresponding to the first storage location.
4. The data storage method according to claim 3, It is characterized in that The embedded data storage system further includes: a flash memory; and determining the target storage location according to the first storage location and the data corresponding to the first storage location includes: The data corresponding to the first storage location is stored in the flash memory, and the first storage location is determined as the target storage location.
5. The data storage method according to claim 4, It is characterized in that The flash memory comprises at least a first storage area and a second storage area; The storing the data corresponding to the first storage location in the flash memory includes: Acquire a current legal slice of the flash memory; wherein the current legal slice is the first storage slice or the second storage slice; Determine whether the current zone state of the current legal zone is full; If the current slice state of the current legal slice is full, taking the next slice immediately following the current legal slice as the target legal slice, and storing the data corresponding to the first storage position in the target legal slice; If the current slice state of the current legal slice is not a full state, the data corresponding to the first storage location is stored in the current legal slice.
6. The data storage method according to claim 5, It is characterized in that The step of taking the next slice immediately following the current legal slice as the target legal slice comprises: Erasing the next slice immediately following the current legal slice, and setting the slice state of the next slice to a receiving state; Setting the slice state of the current legal slice to a full state, and storing the last written data in the current legal slice to the next slice; The current legal slice is erased, and the next slice is used as the target legal slice.
7. The data storage method according to claim 1, It is characterized in that When storing the current data to be stored in the target storage location, the method further includes: Calculating the heat value of the current data to be stored in the random access memory; Counting the number of times the current data to be stored is stored in the random access memory; And record the timestamp of the current data to be stored in the random access memory.
8. The data storage method according to claim 7, It is characterized in that The counting of the number of times the current data to be stored is stored in the random access memory includes: The number of times the current data to be stored is stored in the random access memory is counted through a global variable.
9. The data storage method according to claim 1, It is characterized in that The random access memory at least includes: a real-time clock random access memory.
10. A data storage device, It is characterized in that Applied to an embedded data storage system, the embedded data storage system at least comprises: a random access memory; The device comprises: A first acquisition module, used to acquire the current data to be stored; A second acquisition module, used for acquiring the virtual address of the current data to be stored and the current storage space state of the random access memory; a target storage location determination module, configured to determine a target storage location of the data to be stored currently in the random access memory according to a virtual address of the data to be stored currently and a current storage space state of the random access memory; The data storage module is used to store the current data to be stored in the target storage location.
11. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, It is characterized in that When the processor executes the computer program, the data storage method according to any one of claims 1 to 10 is implemented.
12. A computer-readable storage medium having a computer program stored thereon, It is characterized in that When the computer program is executed by a processor, the data storage method according to any one of claims 1 to 10 is implemented.
