An embedded FLASH data storage management method, system and storage medium
Patent Information
- Application Number
- CN202210652057.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-06-09
- Publication Date
- 2026-10-09
- Estimated Expiration
- 2042-06-09
AI Technical Summary
B.擦除时以扇区为单元进行操作,需要先读后写,若涉及到跨扇区,需要多次操作,影响擦除效率;
[0014]After adopting the above scheme, the data storage of this invention is divided into two partitions, achieving overall FLASH load balancing. Based on this, a sliding window method is used to write data, achieving FLASH load balancing within the data table and extending the FLASH's lifespan. Furthermore, when writing data, this invention eliminates the need for searching; it directly writes based on the available storage address. When deleting data, there is no need to erase the corresponding sector; simply setting the corresponding flag to 0 is sufficient. Erasing is performed on the entire data table, without needing to consider the content of each sector, eliminating the need for read-then-write operations; the entire block is erased, improving read and write efficiency.
Smart Images

Figure CN115185857B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer data storage, and specifically to an embedded FLASH data storage management method, system, and storage medium. Background Technology
[0002] With the continuous development of the Internet of Things (IoT), embedded devices are widely used in various fields. Most devices involve data storage and management, and the implementation of storage and management methods greatly affects the efficiency and lifespan of the device.
[0003] For example, patent application number 202111095921.7 discloses a data storage management method for an embedded NOR FLASH chip. This method divides the NOR FLASH chip's storage space into three parts: an index table area, a flag management table area, and a data storage area. It searches for data to be erased using data occupancy flags in the index table area, data processing flags in the flag management table area, and data weights, and places its address in the erasure area. When Flash storage space is insufficient, data in the data storage area is erased sequentially according to the data address in the erasure area. The method disclosed in this patent application has the following problems: A. When erasing data, a full index table search is required. When the data is large, the search speed is slow, and even if it is divided into multiple rounds of search, the efficiency is not high. B. Erasing is performed on a sector-by-sector basis, requiring a read-then-write operation. If cross-sector operations are involved, multiple operations are required, which affects erasing efficiency. C. The read / write load balancing of the flash memory was not considered, resulting in some areas being frequently erased and rewritten, which affects the lifespan of the flash memory. Summary of the Invention
[0004] In view of the problems existing in the prior art, the purpose of this invention is to provide a sliding table storage management method, system and storage medium based on embedded FLASH chip, so as to achieve load balancing and extend the service life of FLASH chip.
[0005] To achieve the above objectives, the technical solution adopted by the present invention is as follows: An embedded FLASH data management method, comprising: The FLASH storage area is divided into two storage areas: the storage area currently in use is defined as the current storage area, and the other storage area is defined as the redundant storage area. When adding data, check if there is free space in the current storage area. If there is, add the data to the current storage area; otherwise, switch storage areas. When deleting data, mark the data to be deleted; The storage area switching process involves: erasing the entire redundant storage area, moving unmarked data from the current storage area to the redundant storage area, then switching the current storage area to the redundant storage area, and finally switching the redundant storage area back to the current storage area.
[0006] The FLASH storage area is configured with a sliding table to assist in data addition, deletion, and storage switching operations. The structure of the sliding table includes: current storage starting sector number, redundant storage starting sector number, write index array, current write index, delete index array, current delete index, maximum number of stored records, actual maximum number of stored records, number of stored records, and length of a single data record. When adding data, check if the current write index of the sliding table is less than the maximum number of records to store. If it is, write the sector corresponding to the current write index directly, set the index position corresponding to the write index array to 0, and increment the current write index by 1. Otherwise, it means that there is no available free index in the current sliding table, and then switch storage areas. or When adding data, check if the current write index of the sliding table is less than or equal to the maximum number of records to be stored. If so, write the data directly to the sector corresponding to the current write index, set the corresponding index position in the write index array to 0, and increment the current write index by 1 to achieve sliding data writing. Otherwise, check if the current write index is less than the actual maximum number of records to be stored. If it is less than the actual maximum number of records to be stored, set the corresponding delete index position in the delete index array to 0, set the current delete index to the first non-zero index of the delete index array, set the corresponding index position in the write index array to 0, and increment the current write index by 1. If it is greater than the actual maximum number of records to be stored, it means that there are no available free indexes in the current sliding table, and the storage area needs to be switched.
[0007] When deleting data, the corresponding bit in the deletion index array is set to 0, which indicates that the data is in a deleted state. Then, the current deletion index is set to the first non-zero index of the deletion index array.
[0008] The specific method for switching storage areas is as follows: The specific switching operation of the storage area switching module is as follows: the data area of the redundant storage area is completely erased, and the corresponding valid data in the sliding table is moved and written into the redundant storage area. Invalid data is discarded and not operated. After the transfer of valid data is completed, the current storage starting sector number and the redundant storage starting sector number of the sliding table are switched. The valid data refers to the data whose corresponding write index array is 0 and whose delete index array is not 0.
[0009] Initialize the sliding table before using FLASH to store data; The initialization method of the sliding table is as follows: Based on the maximum number of storage entries and the size of a single data entry, the size of a single storage area is calculated. When a single storage area is less than 4K, the two storage areas are aligned to 4K, meaning the first and second storage areas each allocate 4K of storage space. When a single storage area is greater than 4K and less than or equal to 64K, the first and second storage areas each allocate 64K of storage space. When a single storage area is greater than 64K, the first and second storage areas each allocate a storage space that is an integer multiple of 4K. The current write index and the current delete index are initialized to 0, and the write index array and the delete index array are initialized to all 1s.
[0010] A computer-readable storage medium storing instructions that, when executed on a terminal device, cause the terminal device to perform an embedded FLASH data management method as described above.
[0011] An embedded FLASH data management system is provided. The management system is used to store data in FLASH storage space. The FLASH storage area includes two storage areas. The storage area currently in use is defined as the current storage area, and the other storage area is defined as the redundant storage area. The management system includes a data addition module, a data deletion module, and a storage area switching module; The data addition module is used to determine whether there is free space in the current storage area when adding data. If there is, the data is added to the current storage area; if not, the storage area switching module is activated. The data deletion module is used to mark the data to be deleted when deleting data; The storage area switching module is used to erase the entire redundant storage area, then move the unlabeled data in the current storage area to the redundant storage area, and then switch between the current storage area and the redundant storage area, that is, the current storage area is switched to the redundant storage area, and the redundant storage area is switched to the current storage area.
[0012] The FLASH storage area is configured with a sliding table, the structure of which includes: current storage starting sector number, redundant storage starting sector number, write index array, current write index, delete index array, current delete index, maximum number of storage rows, actual maximum number of storage rows, number of stored rows, and length of a single data row; When the data addition module adds data, it determines whether the current write index of the current sliding table is less than the maximum number of storage rows. If so, it directly writes to the sector corresponding to the current write index, sets the index position corresponding to the write index array to 0, and increments the current write index by 1. Otherwise, it indicates that there are no available free indexes in the current sliding table, and the storage area switching module is activated; or The system checks if the current write index of the sliding table is less than or equal to the maximum number of records to be stored. If so, it directly writes the data to the sector corresponding to the current write index, sets the corresponding index position in the write index array to 0, and increments the current write index by 1 to achieve sliding data writing. Otherwise, it checks if the current write index is less than the actual maximum number of records to be stored. If it is less than the actual maximum number of records to be stored, it sets the corresponding delete index array bit to 0, sets the current delete index to the first non-zero index of the delete index array, sets the corresponding index position in the write index array to 0, and increments the current write index by 1. If it is greater than the actual maximum number of records to be stored, it means that there are no available free indexes in the current sliding table, and the storage area switching module is activated. and / or When the data deletion module deletes data, it sets the corresponding bit of the deletion index array to 0, that is, the data is represented as deleted, and then sets the current deletion index to the first non-zero index of the deletion index array; and / or The specific switching operation of the storage area switching module is as follows: the data area of the redundant storage area is completely erased, and the corresponding valid data in the sliding table is moved and written into the redundant storage area. Invalid data is discarded and not operated. After the transfer of valid data is completed, the current storage starting sector number and the redundant storage starting sector number of the sliding table are switched. The valid data refers to the data whose corresponding write index array is 0 and whose delete index array is not 0.
[0013] The management system also includes an initialization module for initializing the sliding table; the specific initialization method is as follows: Based on the maximum number of storage entries and the size of a single data entry, the size of a single storage area is calculated. When a single storage area is less than 4K, the two storage areas are aligned to 4K, meaning the first and second storage areas each allocate 4K of storage space. When a single storage area is greater than 4K and less than or equal to 64K, the first and second storage areas each allocate 64K of storage space. When a single storage area is greater than 64K, the first and second storage areas each allocate a storage space that is an integer multiple of 4K. The current write index and the current delete index are initialized to 0, and the write index array and the delete index array are initialized to all 1s.
[0014] After adopting the above scheme, the data storage of this invention is divided into two partitions, achieving overall FLASH load balancing. Based on this, a sliding window method is used to write data, achieving FLASH load balancing within the data table and extending the FLASH's lifespan. Furthermore, when writing data, this invention eliminates the need for searching; it directly writes based on the available storage address. When deleting data, there is no need to erase the corresponding sector; simply setting the corresponding flag to 0 is sufficient. Erasing is performed on the entire data table, without needing to consider the content of each sector, eliminating the need for read-then-write operations; the entire block is erased, improving read and write efficiency. Attached Figure Description
[0015] Figure 1 Flowchart for initializing a sliding table; Figure 2 To add a data flow diagram; Figure 3 Flowchart for deleting data; Figure 4 This is a flowchart of the sliding table switching process. Detailed Implementation
[0016] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. The components of the embodiments of the present invention described and shown in the accompanying drawings can generally be arranged and designed in various different configurations.
[0017] Therefore, the following detailed description of the embodiments of the invention provided in the accompanying drawings is not intended to limit the scope of the claimed invention, but merely to illustrate selected embodiments of the invention. All other embodiments obtained by those skilled in the art based on the embodiments of the invention without inventive effort are within the scope of protection of the invention.
[0018] Example 1 This embodiment discloses an embedded FLASH data management method, which includes: A sliding list is configured in the FLASH memory area to divide it into two memory areas. The two memory areas are used alternately through the sliding list. The memory area currently in use is defined as the current memory area, and the other memory area is defined as the redundant memory area.
[0019] The sliding list structure includes: current starting sector number, redundant starting sector number, write index array, current write index, delete index array, current delete index, maximum number of records to store, actual maximum number of records to store, number of records already stored, and single record length. The maximum number of records to store and the single record length are used during initialization to configure the desired storage partition size (i.e., maximum number of records to store * single record length). During data addition, the maximum number of records to store is used as a boundary check to see if it exceeds the maximum or actual maximum number of records to store. The single record length is used during data addition to calculate the offset write position (i.e., write address = current starting partition address + current write index * single record length). The starting partition address is calculated from the starting sector number. The same logic applies to deletion.
[0020] like Figure 1 As shown, the sliding table is initialized before using FLASH to store data.
[0021] During use, the sliding table can be configured and initialized according to business needs. In this embodiment, when initializing the sliding table, whether it is the current storage table or the redundant storage table, the starting address will be aligned to 4K address to improve subsequent read and write efficiency.
[0022] The index array is allocated based on the actual number of data records to be used. Each index (one bit) in the array corresponds to one data record, with bit 0 and bit 1 representing the status of that data record. The index array is initialized to all 1s by default. The current write index and the current delete index are initialized to 0. These two variables are used to implement a sliding window to control data reading and writing and the determination of valid data. For the write index array, if the index array value is ['0','0','0','0','1','1','1','1'], it means that data has been written to the storage locations corresponding to indices 1-4, and no data has been written to the storage locations corresponding to indices 5-8. For the delete index array, if the index array value is ['0','0','1','1','1','1','1','1','1'], it means that data has been deleted to the storage locations corresponding to indices 1-2, and no data has been deleted to the storage locations corresponding to indices 3-8.
[0023] Based on the states of the two index arrays above, we can conclude that there are currently 2 valid data entries (because 4 entries were written and 2 were deleted). The specific initialization is as follows: Based on the maximum number of storage entries and the size of a single data entry, the size of a single storage area is calculated. When a single storage area is less than 4K, the two storage areas are aligned to 4K, meaning that the first and second storage areas each allocate 4K of storage space. When a single storage area is greater than 4K and less than or equal to 64K, the first and second storage areas each allocate 64K of storage space. When a single storage area is greater than 64K, the first and second storage areas each allocate a storage space that is an integer multiple of 4K (for example, if the space is 125K, then it is allocated as 128K).
[0024] The so-called initialization actually involves initializing the sliding table header and the two storage areas. The header records information about both storage areas. The size of each storage area is determined by the maximum number of records and the size of a single record; both storage areas are the same size. Storage area size = maximum number of records * size of a single record, then address alignment is performed.
[0025] For example: For example, during initialization, if the length of a single data entry is set to 100 bytes and the maximum number of data entries to be stored is 40, then the size of each storage area is 100 * 40 = 4000 bytes.
[0026] If the starting address of the FLASH storage area is 3800, then the starting address of the first storage area is 4096 (3800 is 4K aligned). The starting sector number of the first storage area = starting address / 4096, i.e., 4096 / 4096 = 1; the size of the first storage area is 4K (4000 bytes is less than 4K, so it is divided into 4K). The starting address of the second storage area = the starting address of the first storage area + the size of the first storage area, i.e., 4096 + 4096 = 8192. The starting sector number of the second storage area = starting address / 4096, i.e., 8192 / 4096 = 2; the size of the second storage area is also 4K (4000 bytes is less than 4K, so it is divided into 4K). The current write index and the current delete index are initialized to 0, and the write index array and the delete index array are initialized to all 1s.
[0027] For example, during initialization, if the length of a single data entry is set to 200 bytes and the maximum number of entries to be stored is 4000, then the partition size = 200 * 4000 = 800000 bytes.
[0028] If the starting address of the FLASH storage area is 18700, then the starting address of the first storage area is 20480 (18700 is 4K aligned). The size of the first storage area is 784K (800,000 bytes is greater than 64K, so it should be divided into multiples of 4K; calculation shows 196 4K blocks are needed, i.e., 196 * 4096 = 802,816 bytes). The starting sector number of the first storage area = starting address / 4096, i.e., 20480 / 4096 = 5. The starting address of the second storage area = starting address of the first storage area + size of the first storage area, i.e., 20480 + 802,816 = 823,296. The starting sector number of the second storage area = starting address / 4096, i.e., 823,296 / 4096 = 201; the size of the second storage area is also 823,296 bytes. The current write index and the current delete index are initialized to 0, and the write index array and the delete index array are initialized to all 1s.
[0029] like Figure 2-4 As shown, the process of using FLASH to store data includes adding and deleting data.
[0030] When adding data, check if the current write index of the sliding table is less than or equal to the maximum number of records to store. If it is, write the data directly to the sector corresponding to the current write index, set the index position corresponding to the write index array to 0, and increment the current write index by 1 to achieve data writing in a sliding manner. Otherwise, it means that there is no available free index in the current sliding table and the storage area needs to be switched.
[0031] The maximum number of storage rows is generally less than or equal to the actual maximum number of storage rows. When they are equal, the decision to switch storage areas is based on either the maximum or the actual maximum number of storage rows, and the result is the same. When the maximum number of storage rows is less than the actual maximum number of storage rows, the data storage process and results differ slightly depending on whether the decision is based on the maximum number of storage rows or the actual maximum number of storage rows. The data storage process based on the maximum number of storage rows is as described above. The data storage process based on the actual maximum number of storage rows is as follows: When adding data, check if the current write index of the sliding table is less than or equal to the maximum number of records to be stored. If so, write the data directly to the sector corresponding to the current write index, set the corresponding index position in the write index array to 0, and increment the current write index by 1 to achieve sliding data writing. Otherwise, check if the current write index is less than the actual maximum number of records to be stored. If it is less than the actual maximum number of records to be stored, set the corresponding delete index position in the delete index array to 0, set the current delete index to the first non-zero index of the delete index array, set the corresponding index position in the write index array to 0, and increment the current write index by 1. If it is greater than the actual maximum number of records to be stored, it means that there are no available free indexes in the current sliding table, and the storage area needs to be switched.
[0032] The specific steps for switching storage areas are as follows: The entire data area of the redundant storage area is erased, and the corresponding valid data in the sliding table (i.e., data whose corresponding write index array is 0 and whose delete index array is not 0) is moved and written to the redundant storage area. Invalid data is discarded and not processed. After the transfer of valid data is completed, the starting sector number of the current storage and the starting sector number of the redundant storage are switched. For example, if the starting sector number of the current storage area is the starting sector number of the first storage area, and the starting sector number of the redundant storage is the starting sector number of the second storage area, after switching the storage areas, the starting sector number of the current storage area is the starting sector number of the second storage area, and the starting sector number of the redundant storage is the starting sector number of the first storage area.
[0033] Because both the current sliding table and the redundant sliding table use 4K address alignment, the actual maximum number of stored rows will be more than the maximum number of stored rows allocated by the application. This avoids the problem of repeatedly moving the entire data when the allocated row limit is exceeded, and prevents repeated flash writes and erases. In addition, because dual partition switching is set up, flash load balancing can be achieved, avoiding continuous reading and writing of the same area.
[0034] When deleting data, simply set the corresponding bit of the deletion index array to 0, which indicates that the data is in a deleted state. There is no need to erase the corresponding sector, which greatly improves the efficiency of the deletion operation. Then, set the current deletion index to the first non-zero index of the deletion index array.
[0035] Example 2 Based on a unified inventive concept, this embodiment discloses an embedded FLASH data management system, characterized in that: the management system is used to store data in the FLASH storage space, the FLASH storage area includes two storage areas, of which the storage area currently in use is defined as the current storage area, and the other storage area is defined as the redundant storage area.
[0036] The management system includes a data addition module, a data deletion module, and a storage area switching module. The data addition module checks for available space in the current storage area when adding data; if available, it adds the data to the current storage area; otherwise, it activates the storage area switching module. The data deletion module marks the deleted data. The storage area switching module erases the entire redundant storage area, moves unmarked data from the current storage area to the redundant storage area, and then switches between the current and redundant storage areas—that is, the current storage area becomes the redundant storage area, and the redundant storage area becomes the current storage area.
[0037] More preferably, a sliding table is configured in the FLASH storage area to assist in adding, deleting, and switching storage areas. The structure of the sliding table includes: current storage starting sector number, redundant storage starting sector number, write index array, current write index, delete index array, current delete index, maximum number of stored rows, actual maximum number of stored rows, number of stored rows, and length of a single data row.
[0038] When adding data, the data addition module determines whether the current write index of the sliding table is less than the maximum number of records to be stored. If so, it directly writes the sector corresponding to the current write index, sets the index position of the write index array to 0, and increments the current write index by 1. Otherwise, it indicates that there are no available free indexes in the current sliding table, and the storage area switching module is activated. Alternatively, it determines whether the current write index of the sliding table is less than or equal to the maximum number of records to be stored. If so, it directly writes the data to the sector corresponding to the current write index, sets the index position of the write index array to 0, and increments the current write index by 1, thus implementing sliding data writing. Otherwise, it determines whether the current write index is less than the actual maximum number of records to be stored. If it is less than the actual maximum number of records to be stored, it sets the delete index array corresponding to the current delete index to 0, sets the current delete index to the first non-zero index of the delete index array, sets the index position of the write index array to 0, and increments the current write index by 1. If it is greater than the actual maximum number of records to be stored, it indicates that there are no available free indexes in the current sliding table, and the storage area switching module is activated. When the data deletion module deletes data, it sets the corresponding bit of the deletion index array to 0, that is, it represents the data as deleted, and then sets the current deletion index to the first non-zero subscript of the deletion index array.
[0039] The specific switching operation of the storage area switching module is as follows: The entire data area of the redundant storage area is erased, and the corresponding valid data from the sliding table is moved and written to the redundant storage area. Invalid data is discarded without further operation. After the valid data is moved, the current storage starting sector number and the redundant storage starting sector number of the sliding table are switched. The valid data refers to data whose corresponding write index array is 0 and whose delete index array is not 0.
[0040] The management system also includes an initialization module for initializing the sliding table. The specific initialization method is as follows: Based on the maximum number of storage rows and the size of a single data row, the size of a single storage area is calculated. When a single storage area is less than 4K, the two storage areas are aligned to 4K, meaning the first and second storage areas each allocate 4K of storage space. When a single storage area is greater than 4K and less than or equal to 64K, the first and second storage areas each allocate 64K of storage space. When a single storage area is greater than 64K, the first and second storage areas each allocate a storage space that is an integer multiple of 4K. The currently written index and the currently deleted index are initialized to 0, and the write index array and the delete index array are initialized to all 1s.
[0041] Example 3 This embodiment discloses a computer-readable storage medium storing instructions that, when executed on a terminal device, cause the terminal device to perform an embedded FLASH data management method as described in Embodiment 1.
[0042] In summary, the data storage dual-partitioning of this invention achieves overall FLASH load balancing. Furthermore, the sliding window method for writing data further balances the FLASH load within the data table, extending the FLASH's lifespan. Moreover, this invention eliminates the need for searching when writing data; it directly writes data based on the available storage address. When deleting data, there's no need to erase the corresponding sector; simply setting the corresponding flag to 0 suffices. Erasing is performed on the entire data table, eliminating the need to monitor the content of each sector and avoiding the need for read-then-write operations; the entire block is erased, improving read and write efficiency.
[0043] Those skilled in the art will understand that embodiments of the present invention can be provided as methods, systems, or computer program products. Therefore, the present invention can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present invention can take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0044] This invention is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart illustrations and / or block diagrams. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0045] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.
[0046] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0047] It should be noted that any reference signs placed between parentheses in the claims should not be construed as limiting the claims. The word "comprising" does not exclude the presence of components or steps not listed in the claims. The word "a" or "an" preceding a component does not exclude the presence of a plurality of such components. The invention can be implemented by means of hardware comprising several different components and by means of a suitably programmed computer. In a unit claim enumerating several means, several of these means may be embodied by the same item of hardware. The use of the words first, second, and third, etc., does not indicate any order. These words can be interpreted as names.
[0048] Although preferred embodiments of the invention have been described, those skilled in the art, upon learning the basic inventive concept, can make other changes and modifications to these embodiments. Therefore, the appended claims are intended to be interpreted as including both the preferred embodiments and all changes and modifications falling within the scope of the invention.
[0049] Obviously, those skilled in the art can make various modifications and variations to this invention without departing from its spirit and scope. Therefore, if these modifications and variations fall within the scope of the claims of this invention and their equivalents, this invention also intends to include these modifications and variations.
[0050] In the description of this specification, the references to terms such as "one embodiment," "some embodiments," "example," "specific example," or "some examples," etc., refer to specific features, structures, materials, or characteristics described in connection with that embodiment or example, which are included in at least one embodiment or example of the present invention. In this specification, the illustrative expressions of the above terms should not be construed as necessarily referring to the same embodiment or example. Furthermore, the specific features, structures, materials, or characteristics described may be combined in any suitable manner in one or more embodiments or examples. Moreover, without contradiction, those skilled in the art can combine and integrate the different embodiments or examples described in this specification, as well as the features of different embodiments or examples.
Claims
1. An embedded FLASH data management method, characterized in that: The method includes: The FLASH storage area is divided into two storage areas: the storage area currently in use is defined as the current storage area, and the other storage area is defined as the redundant storage area. When adding data, check if there is free space in the current storage area. If there is, add the data to the current storage area; otherwise, switch storage areas. When deleting data, mark the data to be deleted; The storage area switching process is as follows: erase the entire redundant storage area, move the unlabeled data in the current storage area to the redundant storage area, then switch the current storage area to the redundant storage area, and then switch the redundant storage area to the current storage area. The FLASH storage area is configured with a sliding table to assist in data addition, deletion, and storage switching operations. The structure of the sliding table includes: current storage starting sector number, redundant storage starting sector number, write index array, current write index, delete index array, current delete index, maximum number of stored records, actual maximum number of stored records, number of stored records, and length of a single data record. When adding data, check if the current write index of the sliding table is less than the maximum number of records to store. If it is, write the sector corresponding to the current write index directly, set the index position corresponding to the write index array to 0, and increment the current write index by 1. Otherwise, it means that there is no available free index in the current sliding table, and then switch storage areas. or When adding data, check if the current write index of the sliding table is less than or equal to the maximum number of records to be stored. If so, write the data directly to the sector corresponding to the current write index, set the corresponding index position in the write index array to 0, and increment the current write index by 1 to achieve sliding data writing. Otherwise, check if the current write index is less than the actual maximum number of records to be stored. If it is less than the actual maximum number of records to be stored, set the corresponding delete index position in the delete index array to 0, set the current delete index to the first non-zero index of the delete index array, set the corresponding index position in the write index array to 0, and increment the current write index by 1. If it is greater than the actual maximum number of records to be stored, it means that there are no available free indexes in the current sliding table, and it is necessary to switch to another storage area.
2. The embedded FLASH data management method according to claim 1, characterized in that: When deleting data, the corresponding bit in the deletion index array is set to 0, which indicates that the data is in a deleted state. Then, the current deletion index is set to the first non-zero index of the deletion index array.
3. The embedded FLASH data management method according to claim 1, characterized in that: The specific method for switching storage areas is as follows: Erase the entire data area of the redundant storage area, and move the corresponding valid data from the sliding table into the redundant storage area. Discard invalid data without any operation. After the transfer of valid data is completed, switch the current storage starting sector number of the sliding table and the redundant storage starting sector number. The valid data refers to the data whose corresponding write index array bit is 0 and whose delete index array bit is not 0.
4. An embedded FLASH data management method according to any one of claims 1-3, characterized in that: Initialize the sliding table before using FLASH to store data; The initialization method of the sliding table is as follows: Based on the maximum number of storage entries and the size of a single data entry, the size of a single storage area is calculated. When a single storage area is less than 4K, the two storage areas are aligned to 4K, meaning the first and second storage areas each allocate 4K of storage space. When a single storage area is greater than 4K and less than or equal to 64K, the first and second storage areas each allocate 64K of storage space. When a single storage area is greater than 64K, the first and second storage areas each allocate a storage space that is an integer multiple of 4K. The current write index and the current delete index are initialized to 0, and the write index array and the delete index array are initialized to all 1s.
5. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores instructions that, when executed on a terminal device, cause the terminal device to perform an embedded FLASH data management method as described in any one of claims 1-4.
6. An embedded FLASH data management system, characterized in that: The management system is used to store data in the FLASH storage space. The FLASH storage area includes two storage areas. The storage area that is currently in use is defined as the current storage area, and the other storage area is defined as the redundant storage area. The management system includes a data addition module, a data deletion module, and a storage area switching module; The data adding module is used to determine whether there is free space in the current storage area when adding data; if so, the data is added to the current storage area. If not, then activate the storage area switching module; The data deletion module is used to mark the data to be deleted when deleting data; The storage area switching module is used to erase the entire redundant storage area, then move the unlabeled data in the current storage area to the redundant storage area, and then switch the current storage area and the redundant storage area, that is, the current storage area is switched to the redundant storage area, and the redundant storage area is switched to the current storage area. The FLASH storage area is configured with a sliding table, the structure of which includes: current storage starting sector number, redundant storage starting sector number, write index array, current write index, delete index array, current delete index, maximum number of storage rows, actual maximum number of storage rows, number of stored rows, and length of a single data row; When the data addition module adds data, it determines whether the current write index of the current sliding table is less than the maximum number of storage rows. If so, it directly writes to the sector corresponding to the current write index, sets the corresponding index position in the write index array to 0, and increments the current write index by 1. Otherwise, it indicates that there are no available free indexes in the current sliding table, and the storage area switching module is activated. The system checks if the current write index of the sliding table is less than or equal to the maximum number of records to be stored. If so, it directly writes the data to the sector corresponding to the current write index, sets the corresponding index position in the write index array to 0, and increments the current write index by 1 to achieve sliding data writing. Otherwise, it checks if the current write index is less than the actual maximum number of records to be stored. If it is less than the actual maximum number of records to be stored, it sets the corresponding delete index position in the delete index array to 0, sets the current delete index to the first non-zero index in the delete index array, sets the corresponding index position in the write index array to 0, and increments the current write index by 1. If it is greater than the actual maximum number of records to be stored, it means that there are no available free indexes in the current sliding table, and the storage area switching module is activated.
7. An embedded FLASH data management system according to claim 6, characterized in that... When the data deletion module deletes data, it sets the corresponding bit of the deletion index array to 0, that is, it represents the data as deleted, and then sets the current deletion index to the first non-zero subscript of the deletion index array; and / or The specific switching operation of the storage area switching module is as follows: the data area of the redundant storage area is completely erased, and the corresponding valid data in the sliding table is moved and written into the redundant storage area. Invalid data is discarded and not operated. After the transfer of valid data is completed, the current storage starting sector number and the redundant storage starting sector number of the sliding table are switched. The valid data refers to data whose corresponding write index array is 0 and whose delete index array is not 0.
8. An embedded FLASH data management system according to claim 7, characterized in that: The management system also includes an initialization module for initializing the sliding table; the specific initialization method is as follows: Based on the maximum number of storage entries and the size of a single data entry, the size of a single storage area is calculated. When a single storage area is less than 4K, the two storage areas are aligned to 4K, meaning the first and second storage areas each allocate 4K of storage space. When a single storage area is greater than 4K and less than or equal to 64K, the first and second storage areas each allocate 64K of storage space. When a single storage area is greater than 64K, the first and second storage areas each allocate a storage space that is an integer multiple of 4K. The current write index and the current delete index are initialized to 0, and the write index array and the delete index array are initialized to all 1s.
Citation Information
Patent Citations
A data storage management method for embedded NOR FLASH chip
CN113886281B
Serial flash memory, data processing method and device thereof and storage medium
CN114281241A