Data read-write method, device and equipment for EEPROM (Electrically Erasable Programmable

By dividing the EEPROM into a management area and a data area, and determining and updating the target storage page based on the status information, problems such as local wear, high CPU usage, and insufficient RAM resources in the existing EEPROM operation mode are solved, and the balance of data erasing and long memory life are achieved.

CN120066423AActive Publication Date: 2025-05-30BEIJING GUODIAN GAOKE TECH CO LTD

Patent Information

Application Number
CN202510555824.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-04-29
Publication Date
2025-05-30
Estimated Expiration
2045-04-29

AI Technical Summary

Technical Problem

The existing EEPROM operation methods have problems such as intensified local wear, high CPU occupation and system delay, rapid increase in the number of invalid writes, RAM resource bottlenecks, data migration risks, high power consumption and write conflicts, which affect the service life of storage media and the stability of system performance.

Method used

By dividing the EEPROM into a management area and a data area, the management area is used to store the status information of each storage page, and the data area is used to store the written data. Read the status information according to the operation instructions, determine the target storage page, and execute the operation instructions in the target storage page, updating the status information to optimize the data writing and reading process.

Benefits of technology

It realizes the balance of data erasing, reduces CPU usage and RAM overhead, reduces the number of invalid erasing times, extends the service life of the memory, reduces power consumption, and avoids data write collisions and errors.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120066423A_ABST
    Figure CN120066423A_ABST
Patent Text Reader

Abstract

The invention provides a data read-write method, device and equipment for an EEPROM (Electrically Erasable Programmable Read-Only Memory), and belongs to the field of data processing. The method comprises the steps that an operation instruction for an EEPROM is received, the operation instruction indicates that data are written into a data area of the EEPROM or read from the data area of the EEPROM, the EEPROM is divided into a management area and the data area, the management area is used for storing state information of each storage page included in the data area, and each storage page included in the data area is used for storing the written data; reading state information of each storage page stored in the management area according to the operation instruction; determining a target storage page according to the state information; and executing a target operation corresponding to the operation instruction in the target storage page, and updating state information of the target storage page in the management area according to the target operation. According to the method, the balance of data erasing and writing can be guaranteed, meanwhile, high CPU occupation and RAM occupation are avoided, power consumption is reduced, and the service life of the EEPROM is prolonged.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application belongs to the field of data processing, and particularly relates to a data reading and writing method, device, and equipment for EEPROM. Background Art

[0002] Electrically Erasable Programmable Read-Only Memory (EEPROM) is commonly used to store data that needs to be retained for a long time. A common EEPROM operation method is: store one data packet per page, and at the same time set a flag bit in the first 8 bytes of this page to indicate the status of the page data. The data writing operation starts from the first page in sequence and arranges page by page backward. When the last page is full, it starts to cycle and overwrite from the first page. When reading data, read page by page from the beginning until the required data packet is found.

[0003] This implementation is simple and easy, but there are some design limitations.

[0004] Increased local wear: Data is always written sequentially from the starting page and cycles and overwrites after being full, resulting in the number of erase and write cycles of the starting page (such as Page 0) being much higher than that of subsequent pages, forming a local hot spot area. This unbalanced usage method violates the principle of balanced use of the storage medium, thus greatly shortening the overall service life of the EEPROM.

[0005] High CPU occupancy and system latency: After reading the data of the first page each time, in order to maintain the continuity of the data, it is necessary to move all subsequent page data forward one page by one page. This process requires frequent use of the CPU for data transfer, resulting in real-time tasks being blocked and the interrupt response latency increasing, thereby affecting the timing stability of the system.

[0006] Explosion of invalid write times: During the data migration process, it is necessary to rewrite all subsequent page data page by page, which generates a large number of redundant erase and write operations. For example, when N pages of data need to be migrated, the actual number of erase and write cycles will reach N times. This kind of invalid write directly exacerbates the wear of the EEPROM.

[0007] Random Access Memory (RAM) resource bottleneck: During data migration, it is necessary to temporarily store the data of multiple pages (such as 128 bytes / page) in the RAM. For an MCU with limited resources (such as only 2KB RAM), a single migration may occupy more than 20% of the memory resources, which will not only reduce the system performance but may even cause the migration operation to fail.

[0008] Data migration risk: During the process of data forward migration, if power failure or external interference occurs, it may damage the continuity of the original data chain, resulting in data loss or logical disorder. In addition, due to the lack of a breakpoint resumption mechanism, once the migration process is interrupted, data recovery will become very difficult.

[0009] High power consumption problem: The increase in the number of invalid writes also brings power consumption problems. The current during each write operation can reach the mA level (10 - 100 times higher than reading), which will significantly shorten the battery life for battery-powered devices (such as IoT sensors).

[0010] Write conflict and data error: During the data migration process, if an external attempt is made to write new data, a write conflict will occur. This may lead to incorrect or unsuccessful data writing, further increasing the complexity and risk of data management.

[0011] In summary, the existing operation methods of EEPROM have various defects, which not only affect the service life of the storage medium and the performance stability of the system, but also increase the complexity and risk of data management. Summary of the Invention

[0012] This application provides a data reading and writing method, device, and equipment for EEPROM to ensure the balance of data erasing and writing, while avoiding problems such as increased power consumption caused by high CPU occupancy, RAM occupancy, and multiple repeated writes to FLASH, as well as avoiding the risk of new data writing colliding with data migration, and improving the service life of EEPROM.

[0013] This application provides a data reading and writing method for EEPROM, including: Receiving an operation instruction for EEPROM, the operation instruction indicating writing data to the data area of EEPROM or reading data from the data area of EEPROM. The EEPROM is divided into a management area and the data area. The management area is used to store the status information of each storage page included in the data area. Each storage page included in the data area is used to store the written data. The status information is used to characterize the data reading and writing situation of each storage page; Reading the status information of each storage page stored in the management area according to the operation instruction; Determining a target storage page according to the status information; Performing a target operation corresponding to the operation instruction in the target storage page, and updating the status information of the target storage page in the management area according to the target operation.

[0014] According to the data reading and writing method for EEPROM provided by the present application, the determining of the target storage page according to the status information includes: when the operation instruction indicates writing data to the data area of the EEPROM, determining at least one empty page among multiple storage pages in the data area according to the status information, and the number of erase-write times of the at least one empty page; determining the target storage page from the at least one empty page according to the number of erase-write times.

[0015] According to the data reading and writing method for EEPROM provided by the present application, the updating of the status information of the target storage page in the management area according to the target operation includes: determining the operation type of the target operation, where the operation type includes packetized writing or non-packetized writing; when the operation type is packetized writing, determining the packet type corresponding to the target operation and the packet sequence number of the packet, where the packet type includes the first packet, middle packet or last packet; after the target operation is completed, determining that the number of erase-write times of the target storage page is incremented by 1 to obtain the current number of erase-write times of the target storage page; updating the status information of the target storage page according to the operation type, the packet type, the packet sequence number and the current number of erase-write times.

[0016] According to the data reading and writing method for EEPROM provided by the present application, the determining of the target storage page according to the status information includes: when the operation instruction indicates reading data from the data area of the EEPROM, determining the data reading type of the operation instruction, where the data reading type includes packetized reading or non-packetized reading; when the data reading type is packetized reading, determining a first reference storage page storing packetized data and the first page number sequence number of the first reference storage page among multiple storage pages in the data area according to the status information; determining the first urgency level of the data stored in the first reference storage page according to the status information, and whether the data stored in the first reference storage page is the first packet data; determining the target storage page according to the first page number sequence number, the first urgency level and whether the data stored in the first reference storage page is the first packet data.

[0017] According to the data reading and writing method for EEPROM provided by the present application, the determining of the target storage page according to the status information includes: when the data reading type is non-packetized reading, determining a second reference storage page storing non-packetized data and the second page number sequence number of the second reference storage page among multiple storage pages in the data area according to the status information; determining the second urgency level of the data stored in the second reference storage page according to the status information; determining the target storage page according to the second reference storage page and the second urgency level.

[0018] According to the data reading and writing method for EEPROM provided by the present application, performing a target operation corresponding to the operation instruction in the target storage page, and updating the status information of the target storage page in the management area according to the target operation includes: reading the data stored in the target storage page, and erasing the data stored in the target storage page; updating the status information of the target storage page and obtaining the data packet sequence number of the data stored in the target storage page, and the updated status information indicates that the target storage page is an empty page; determining the next page to be read from the data area according to the data packet sequence number, and determining whether the next page to be read is the last page; in the case where the next page to be read is not the last page, determining the next page to be read as the target storage page, and repeating the above steps; in the case where the next page to be read is the last page, reading the data stored in the next page to be read, and erasing the data stored in the next page to be read, and updating the status information of the next page to be read, and the updated status information indicates that the next page to be read is an empty page.

[0019] According to the data reading and writing method for EEPROM provided by the present application, the management area includes a main management area and a backup management area, and updating the status information of the target storage page in the management area according to the target operation includes: updating the status information of the target storage page in the backup management area; after confirming the target operation, synchronizing the updated status information in the backup management area to the main management area.

[0020] According to the data reading and writing method for EEPROM provided by the present application, after performing the target operation corresponding to the operation instruction in the target storage page, the method further includes: obtaining feedback information for the target operation, where the feedback information is used to indicate the execution situation of the target operation; in the case where the feedback information indicates that the target operation fails to execute, updating the status information of the target storage page, and the updated status information indicates that the target storage page is a bad page; performing multiple data writing and reading operations on the target storage page, and verifying whether the written and read data are consistent each time to obtain multiple verification results; if the multiple verification results all indicate that the written and read data are consistent, updating the status information of the target storage page again, and the status information updated again indicates that the target storage page is a normal page.

[0021] The present application also provides a data reading and writing device for EEPROM, including: A receiving unit, configured to receive an operation instruction for an EEPROM, where the operation instruction indicates writing data to a data area of the EEPROM or reading data from the data area of the EEPROM. The EEPROM is divided into a management area and the data area. The management area is used to store status information of each storage page included in the data area. Each storage page included in the data area is used to store the written data. The status information is used to characterize the data reading and writing conditions of each storage page; A reading unit, configured to read the status information of each storage page stored in the management area according to the operation instruction; A determining unit, configured to determine a target storage page according to the status information; An execution unit, configured to perform a target operation corresponding to the operation instruction in the target storage page, and update the status information of the target storage page in the management area according to the target operation.

[0022] This application further provides an electronic device, including a memory, a processor, and a computer program stored on the memory and executable on the processor. When the processor executes the computer program, the data reading and writing method for an electrically erasable programmable read-only memory (EEPROM) as described in any one of the above is implemented.

[0023] This application further provides a non-transitory computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the data reading and writing method for an electrically erasable programmable read-only memory (EEPROM) as described in any one of the above is implemented.

[0024] This application further provides a computer program product, including a computer program. When the computer program is executed by a processor, the data reading and writing method for an electrically erasable programmable read-only memory (EEPROM) as described in any one of the above is implemented.

[0025] The data reading and writing method, apparatus, and device for an EEPROM provided by this application first receive an operation instruction for the EEPROM. The operation instruction indicates writing data to a data area of the EEPROM or reading data from the data area of the EEPROM. The EEPROM is divided into a management area and the data area. The management area is used to store status information of each storage page included in the data area. Each storage page included in the data area is used to store the written data. Then, the status information of each storage page stored in the management area is read according to the operation instruction. Then, a target storage page is determined according to the status information. Finally, the target operation corresponding to the operation instruction is performed in the target storage page, and the status information of the target storage page in the management area is updated according to the target operation.

[0026] It can be seen that in this embodiment, the memory is divided into a management area and a data area, realizing operation isolation, ensuring data security, and at the same time improving the convenience of data access. When reading data, there is no need for data migration, which can reduce the RAM overhead and CPU occupancy. At the same time, the number of invalid erasures and writes is reduced, the wear of the memory is reduced, and the service life of the memory is extended. Since there is no need for data migration, the number of data erasures and writes is also reduced, thus reducing power consumption. At the same time, the problem of data errors or failures caused by the original data migration and data write conflicts is solved. BRIEF DESCRIPTION OF THE DRAWINGS

[0027] In order to more clearly illustrate the technical solutions in the present invention or the prior art, the following will briefly introduce the drawings required for the description of the embodiments or the prior art. Obviously, the drawings in the following description are some embodiments of the present invention. For those of ordinary skill in the art, without creative efforts, other drawings can also be obtained based on these drawings.

[0028] Figure 1 It is a flowchart showing a data reading and writing method for an EEPROM provided by the present application.

[0029] Figure 2 It is a block diagram showing the functional units of a data reading and writing device for an EEPROM provided by the present application.

[0030] Figure 3 It is a schematic diagram showing the structure of an electronic device provided by the present application. DETAILED DESCRIPTION OF THE EMBODIMENTS

[0031] To make the objectives, technical solutions and advantages of the present invention clearer, the following will clearly and completely describe the technical solutions in the present invention with reference to the drawings in the present invention. Obviously, the described embodiments are some, but not all, of the embodiments of the present invention. All other embodiments obtained by those of ordinary skill in the art without creative efforts based on the embodiments in the present invention belong to the scope of protection of the present invention.

[0032] The terms "first", "second", etc. in the specification and claims of the present application and the above drawings are used to distinguish different objects, rather than to describe a specific order. In addition, the terms "comprising" and "having" and any variations thereof are intended to cover non-exclusive inclusion. For example, a process, method, system, product or device that includes a series of steps or units is not limited to the listed steps or units, but optionally further includes steps or units not listed, or optionally further includes other steps or units inherent to these processes, methods, products or devices.

[0033] References to "embodiments" in this specification mean that a particular feature, structure, or characteristic described in connection with the embodiments can be included in at least one embodiment of the present application. The phrase appears in various places in the specification and does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment mutually exclusive with other embodiments. Those skilled in the art will explicitly and implicitly understand that the embodiments described herein can be combined with other embodiments.

[0034] The operation mode of existing EEPROMs has various defects, which not only affect the service life of the storage medium and the performance stability of the system, but also increase the complexity and risk of data management.

[0035] In view of the above problems, the present application provides a data reading and writing method, device, and equipment for EEPROM. Please refer to Figure 1 , the data reading and writing method for EEPROM includes the following steps.

[0036] S101, receive an operation instruction for the EEPROM.

[0037] Among them, the operation instruction indicates writing data to the data area of the EEPROM or reading data from the data area of the EEPROM. The EEPROM is divided into a management area and the data area. The management area is used to store the status information of each storage page included in the data area. Each storage page included in the data area is used to store the written data. The status information is used to characterize the data reading and writing situation of each storage page. This data reading and writing situation includes whether the storage page has written data, whether the written data is packetized or non-packetized data, and the number of erase and write cycles of the storage page, etc.

[0038] In a specific implementation, the management area can occupy the first 31 pages of the memory, with each page being 128 bytes. Status information such as a page index table, access permission flag bits, and erase and write counts of the data area can be stored in this management area. The data area is the subsequent 480 pages of the memory, which are divided into storage units accessible by users by page. In particular, the management area can be placed at the physical front end (low address segment) of the memory, making full use of the linear addressing feature of the storage controller to reduce access latency and improve operation efficiency.

[0039] S102, read the status information of each storage page stored in the management area according to the operation instruction.

[0040] Among them, when the content indicated by the operation instruction is different, the read status information can also be different. For example, when the operation instruction indicates writing data to the data area of the EEPROM, the read status information may include whether the storage page is an empty page, the number of erase / write cycles of the storage page, etc. If the operation instruction indicates reading data from the data area of the EEPROM, the read status information may include whether the storage page is an empty page, whether the data stored in the storage page is packetized data or non-packetized data, when the storage page is packetized data, whether the data stored in the storage page is the first packet data, and the urgency of the data stored in the storage page, etc.

[0041] S103. Determine a target storage page according to the status information.

[0042] Among them, the management area strictly aligns the page boundaries according to the page alignment mechanism (for example, aligns with a 128-byte page boundary), that is, when writing data or reading data, it all starts from a complete page, avoiding split operations caused by cross-page reading and writing. In particular, the status information of the target storage page indicates that the target storage page is a normal page, that is, when writing data, skip the bad page and do not perform the writing operation, and when reading data, skip the bad page and do not perform the reading operation.

[0043] S104. Perform a target operation corresponding to the operation instruction in the target storage page, and update the status information of the target storage page in the management area according to the target operation.

[0044] It can be seen that in this embodiment, the memory is divided into a management area and a data area to achieve operation isolation, ensure data security, and at the same time improve the convenience of data access. When reading data, there is no need to perform data migration, which can reduce the RAM overhead and CPU occupancy. At the same time, it reduces the number of ineffective erase / write cycles, reduces the wear of the memory, and extends the service life of the memory. Since there is no need for data migration, the number of data erase / write cycles is also reduced, thereby reducing power consumption, and at the same time solving the problem of data errors or failures caused by the original data migration and data write conflicts.

[0045] In a possible embodiment, the determining the target storage page according to the status information includes: when the operation instruction indicates writing data to the data area of the EEPROM, determining at least one empty page among multiple storage pages in the data area according to the status information, and the number of erase / write cycles of the at least one empty page; determining the target storage page from the at least one empty page according to the number of erase / write cycles.

[0046] Among them, when writing data to the data area of the EEPROM, it is possible to determine whether it is single-page writing (≤128 bytes) or multi-page writing (>128 bytes) based on the data size. If it is single-page writing, the target storage page includes one page. If it is multi-page writing, the number of required pages can be calculated according to the size of the written data to obtain the number of pages of the target storage page.

[0047] In a specific implementation, when determining the target storage page, the empty page with fewer erase / write cycles is preferentially determined as the target storage page. When the target storage page includes multiple pages, multiple consecutive empty pages among the multiple empty pages can be first determined as the target storage page. When there are multiple consecutive empty pages, the empty page with the least total number of erase / write cycles among the multiple consecutive empty pages can be preferentially determined as the target storage page. In particular, after determining the empty page, it is also possible to determine whether the empty page is a bad page according to the status information. If it is not a bad page, the target storage page is determined based on the total number of erase / write cycles.

[0048] It can be seen that in this embodiment, the access to the memory adopts the balancing principle, solves the hot access area caused by sequential storage, reduces the bad page rate, and extends the service life of the memory.

[0049] In a possible embodiment, the updating the status information of the target storage page in the management area according to the target operation includes: determining the operation type of the target operation, where the operation type includes packetized writing or non-packetized writing; in the case where the operation type is packetized writing, determining the packet type corresponding to the target operation and the packet sequence number of the packet, where the packet type includes the first packet, middle packet, or last packet; after the target operation is completed, determining that the number of erase / write cycles of the target storage page is incremented by 1 to obtain the current number of erase / write cycles of the target storage page; and updating the status information of the target storage page according to the operation type, the packet type, the packet sequence number, and the current number of erase / write cycles.

[0050] Among them, packetized writing means that the target storage page includes multiple pages and the data needs to be written in multiple pages. At this time, after writing a packetized data into a target storage page, the status of whether the stored data corresponding to the target storage page is packetized data will be updated to packetized data. At the same time, if the data stored in the target storage page is the first packet data, the status of the packet type of the target storage page will be updated to the first packet status, and the packet sequence number of the packet will be recorded in the status and the number of erase / write cycles of the target storage page will be incremented by 1. When recording the packet sequence number, a chained storage structure is adopted, and the sequence number of the next packet is stored in the management area.

[0051] In a specific implementation, the management area can record the corresponding status information through different flag bits, and the values of the flag bits correspond to different status information. For example, if the value of the flag bit used to determine whether a storage page is an empty page is 1, it is considered that the status information indicates that there is data stored in the storage page. If the value is 0, it is considered that the storage page is an empty page.

[0052] It can be seen that in this embodiment, the status information of the target storage page is updated based on the written data, so that when reading data, the read content can be determined based on the status information, improving the read and write efficiency.

[0053] In a possible embodiment, determining the target storage page according to the status information includes: when the operation instruction indicates reading data from the data area of the EEPROM, determining the data reading type of the operation instruction, where the data reading type includes packet-by-packet reading or non-packet reading; when the data reading type is packet-by-packet reading, determining a first reference storage page storing packet data and a first page number sequence number of the first reference storage page among multiple storage pages in the data area according to the status information; determining a first urgency level of the data stored in the first reference storage page according to the status information, and whether the data stored in the first reference storage page is the first packet data; and determining the target storage page according to the first page number sequence number, the first urgency level, and whether the data stored in the first reference storage page is the first packet data.

[0054] Among them, when reading data packet by packet, first, based on the status information of each storage page stored in the management area, find the page that has stored data and the stored data is packet data. Then it is also necessary to determine whether the data stored in this storage page is the first packet data, and then determine the page to be read according to the page number sequence number and whether the data is urgent.

[0055] For example, when it is determined that the data stored in the storage page is packet data, if the packet data is a middle packet, the corresponding first packet data can be found according to the page number sequence number. If the middle packet data is urgent data, it is determined that the storage page corresponding to the middle packet data is the target storage page. If the middle packet data is ordinary data, it is determined that the storage page corresponding to the corresponding first packet data is the target storage page.

[0056] Specifically, after reading the data of the target storage page, the data of this page is erased, and the status information of this page is changed to an empty page.

[0057] It can be seen that in this embodiment, the target storage page is determined based on whether it is the first packet data, the page number sequence number, and the urgency level, and the storage page that needs to be read can be quickly located based on the status information.

[0058] In a possible embodiment, determining the target storage page according to the status information includes: when the data reading type is the non-packet reading, determining a second reference storage page storing non-packet data and a second page number sequence number of the second reference storage page among multiple storage pages in the data area according to the status information; determining a second urgency level of the data stored in the second reference storage page according to the status information; and determining the target storage page according to the second reference storage page and the second urgency level.

[0059] Among them, when reading data without packetizing, first find the storage page that already stores data, then determine the storage page that stores non-packet data based on whether the stored data is packetized data, and finally determine the target storage page according to the page number sequence number and whether the data is urgent.

[0060] In particular, after reading the data of the target storage page, erase the data of this page and change the status information of this page to an empty page.

[0061] It can be seen that in this embodiment, determining the target storage page based on the page number sequence number and the urgency level can quickly locate the storage page to be read based on the status information.

[0062] In a possible embodiment, performing the target operation corresponding to the operation instruction in the target storage page and updating the status information of the target storage page in the management area according to the target operation includes: reading the data stored in the target storage page and erasing the data stored in the target storage page; updating the status information of the target storage page and obtaining the data packet sequence number of the data stored in the target storage page, and the updated status information indicates that the target storage page is an empty page; determining the next page to be read from the data area according to the data packet sequence number and determining whether the next page to be read is the last page; when the next page to be read is not the last page, determining the next page to be read as the target storage page and repeating the above steps; when the next page to be read is the last page, reading the data stored in the next page to be read, erasing the data stored in the next page to be read, and updating the status information of the next page to be read, and the updated status information indicates that the next page to be read is an empty page.

[0063] Among them, after determining the target storage page, reading the data of the target storage page, erasing the data of the target storage page, and then updating the status information of whether the target storage page in the management area is an empty page to an empty page. At the same time, record the data packet sequence number of the data packet stored in the target storage page. Then, find the next storage page to be read according to the distance data packet sequence number. And determine whether the next storage page to be read is the last page. If it is the last page, read the data of the last page, erase the page data, and update the corresponding status information to an empty page. If it is not the last page, determine the storage page as the target storage page, read the data again, erase the data, and determine the next storage page to be read until the next storage page to be read is the last page.

[0064] It can be seen that in this embodiment, after each storage page is read, the next storage page to be read is determined based on the data packet sequence number, without moving the data of the subsequent pages forward one by one, which can reduce the RAM overhead and CPU occupancy. At the same time, since the data does not need to be migrated, the number of invalid erasure and write operations is reduced, the wear of the memory is reduced, and the service life of the memory is extended.

[0065] In a possible embodiment, the management area is divided into multiple byte groups, each byte group is used to store the status information of a storage page, and each byte group includes multiple flag bits, and the values of the multiple flag bits are used to indicate the status information of the energy storage page; among them, the value of the first flag bit is used to indicate whether the storage page is an empty page; the value of the second flag bit is used to indicate whether there is a data packet split in the data in the storage page; the value of the third flag bit is used to indicate the type of the data packet in the storage page, and the data includes types such as the first packet, the middle packet, or the last packet; the value of the fourth flag bit is used to indicate whether the data stored in the storage page is emergency data; the value of the fifth flag bit is used to indicate whether the storage page is a bad page; the value of the sixth flag bit is used to indicate the storage order of the data packets stored in the storage page; the value of the seventh flag bit is used to indicate the number of erasure and write operations of the storage page.

[0066] Among them, each byte group in the management area can be 4 bytes, and every 4 bytes correspond to the status information of a storage page. For example, the 128 bytes of the 0th page in the management area record the status of each page from the 32nd to the 63rd page in the data area, and the 128 bytes of the 1st page in the management area record the status of each page from the 64th to the 95th page in the data area, and so on. The 128 bytes of the 15th page in the management area record the status of each page from the 480th to the 511th page in the data area.

[0067] The corresponding relationship between every 4 bytes in the management area and the data pages is shown in Table 1 below.

[0068] Table 1

[0069]

[0070] In a specific implementation, these 4 bytes can be used to flag the status of the corresponding frame through the combination of each bit or bits. The function description of each bit in the 4 bytes is shown in Table 2 below: Table 2

[0071] The first flag bit, bit0: Flags whether the corresponding storage page is empty. If it is empty, a write operation can be performed; if it is not empty, a read operation can be performed.

[0072] The second flag bit, bit1: Flags whether there are sub - packets in the data of this page. 0 - no sub - packets, 1 - there are sub - packets.

[0073] The third flag bit, bit2 - bit3: Flags the packet type. 00 - first packet, 01 - middle packet, 02 - last packet. If there is no packet splitting, it is defaulted to 00.

[0074] The fourth flag bit, bit4: The urgency level of the data. 0 - ordinary data, 1 - urgent data. Urgent data needs to be read out as soon as possible and corresponding processing is done.

[0075] The fifth flag bit, bit5: Bad page flag bit. 1 - bad page, 0 - normal bit6: Reserved The sixth flag bit, bit7 - bit15: The sequence number when the data packet is stored in the memory. This sequence number can be used as the basis for the data processing sequence.

[0076] The seventh flag bit, bit16 - bit31: A total of two bytes, mainly used to record the number of erase and write operations of this page, ensuring that the number of erase and write operations of each page is equal to implement the principle of balanced use of the memory. When the number of erase and write operations of all pages reaches 65535 times, the erase count is cleared simultaneously and starts counting from zero.

[0077] It can be seen that in this embodiment, based on the values of the flag bits in the management area, the status information of each storage page is determined, and data read and write operations are performed based on the status information, which can ensure data security, provide convenience for data access at the same time, and reduce the wear of the memory. At the same time, the bad pages of the memory can be isolated and processed according to the status information to ensure the integrity and reliability of data storage.

[0078] In a possible embodiment, the management area includes a main management area and a backup management area. Updating the status information of the target storage page in the management area according to the target operation includes: updating the status information of the target storage page in the backup management area; after confirming the target operation, synchronizing the updated status information in the backup management area to the main management area.

[0079] Among them, the management area can be divided into a primary management zone (PMZ) and a backup management zone (BMZ). In a specific implementation, the primary management zone can occupy the first 16 pages of the memory, and the backup management zone can be located on pages 16 - 31 of the memory, and the content of the PMZ is synchronously mirrored in real time, and a double - buffer mechanism is adopted to ensure data consistency.

[0080] The division of this EEPROM can be as shown in Table 3 below.

[0081] Table 3

[0082]

[0083] In a specific implementation, the copy - on - write strategy can be adopted. Each time the PMZ is updated, it is first written into the mirror buffer of the BMZ. When the system needs to update the primary PMZ, the modification operation will be first written into the BMZ, which can ensure that the original data is not immediately overwritten. Only after the modification is completed and confirmed to be correct, the modification result will be truly applied to the PMZ.

[0084] It can be seen that in this embodiment, the redundant design of the management area, which is divided into a primary management area and a backup management area, can prevent single - point failures and can repair the primary management area according to the backup area. And updating the data in the BMZ first can improve data consistency, avoid data loss, and improve performance (by reducing unnecessary operations).

[0085] In a possible embodiment, after performing the target operation corresponding to the operation instruction in the target storage page, the method further includes: obtaining feedback information for the target operation, where the feedback information is used to indicate the execution situation of the target operation; in the case where the feedback information indicates that the target operation fails, updating the status information of the target storage page, and the updated status information indicates that the target storage page is a bad page; performing multiple data writing and reading operations on the target storage page and verifying whether the written and read data is consistent each time to obtain multiple verification results; if the multiple verification results all indicate that the written and read data is consistent, updating the status information of the target storage page again, and the status information after the second update indicates that the target storage page is a normal page.

[0086] Among them, when the target operation instruction indicates writing data to the data area of the EEPROM and the feedback information indicates that the write data return is unsuccessful, the target storage page is temporarily marked as a bad page. When the target operation instruction indicates reading data from the data area of the EEPROM and the feedback information indicates that the data verification is unsuccessful after reading the data, the target storage page is temporarily marked as a bad page. In a specific implementation, the update of the status information of the target storage page can be performed in the BMZ at this time.

[0087] After updating the status information of the target stored data, without obtaining the next operation instruction (i.e., without a normal read / write operation task), multiple (e.g., 5 times) data read / write verification operations can be continuously performed. That is, each time, the data is first written to the target storage page, then the data is read from the target storage page, and then it is compared whether the written data and the read data are consistent. If the verification results of multiple consecutive times all indicate that the written data and the read data are consistent, the status information of the target storage page is updated to a normal page again. If it is found that there is one verification result indicating inconsistency, it is determined that the target storage page is a bad page. In a specific implementation, the update can be for the PMZ when updating again. That is, based on the verification result, the status information of the target storage page is updated in the PMZ to indicate that the target storage page is a bad page or a normal page.

[0088] It can be seen that in this embodiment, marking the bad pages in the storage page can ensure that operations are not performed on the bad pages during data read / write, which can guarantee the correctness of the data and isolate the bad pages of the memory, ensuring the integrity and reliability of data storage. At the same time, verifying whether the storage page is a bad page can improve the rigor and accuracy of determining the status information of the storage page.

[0089] Next, a data read / write device for the EEPROM provided by the present application will be described. The data read / write device for the EEPROM described below corresponds and refers to the data read / write method for the EEPROM described above.

[0090] Please refer to Figure 2, a data reading and writing device 200 for an EEPROM includes: a receiving unit 201, configured to receive an operation instruction for the EEPROM, where the operation instruction indicates writing data to a data area of the EEPROM or reading data from the data area of the EEPROM. The EEPROM is divided into a management area and the data area. The management area is used to store the status information of each storage page included in the data area, and each storage page included in the data area is used to store the written data. The status information is used to characterize the data reading and writing conditions of each storage page; a reading unit 202, configured to read the status information of each storage page stored in the management area according to the operation instruction; a determining unit 203, configured to determine a target storage page according to the status information; and an executing unit 204, configured to execute a target operation corresponding to the operation instruction in the target storage page and update the status information of the target storage page in the management area according to the target operation.

[0091] In a possible embodiment, in terms of determining the target storage page according to the status information, the determining unit 203 is specifically configured to: when the operation instruction indicates writing data to the data area of the EEPROM, determine at least one empty page among multiple storage pages in the data area according to the status information, and the number of erase-write times of the at least one empty page; and determine the target storage page from the at least one empty page according to the number of erase-write times.

[0092] In a possible embodiment, in terms of updating the status information of the target storage page in the management area according to the target operation, the executing unit 204 is specifically configured to: determine the operation type of the target operation, where the operation type includes packetized writing or non-packetized writing; when the operation type is packetized writing, determine the packet type corresponding to the target operation and the packet sequence number of the packet, where the packet type includes a first packet, a middle packet, or a last packet; after the target operation is completed, determine that the number of erase-write times of the target storage page is incremented by 1 to obtain the current number of erase-write times of the target storage page; and update the status information of the target storage page according to the operation type, the packet type, the packet sequence number, and the current number of erase-write times.

[0093] In a possible embodiment, in terms of determining the target storage page according to the status information, the determining unit 203 is specifically configured to: when the operation instruction indicates reading data from the data area of the EEPROM, determine the data reading type of the operation instruction, where the data reading type includes packet-by-packet reading or non-packet reading; when the data reading type is packet-by-packet reading, determine, according to the status information, a first reference storage page storing packetized data among multiple storage pages in the data area and a first page number sequence number of the first reference storage page; determine, according to the status information, a first urgency level of the data stored in the first reference storage page, and whether the data stored in the first reference storage page is the first packet of data; and determine the target storage page according to the first page number sequence number, the first urgency level, and whether the data stored in the first reference storage page is the first packet of data.

[0094] In a possible embodiment, in terms of determining the target storage page according to the status information, the determining unit 203 is specifically configured to: when the data reading type is non-packet reading, determine, according to the status information, a second reference storage page storing non-packetized data among multiple storage pages in the data area and a second page number sequence number of the second reference storage page; determine, according to the status information, a second urgency level of the data stored in the second reference storage page; and determine the target storage page according to the second reference storage page and the second urgency level.

[0095] In a possible embodiment, in terms of performing the target operation corresponding to the operation instruction in the target storage page and updating the status information of the target storage page in the management area according to the target operation, the execution unit 204 is specifically configured to: read the data stored in the target storage page, and erase the data stored in the target storage page; update the status information of the target storage page and obtain the data packet sequence number of the data stored in the target storage page, where the updated status information indicates that the target storage page is an empty page; determine the next page to be read from the data area according to the data packet sequence number, and determine whether the next page to be read is the last page; when the next page to be read is not the last page, determine the next page to be read as the target storage page, and repeat the above steps; when the next page to be read is the last page, read the data stored in the next page to be read, and erase the data stored in the next page to be read, and update the status information of the next page to be read, where the updated status information indicates that the next page to be read is an empty page.

[0096] In a possible embodiment, the management area includes a primary management area and a backup management area. In terms of updating the status information of the target storage page in the management area according to the target operation, the execution unit 204 is specifically configured to: update the status information of the target storage page in the backup management area; after confirming the target operation, synchronize the updated status information in the backup management area to the primary management area.

[0097] In a possible embodiment, after performing the target operation corresponding to the operation instruction in the target storage page, the execution unit 204 is further configured to: obtain feedback information for the target operation, where the feedback information is used to indicate the execution status of the target operation; in the case where the feedback information indicates that the target operation fails, update the status information of the target storage page, and the updated status information indicates that the target storage page is a bad page; perform multiple data write and read operations on the target storage page, and verify whether the data written and read each time is consistent to obtain multiple verification results; if the multiple verification results all indicate that the data written and read is consistent, update the status information of the target storage page again, and the status information after the second update indicates that the target storage page is a normal page.

[0098] Please refer to Figure 3 , Figure 3 is a schematic structural diagram of an electronic device provided by the present application. As Figure 3 shown, the electronic device may include: a processor 310, a communication interface 320, a memory 330, and a communication bus 340. Among them, the processor 310, the communication interface 320, and the memory 330 communicate with each other through the communication bus 340. The processor 310 may call logic instructions in the memory 330 to execute a data reading and writing method for the EEPROM, and the method includes: receiving an operation instruction for the EEPROM, where the operation instruction indicates writing data to the data area of the EEPROM or reading data from the data area of the EEPROM. The EEPROM is divided into a management area and the data area. The management area is used to store the status information of each storage page included in the data area, each storage page included in the data area is used to store the written data, and the status information is used to characterize the data reading and writing conditions of each storage page; reading the status information of each storage page stored in the management area according to the operation instruction; determining a target storage page according to the status information; performing the target operation corresponding to the operation instruction in the target storage page, and updating the status information of the target storage page in the management area according to the target operation.

[0099] In addition, when the logical instructions in the aforementioned memory 330 can be implemented in the form of software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on such an understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or a part of this technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods described in various embodiments of the present invention. The aforementioned storage medium includes: various media such as USB flash drives, mobile hard disks, read-only memories (ROMs), random access memories (RAMs), magnetic disks, or optical discs that can store program codes.

[0100] On the other hand, the present invention also provides a non-transitory computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, it is used to implement a data reading and writing method for an EEPROM provided by the above-mentioned various methods. The method includes: receiving an operation instruction for the EEPROM, where the operation instruction indicates writing data to the data area of the EEPROM or reading data from the data area of the EEPROM. The EEPROM is divided into a management area and the data area. The management area is used to store the status information of each storage page included in the data area. Each storage page included in the data area is used to store the written data. The status information is used to characterize the data reading and writing conditions of each storage page; reading the status information of each storage page stored in the management area according to the operation instruction; determining a target storage page according to the status information; performing a target operation corresponding to the operation instruction in the target storage page, and updating the status information of the target storage page in the management area according to the target operation.

[0101] In another aspect, the present application also provides a computer program product, including a computer program, which when executed by a processor implements any of the above data reading and writing methods for EEPROM. The method includes: receiving an operation instruction for the EEPROM, the operation instruction indicating writing data to the data area of the EEPROM or reading data from the data area of the EEPROM. The EEPROM is divided into a management area and the data area. The management area is used to store the status information of each storage page included in the data area. Each storage page included in the data area is used to store the written data. The status information is used to characterize the data reading and writing conditions of each storage page; reading the status information of each storage page stored in the management area according to the operation instruction; determining a target storage page according to the status information; performing a target operation corresponding to the operation instruction in the target storage page, and updating the status information of the target storage page in the management area according to the target operation.

[0102] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separated. The components shown as units may or may not be physical units, that is, they may be located in one place or distributed to multiple network units. Some or all of the modules can be selected according to actual needs to achieve the purpose of the solution of this embodiment. Those of ordinary skill in the art can understand and implement it without creative efforts.

[0103] Through the description of the above embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of software plus a necessary general hardware platform, and of course, it can also be implemented by hardware. Based on such an understanding, the above technical solutions, in essence, or the part that contributes to the prior art can be embodied in the form of a software product. The computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, magnetic disk, optical disk, etc., and includes several instructions for causing a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.

[0104] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that they can still modify the technical solutions described in the foregoing embodiments, or perform equivalent replacements for some of the technical features; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.

Claims

1. A method for reading and writing data of an electrically erasable programmable read-only memory (EEPROM), characterized in that: include: receiving an operation instruction for an EEPROM, wherein the operation instruction instructs writing data to a data area of ​​the EEPROM or reading data from a data area of ​​the EEPROM, wherein the EEPROM is divided into a management area and the data area, wherein the management area is used to store status information of each storage page included in the data area, and each storage page included in the data area is used to store written data, and the status information is used to characterize the data reading and writing status of each storage page; Reading the status information of each storage page stored in the management area according to the operation instruction; Determine a target storage page according to the status information; A target operation corresponding to the operation instruction is executed in the target storage page, and state information of the target storage page in the management area is updated according to the target operation.

2. The method according to claim 1, characterized in that The determining the target storage page according to the state information includes: In the case where the operation instruction indicates to write data into the data area of ​​the EEPROM, determining at least one empty page among a plurality of storage pages in the data area and the number of times of erasing and writing the at least one empty page according to the state information; A target storage page is determined from the at least one empty page according to the number of erasures and writes.

3. The method according to claim 2, characterized in that The updating of the state information of the target storage page in the management area according to the target operation includes: Determine an operation type of the target operation, where the operation type includes writing in packets or writing without packets; In the case where the operation type is the packet writing, determining a data packet type corresponding to the target operation and a data packet sequence number of the data packet, the data packet type including a first packet, a middle packet or a last packet; After the target operation is completed, determine the number of erase / write times of the target storage page plus 1 to obtain the current number of erase / write times of the target storage page; The state information of the target storage page is updated according to the operation type, the data packet type, the data packet sequence number and the current erase and write times.

4. The method according to claim 1, characterized in that: The determining the target storage page according to the state information includes: In the case where the operation instruction indicates to read data from the data area of ​​the EEPROM, determining a data reading type of the operation instruction, the data reading type including packet reading or non-packet reading; In the case where the data read type is the sub-packet read, determining, according to the state information, a first reference storage page storing sub-packet data and a first page number sequence number of the first reference storage page among a plurality of storage pages in the data area; Determining, according to the state information, a first urgency level of the data stored in the first reference storage page, and whether the data stored in the first reference storage page is first packet data; The target storage page is determined according to the first page number sequence, the first urgency level, and whether the data stored in the first reference storage page is the first packet of data.

5. The method according to claim 4, characterized in that The determining the target storage page according to the state information includes: In the case where the data reading type is the non-packetized reading, determining, according to the state information, a second reference storage page storing non-packetized data and a second page number sequence number of the second reference storage page among the plurality of storage pages in the data area; determining a second urgency level of the data stored in the second reference storage page according to the status information; A target storage page is determined according to the second reference storage page and the second urgency level.

6. The method according to claim 4, characterized in that The performing the target operation corresponding to the operation instruction in the target storage page, and updating the state information of the target storage page in the management area according to the target operation, includes: Reading data stored in the target storage page, and erasing data stored in the target storage page; Updating the status information of the target storage page and obtaining the data packet sequence number of the data stored in the target storage page, the updated status information indicating that the target storage page is an empty page; Determine the next page to be read from the data area according to the data packet sequence number, and determine whether the next page to be read is the last page; In the case that the next page to be read is not the last page, determining that the next page to be read is the target storage page, and repeating the above steps; When the next page to be read is the last page, data stored in the next page to be read is read, data stored in the next page to be read is erased, and status information of the next page to be read is updated, and the updated status information indicates that the next page to be read is an empty page.

7. The method according to claim 1, characterized in that The management area includes a primary management area and a backup management area, and the updating of the state information of the target storage page in the management area according to the target operation includes: Updating the status information of the target storage page in the backup management area; After confirming the target operation, the updated status information in the backup management area is synchronized to the main management area.

8. The method according to any one of claims 1 to 7, characterized in that: After executing the target operation corresponding to the operation instruction in the target storage page, the method further includes: Acquire feedback information for the target operation, where the feedback information is used to indicate the execution status of the target operation; When the feedback information indicates that the target operation fails to be executed, updating the status information of the target storage page, wherein the updated status information indicates that the target storage page is a bad page; Performing multiple data writing and reading operations on the target storage page, and verifying whether the data written and read each time are consistent, to obtain multiple verification results; If the multiple verification results all indicate that the written data and the read data are consistent, the status information of the target storage page is updated again, and the updated status information indicates that the target storage page is a normal page.

9. A data reading and writing device for EEPROM, characterized in that: include: a receiving unit, configured to receive an operation instruction for the EEPROM, wherein the operation instruction instructs to write data to a data area of ​​the EEPROM or read data from the data area of ​​the EEPROM, wherein the EEPROM is divided into a management area and the data area, wherein the management area is used to store status information of each storage page included in the data area, and each storage page included in the data area is used to store written data, and the status information is used to characterize the data reading and writing status of each storage page; a reading unit, configured to read the status information of each storage page stored in the management area according to the operation instruction; A determination unit, configured to determine a target storage page according to the state information; An execution unit is used to execute a target operation corresponding to the operation instruction in the target storage page, and update the status information of the target storage page in the management area according to the target operation.

10. An electronic device comprising a memory, a processor, and a computer program stored in the memory and running on the processor, characterized in that: When the processor executes the computer program, the method for reading and writing data for an electrically erasable programmable read-only memory (EEPROM) as claimed in any one of claims 1 to 8 is implemented.

Citation Information

Patent Citations

  • Data processing method and device, electronic equipment and storage medium

    CN114253718A

  • Storage management method, system and device for data of intelligent electric meter

    CN114253871A

  • Storage control method for prolonging erasing and writing life of NOR FLASH

    CN115268768A

  • Method for realizing uniform wear of FLASH by simulating universal memory

    CN116893986A

  • Storage wear balancing method and device

    CN119597215A

Cited By

  • Memory erasing management method and device, electronic equipment and storage medium

    CN121636369A