A bit-flipping based flash data storage method and intelligent hotel door lock

By combining bit-flipping mechanisms and circular storage areas, the problems of short lifespan and low data recognition of FLASH memory are solved, achieving high reliability and long lifespan data storage, which is suitable for embedded devices such as smart hotel door locks.

CN122111338APending Publication Date: 2026-05-29GLOBAL CARD SYSTEMS CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
GLOBAL CARD SYSTEMS CO LTD
Filing Date
2026-02-24
Publication Date
2026-05-29

AI Technical Summary

Technical Problem

In embedded systems, the physical erase and write life of FLASH memory is limited, and high-frequency data updates can cause device failure. Existing technologies have difficulty effectively distinguishing between valid data and idle areas, leading to data parsing errors and reducing system robustness.

Method used

A bit-flipping mechanism is used to invert the data bit by bit before writing. Combined with a circular storage area, the data is written by combining a valid status flag and the inverted data to ensure that there is a significant difference in physical level between the data and the idle state, reducing erase operations and cleaning up only when storage space is insufficient.

Benefits of technology

It significantly extends the lifespan of FLASH memory, improves data identification and system robustness during anomaly recovery, reduces battery power consumption, and ensures the continuity and accuracy of data recording.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122111338A_ABST
    Figure CN122111338A_ABST
Patent Text Reader

Abstract

The application discloses a bit-flip-based FLASH data storage method and an intelligent hotel door lock, and relates to the technical field of embedded storage. The method configures a cyclic storage area in an initial erasing state (data bits are usually logical 1) in a FLASH; when writing, the bitwise negation value of target data is calculated, and effective state flags and negation data are sequentially written into idle positions, and the writing process does not need erasing; when reading, the flags are reversely looked up, the negation data is read and restored. The application uses a data negation mechanism, ensures that even if the effective data is consistent with the erasing state (such as 0xFF), there is a significant difference between the physical level and the FLASH erasing state, and completely solves the idle state confusion problem caused by pointer loss; meanwhile, combined with cyclic additional writing, erasing is only performed when the storage area is saturated, thereby significantly prolonging the service life of the FLASH. The method is particularly suitable for door opening record storage of the intelligent door lock and can effectively guarantee the data integrity under a power-off condition.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of embedded data storage technology, and in particular to a bit-flipping-based FLASH data storage method, apparatus, and smart hotel door lock using this method. Background Technology

[0002] In embedded system applications, FLASH memory is not only used to store program code, but is also often used to store critical configuration parameters or runtime logs. For example, in the field of smart hotel door locks, it is necessary to record data such as the time of each door opening and identification information. This data is updated frequently and must be non-volatile (i.e., not lost when power is off).

[0003] However, the FLASH memory commonly used in embedded systems has a limited physical erase / write lifespan (typically 10,000 to 100,000 cycles). Traditional storage methods follow a "read-modify-erase-write" process, meaning that each data update requires erasing the entire sector. For frequently updated data, this method causes the FLASH memory cells to quickly run out of durability, leading to device failure.

[0004] While existing technologies employ "append-only" or "circular storage" methods to mitigate lifespan issues, they typically write raw data directly to the Flash memory. In practical applications, the idle state after Flash erasure is usually in an "erased state," with its physical level typically displaying all logic 1s (i.e., hexadecimal 0xFF). If the valid raw data to be stored is also 0xFF, its physical state after direct writing is identical to the idle state. If a system anomaly occurs (such as a power outage causing the write pointer position to be lost), during system restart and recovery scanning, it becomes difficult to distinguish between the "valid area storing 0xFF" and the "unused free area" based solely on the data content. This can easily lead to data parsing errors and reduce system robustness.

[0005] Therefore, how to provide a data storage method that can both extend the lifespan of FLASH and improve the identification of idle and valid data has become a technical problem that urgently needs to be solved in this field. Summary of the Invention

[0006] The present invention aims to solve the above-mentioned technical problems and provide a FLASH data storage method based on bit flipping and a smart hotel door lock.

[0007] This invention provides a FLASH data storage method based on bit flipping, comprising the following steps: Configure a contiguous physical address space in the FLASH memory as a circular storage area, and confirm that the circular storage area is in an erase state; In response to a data write request, retrieve the target data to be written; Calculate the bitwise inverse of the target data and generate the inverted data; The current write pointer position in the circular storage area is detected, and without performing an erase operation, the valid status flag and the inverted data are sequentially written to the current write pointer position using the programming characteristics of the FLASH memory. In response to a data read request, the system searches backwards in the circular storage area for a record that matches a valid status flag and reads the inverted data from that record. Perform a bitwise NOT operation on the read inverted data to restore the target data.

[0008] As can be seen, this invention, by inverting the bits of data before writing, ensures that even original data with the same value as the erase state (e.g., 0xFF) will be stored in the FLASH memory in a state opposite to its physical voltage level (e.g., 0x00). This ensures that the valid data always maintains a significant difference in physical voltage level from the FLASH erase state, greatly improving the data's recognizability during anomaly recovery and the system's robustness. Simultaneously, combined with a circular storage mechanism, data update operations are transformed into simple bit programming operations, eliminating the need for erasure with every update; erasure only occurs when the remaining storage space is insufficient, significantly extending the FLASH's lifespan.

[0009] Furthermore, the method also includes a space reclamation (garbage collection) step: detecting the remaining free space capacity of the circular storage area; if the remaining free space capacity is less than a preset write threshold, then reading the latest valid record from the circular storage area and parsing it to obtain the current valid data; performing a physical page erase operation on the entire circular storage area to restore the data in the circular storage area to the erased state; and writing the bitwise inverse value of the current valid data and the valid status flag to the starting physical address of the erased circular storage area.

[0010] As can be seen, through the space reclamation mechanism, the system can automatically clean up invalid historical data when the storage space is about to run out, and only retain the latest valid data, realizing the cyclical reuse of limited physical space and ensuring the continuity of data records.

[0011] Furthermore, the steps of reversely searching for a record matching a valid status flag within the circular storage area specifically include: starting from the end physical address of the circular storage area, scanning byte by byte towards the starting physical address; locating the first byte encountered that is equal to the value of the valid status flag, and identifying it as the header of the latest record; based on the position of the header of the latest record, reading subsequent bytes of a preset length as inverted data.

[0012] As can be seen, the reverse scanning strategy can locate the latest written data record at the fastest speed without traversing the entire storage area, thus improving data reading efficiency.

[0013] Furthermore, the data bit logic value in the erase state is 1 (i.e., hexadecimal 0xFF); the valid status flag is configured as 0xAA; the free area in the circular storage area that has not been written to remains in the erase state; when the value of the target data is consistent with the value of the erase state (i.e., 0xFF), the inverted data written to the FLASH memory is 0x00, thereby creating a difference in physical level between the storage state of the valid data and the data state of the free area.

[0014] It is evident that selecting 0xAA as the flag bit (binary 10101010) can effectively detect interference from adjacent bits. Furthermore, in conjunction with the data inversion mechanism (0xFF flipped to 0x00), a strong contrast between "valid data" and "idle background" is constructed at the physical level, completely solving the problem of data being unrecognizable after pointer loss.

[0015] Furthermore, the step of sequentially writing the valid status flag and the inverted data to the current write pointer position specifically includes: combining the valid status flag and the inverted data into a write frame; using FLASH programming instructions to program the write frame to the current write pointer position in one go; and after writing is completed, shifting the current write pointer position backward by the length of the write frame.

[0016] As can be seen, by combining the write frames and programming at once, the number of operations on the FLASH is reduced, and the write efficiency is improved. At the same time, by managing the pointer offset, continuous append writing of data is achieved, avoiding address conflicts.

[0017] The present invention also provides a bit-flipping-based FLASH data storage device, including a memory and a processor, wherein the memory is of type FLASH and is used to provide a circular storage area; the processor is configured to execute any of the methods described above.

[0018] As can be seen, this device achieves highly reliable and long-life data storage through the combination of hardware and software, making it suitable for various embedded devices with high data security requirements.

[0019] The present invention also provides a smart hotel door lock, comprising: Lock body actuator; The credential reading module is used to read unlocking credentials; The FLASH storage module is used to store door lock operation data, which includes at least unlocking record data. The main control module is connected to the lock body actuator, the credential reading module, and the FLASH storage module; The main control module is configured to execute any of the above methods when storing unlock record data.

[0020] It is evident that applying this method to smart hotel door locks can significantly reduce the frequency of FLASH erasure caused by frequent door opening log recording, greatly extend the lifespan of the door lock, and reduce battery power consumption.

[0021] Furthermore, the unlocking record data includes identification information (such as card number) and timestamp information; after the main control module detects that the credential reading module has read a valid unlocking credential and controls the lock body execution mechanism to unlock, it generates unlocking record data, performs bit-by-bit inversion processing on the unlocking record data, and writes it to the FLASH storage module.

[0022] As can be seen, the inversion protection for critical identity recognition and time data in door lock scenarios ensures that even if the writing process is interrupted due to battery depletion or abnormal power failure, the incomplete data will not be presented as an erased state (all 1s) and misjudged as a free area, thus guaranteeing the accuracy and security of security audit data.

[0023] Furthermore, the main control module includes a microcontroller or processor, and the size of the circular storage area is configured as one physical page or multiple consecutive physical pages of the FLASH storage module.

[0024] It is evident that by properly configuring the size of the circular storage area, the storage space utilization and erasure frequency can be balanced according to actual application needs, resulting in high flexibility.

[0025] The present invention also provides a computer-readable storage medium storing a computer program, which, when executed by a processor, implements any of the methods described above.

[0026] It is evident that implementing this method through computer programs facilitates its portability and promotion across different hardware platforms, demonstrating good versatility. Attached Figure Description

[0027] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments of the invention and, together with their description, serve to explain the principles of the invention.

[0028] Figure 1 This is a flowchart of the method in Embodiment 1 of the present invention; Figure 2 This is a mapping diagram of the logical structure and physical state of the circular storage area in Embodiment 1 of the present invention; Figure 3 This is a hardware module block diagram of the smart hotel door lock in Embodiment 2 of the present invention. Detailed Implementation

[0029] Various exemplary embodiments of the present invention will now be described in detail with reference to the accompanying drawings. It should be noted that, unless otherwise specifically stated, the relative arrangement, numerical expressions, and values ​​of the components and steps set forth in these embodiments do not limit the scope of the invention.

[0030] The following description of at least one exemplary embodiment is merely illustrative and is in no way intended to limit the invention or its application or use.

[0031] Techniques, methods, and equipment known to those skilled in the art may not be discussed in detail, but where appropriate, they should be considered part of the specification.

[0032] In all the examples shown and discussed herein, any specific values ​​should be interpreted as merely exemplary and not as limitations. Therefore, other examples of exemplary embodiments may have different values.

[0033] It should be noted that similar labels and letters in the following figures indicate similar items; therefore, once an item is defined in one figure, it does not need to be discussed further in subsequent figures. Example

[0034] This embodiment introduces a bit-flip-based FLASH data storage method. This method runs in an embedded processor (such as a microcontroller MCU) and is used to manage on-chip or off-chip NOR FLASH memory. Figure 1 As shown, this method achieves persistent storage and retrieval of data through unique bit manipulation logic.

[0035] 1. Storage space configuration and initialization Configure a sector or page in the FLASH memory as a "circular storage area". Assume the FLASH erase unit (physical page size) is 256 bytes. Initially, or after executing a physical erase command, this area is in the "erasure state", and usually all bits are logic "1", that is, the hexadecimal value of each byte is 0xFF.

[0036] like Figure 2 As shown, the structure of a data storage unit (i.e., a record) is defined as: [Header (1 byte)] + [Data body (N bytes)].

[0037] The header is a "valid status flag," and in this embodiment, 0xAA (binary 10101010) is selected as the flag. 0xAA is chosen because its bits alternate between 0 and 1, effectively detecting interference between adjacent bits during FLASH programming. The data body contains business data, and its length N is set according to actual needs, for example, N=4 bytes.

[0038] 2. Data writing process (bit flipping mechanism) When the processor generates "target data" that needs to be persistently saved, it performs the following steps: Step 1: Calculate the one's complement (invert each bit).

[0039] The processor reads the target data. Assume the target data is a 32-bit unsigned integer 0xFFFFFFFF (this value corresponds to the erase state of the FLASH memory). The processor executes a bitwise NOT instruction to calculate the inverted data: Inverted data = ~Target data = ~0xFFFFFFFF = 0x00000000. This step converts logically "all 1s" data into physically "all 0s" data. Figure 2 The document demonstrates the process of mapping logical data 0xFFFFFFFF to physical data 0x00000000.

[0040] Step 2: Construct the write frame.

[0041] The valid status flag 0xAA is concatenated with the calculated inverted data to form a write frame: write frame = [0xAA, 0x00, 0x00, 0x00, 0x00].

[0042] Step 3: Location and Programming.

[0043] The processor maintains a "write pointer" pointing to the currently free location in the circular memory area. The processor calls the programming function of the FLASH driver to write the write frame to the physical address pointed to by this write pointer. Because the physical characteristics of FLASH support programming logic "1"s to logic "0"s (this process does not require erasure), and the initial content at the current address is in an erased state (i.e., all 1s), the write operation can be executed successfully. After the write is complete, the write pointer is offset forward by 5 bytes.

[0044] 3. Data reading process When the system powers on and resets or needs to read data, perform the following operations: The processor searches byte by byte backwards from the end of the circular memory area. Once a byte value of 0xAA is found, it determines that this location is the starting position of the latest record (i.e., the header position). The processor reads the N bytes following this flag and obtains the inverted data (e.g., 0x00000000). The processor then performs bitwise inversion again: target data = ~inverted data = 0xFFFFFFFF. At this point, the original data has been successfully restored.

[0045] 4. Space recycling (or waste recycling) When the write pointer reaches the end of the page and the remaining space is insufficient to write the next complete record (e.g., less than 5 bytes), the space reclamation process is triggered: (1) Read out the latest valid record and temporarily store it in the processor's random access memory (RAM).

[0046] (2) Execute the FLASH page erase command to restore the data of the entire page to the erased state (all 0xFF).

[0047] (3) Rewrite the temporarily stored records (including 0xAA and the inverted data) back to the top of the page. Example

[0048] This embodiment applies the above method to a smart hotel door lock product.

[0049] 1. Smart door lock hardware architecture like Figure 3 As shown in the figure, the smart hotel door lock provided in this embodiment includes the following core hardware modules: 1. Main control module 1: As the control core of the door lock, it adopts a low-power 32-bit processor (such as STM32L series MCU) and is responsible for performing data processing, logic judgment and peripheral control.

[0050] 2. FLASH storage module 2: Used to store door lock operation logs. It can use the last two sectors of the FLASH built into the main control module 1 as a dual backup log storage area, or use an external NOR FLASH chip with serial interface (SPI).

[0051] 3. Credential reading module (e.g., RFID card reader / writer module 3): includes an RFID chip (e.g., MFRC522) and antenna circuit, used to read unlocking credentials such as proximity room cards, and send the read identity information (e.g., card number) to the main control module 1.

[0052] 4. Lock body actuator 4: includes a motor, a drive chip (such as L9110) and a clutch device, used to execute unlocking or locking actions in response to the instructions of the main control module 1.

[0053] 5. Power module 5: Usually powered by batteries (such as 4 dry batteries), with low voltage detection circuit (LVD) to provide stable operating voltage for all components of the system.

[0054] 2. Business Process: Door Opening Record Storage One of the core functions of smart door locks is "door opening log auditing." Whenever a door is opened, the identification information and the time must be recorded.

[0055] Scene recreation: The guest opens the door with their card. The credential reading module reads the card number (identity information = 0xA1B2C3D4). The main control module 1 obtains the current time (timestamp information = 0x65432100) through the real-time clock (RTC). The data is then combined to obtain the target data to be stored: [A1 B2 C3 D4, 65 43 21 00].

[0056] Writing steps: Step 1: Invert the value.

[0057] Main control module 1 performs bitwise inversion operations on the card number and time respectively: Invert the card number = ~0xA1B2C3D4 = 0x5E4D3C2B Inverted time = ~0x65432100 = 0x9ABCDEFF The final generated inverted data stream is: [5E 4D 3C 2B, 9A BC DE FF].

[0058] Step 2: Physical writing.

[0059] The main control module 1 sequentially writes the header and inverted data into the FLASH log area: [AA, 5E, 4D, 3C, 2B, 9A, BC, DE, FF].

[0060] 3. Verification of technical effectiveness Regarding resolving idle state confusion: Suppose there is a special "master control card" with identification information (card number) of 0xFFFFFFFF. If no inversion operation is performed, the data written directly to the FLASH memory would be: [AA, FF, FF, FF, FF...]. If an abnormal power outage occurs after writing the header (AA) but before writing the data, or if the header itself experiences a bit flip error, a string of 0xFF will be left in the FLASH memory. During the next scan, the system will consider this an unused free area (erased state), resulting in the loss of this important door opening record.

[0061] Using the inversion scheme in this embodiment, the card number 0xFFFFFFFF is converted to 0x00000000. The written data is: [AA, 00, 00, 00, 00...]. Even if the header is damaged, as long as the data area contains content that is not erased (i.e., 0x00), the system can identify during scanning that "a write operation has been performed here, but the data is corrupted," thereby triggering a data repair or alarm mechanism, rather than misjudging it as a free area.

[0062] Regarding extending battery life and FLASH life: Door locks are typically battery powered, and the instantaneous current draw of a FLASH erase operation is relatively high (up to mA) and the process takes a long time (tens of milliseconds). This solution stores approximately 50-100 records per page before performing an erase operation. Compared to the traditional method of erasing every single record, FLASH erasing significantly reduces average energy consumption, effectively extending the battery replacement cycle of the door lock. Simultaneously, the number of FLASH write / erase cycles is increased from 100,000 to millions, ensuring the log storage function remains effective throughout the door lock's entire lifespan (e.g., 10 years).

[0063] In summary, by introducing bit-flipping logic into the underlying driver, this invention solves the lifespan bottleneck and data ambiguity problem in smart door lock data storage with minimal software overhead.

[0064] While specific embodiments of the invention have been described in detail by way of examples, those skilled in the art should understand that the examples are for illustrative purposes only and not intended to limit the scope of the invention. Those skilled in the art should understand that modifications can be made to the above embodiments without departing from the scope and spirit of the invention. The scope of the invention is defined by the appended claims.

Claims

1. A FLASH data storage method based on bit flipping, characterized in that, Includes the following steps: Configure a contiguous physical address space as a circular storage area in the FLASH memory, and confirm that the circular storage area is in an erase state; In response to a data write request, retrieve the target data to be written; Calculate the bitwise inverse of the target data to generate inverted data; The current write pointer position in the circular storage area is detected, and without performing an erase operation, the valid status flag and the inverted data are sequentially written to the current write pointer position using the programming characteristics of the FLASH memory. In response to a data read request, a record matching the valid status flag is searched in reverse order within the circular storage area, and the inverted data in that record is read. Perform a bitwise NOT operation on the read inverted data to restore the target data.

2. The FLASH data storage method based on bit flipping according to claim 1, characterized in that, It also includes space reclamation steps: Detect the remaining free space capacity of the circular storage area; If the remaining free space capacity is less than the preset write threshold, then the latest valid record is read from the circular storage area and the current valid data is parsed. Perform a physical page erase operation on the entire circular storage area to restore the data in the circular storage area to the erased state; Write the bitwise inverse of the current valid data and the valid status flag to the starting physical address of the erased circular storage area.

3. The FLASH data storage method based on bit flipping according to claim 1, characterized in that, The steps of reversely searching for records with matching valid status flags in the circular storage area specifically include: Starting from the end physical address of the circular storage area, scan byte by byte towards the starting physical address; Locate the first byte encountered that has a value equal to the valid status flag and identify it as the header of the latest record; Based on the position of the header of the latest record, read the subsequent bytes of a preset length as the inverted data.

4. The FLASH data storage method based on bit flipping according to claim 1, characterized in that, Each bit of the data in the erased state is logic 1; The valid status flag is configured to a value that differs from the erase status by a bit; The unwritten free areas within the circular storage area remain in the erased state; When the value of the target data matches the value of the erase state, all bits of the inverted data written to the FLASH memory are logic 0, thereby creating a physical level difference between the storage state of the valid data and the data state of the free area.

5. The FLASH data storage method based on bit flipping according to claim 1, characterized in that, The step of sequentially writing the valid status flag and the inverted data to the current write pointer position specifically includes: The valid status flag and the inverted data are combined into a write frame; The write frame is programmed to the current write pointer position in one go using FLASH programming instructions; After writing is complete, the current write pointer position is shifted backward by the length of the write frame.

6. A bit-flip-based FLASH data storage device, comprising a memory and a processor, characterized in that, The memory is of type FLASH and is used to provide the circular storage area; The processor is configured to perform the method as described in any one of claims 1 to 5.

7. A smart hotel door lock, characterized in that, include: Lock body actuator; The credential reading module is used to read unlocking credentials; The FLASH storage module is used to store door lock operation data, which includes at least unlocking record data; The main control module is connected to the lock body actuator, the credential reading module, and the FLASH storage module; The main control module is configured to perform the method as described in any one of claims 1 to 5 when storing the unlocking record data.

8. The smart hotel door lock according to claim 7, characterized in that, The unlocking record data includes identity information and timestamp information; After the main control module detects that the credential reading module has read a valid unlocking credential and controls the lock body execution mechanism to unlock, it generates the unlocking record data, performs bit-by-bit inversion on the unlocking record data, and writes it into the FLASH storage module.

9. The smart hotel door lock according to claim 7, characterized in that, The main control module includes a microcontroller or a processor, and the size of the circular storage area is configured as one physical page or multiple consecutive physical pages of the FLASH storage module.

10. A computer-readable storage medium, characterized in that, The storage medium stores a computer program that, when executed by a processor, implements the method as described in any one of claims 1 to 5.