Flash memory for circular data recording and data recording method

By dividing sectors and blocks in Flash memory and using flags to quickly calculate the location to be written, the problem of difficulty in determining the address to be written in the cyclic data record of Flash memory in embedded devices is solved, and the rapid start-up capability and data recording efficiency of the device are improved.

CN119902709APending Publication Date: 2025-04-29SHAANXI AVIATION ELECTRICAL
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202411972742.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-30
Publication Date
2025-04-29

AI Technical Summary

Technical Problem

In embedded devices, when using Flash memory for cyclic data recording, it is difficult for the prior art to quickly determine the address to be written, and the number of erases is limited, resulting in low data recording efficiency and slow device startup.

Method used

By dividing the designated storage area of ​​the Flash memory into sectors, each sector sets a flag for blocks. The flag is binary in all 1 when data is not written and all 0 when data is written. These flags are used to quickly calculate the position to be written.

Benefits of technology

It realizes the rapid reading of Flash to be written in embedded devices, improves the rapid start-up capability of the device, and effectively maintains the storage unit when the number of erases is limited.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119902709A_ABST
    Figure CN119902709A_ABST
Patent Text Reader

Abstract

The invention belongs to the technical field of data storage, and relates to a Flash memory for cyclic data recording and a data recording method. The method comprises the following steps: traversing a termination mark of each sector; when the binary system is all 1, reading a start mark; when the start mark is not the binary full 1, the current sector is the sector to be written, and traversal is quitted, otherwise, the sector with the termination mark and the start mark which are the binary full 1 for the first time in the traversal process is regarded as a temporary sector to be written; when the sector to be written exists, taking the initial address of the block corresponding to the first mark with the binary value of 1 in the sector to be written as the address of the data to be written; and when all sectors are traversed and the sectors to be written do not exist, taking the initial address of the temporary sector to be written as the address of the data to be written, and when the sectors to be written and the temporary sector to be written do not exist, taking the initial address of the initial sector as the address of the data to be written. The method is beneficial to quick starting of the equipment.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application belongs to the technical field of data storage, and in particular relates to a Flash memory for cyclic data recording and a data recording method. Background Art

[0002] Some embedded devices have data recording functions, which record the data collected and output by the device in real time in the form of data packets, so that the data can be downloaded and the cause of the failure can be analyzed when the device fails. The data is stored in a specified area of ​​the non-volatile memory, and the recording cycle ranges from a few milliseconds to hundreds of milliseconds. When the record is full, it is overwritten from the starting address of the area. When the device is powered off, the software in the device stops running. When it is powered on again, it is necessary to identify the address to be written to the data record and continue recording data from the address to be written.

[0003] In some early embedded devices, the recorded data is stored in NVRAM, and the address to be written is stored in the form of a numerical value at the address specified by NVRAM. However, due to the small capacity of NVRAM and the large area occupied by the printed circuit board, it cannot meet the data recording time requirements, so it is changed to or increased to use Flash memory for data recording. Unlike NVRAM, which can be written directly, all bits of Flash memory can only be written from "1" to "0", and writing from "0" to "1" requires erasing the sector where the bit is located first. The typical erase time of existing Flash memory is hundreds of milliseconds to several seconds, which is usually longer than the recording cycle. Therefore, if there is only one Flash memory in the non-volatile memory that can be used for data recording in the device, the address to be written cannot be written in the form of a numerical value to the fixed address of the non-volatile memory. In addition, since the Flash memory allows a small number of erase and write times, even if the address to be written can be stored in the form of a numerical value at the fixed address of the Flash memory, it is not conducive to wear leveling.

[0004] In the prior art, the location to be written may also be determined by searching for special values ​​such as the header and sequence number of the data packet. If the search method is sequential traversal, for a typical case, that is, when the storage area is several MB and each data packet is dozens of bytes, the expected number of searches is tens of thousands, which is not conducive to the fast startup of the embedded device.

[0005] If the search method is binary search, the data to be searched is required to be ordered in the storage area. If the content of the binary search is a serial number, even if integer overflow is considered, the write address can still be obtained based on the binary search with a time complexity of O(log(number of serial numbers)). This method is feasible in theory, but in practice, once the wrong serial number is written or read due to power failure, electromagnetic interference, storage unit failure, etc., the serial number may not meet the order condition in the storage area, and the binary search program will be executed to obtain an incorrect write address. Writing the new serial number to the wrong address may destroy the binary search condition, and the cycle will eventually fail to maintain the order of the serial number in the storage area.

[0006] Binary search cannot be used for packet headers. In the practice of circular data recording, in order to ensure that as much data as possible is recorded, the area to be written after the recording is full is usually less than two sectors. Let's assume that a storage area has a sector without a packet header, and all other sectors are full of data packets with packet headers. The starting address of the sector without a packet header is the address to be written. Reading at most one set of data for each sector can determine whether the sector has a packet header. At this time, no matter in what order the reading is carried out, there is always a situation where all sectors with packet headers are read, and the sector without a packet header is read last. Therefore, the worst time complexity of finding the packet header must be greater than the worst time complexity of using binary search, and binary search cannot be used for the packet header.

[0007] A Chinese invention patent with publication number CN108694129A proposes a method for determining the last written position in the Flash memory storage area using sequential traversal and binary search. However, in the practice of cyclic data recording, according to the above analysis, when using sequential traversal and binary search, it is necessary to select appropriate storage data, control time complexity, and consider exception safety. Summary of the invention

[0008] In order to solve the above problems, the present application provides a Flash memory and a data recording method for cyclic data recording, which does not rely on the characteristics of data packets, but relies on the pre-assigned addresses of each sector to achieve rapid calculation of the location to be written in the Flash memory.

[0009] In a first aspect, the present application provides a Flash memory for cyclic data recording, wherein a designated storage area of ​​the Flash memory is divided into one or more sectors, each sector having a plurality of blocks, the addresses in each block being continuous, each sector setting a corresponding flag for each block therein, the flag occupying a fixed address and corresponding to the block one by one, the flag being binary all 1 when no data is written into the corresponding block, and being binary all 0 when data starts to be written into the corresponding block, and the sectors, blocks, flags and addresses are all defined in order in the following manner:

[0010] When no data is written into the designated storage area, the sector where the first data is written is the starting sector, and the sector where the last data is written is the ending sector; when no data is written into the designated sector, the address where the first data is written into the sector is the starting address of the sector, the address where the last data is written is the ending address of the sector, the block where the starting address of the sector is located is the starting block of the sector, the block where the ending address of the sector is located is the ending block of the sector, the mark corresponding to the starting block of the sector is the starting mark of the sector, and the mark corresponding to the ending block is the ending mark of the sector.

[0011] Preferably, the flags of all blocks of each sector are continuously stored in the low address storage word of the sector, and the address of each flag has a specified address offset relationship with the start address of the block corresponding to the flag.

[0012] A second aspect of the present application provides a data recording method of a Flash memory, using the Flash memory for cyclic data recording as described above to perform data recording, the method comprising:

[0013] Step S1, traverse the termination mark of each sector;

[0014] Step S2: when the end mark is all 1s in binary, read the start mark of the current sector;

[0015] Step S3, when the start flag is not binary all 1, determine the current sector as the sector to be written, and exit the traversal, otherwise, determine the current sector that appears for the first time in the traversal process with the end flag being binary all 1 and the start flag being binary all 1 as the tentative sector to be written;

[0016] Step S4, when there is a sector to be written, search for the first flag whose value is all 1 in binary in the sector to be written, and use the starting address of the block corresponding to the flag as the address of the data to be written;

[0017] Step S5: When all sectors are traversed and there is no sector to be written, the starting address of the tentative sector to be written is used as the address of the data to be written; when there is no sector to be written and there is no tentative sector to be written, the starting address of the starting sector is used as the address of the data to be written.

[0018] Preferably, in step S4, the first mark is searched in the sector to be written using a binary search method.

[0019] Preferably, during data recording, when the data recording position reaches a designated address, the next sector defined in the erasure sequence is erased.

[0020] Preferably, determining whether the data recording position reaches the designated address includes before the end mark of the current sector is modified to binary all 0s.

[0021] This application can quickly read the Flash address to be written when the power is turned on again, which is conducive to the rapid startup of the device. BRIEF DESCRIPTION OF THE DRAWINGS

[0022] Figure 1 It is a schematic diagram of the memory architecture of a preferred embodiment of the Flash memory used for cyclic data recording in the present application.

[0023] Figure 2It is a flow chart of a preferred embodiment of the data recording method of the Flash memory of the present application.

[0024] Figure 3 It is a flow chart of the data reading method of the Flash memory of the present application. DETAILED DESCRIPTION

[0025] In order to make the purpose, technical scheme and advantages of the implementation of this application clearer, the technical scheme in the implementation of this application will be described in more detail in combination with the drawings in the implementation of this application. In the drawings, the same or similar reference numerals throughout represent the same or similar elements or elements with the same or similar functions. The described implementation is a part of the implementation of this application, not all of the implementations. The implementation described below with reference to the drawings is exemplary and is intended to be used to explain this application, and cannot be understood as a limitation on this application. Based on the implementation in this application, all other implementations obtained by ordinary technicians in this field without making creative work are within the scope of protection of this application. The implementation of this application is described in detail below in combination with the drawings.

[0026] In a first aspect, the present application provides a Flash memory for cyclic data recording, such as Figure 1 As shown, the designated storage area of ​​the Flash memory is divided into one or more sectors, each sector has multiple blocks, the addresses in each block are continuous, each sector sets a corresponding flag for each block therein, the flag occupies a fixed address and corresponds to the block one by one, the flag is binary all 1 when no data is written in the corresponding block, and is set to binary all 0 when data starts to be written to the corresponding block, and the sectors, blocks, flags and addresses are defined in the following order:

[0027] When no data is written into the designated storage area, the sector where the first data is written is the starting sector, and the sector where the last data is written is the ending sector; when no data is written into the designated sector, the address where the first data is written into the sector is the starting address of the sector, the address where the last data is written is the ending address of the sector, the block where the starting address of the sector is located is the starting block of the sector, the block where the ending address of the sector is located is the ending block of the sector, the mark corresponding to the starting block of the sector is the starting mark of the sector, and the mark corresponding to the ending block is the ending mark of the sector.

[0028] The physical addresses of the sectors in this application may be continuous or discontinuous.

[0029] In a specific embodiment, a device has a Flash memory of 256 sectors×64K words / sector×16 bits / word, and sectors 1 to 127 are selected for cyclic data recording, and these sectors are designated storage areas.

[0030] In some optional implementations, the flags of all blocks of each sector are continuously stored in the low address storage word of the sector, and the address of each flag has a specified address offset relationship with the start address of the block corresponding to the flag.

[0031] For example, for the device that performs cyclic data recording in sectors 1 to 127 mentioned above, the lowest 64 words of each sector are used to store flags, and the rest are used to record data. For a sector that has not written data, first write 0x0000 to the 0x0000 address (the flag address of the first block). This is the data in the flag address. When it is binary all 0, it means that the corresponding block has been used to write data. The address of the corresponding block is 0x0040, which means that data is written to the 0x0040 address and continues to the 0x03FF address. At this time, if data is continued to be written, write binary all 0: 0x0000 to the flag address 0x0001 of the second block, and then write data to the starting address 0x0400 of the second block and continue to write to the 0x07FF address; and so on.

[0032] If no error occurs in data access, there must be at least one sector with a 0x003F address (the mark address of the last block in the sector) with a value of 0xFFFF (all 1s in binary), and no matter the data has not fully written to the storage area or the data has been overwritten in a loop, the first sector with a 0x003F address value of 0xFFFF when traversing the sectors in ascending order is the sector to be written.

[0033] After the sector to be written is determined in the above method, the specific writing block needs to be determined in the sector to be written. There must be a flag address in the flag address of the sector to be written 0x0000~0x003F, and the values ​​of the addresses below it (if any) are all 0x0000, and the values ​​of the addresses not lower than it are all 0xFFFF; the address shifted left by 10 bits is the starting address of the corresponding block that meets the conditions, that is, the address to be written.

[0034] In alternative implementations, each marker may be located in the corresponding block instead of outside the corresponding block, or each marker may occupy fewer or more bits, or the data packet length and the block length may not be positive integer powers of 2, or after locating the block, the last write address may be searched forward in conjunction with the data record header.

[0035] A second aspect of the present application provides a data recording method of a Flash memory, using the Flash memory for cyclic data recording as described above to record data, such as Figure 2 As shown, the method includes:

[0036] Step S1, traverse the termination mark of each sector;

[0037] Step S2: when the end mark is all 1s in binary, read the start mark of the current sector;

[0038] Step S3, when the start flag is not binary all 1, determine the current sector as the sector to be written, and exit the traversal, otherwise, determine the current sector that appears for the first time in the traversal process with the end flag being binary all 1 and the start flag being binary all 1 as the tentative sector to be written;

[0039] Step S4, when there is a sector to be written, search for the first flag whose value is all 1 in binary in the sector to be written, and use the starting address of the block corresponding to the flag as the address of the data to be written;

[0040] Step S5: When all sectors are traversed and there is no sector to be written, the starting address of the tentative sector to be written is used as the address of the data to be written; when there is no sector to be written and there is no tentative sector to be written, the starting address of the starting sector is used as the address of the data to be written.

[0041] exist Figure 2 In, there are three branches, the first branch is that in step S3, the traversal reaches the end mark binary all 1, and the start mark is not binary all 1, then exit the traversal, and the most clear sector to be written has been found, and in step S4, the specific block can be found in the sector. The second branch is that in step S5, there is a situation where the end mark binary all 1 exists, but there is no situation where the start mark is not binary all 1. At this time, the first sector with the start mark of binary all 1 is used as a tentative sector to be written, and written to the cache. The so-called "tentative" means that a sector to be written is determined here, but it may not be the final sector to be written. All sectors are still traversed in the future. If the sector to be written under the first branch situation appears, the traversal is terminated and processed according to the first branch. If the sector to be written under the first branch situation still does not appear after traversing to the end, the first tentative sector to be written in the cache can only be used for data recording. The third branch is that in the traversal process, in step S2, no sector with the end mark of binary all 1 is found, and at this time, only the starting address of the starting sector can be used.

[0042] In some optional implementations, in step S4, the first marker is searched for in the sector to be written using a binary search method.

[0043] In some optional implementations, during the data recording process, when the data recording position reaches a specified address, the next sector defined in the erasure sequence is erased.

[0044] In some optional implementations, determining whether the data recording position reaches the specified address includes before the end mark of the current sector is modified to binary all 0s.

[0045] In this embodiment, as in the device described above, the lowest 64 words of each sector are used to store flags, and the rest are used to record data. A data packet is written every 0.5 seconds, and the length of the data packet is 32 words. Data is written sequentially from low address to high address. Since the nominal single-sector erase time of the Flash memory is 3.5 seconds, the next sector erase can be started when the write position reaches the address 0xF000 in the sector.

[0046] In some optional implementations, the present application further includes reading the recorded data by traversing each sector, and traversing each sector includes:

[0047] Traverse in address order, including from the start address of the start sector to the end address of the end sector (inclusive), in the same order as the data writing order;

[0048] Traverse in record order, including from the address to be written at the beginning of the traversal to the end address of the end sector (inclusive), and then from the start address of the starting sector to the address to be written at the beginning of the traversal (excluding), in the same order as the data writing order.

[0049] The present application can read the address to be written in Flash when power is restored by maintaining a smaller proportion of storage units in Flash when the available non-volatile memory is only equipped with Flash memory and the data recording time interval is less than the time taken to erase a single sector of Flash memory. There is no need to change the erase management mode of writing a sector and erasing the next sector, and the worst read count is 2×the number of sectors+log2 (the number of blocks in a sector), which is conducive to rapid startup of the device.

[0050] The application also provides steps for recording data reading, such as Figure 3 As shown, each flag of each sector of the specified storage area is traversed; for each flag, if the value of the flag is binary all 0, all data in the block corresponding to the flag are read, otherwise no operation is performed.

[0051] Although the present application has been described in detail above with general descriptions and specific implementation schemes, it is obvious to those skilled in the art that some modifications or improvements may be made to the present application. Therefore, these modifications or improvements made without departing from the spirit of the present application all fall within the scope of protection claimed in the present application.

Claims

1. A Flash memory for cyclic data recording, characterized in that: The designated storage area of ​​the Flash memory is divided into one or more sectors, each sector has multiple blocks, the addresses in each block are continuous, each sector sets a corresponding flag for each block therein, the flag occupies a fixed address and corresponds to the block one by one, the flag is binary all 1 when no data is written in the corresponding block, and is set to binary all 0 when data starts to be written to the corresponding block, and the sectors, blocks, flags and addresses are defined in the following order: When no data is written into the designated storage area, the sector where the first data is written is the starting sector, and the sector where the last data is written is the ending sector; when no data is written into the designated sector, the address where the first data is written into the sector is the starting address of the sector, the address where the last data is written is the ending address of the sector, the block where the starting address of the sector is located is the starting block of the sector, the block where the ending address of the sector is located is the ending block of the sector, the mark corresponding to the starting block of the sector is the starting mark of the sector, and the mark corresponding to the ending block is the ending mark of the sector.

2. The Flash memory for cyclic data recording according to claim 1, characterized in that: The flags of all blocks of each sector are continuously stored in the low address storage word of the sector, and the address of each flag has a specified address offset relationship with the start address of the block corresponding to the flag.

3. A data recording method for a Flash memory, characterized in that: Using the Flash memory for cyclic data recording according to claim 1 to perform data recording, the method comprises: Step S1, traverse the termination mark of each sector; Step S2: when the end mark is all 1s in binary, read the start mark of the current sector; Step S3, when the start flag is not binary all 1, determine the current sector as the sector to be written, and exit the traversal, otherwise, determine the current sector that appears for the first time in the traversal process with the end flag being binary all 1 and the start flag being binary all 1 as the tentative sector to be written; Step S4, when there is a sector to be written, search for the first flag whose value is all 1 in binary in the sector to be written, and use the starting address of the block corresponding to the flag as the address of the data to be written; Step S5: When all sectors are traversed and there is no sector to be written, the starting address of the tentative sector to be written is used as the address of the data to be written; when there is no sector to be written and there is no tentative sector to be written, the starting address of the starting sector is used as the address of the data to be written.

4. The data recording method of the Flash memory according to claim 3, characterized in that: In step S4, the first mark is searched in the sector to be written using a binary search method.

5. The data recording method of the Flash memory according to claim 3, characterized in that: During data recording, when the data recording position reaches a specified address, the next sector defined in the erasure sequence is erased.

6. The data recording method of the Flash memory according to claim 5, characterized in that: The determination of whether the data recording position reaches the specified address includes before the end mark of the current sector is modified to binary all 0s.

Citation Information

Patent Citations

  • Method for determining last writing position in storage area of Flash memory

    CN108694129A