Data management method and system for improving FLASH storage times
By dividing the data area and management area in FLASH storage, and using the management area to record address information for sector cycle storage and cross-sector erasure, the problem of waste of storage resources and shortened life is solved, and more efficient data management and storage expansion are achieved. , extending the service life of the FLASH chip.
Patent Information
- Application Number
- CN202410752684.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-12
- Publication Date
- 2024-09-10
AI Technical Summary
When existing technology frequently erases and stores large amounts of data of variable length, FLASH storage resources are wasted and service life is shortened, especially in embedded smart products, which affects device reliability and robustness.
By dividing the FLASH storage space into a data area and a management area, and using the management area to record data address information, sector circular storage and cross-sector erasure are realized, data management and erasure times are optimized, and resource waste and erasure times are reduced.
Effectively utilize sector resources to extend the service life of FLASH chips, improve storage times and data reading and writing efficiency, and reduce erasure time. It is suitable for small-capacity FLASH chips to meet large storage needs.
Smart Images

Figure CN118626012A
Abstract
Description
Technical Field
[0001] The present invention relates to the field of FLASH storage technology, and in particular to a data management method and system for improving FLASH storage times. Background Art
[0002] At present, more and more embedded intelligent products use FLASH to store data. For applications that require large amounts of data storage and can export historical data, such as data collection and monitoring in industries such as electricity and meteorology, FLASH needs to be frequently erased and data recorded. Mainstream products on the market, such as Nand FLASH and Nor FLASH, both have sectors as their minimum erase unit. If the number of FLASH storage times is not managed, the reliability and robustness of embedded devices will be greatly affected.
[0003] The existing methods for increasing the number of FLASH storage times of single-chip microcomputers are mostly based on multi-sector cyclic storage, detecting the content of the data storage unit corresponding to the pre-stored base address, and judging the storage result according to the schemes such as CRC, magic number flag or setting storage threshold, to judge whether the stored content is a valid value. The advantage is that the designated sector is not frequently erased and written, but all sectors are reasonably used for cyclic erasing and writing. If the FLASH erase life is 10,000 times, it can be increased to 10,000*N times (N represents the number of sectors divided), but this is for the case when the amount of data stored each time is far less than the size of a sector, and the minimum erase unit of the commonly used FLASH is a sector, then the unused storage area in a sector causes a waste of resources; when a large amount of indefinite length data information needs to be stored at one time, the size of a sector may not be enough, and opening a specified number of sectors for storage will also cause space waste because the number of bytes of the indefinite length data is less than the number of bytes of the specified number of sectors, and will cause frequent erasing of FLASH to obtain sectors of a specified size, affecting the service life. Summary of the invention
[0004] The present invention provides a data management method and system for improving the number of FLASH storage times, so as to solve the problem that the waste of storage resources leads to frequent erasing of sectors and affects the service life of FLASH.
[0005] The present invention is achieved through the following technical solutions:
[0006] A first aspect of the present invention provides a data management method for improving FLASH storage times, comprising:
[0007] The FLASH storage space is divided into a data area and a management area in units of sectors, wherein the data area is used to store data recording information, and the management area is used to store data management information;
[0008] When data record information is to be written, data management information is read from the management area to obtain a stored address of the data record information; a first address of the data area is determined according to the stored address, and the data record information to be written is written from the first address;
[0009] A second address of the management area is determined based on the read data management information, and data management information corresponding to the written data recording information is written from the second address.
[0010] The present invention uses data management information and data recording information methods together, divides FLASH into a data area and a management area, the data area can store a large amount of indefinite length information, the management area can record the acquired address of the recording area, and implements sector cyclic storage of the recording area according to the information of the management area, making full use of the remaining area of a sector, greatly increasing the life of the recording area. At the same time, the reading and writing of the management area is managed, and the storage space of the management area is reasonably utilized by using the data management information, realizing the storage optimization of the management area, reducing the number of erasures in the same use time, and further extending the service life of the FLASH chip.
[0011] Further, determining the first address of the data area according to the stored address includes:
[0012] S21, obtaining the latest storage address among the stored addresses, and determining whether the latest storage address exceeds the address range of the data area, if so, executing step S22, and if not, executing step S23;
[0013] S22, initializing the latest storage address as a base address, and using the base address as a first address;
[0014] S23, taking the modulus of the latest storage address and the sector size, if it is 0, executing step S24, if it is not 0, taking the latest storage address as the first address;
[0015] S24, erasing the sector where the latest storage address is located, and taking the first address of the sector where the latest storage address is located as the first address.
[0016] Further, the reading of data management information from the management area to obtain a stored address of data record information includes:
[0017] S110, initializing data management information;
[0018] S120, reading the previous sector full flag in each sector in turn, if the read previous sector full flag is not a specified value, then the previous sector of the sector that is not a specified value is used as the target reading sector, if the loop reads to the last sector, it is assumed that the last sector is not full, and the last sector is used as the target reading sector;
[0019] S130, reading the data management information in the target read sector, and determining whether the stored flag in the read data management information is a valid value, if so, continuing to read the next data management information, if not, stopping reading;
[0020] S140, obtaining a stored address of the data record information according to the read data management information.
[0021] Furthermore, the initialization data management information includes:
[0022] Read the data management system information from the starting address of the first sector, and determine whether it is in the initial state based on the stored flag of the read data management information. If not, execute step S120; if so, write the initialization information at the starting address of the first sector and execute step S120; the first sector is the first sector of the management area.
[0023] Furthermore, the step S130 further includes:
[0024] If the stored flag of the read data management information is a valid value, a CRC check is performed to determine whether the target read sector is damaged. If not, the next data management information is read.
[0025] Further, determining the second address of the management area according to the data management information includes:
[0026] S310, determining whether the target read sector is full, if it is full, executing step S320; if it is not full, taking the address of the unstored area of the target read sector as the second address;
[0027] S320, determine whether the target read sector is the last sector of the management area, if not, use the starting address of the next sector as the second address; if yes, erase the first sector and the second sector, and use the starting address of the first sector as the second address; the first sector is the first sector of the management area, and the second sector is the second sector of the management area.
[0028] Furthermore, the method further includes, if the judgment result of S320 is no, judging whether the target read sector is the penultimate sector, and if not, erasing the next-next sector of the target read sector.
[0029] Furthermore, the data management information also includes the number of sector erases. Before step S310, the method also includes: determining whether the number of sector erases of the target read sector exceeds an erase threshold. If so, taking the next sector of the target read sector as a new target read sector and then executing step S310; if not, directly executing step S310.
[0030] Further, writing the data record information to be written from the first address includes: writing in a page-by-page cyclic manner starting from the first address according to the size of the data record information to be written.
[0031] A second aspect of the present invention provides a data management system for improving the number of FLASH storage times, comprising:
[0032] A Flash management module, used to divide the FLASH storage space into a data area and a management area in units of sectors, wherein the data area is used to store data recording information, and the management area is used to store data management information;
[0033] A data reading module, used to read data management information from the management area and obtain the stored address of data record information;
[0034] A data writing module is used to determine the first address of the data area according to the stored address, and write the data record information to be written from the first address; and determine the second address of the management area according to the read data management information, and write the data management information corresponding to the written data record information from the second address.
[0035] Compared with the prior art, the present invention has the following advantages and beneficial effects:
[0036] The present invention achieves full utilization of a sector resource by optimizing read-write management of data management information and data recording information, while reducing the erasure times of the management area and the data area, thereby extending the service life of the FLASH chip. By cyclic read storage within the sector and cyclic storage of multiple sectors, the storage space is effectively configured, the number of FLASH storage times is increased, and a smaller capacity FLASH chip can be used to achieve a larger storage demand. By cross-area erasing, the erasure time is shortened, and the data read-write efficiency is improved. BRIEF DESCRIPTION OF THE DRAWINGS
[0037] In order to more clearly illustrate the technical solutions of the exemplary embodiments of the present invention, the following briefly introduces the drawings required for use in the embodiments. It should be understood that the following drawings only illustrate certain embodiments of the present invention and should not be regarded as limiting the scope. For those of ordinary skill in the art, other relevant drawings can be obtained based on these drawings without creative work. In the drawings:
[0038] Figure 1 is a flow chart of a data storage method according to an embodiment of the present invention;
[0039] Figure 2 is a flow chart of a management area cyclic reading according to an embodiment of the present invention;
[0040] Figure 3 It is a flow chart of circular storage of a recording area according to an embodiment of the present invention;
[0041] Figure 4 The present invention is a flow chart of a management area cyclic storage according to an embodiment of the present invention. DETAILED DESCRIPTION
[0042] In order to make the objectives, technical solutions and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with embodiments and drawings. The exemplary embodiments of the present invention and their description are only used to explain the present invention and are not intended to limit the present invention.
[0043] It should be noted that the terms "including" and "having" and any variations thereof in the specification and claims of the present invention and the above-mentioned drawings are intended to cover non-exclusive inclusions. For example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to or inherent to other steps or units of the device.
[0044] The terms used in the various embodiments of the application are only used to describe the purpose of specific embodiments and are not intended to limit the various embodiments of the application. As used herein, the singular form is intended to also include the plural form, unless the context clearly indicates otherwise. Unless otherwise limited, all terms used here (including technical terms and scientific terms) have the same meaning as the meanings commonly understood by ordinary technicians in the field of the various embodiments of the application. The terms (such as the terms defined in the dictionary generally used) will be interpreted as having the same meaning as the contextual meaning in the relevant technical field and will not be interpreted as having an idealized meaning or an overly formal meaning, unless clearly defined in the various embodiments of the application.
[0045] The embodiment of the present invention provides a data management method and system for improving the number of FLASH storage times, which is applicable to the storage management of mainstream Nand FLASH and Nor FLASH in the market, and is beneficial to reducing the number of erasure times and improving the service life of FLASH.
[0046] FLASH needs to be erased before writing new data, and the minimum unit of erasure is the sector. In order to reduce the number of sector erases within the same usage time, a multi-sector circular storage method is generally used, that is, the pre-stored base address is detected to read the corresponding content, and the current sector storage flag or the adjacent sector storage flag is obtained to determine whether the result stored in the current sector is a valid value, until a valid value is obtained, and then polling is performed. In addition, a storage threshold judgment method is adopted, and sectors are selected according to the number of erase times. When it is determined that the number of storage times of a certain sector reaches the threshold, the next sector is transferred to storage, and so on until the last sector, and then the cycle starts from the first sector. The advantage of multi-sector circular storage is that it does not erase and write to the specified sector, but makes rational use of all sectors. However, when the amount of data stored each time is much smaller than the size of a sector, a sector still needs to be erased for storage, so the unused storage area in the sector causes a waste of resources; and when a large amount of variable-length data needs to be stored at one time, the storage space of a sector is often not enough, and opening a specified number of sectors will also cause space waste due to the difference in the number of bytes of the variable-length data and the number of bytes of the specified number of sectors. And frequently erasing FLASH to obtain sectors of a specified size will take a certain amount of time each time. If too many sectors are erased, it will take too much time and the real-time performance will be reduced.
[0047] The present invention mainly manages the data reading and writing of the mainstream Nand FLASH and Nor FLASH on the market, which use sectors as the minimum erasing unit, and uses a sector cycle combined with an intra-sector cycle to store data. While improving the erasure life, it reduces the number of erasures compared to the above technology within the same time, thereby further extending the service life of the FLASH chip. The method of the present invention comprises the following steps:
[0048] First, the data area and management area are divided into sectors, where the data area is used to store data recording information and the management area is used to store data management information. The data recording information mainly records the information that will be added and modified in real time, and is the data source that users really need. The data management information mainly records the historical acquisition address of the data recording information, the latest acquisition address of the data recording information, the stored flag of the data management information, the last sector full flag, the equipment production date and number, the CRC check code, the number of sector erases, etc. The specific content of the data management information can be increased or decreased according to the actual situation, and can be defined in the form of data structure.
[0049] The data area and management area are divided into sectors. For example, the FLASH storage capacity is Cap sectors, which can be divided into blocks, sectors, and pages according to Cap bytes. The conversion results are different for different chips. Assuming that the size of a sector is Sector bytes, the data management information area is divided into Msg sectors, and the data recording information area is divided into Record sectors, so Cap = Msg + Record. Each sector has a corresponding mark, such as a sector number, which is convenient for calculation. If the erase life of FLASH is M times, then when the data recording information is recorded once every N minutes and the data management information is refreshed once, the size of the data management information is recorded as MsgMng bytes, and one sector erase can use N*Sector / MsgMng minutes. Since the life of each sector is M times, a sector can be used for M*N*Sector / MsgMng minutes. Since there are Msg sectors in the data management information area, the usable time can reach MsgMint=Msg*M*N*Sector / MsgMng minutes. By this, we can calculate how many bytes of data are stored in the recording area every N minutes to achieve the same time, set it as RecdByte, then RecdByte=(Cap-Msg)*M*N*Sector / MsgMint=MsgMng(Cap-Msg) / Msg.
[0050] For example, when Cap = 256, Msg = 8, M = 100000, N = 1, Sector = 4096, MsgMng = 40, the usable time of the management area is approximately equal to 159.8 years, and the data recording information area can store 1240 bytes per minute, and only 1 megabyte FLASH storage capacity can meet the large-capacity storage. The above values can be set according to specific circumstances to adapt to different application scenarios.
[0051] The data area can store a large amount of indefinite length information. Through the address information of the data recording information recorded in the data management information, a large amount of indefinite length data stored can be read out or written according to the address, and the data recording information is stored in sectors according to the data management information, thereby increasing the service life of the recording area. Since a management area always needs to be frequently erased to update the address of the data recording information, the present invention optimizes the erasure and storage of the management area, thereby reducing the number of erasures of the management area.
[0052] In the data management information, the historical acquisition address refers to the storage address where data was stored before the last data record information was written, and the latest acquisition address is the storage address of the last written data record information. The historical acquisition address and the latest acquisition address can be collectively referred to as the stored address of the data record information.
[0053] When data record information is written in the data area, the address information of the data record information will be refreshed in the management area accordingly. The data management information stored flag is a flag added when writing data management information, indicating that the (current) data management information has been stored. The previous sector full flag is a flag stored in the current sector indicating that the previous sector is full, such as a magic number, usually 0x54595954. For example, when the magic number of the current sector is read as 0x54595954, it means that the previous sector of the current sector is full. The production date and number of the device are the production date and number of the FLASH. The CRC checksum is written with the data and is generally placed at the end of the data to verify the validity of the data. It should be noted that "current" in this manual is used to indicate the time relationship, such as "current sector" refers to the sector read or written at the current time, "current data management information" refers to the data management information currently read or written, "previous sector" or "previous sector" is used to refer to the object processed at the time before the "current time", and so on. Figure 1 The flowchart of a data storage method of the present invention is shown, which includes the following steps:
[0054] S1, when there is data record information to be written, read the data management information from the management area to obtain the stored address of the data record information and the stored flag of the data management information;
[0055] S2, determining a first address of the recording area according to the stored address, and writing the data recording information to be written from the first address;
[0056] S3, determining a second address of the management area according to the stored flag, and writing data management information corresponding to the data recording information to be written from the second address.
[0057] Step S1 involves cyclic reading of the management information area and cyclic storage of the data area. When writing data record information, the information of the management area is read, and the indefinite length data record information to be stored is written into the record area according to the stored address of the data record information recorded in the data management information. Accordingly, when reading data record information, the data management information corresponding to the data record information recorded in the management area is read, the storage address of the data record information is obtained, and the data record information is read and derived according to the address. Reading and writing are corresponding steps, and the present invention focuses on how to store data to reduce the number of erasures.
[0058] The data in the management area is read by a double loop reading process of "large loop of sectors" + "small loop within sectors", that is, first traverse different sectors in the management area, and then traverse within the sectors. Figure 2 The flowchart of the management area cyclic reading is shown, which includes the following steps:
[0059] S110, initializing data management information.
[0060] Specifically, the content of the management area is read from the starting address of the first sector, and according to the stored flag of the data management information read from the first sector, it is determined whether it is in the initial state, that is, the full F state. If not, step S120 is executed; if yes, initialization information is written to the starting address of the first sector, and step S120 is executed;
[0061] In this step, the first sector refers to the first sector of the Msg sectors allocated to the management area. The reading and storage order of the sectors is determined by their sector numbers. For example, if the Msg sectors are numbered 0, 1, 2, ... Msg-1, the sector numbered 0 is the first sector. The FLASH initial state assumes that the FLASH chip has been completely erased once. If the judgment result is the initial state, the initialization information is written to the starting address of the first sector. The initialization information includes the base address of the initialization recording area, the full flag, and the CRC of the written information. The CRC of the written information is calculated by dividing the CRC byte by the data structure of the written information.
[0062] Furthermore, the written initialization information is verified, and the CRC is read out and verified. If the CRC verification passes, the process proceeds to step S120 . If the CRC verification fails, it is determined that the FLASH is damaged.
[0063] S120, read the previous sector full flag in each sector in turn. If the previous sector full flag read is not a specified value, the previous sector of the current sector that is not a specified value is used as the target reading sector; if the last sector is read in a loop, it is assumed that the last sector is not full, and the last sector is used as the target reading sector.
[0064] This step can be called a large sector loop, and its purpose is to find out the unfilled sectors in the management area. Since this method adopts a sector loop storage method, the next sector is stored after a sector is full. When writing the next sector, the full flag of the previous sector is written at the same time. Therefore, by reading the full flag of the previous sector data management information in the current sector, when the full flag is a specified value (for example, the magic number 0x54595954), it indicates that the previous sector is full, and then continue to read the previous sector full flag in the next sector. If it is not a specified value (such as all F), it indicates that the previous sector is not full, then stop the loop reading, and use the previous sector of the currently read sector that is not the specified value as the target reading sector. When the last sector is read, that is, the Msg-1 sector, it is assumed that the Msg-1 sector is not full, and the Msg-1 sector is used as the target reading sector.
[0065] The cyclic reading step S120 may specifically be:
[0066] S121, record the sector loop reading count variable as SectorNumCnt, and initialize the value to 0 (the initial count is 0, and the count increases by 1 each time a sector is read, and the total number of loops is Msg-1, that is, when SectorNumCnt=Msg-1, it just loops to the last sector of the management area).
[0067] S122, read the SectorNumCnt-th sector (the initial value of SectorNumCnt is 0, corresponding to the first sector of the management area), and determine whether the previous sector is full by reading the previous sector full flag in the current sector. If it is full, SectorNumCnt is incremented by 1, and step S122 is repeated; if the reading result is that the previous sector is not full, the previous sector is used as the target reading sector, and step S130 is entered.
[0068] S123, when the last sector is read, it is assumed that the last sector is not full, and the last sector is directly used as the target sector to be read, and the process goes to step S130.
[0069] Furthermore, during the process of cyclic reading of sectors, the sector cycle count variable is recorded as SectorCycleNumCnt, and the initialization value is Msg-1. When SectorCycleNumCnt changes from Msg-1 to 0, it indicates that there is a damaged sector, and the loop is automatically exited. It should be noted that SectorCycleNumCnt is used for large cycle monitoring. Unlike the SectorNumCnt variable, when valid management information is read, the value is assigned to 0 and the reading loop is jumped out. If it changes from Msg-1 to 0, it indicates that the sector is damaged.
[0070] S130, sequentially read the data management information in the target read sector, determine whether the stored flag of the current data management information is a valid value, if it is a valid value, continue to read the next data management information, until an invalid flag value is read, then stop reading.
[0071] This step can be called a small loop within the sector, and its purpose is to read the latest data management information in the sector. For example, the stored flag is set to 1. If the read stored flag is judged to be 1, it means that the currently stored management information is valid, but not necessarily the latest data management information. Until the next unstored management information is read, that is, the read flag value is not 1, it means that the previous valid management information is the latest data management information. The unstored area is all 0xFF, so the read invalid flag is 0xFF, which is used as a basis to judge whether the previous data management information is the latest data management information.
[0072] The cyclic reading step S130 within the sector may specifically be:
[0073] S131, record the loop count variable in the sector as ManMsgNum, and initialize the value to 0;
[0074] S132, read the ManMsgNum data management information, and determine whether the storage flag is valid by reading the storage flag of the current data management information. The valid flag value is a set value, such as 1, and the invalid flag value is generally all F. If valid, ManMsgNum is incremented by 1 and step S132 is repeated; if invalid, jump out of the loop.
[0075] Furthermore, if the stored flag of the current data management information is a valid value, a CRC check is performed to determine whether the sector is damaged. If damaged, the FLASH is considered damaged; if not damaged, ManMsgNum is incremented by 1, and step S132 is repeated. It can be understood that if the CRC check passes, it indicates that the current data management information is correct, and the sector is determined to be not damaged. If the CRC check fails, the sector is determined to be damaged.
[0076] According to the large sector loop, the unfilled sectors in the management area can be obtained, that is, the sectors corresponding to the sector loop count variable SectorNumCnt (if the sector loop count variable SectorNumCnt is finally 3, it indicates that the third sector is not full), and the data management information can be obtained according to the internal sector loop.
[0077] Furthermore, after step S130, the method further includes S140 of acquiring a stored address of the data record information according to the read data management information.
[0078] The write address of the data record information to be written can be determined based on the stored address of the data record information, so that the indefinite length data can be stored in the corresponding address to avoid wasting the storage space of the data area. The write address of the data management information to be written can be determined based on the stored flag valid information of the data management information to avoid wasting the storage space of the management area, thereby reducing the number of erasures.
[0079] In step S2, the storage of data record information adopts the mode of sector circulation storage, and the recording area can reserve the space of generating storage maximum byte number, ensures not to exceed space when scrolling to the end, and also reserves this size space when reading, if judges to exceed, then reads to the starting address.For example, the maximum byte number that the data record information of each storage may produce is 128 bytes, then 128 bytes should be reserved at the end of whole recording area.If reserve 50 bytes, namely critical storage address is for dividing recording area maximum critical value-50 bytes, when just being stored to critical storage address (do not exceed critical storage address at this moment, then address validity verification passes through, see step S21, promptly can not use base address), if the last storage byte number is 128, then can exceed the area size of the distribution of recording area, if reserved area is just 128 bytes, then just suitable.
[0080] When there is data record information to be written, the stored address of the data record information is read according to the double-cycle reading method of the data management information, and the first address of the data area is determined according to the stored address, that is, the address to be written of the data record information, such as Figure 3 The flowchart of recording area loop storage is shown, including the following steps:
[0081] S21, obtain the latest storage address among the stored addresses, and determine whether the latest storage address exceeds the address range of the data area (i.e., address validity verification). If it exceeds, execute step S22; if it does not exceed, execute step S23.
[0082] S22, initializing the latest storage address as a base address, and using the base address as the first address.
[0083] S23, modulo the latest storage address by the sector size, if it is 0, execute step S24, if it is not 0, take the latest storage address as the first address.
[0084] S24, erasing the current sector, and taking the first address of the current sector as the first address.
[0085] Specifically, the latest storage address variable of the accumulated data record information read out earlier or stored later is set as DataRecordNewAddr, and the address validity is verified to determine whether it exceeds the record area range. If it exceeds the range, the current data record information is stored in the base address.
[0086] If it is determined that the latest storage address variable DataRecordNewAddr does not exceed the range of the recording area, the read DataRecordNewAddr value is used for storage. There are two types of DataRecordNewAddr values. One is when the FLASH is stored for the first time, the latest address of the last storage is read from the data management information area. The other is not the first storage, that is, the length of the data record information has been superimposed on the basis of the first storage, that is, the starting address of the next storage. The value of the FLASH management information area is initially read at power-on, and DataRecordNewAddr is the address of the last storage of the data record information of the previous device. When this is the first storage, it is used as the latest write address. If it is not the first storage, each storage of the data record information content will superimpose the length of the data record information on the basis of the last storage, and DataRecordNewAddr will be continuously superimposed and updated. For example, if 200 bytes are stored for the first time, the starting address of the next storage is DataRecordNewAddr+200.
[0087] If the remainder in step S24 is 0, the current sector is erased. This is mainly used to erase the contents of the sector where the base address is located when the storage loop reaches the base address (i.e., after exceeding the range), and then store at the current base address, which not only solves the problem of address exceeding the range in step S21, but also solves the problem of erasing the stored contents when the data record storage loops back to the starting address.
[0088] Finally, the data recording information is written in a page-by-page cyclical manner starting from the first address according to the size of the written data recording information. The cyclical writing technology is mature and will not be described in detail here.
[0089] When the data record information changes, the corresponding data management information also needs to be refreshed, and step S3 is executed. Every time data record information of a certain byte length is written, the DataRecordNewAddr variable increases by a certain byte length to achieve data record address refresh.
[0090] Step S3 involves the storage of data management information. Since the management area needs to be frequently erased to update the record information of the data record information, the present invention adopts intra-sector circular storage in the management area until it is determined that a sector memory is full, and then jumps to the next sector storage. While improving the erasure life, the number of erasures is reduced, thereby further extending the service life of the FLASH chip.
[0091] When storing in a sector in a loop, a MsgMng byte size will be reserved to ensure that the last MsgMng read in the loop reading step is used as the valid flag of the second to last MsgMng, so the storage will only be stored to the second to last MsgMng. Before writing to the sector, the CRC value of the current data management information content will be recalculated and written to the end of the data management information.
[0092] In the step of reading the data management information in a loop, the unfilled sectors and data management information are read, and the corresponding sector loop count SectorNumCnt and the intra-sector loop count ManMsgNum are obtained. The initial values of SectorNumCnt and ManMsgNum are derived from the values traversed in steps S121-S132, such as Figure 4 The flowchart of managing data area cyclic storage is shown, including the following steps:
[0093] S310, determine whether the target read sector is full. That is, determine whether the self-incremented value of ManMsgNum is equal to the value of (Sector / MsgMng)-1. If they are equal, it means that the current sector is full, and execute step S320; if they are not equal, the address of the unstored area of the target read sector is used as the second address. Specifically, the write address is determined according to the values of SectorNumCnt and ManMsgNum. The write address = base address + sector address offset by SectorNumCnt + management information fixed-length data size length * ManMsgNum, that is, the base address plus the superimposed sector of SectorNumCnt, plus the byte size of the management information structure size * ManMsgNum, to obtain the current write address.
[0094] S320, determine whether the target read sector is the last sector of the management area, that is, whether SectorNumCnt is less than or equal to Msg-2 (Msg-2 represents the second to last sector of the management area); if not (that is, SectorNumCnt≤Msg-2), use the starting address of the next sector as the second address and write the data management information to the starting address of the next sector; if so, execute step S330.
[0095] The purpose of this judgment is to prevent the data management information written into the next sector from exceeding the zone. SectorNumCnt starts counting from 0. For example, if SectorNumCnt=Msg-1, that is, SectorNumCnt>Msg-2, the Msg+1th sector will be written, resulting in exceeding the zone.
[0096] S330, erase the first sector and the second sector of the management area, and use the starting address of the first sector as the second address, that is, write the content to the starting address of the first sector. The significance of this step is that when the last sector is also full, the first two sectors need to be erased, because this method adopts the erasing method across a sector (erasing the sector of SectorNumCnt+2), the first two sectors are not erased after being used for the first time and filled, so the entire sector needs to be filled before erasing.
[0097] Further, if the judgment result of S320 is no, it is determined whether the target read sector is the second to last sector, that is, it is further determined whether the SectorNumCnt value is less than Msg-2. If not (SectorNumCnt<2), the next sector of the current sector SectorNumCnt, that is, the SectorNumCnt+2 sector, is erased, and the SectorNumCnt count is incremented by 1, indicating that the next sector has been stored.
[0098] Furthermore, the data management information area can also adopt a storage threshold method to allocate a certain size sector to the data management information area. Each sector has a specified erase life value. The storage threshold can be slightly lower than the erase life value, so that when the erasure of a sector reaches the threshold, a flag that the sector has reached the threshold is filled in, such as a magic number. When the magic number is read during multi-sector cyclic storage, the sector is directly skipped. The same is true when storing. Before step S310, first determine whether the sector erase count of the target read sector exceeds the erase threshold. If it exceeds, the next sector of the target read sector is used as the new target read sector, and then step S310 is executed; if it does not exceed, step S310 is directly executed. Through this method, if the divided sector value is A and the FLASH life value is M, it is considered that the threshold is approximately equal to M, then a block of FLASH can be erased and used approximately A*M times. This also greatly increases the number of FLASH storage times.
[0099] If you want to further increase the number of storage times, you can start with this solution and use the remaining space in a sector. Since the amount of data management information is not large, and each erasure can only be done in sectors, a sector will be erased before it is fully written (less than one page is written), and the space cannot be used reasonably. When the patented large cycle between sectors + small cycle within sectors is adopted, the judgment basis of the large cycle between sectors is changed to whether the current sector storage times reaches the storage threshold, which can make full use of the space within a sector and reduce the number of erasures of a single sector.
[0100] The present invention stores the management area through intra-sector circular storage + multi-sector circular storage, effectively utilizing unused resources, thereby greatly improving the FLASH storage times, so that a smaller capacity FLASH chip can be used to meet storage needs and life requirements, effectively saving costs and enhancing product reliability and robustness.
[0101] A second aspect of the present invention provides a data management system for improving the number of FLASH storage times, characterized in that it includes:
[0102] The Flash storage module comprises a data area and a management area, wherein the data area is used to store data record information, and the management area is used to store data management information; the data management information comprises a stored address of the data record information and a stored flag of the data management information;
[0103] A data reading module is used to read data management information from the management area and obtain the stored address of data record information;
[0104] A data writing module is used to determine the first address of the data area according to the stored address, and write the data record information to be written from the first address; and determine the second address of the management area according to the data management information, and write the data management information corresponding to the data record information to be written from the second address.
[0105] The data reading module reads data according to the method steps of the data management method embodiment of the present invention recorded above, and is further used to respond to the data record information reading instruction, read the stored address of the data record information from the management area, read the data record information according to the address and export it. The data writing module writes the data record information and the corresponding data management information according to the method steps of the data management method embodiment of the present invention recorded above. The functions of the modules correspond to the method steps one by one, so they are not repeated here.
[0106] The specific implementation methods described above further illustrate the objectives, technical solutions and beneficial effects of the present invention in detail. It should be understood that the above description is only a specific implementation method of the present invention and is not intended to limit the scope of protection of the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present invention should be included in the scope of protection of the present invention.
Claims
1. A data management method for improving FLASH storage times, characterized in that: include: The FLASH storage space is divided into a data area and a management area in units of sectors, wherein the data area is used to store data recording information, and the management area is used to store data management information; When data record information is to be written, data management information is read from the management area to obtain a stored address of the data record information; a first address of the data area is determined according to the stored address, and the data record information to be written is written from the first address; A second address of the management area is determined based on the read data management information, and data management information corresponding to the written data recording information is written from the second address.
2. The data management method for improving FLASH storage times according to claim 1, characterized in that: The determining the first address of the data area according to the stored address comprises: S21, obtaining the latest storage address among the stored addresses, and determining whether the latest storage address exceeds the address range of the data area, if so, executing step S22, if not, executing step S23; S22, initializing the latest storage address as a base address, and using the base address as a first address; S23, taking the modulus of the latest storage address and the sector size, if it is 0, executing step S24, if it is not 0, taking the latest storage address as the first address; S24, erasing the sector where the latest storage address is located, and taking the first address of the sector where the latest storage address is located as the first address.
3. The data management method for improving FLASH storage times according to claim 1, characterized in that: The step of reading the data management information from the management area to obtain the stored address of the data record information includes: S110, initializing data management information; S120, reading the previous sector full flag in each sector in turn, if the read previous sector full flag is not a specified value, then the previous sector of the sector that is not a specified value is used as the target reading sector, if the loop reads to the last sector, it is assumed that the last sector is not full, and the last sector is used as the target reading sector; S130, reading the data management information in the target read sector, and determining whether the stored flag in the read data management information is a valid value, if so, continuing to read the next data management information, if not, stopping reading; S140, obtaining a stored address of the data record information according to the read data management information.
4. The data management method for improving FLASH storage times according to claim 3, characterized in that: The initialization data management information includes: Read data management information from the starting address of the first sector, and determine whether it is in the initial state based on the stored flag of the read data management information. If not, execute step S120; if so, write initialization information at the starting address of the first sector and execute step S120; the first sector is the first sector of the management area.
5. The data management method for improving FLASH storage times according to claim 3, characterized in that: The step S130 further includes: If the stored flag of the read data management information is a valid value, a CRC check is performed to determine whether the target read sector is damaged. If not, the next data management information is read.
6. The data management method for improving FLASH storage times according to claim 3, characterized in that: The determining the second address of the management area according to the data management information comprises: S310, determining whether the target read sector is full, if it is full, executing step S320; if it is not full, taking the address of the unstored area of the target read sector as the second address; S320, determine whether the target read sector is the last sector of the management area, if not, use the starting address of the next sector as the second address; if yes, erase the first sector and the second sector, and use the starting address of the first sector as the second address; the first sector is the first sector of the management area, and the second sector is the second sector of the management area.
7. The data management method for improving the number of FLASH storage times according to claim 6, characterized in that: The method further includes, if the determination result of S320 is no, determining whether the target read sector is the penultimate sector, and if not, erasing the next-next sector of the target read sector.
8. The data management method for improving FLASH storage times according to claim 6, characterized in that: The data management information also includes the number of sector erases. Before step S310, the method also includes: determining whether the number of sector erases of the target read sector exceeds an erase threshold. If so, taking the next sector of the target read sector as a new target read sector and then executing step S310; if not, directly executing step S310.
9. The data management method for improving FLASH storage times according to claim 1, characterized in that: Writing the data record information to be written from the first address includes: writing in a page-by-page cycle from the first address according to the size of the data record information to be written.
10. A data management system for improving the number of FLASH storage times, characterized in that: include: A Flash management module, used to divide the FLASH storage space into a data area and a management area in units of sectors, wherein the data area is used to store data recording information, and the management area is used to store data management information; A data reading module, used to read data management information from the management area and obtain the stored address of data record information; A data writing module, used for determining a first address of the data area according to the stored address, and writing the data record information to be written from the first address; And determining a second address of the management area according to the read data management information, and writing data management information corresponding to the written data recording information from the second address.
Citation Information
Cited By
Data storage and uploading method and device for data acquisition terminal
CN119383577A
A data storage and uploading method and apparatus for a data acquisition terminal
CN119383577B
XDMA-based random trigger type data stream transmission method and device
CN120029950A
A random triggered data stream transmission method and device based on XDMA
CN120029950B
Data storage method and device, equipment and storage medium
CN121029632A
