FLASH data storage initial address searching method
By employing a two-stage lookup strategy and a sector pre-erasure mechanism, the problem of low lookup efficiency in traditional FLASH memory is solved, enabling fast and accurate address positioning and improving the storage performance and stability of avionics equipment.
Patent Information
- Application Number
- CN202511416610.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-09-30
- Publication Date
- 2025-12-26
AI Technical Summary
Traditional FLASH memory is inefficient when looking up the starting address, especially in scenarios with large storage capacity or frequent writes, which affects the system response speed and overall efficiency, making it difficult to meet the high real-time requirements of modern avionics systems.
A two-stage search strategy is adopted: the first stage quickly locates the target sector through polling, and the second stage uses binary search within the sector to accurately locate the address. Combined with the sector pre-erasure mechanism and setting a minimum search unit, a balance between search accuracy and efficiency is ensured.
It significantly improves address lookup speed and system response capability, ensuring high efficiency and reliability of FLASH storage operations in avionics equipment, and adapting to the needs of different application scenarios.
Smart Images

Figure CN121209795A_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of aviation electromechanical systems and relates to a method for finding the starting address of FLASH data storage. Background Technology
[0002] In avionics systems, the real-time performance, reliability, and storage efficiency of data are crucial for ensuring flight safety and stable system operation. Flash memory, due to its non-volatility, high density, and low cost, is widely used in data recording and storage modules of avionics equipment. However, due to limitations in the physical characteristics and operating mechanisms of flash memory, some problems affecting system performance exist in practical applications, especially in finding the starting address.
[0003] Traditional FLASH write address lookup methods typically employ a polling approach, comparing each address sequentially from the starting address until a blank address without any data has been written is found. While simple to implement, this method becomes time-consuming in scenarios with large storage capacities or frequent writes, severely impacting system response speed and overall efficiency. Furthermore, with the increasing demands for data acquisition frequency and real-time storage in avionics systems, traditional methods are no longer sufficient to meet the requirements of modern high-real-time tasks.
[0004] To improve the efficiency of FLASH storage operations, a more efficient and intelligent write address lookup mechanism is urgently needed. Some existing improvement schemes attempt to reduce the number of traversals by optimizing the lookup logic, but their improvement effect is limited due to insufficient consideration of the characteristics of FLASH sector structure and data writing mode, and their stability is insufficient in complex environments.
[0005] Against this backdrop, this invention proposes a method for finding the starting address of FLASH data storage in aviation electromechanical systems. It breaks through the limitations of the traditional polling mechanism and introduces a two-stage strategy of "first locating the sector, then performing a binary search within the sector", which significantly improves the address lookup speed and system response capability, providing an efficient and reliable technical path for FLASH storage operations in avionics equipment. Summary of the Invention
[0006] Purpose of the invention This invention provides a method for finding the starting address of FLASH data storage, introducing a two-stage strategy of "first locating the sector, then performing a binary search within the sector." This invention significantly improves the speed of FLASH storage address lookup, solves the long-standing problem of low lookup efficiency in the industry, and greatly enhances the overall performance and reliability of FLASH data storage. This improvement is particularly suitable for avionics equipment with stringent requirements for real-time performance and stability.
[0007] Technical solution A method for finding the starting address in FLASH data storage, characterized by employing a two-stage positioning strategy for address lookup: 1) The first stage is the sector positioning stage: quickly locate the target FLASH sector according to preset rules; 2) The second stage is the precise address location stage within the sector: the specific write address is efficiently determined within the target sector using the binary search method.
[0008] The sector positioning stage employs a polling method to sequentially detect the status of each sector from the starting sector, specifically including: 3) Determine the data status of the header, middle, and tail addresses of each sector; 4) If the header, middle and tail addresses of a sector are not empty, then the sector is considered full; 5) If the header, middle and tail addresses of a sector are all empty, then the sector is determined to be empty; 6) In other cases, the sector is determined to be in a state where there is data but it is not full.
[0009] 7) Otherwise, the starting sector is used as the current sector to write.
[0010] The precise address location stage within the sector uses a binary search method, with the specific steps as follows: 8) If the header address data is empty, then the starting address is the header address; 9) If the header address is not empty, continue checking the middle address data: a) If the middle address is empty, continue searching towards the lower address; b) If the middle address is not empty, continue searching towards higher addresses; Furthermore, in step 7), if all FLASH sectors are determined to be full, an erase operation is performed on the starting sector, and the starting sector is used as the currently active write sector.
[0011] Furthermore, before writing data, an erase operation must be performed on the next FLASH sector to be used to ensure that at least one empty sector is reserved in the FLASH memory, thereby ensuring that the lookup strategy can accurately identify the currently writable address.
[0012] Furthermore, during the search process, address units of a set length are used as the smallest search unit to achieve a balance between search accuracy and search efficiency.
[0013] Furthermore, in step 6), if the starting sector is in a state with data but not full, it is taken as the currently used write sector; Furthermore, in step 6), if the starting sector is empty, the state of the ending sector is further determined: Furthermore, in step 6), if the ending sector is in a state with data but not full, it is taken as the current writing sector; Furthermore, it also includes step 10), repeating steps 3) to 9), iterating multiple times until the first empty address is found, thus completing the precise location of the write address.
[0014] The beneficial effects of this application are as follows: 1. Fast and accurate address lookup 1) Sector Location Stage: Quickly locate the target FLASH sector using preset rules. Use a polling method to check the status of each sector (head, middle, and tail) to determine whether the sector is empty, full, or partially full.
[0015] Advantages: Reduces unnecessary full scans, improving search speed and accuracy.
[0016] 2) Precise positioning stage within the sector: The binary search method is used to efficiently determine the specific write address within the target sector.
[0017] Advantages: By iteratively checking the data status of intermediate addresses, the search range is gradually narrowed, ensuring that the first empty address is found quickly.
[0018] 2. Ensure at least one empty sector. 1) Before writing data, perform an erase operation on the next FLASH sector to be used to ensure that at least one empty sector is reserved in the FLASH memory.
[0019] Advantages: Ensures that the system always has available write space, avoiding lookup failures due to lack of available space.
[0020] 3. Set a reasonable search unit length. 1) Use address units of a set length as the smallest search unit to balance search accuracy and search efficiency.
[0021] Advantages: It adapts to the needs of different application scenarios, ensuring both search accuracy and search speed.
[0022] 4. Flexible selection of write sectors 1) Based on the status of the starting and ending sectors, flexibly select the sector currently being written. If all sectors are full, perform an erase operation on the starting sector and use it as the current sector to write.
[0023] Advantages: Dynamically adjusts the write position to ensure continuous system operation and automatically maintains storage space. Attached Figure Description
[0024] Figure 1Flowchart for finding the starting address and storing data in FLASH. Detailed Implementation
[0025] To make the objectives, technical solutions, and advantages of this invention clearer, the technical solutions in the embodiments of this invention will be described in more detail below. In the examples, the same or similar reference numerals denote the same or similar components or elements having the same or similar functions throughout. The described embodiments are some, but not all, of the embodiments of this invention. The embodiments described below with reference to reference are exemplary and intended to explain this invention, and should not be construed as limiting the invention. All other embodiments obtained by those skilled in the art based on the embodiments of this invention without creative effort are within the scope of protection of this invention. The embodiments of this invention will be described in detail below.
[0026] I. Overview of the Two-Stage Search Strategy The core of this invention lies in using a two-stage search strategy to determine the starting address: 1) The first stage is the sector location stage: quickly select the currently used sector from all sectors using preset rules; 2) The second stage is the precise address location stage within the sector: the first empty address is found in the selected sector using the binary search method, and this address is used as the starting address.
[0027] II. Sector Positioning Stage 1. Sector Status Judgment Mechanism In this embodiment, a polling method is used to check the status of each sector of the FLASH sequentially. The data status of three key points of each sector—head address, middle address, and tail address—is selected as the basis for judgment.
[0028] 1) If the head, middle, and tail of a sector are not empty, the sector is considered full. 2) If the head, middle, and tail of a sector are all empty, then the sector is considered empty. 3) Otherwise, the sector is considered to be in a "data present but not full" state.
[0029] 2. Current sector selection logic for writing The process for determining the current sector to be written in this embodiment is as follows: Check the status of the starting sector: 1) If the starting sector is "containing data but not full", then select it as the current sector to write to; 2) If the starting sector is empty, continue checking the ending sector; 3) If the ending sector is "data present but not full", then select it as the current write sector; 4) Otherwise, the starting sector will still be selected as the current sector to write.
[0030] 3. Handling situations where all sectors are full In extreme cases, if all FLASH sectors are determined to be "full", the following operation will be performed: 1) Perform an erase operation on the starting sector; 2) Use the starting sector as the new write sector to ensure that the system can continue to run.
[0031] This approach avoids system outages caused by a lack of available sectors.
[0032] III. Second Stage: Precise Address Location within Sectors In this embodiment, a binary search method is used to quickly locate the first empty write address within the selected sector. The specific steps are as follows: 1. Take the header address of the sector as the initial search starting point; 2. If the header address is empty, return that address directly as the write address; 3. If the header address is not empty, then use the middle address for judgment: 1) If the intermediate address is empty, continue searching towards the lower address; 2) If the intermediate address is not empty, continue searching towards higher addresses; 4. Repeat the above process to gradually narrow down the search range until the first blank address is found.
[0033] This binary search strategy significantly improves address location efficiency, making it particularly suitable for high-capacity FLASH devices.
[0034] IV. Minimum Search Unit Setting To balance search accuracy and efficiency, this embodiment defines a minimum search unit address length. During the actual search process, this length is used as the basic unit for comparison and navigation, which improves speed while avoiding performance loss caused by excessive subdivision.
[0035] V. Sector Pre-erasure Mechanism To ensure that there are always available sectors to search, this embodiment performs an erase operation on the next available sector before each data write. This ensures that at least one free sector always exists, thereby guaranteeing the normal operation of the search strategy.
[0036] Example I. System Configuration Suppose an embedded device uses a 1MB FLASH chip, which is divided into 32 sectors (Sector 0 ~ Sector 31), each sector is 32KB in size, the smallest write unit is a page, and each page is 256 bytes in size.
[0037] In this FLASH memory, data is written sequentially, and the target sector must be empty before each write operation. During system operation, the system needs to dynamically search for currently writable addresses.
[0038] II. Initialization Phase After the system starts up, it first performs an initialization check on the overall status of the FLASH memory: 1) All sectors are set to "empty" by default; 2) The system maintains a global variable current_write_sector to represent the currently used write sector; 3) At the same time, maintain a variable current_write_address to represent the starting address.
[0039] III. First Stage: Sector Positioning 1. Sector polling for judgment When it is time to start writing new data, the following process is executed: 1) Starting from the first sector (e.g., Sector 0), read the data status of the header, middle, and tail addresses of each sector in sequence; 2) The judgment rules are as follows: a) If all three positions are not empty → the sector is full; b) If all three positions are empty → the sector is empty; c) Otherwise → the sector is "data present but not full".
[0040] 2. Current sector selection for writing 1) If the starting sector is "data present but not full", then set it as the current write sector; 2) If the starting sector is empty, continue checking the ending sector (e.g., Sector 31): a) If the ending sector is "data present but not full", then set it as the current write sector; b) Otherwise, the starting sector will still be used as the write sector.
[0041] 3. All sectors are full. If all 32 sectors are determined to be "full", then: 1) Perform an erase operation on the starting sector; 2) Set it as a new write sector; 3) This strategy ensures that writable space always exists in the system.
[0042] IV. Second Stage: Precise Address Location within Sectors After selecting the current sector to write to, use a binary search method to find the first empty address: Example: Find the write address in Sector 5 1. Obtain the starting address start_addr = 0x10000 and the ending address end_addr = 0x18000 for Sector 5; 2. Initialize the search range: low = start_addr, high = end_addr; 3. Loop search: 1) Take the middle address mid = (low + high) / 2; 2) If *mid == 0xFF (meaning it has not been written, i.e., it is empty), continue to narrow the search range towards lower addresses; 3) Otherwise (indicating it has already been written), narrow the search range towards higher addresses; 4. Continue until the first empty address is found.
[0043] Search efficiency analysis Taking a 32KB sector as an example, a traditional linear search requires a maximum of 128 searches (32KB / 256B), while a binary search can be completed in a maximum of 7 searches, significantly improving search efficiency.
[0044] V. Setting the Minimum Search Unit To balance accuracy and efficiency, the minimum search unit is set to 256 bytes (one page). Each jump is performed on a page-by-page basis, which avoids the performance loss caused by overly detailed searches while ensuring sufficient accuracy.
[0045] VI. Pre-erasure mechanism Before each write operation, the system automatically erases the next available sector (e.g., if Sector 5 is currently being written, Sector 6 will be erased) to ensure that subsequent write operations can be seamlessly connected.
[0046] Furthermore, unless otherwise defined, the technical or scientific terms used in this application description shall have the ordinary meaning understood by one of ordinary skill in the art to which this application pertains. The terms "upper," "lower," "left," "right," "center," "vertical," "horizontal," "inner," and "outer," etc., used in this application description to indicate relative direction or positional relationship are used only to indicate relative orientation or positional relationship, and do not imply that the device or component must have a specific orientation, or be constructed and operated in a specific orientation. When the absolute position of the described object changes, its relative positional relationship may also change accordingly, and therefore should not be construed as a limitation on this application. The terms "first," "second," "third," and similar terms used in this application description are used only for descriptive purposes to distinguish different components, and should not be construed as indicating or implying relative importance. The terms "a," "one," or "the," etc., used in this application description should not be construed as an absolute limitation on quantity, but should be construed as indicating the existence of at least one. The terms "including," "comprising," etc., used in this application description mean that the element or object preceding the word covers the element or object listed after the word and its equivalents, without excluding other elements or objects.
[0047] Furthermore, it should be noted that, unless otherwise explicitly specified and limited, terms such as “installation,” “connection,” and “linkage” used in the description of this application should be interpreted broadly. For example, a connection can be a fixed connection, a detachable connection, or an integral connection; it can be a mechanical connection or an electrical connection; it can be a direct connection or an indirect connection through an intermediate medium; or it can be a connection within two components. Those skilled in the art can understand its specific meaning in this application according to the specific circumstances.
[0048] The above description is merely a specific embodiment of the present invention and is not intended to limit the present invention. Within the spirit and principles of the present invention, any person skilled in the art may use the above-disclosed technical content to make changes or modifications to equivalent embodiments and apply them to other fields. However, any simple modifications, equivalent changes and modifications made to the above embodiments based on the technical essence of the present invention without departing from the content of the technical solution of the present invention, as well as any modifications, equivalent substitutions, improvements, etc., should be included within the protection scope of the present invention.
Claims
1. A method for finding the starting address in FLASH data storage, characterized in that, A two-stage location strategy is used for address lookup: 1) The first stage is the sector positioning stage: quickly locate the target FLASH sector according to preset rules; 2) The second stage is the precise address location stage within the sector: the specific write address is efficiently determined within the target sector using a binary search method; The sector positioning stage employs a polling method to sequentially detect the status of each sector from the starting sector, specifically including: 3) Determine the data status of the header, middle, and tail addresses of each sector; 4) If the header, middle and tail addresses of a sector are not empty, then the sector is considered full; 5) If the header, middle and tail addresses of a sector are all empty, then the sector is determined to be empty; 6) In other cases, the sector is determined to be in a state where there is data but it is not full; 7) Otherwise, use the starting sector as the current sector to write; The precise address location stage within the sector uses a binary search method, with the specific steps as follows: 8) If the header address data is empty, then the starting address is the header address; 9) If the header address is not empty, continue checking the middle address data: a) If the middle address is empty, continue searching towards the lower address; b) If the middle address is not empty, continue searching towards higher addresses.
2. The method as described in claim 1, characterized in that, In step 7), if all FLASH sectors are determined to be full, an erase operation is performed on the starting sector, and the starting sector is used as the currently active write sector.
3. The method as described in claim 1, characterized in that, Before writing data, an erase operation must be performed on the next FLASH sector to be used to ensure that at least one empty sector is reserved in the FLASH memory, thereby ensuring that the lookup strategy can accurately identify the current writable address.
4. The method as described in claim 1, characterized in that, During the search process, address units of a set length are used as the smallest search unit to achieve a balance between search accuracy and search efficiency.
5. The method as described in claim 1, characterized in that, In step 6), if the starting sector is in a state where there is data but it is not full, then it is used as the currently used write sector.
6. The method as described in claim 5, characterized in that, In step 6), if the starting sector is empty, the state of the ending sector is further determined.
7. The method as described in claim 6, characterized in that, In step 6), if the ending sector is in a state with data but not full, it is taken as the current writing sector.
8. The method as described in claim 1, characterized in that, It also includes step 10), repeating steps 3) to 9), iterating multiple times until the first empty address is found, thus completing the precise location of the write address.