Data reading and writing method, device and equipment for EEPROM

By dividing EEPROM into management area and data area, and optimizing data read and write operations using state information, the local wear of EEPROM, high CPU usage, RAM resource bottlenecks and power consumption problems are solved, and the service life of the memory and system stability are improved.

CN120066423BActive Publication Date: 2025-08-08BEIJING GUODIAN GAOKE TECH CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

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

AI Technical Summary

Technical Problem

The existing EEPROM operation method leads to intensified local wear, high CPU usage, bottlenecks in RAM resources, increased power consumption and data migration risks, affecting the service life of storage media and system performance stability.

Method used

The EEPROM is divided into a management area and a data area. The management area stores the status information of each storage page. The target storage page is determined through the status information and performs operations to avoid data migration and invalid rewrittening. Subcontracted writing and reading strategies are adopted, and the main backup management area is used to ensure data consistency.

Benefits of technology

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

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120066423B_ABST
    Figure CN120066423B_ABST
Patent Text Reader

Abstract

The present invention provides a data reading and writing method, device, and apparatus for an EEPROM (Electronic Programmable Memory) (EEPROM), belonging to the field of data processing. The method comprises: receiving an operation instruction for the EEPROM, the operation instruction instructing to write data to or read data from a data area of the EEPROM; the EEPROM being divided into a management area and a data area, the management area being used to store status information of each storage page included in the data area, and each storage page included in the data area being used to store written data; reading the status information of each storage page stored in the management area according to the operation instruction; determining a target storage page based on the status information; executing a target operation corresponding to the operation instruction on the target storage page, and updating the status information of the target storage page in the management area according to the target operation. This method ensures balanced data erasure and writing, while avoiding high CPU and RAM usage, reducing power consumption, and increasing the service life of the EEPROM.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to a data processing method, device and apparatus for reading and writing data from an EEPROM. Background Art

[0002] Electrically Erasable Programmable Read-Only Memory (EEPROM) is often used to store data that needs to be retained long-term. A common EEPROM operation method is to store a data packet per page, with a flag bit set in the first 8 bytes of the page to indicate the status of the data on that page. Data is written sequentially, starting with the first page and proceeding backwards. When the last page is full, the data is overwritten again, starting from the first page. When reading data, the data is read page by page, starting from the beginning, until the desired data packet is found.

[0003] This implementation is simple and easy, but it has some design limitations.

[0004] Increased local wear:‌

[0005] Data is always written sequentially from the first page, and overwritten cyclically when the page is full. This causes the first page (such as Page 0) to have a much higher erase and write count than subsequent pages, creating local hotspots. This uneven usage violates the principle of balanced use of storage media, significantly shortening the overall lifespan of the EEPROM.

[0006] High CPU usage and system latency:‌

[0007] After reading the first page of data, all subsequent pages of data must be moved forward one page at a time to maintain data continuity. This process frequently occupies the CPU for data movement, blocking real-time tasks and increasing interrupt response latency, which in turn affects system timing stability.

[0008] The number of invalid writes increased dramatically:‌

[0009] During data migration, all subsequent pages of data must be rewritten page by page, resulting in 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 operations will reach N times. This invalid write directly increases the wear of the EEPROM.

[0010] Random Access Memory (RAM) resource bottleneck:‌

[0011] During data migration, multiple pages of data (e.g., 128 bytes per page) must be temporarily stored in RAM. For resource-constrained MCUs (e.g., with only 2KB of RAM), a single migration may occupy more than 20% of the memory resources, degrading system performance and potentially causing the migration operation to fail.

[0012] Data Migration Risks:‌

[0013] During the data migration process, if a power outage or external interference occurs, the continuity of the original data chain may be disrupted, resulting in data loss or logical confusion. In addition, due to the lack of a breakpoint resume mechanism, if the migration process is interrupted, data recovery will become very difficult.

[0014] High power consumption issue:‌

[0015] The increase in invalid writes also raises power consumption issues. Each write operation can draw mA of current (10-100 times higher than a read), significantly reducing the battery life of battery-powered devices such as IoT sensors.

[0016] Write conflicts and data errors:‌

[0017] During data migration, if an external attempt is made to write new data, a write conflict will occur, which may lead to data write errors or failures, further increasing the complexity and risk of data management.

[0018] In summary, the existing EEPROM operation mode has many defects, which not only affects the service life of the storage medium and the performance stability of the system, but also increases the complexity and risk of data management. Summary of the Invention

[0019] The present application provides a data reading and writing method, device and equipment for EEPROM to ensure the balance of data erasing and writing, while avoiding the problems of high CPU occupancy, RAM occupancy, and increased power consumption caused by repeated writing of FLASH, as well as the risk of collision between new data writing and data migration, thereby improving the service life of EEPROM.

[0020] This application provides a data reading and writing method for EEPROM, including:

[0021] receiving an operation instruction for an EEPROM, the operation instruction instructing to write data to a data area of the EEPROM or to read data from the data area of the EEPROM, the EEPROM being divided into a management area and the data area, the management area being used to store status information of each storage page included in the data area, each storage page included in the data area being used to store written data, and the status information being used to characterize a data read / write status of each storage page;

[0022] Reading the status information of each storage page stored in the management area according to the operation instruction;

[0023] determining a target storage page according to the status information;

[0024] A target operation corresponding to the operation instruction is executed in the target storage page, and status information of the target storage page in the management area is updated according to the target operation.

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

[0026] 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, the operation type including packet write or non-packet write; when the operation type is packet write, determining the data packet type and the data packet sequence number corresponding to the target operation, the data packet type including the first packet, the middle packet or the last packet; after the target operation is completed, determining the number of erase and write times of the target storage page plus 1 to obtain the current number of erase and write times of the target storage page; and updating the status information of the target storage page according to the operation type, the data packet type, the data packet sequence number and the current number of erase and write times.

[0027] According to the data reading and writing method for EEPROM provided by the present application, the method of determining the target storage page according to the status information includes: when the operation instruction indicates to read data from the data area of the EEPROM, determining the data reading type of the operation instruction, the data reading type including packet reading or non-packet reading; when the data reading type is packet reading, determining, according to the status information, a first reference storage page storing packet data among multiple storage pages in the data area and a first page number sequence of the first reference storage page; determining, according to the status information, a first urgency 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 data; and determining the target storage page according to the first page number sequence, the first urgency, and whether the data stored in the first reference storage page is the first packet data.

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

[0029] According to the data reading and writing method for EEPROM provided by the present application, the target operation corresponding to the operation instruction is executed 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, including: 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, the updated status information indicating 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; if 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; if 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, the updated status information indicating that the next page to be read is an empty page.

[0030] According to the data reading and writing method for EEPROM provided in 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.

[0031] According to the data reading and writing method for EEPROM provided by the present application, after executing the target operation corresponding to the operation instruction in the target storage page, the method further includes: obtaining feedback information for the target operation, the feedback information being used to indicate the execution status of the target operation; when the feedback information indicates that the target operation fails to execute, updating the status information of the target storage page, the updated status information indicating 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 and read data are consistent, updating the status information of the target storage page again, the updated status information indicating that the target storage page is a normal page.

[0032] The present application also provides a data reading and writing device for EEPROM, comprising:

[0033] a receiving unit, configured to receive an operation instruction for an EEPROM, wherein the operation instruction instructs writing data to a data area of the EEPROM or reading 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 configured to store status information of each storage page included in the data area, and each storage page included in the data area is configured to store written data, and the status information is configured to represent a data read and write status of each storage page;

[0034] a reading unit, configured to read the status information of each storage page stored in the management area according to the operation instruction;

[0035] a determining unit, configured to determine a target storage page according to the status information;

[0036] An execution unit is configured to execute a target operation corresponding to the operation instruction in the target storage page, and update status information of the target storage page in the management area according to the target operation.

[0037] The present application also provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, it implements any of the above-mentioned methods for reading and writing data for an electrically erasable programmable read-only memory (EEPROM).

[0038] The present application also provides a non-transitory computer-readable storage medium having a computer program stored thereon. When the computer program is executed by a processor, the computer program implements any of the above-mentioned data reading and writing methods for an electrically erasable programmable read-only memory (EEPROM).

[0039] The present application also provides a computer program product, including a computer program, which, when executed by a processor, implements any of the above-mentioned data reading and writing methods for an electrically erasable programmable read-only memory (EEPROM).

[0040] The data reading and writing method, device and equipment for EEPROM provided by the present application first receive an operation instruction for EEPROM, wherein the operation instruction instructs to write data to the data area of EEPROM or read data from the data area of 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 then the status information of each storage page stored in the management area is read according to the operation instruction, and then the target storage page is determined according to the status information, and 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.

[0041] As can be seen, in this embodiment, the memory is divided into a management area and a data area, achieving operational isolation, ensuring data security, and improving the convenience of data access. When reading data, there is no need for data migration, which can reduce RAM overhead and CPU usage. This also reduces the number of invalid erase and write operations, reduces memory wear, and extends the memory lifespan. Since data migration is not required, the number of data erase and write operations is also reduced, which also reduces power consumption. This also solves the problem of data errors or unsuccessful data writes caused by conflicts between data migration and data writing. BRIEF DESCRIPTION OF THE DRAWINGS

[0042] In order to more clearly illustrate the technical solutions in the present invention or the prior art, a brief introduction is given below to the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.

[0043] Figure 1 This is a flow chart of a method for reading and writing data in an EEPROM provided by the present application.

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

[0045] Figure 3 A schematic structural diagram of an electronic device provided in this application. DETAILED DESCRIPTION

[0046] To make the objectives, technical solutions, and advantages of the present invention more clear, the technical solutions of the present invention will be clearly and completely described below in conjunction with the accompanying drawings. Obviously, the embodiments described are only some of the embodiments of the present invention, not all of them. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative efforts shall fall within the scope of protection of the present invention.

[0047] The terms "first," "second," and the like in the specification and claims of this application and the accompanying drawings are used to distinguish between different objects, not to describe a particular order. Furthermore, the terms "including," "having," and any variations thereof, are intended to cover non-exclusive inclusions. For example, a process, method, system, product, or apparatus comprising a series of steps or elements is not limited to the listed steps or elements but may optionally include steps or elements not listed, or may optionally include other steps or elements inherent to the process, method, product, or apparatus.

[0048] References herein to "embodiments" mean that a particular feature, structure, or characteristic described in connection with the embodiments may be included in at least one embodiment of the present application. The appearance of this phrase in various places in the specification does not necessarily refer to the same embodiment, nor does it constitute an independent or alternative embodiment that is mutually exclusive of other embodiments. It is understood, both explicitly and implicitly, by those skilled in the art that the embodiments described herein may be combined with other embodiments.

[0049] The existing EEPROM operation mode has many defects, which not only affects the service life of the storage medium and the performance stability of the system, but also increases the complexity and risk of data management.

[0050] To address the above issues, this application provides a method, device, and apparatus for reading and writing data from an EEPROM. Figure 1 The data reading and writing method for EEPROM includes the following steps.

[0051] S101, receiving an operation instruction for the EEPROM.

[0052] The operation instruction instructs 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 status information of each storage page included in the data area. Each storage page included in the data area is used to store written data. The status information is used to characterize the data reading and writing status of each storage page. The data reading and writing status includes whether data is written to the storage page, whether the written data is sub-packaged data or not, the number of erase and write times of the storage page, etc.

[0053] In a specific implementation, the management area can occupy the first 31 pages of memory, with each page containing 128 bytes. This area can store status information such as the data area's page index table, access permission flags, and erase counts. The data area comprises the subsequent 480 pages of memory, divided into user-accessible storage units by page. Specifically, the management area can be placed at the physical front end of the memory (low-address segment), fully leveraging the linear addressing characteristics of the memory controller to reduce access latency and improve operational efficiency.

[0054] S102: Read the status information of each storage page stored in the management area according to the operation instruction.

[0055] The read status information may also vary depending on the content indicated by the operation instruction. For example, if the operation instruction instructs writing data to the data area of the EEPROM, the read status information may include whether the storage page is empty, the number of erase and write cycles of the storage page, etc. If the operation instruction instructs reading data from the data area of the EEPROM, the read status information may include whether the storage page is empty, whether the storage page stores packetized data or non-packetized data, if the storage page stores packetized data, whether the data stored in the storage page is the first packet of data, and the urgency of the data stored in the storage page.

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

[0057] The management area strictly aligns page boundaries according to a page alignment mechanism (e.g., 128-byte page boundaries). This means that when writing or reading data, the data begins with a complete page, avoiding split operations caused by cross-page reads and writes. Specifically, the status information of the target storage page indicates that the target storage page is a normal page. This means that when writing data, bad pages are skipped and not performed; when reading data, bad pages are skipped and not performed.

[0058] S104 , executing 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.

[0059] As can be seen, in this embodiment, the memory is divided into a management area and a data area, achieving operational isolation, ensuring data security, and improving the convenience of data access. When reading data, there is no need for data migration, which can reduce RAM overhead and CPU usage. This also reduces the number of invalid erase and write operations, reduces memory wear, and extends the memory lifespan. Since data migration is not required, the number of data erase and write operations is also reduced, which also reduces power consumption. This also solves the problem of data errors or unsuccessful data writes caused by conflicts between data migration and data writing.

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

[0061] When writing data to the EEPROM data area, the data size determines whether to write to a single page (≤128 bytes) or multiple pages (>128 bytes). If writing to a single page, the target storage page consists of one page. If writing to multiple pages, the required number of pages can be calculated based on the size of the written data, and the number of target storage pages can be used.

[0062] In a specific implementation, when determining the target storage page, priority is given to empty pages with a low number of erase and write cycles as the target storage page. When the target storage page includes multiple pages, the target storage page can be determined to be a continuous number of empty pages among the multiple empty pages. When there are multiple continuous empty pages, the target storage page can be determined to be the empty page with the least total number of erase and write cycles among the multiple continuous empty pages. In particular, after determining the empty page, it is also possible to determine whether the empty page is a bad page based on the status information. If it is not a bad page, the target storage page is then determined based on the total number of erase and write cycles.

[0063] It can be seen that in this embodiment, the access to the memory adopts the balance principle to solve the hot access area caused by sequential storage, reduce the bad page rate, and extend the service life of the memory.

[0064] In a possible embodiment, 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, the operation type including packet write or non-packet write; when the operation type is packet write, determining the data packet type and the data packet sequence number corresponding to the target operation, the data packet type including the first packet, the middle packet or the last packet; after the target operation is completed, determining the number of erase and write times of the target storage page plus 1 to obtain the current number of erase and write times of the target storage page; updating the status information of the target storage page according to the operation type, the data packet type, the data packet sequence number and the current number of erase and write times.

[0065] Among them, sub-packet writing indicates that the target storage page includes multiple pages, and data needs to be written in multiple pages. At this time, after a sub-packet data is written to a target storage page, the storage data corresponding to the target storage page will be updated to the sub-packet data state. At the same time, if the target storage page stores the first packet data, the data packet type state of the target storage page is updated to the first packet state, and the data packet sequence number of the data packet is recorded in the state and the number of erases and writes of the target storage page is increased by 1. When recording the data packet sequence number, a chain storage structure is adopted, and the next packet sequence number is stored in the management area.

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

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

[0068] In a possible embodiment, determining the target storage page based on the status information includes: when the operation instruction indicates to read data from the data area of the EEPROM, determining the data read type of the operation instruction, the data read type including packet read or non-packet read; when the data read type is packet read, determining a first reference storage page storing packet data and a first page number of the first reference storage page among multiple storage pages in the data area based on the status information; determining a first urgency 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 based on the status information; and determining the target storage page based on the first page number, the first urgency, and whether the data stored in the first reference storage page is first packet data.

[0069] When reading data in packets, the system first locates the page that already stores data, based on the status information of each storage page stored in the management area. It then determines whether the data stored in the storage page is the first packet of data. The page to be read is then determined based on the page number and whether the data is urgent.

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

[0071] In particular, after the data of the target storage page is read, the data of the page is erased, and the status information of the page is changed to an empty page.

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

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

[0074] When reading data without subpackaging, first find the storage page that already stores the data, then determine the storage page that stores the unpacked data based on whether the stored data is subpackaging data, and finally determine the target storage page based on the page number and whether the data is urgent.

[0075] In particular, after the data of the target storage page is read, the data of the page is erased, and the status information of the page is changed to an empty page.

[0076] It can be seen that in this embodiment, the target storage page is determined based on the page number and the urgency, and the storage page that needs to be read can be quickly located based on the status information.

[0077] In a possible embodiment, the target operation corresponding to the operation instruction is executed 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, including: 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, the updated status information indicating 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; if 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; if 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, the updated status information indicating that the next page to be read is an empty page.

[0078] Among them, after determining the target storage page, after reading the data of the target storage page, the data of the target storage page is erased, and then the status information of whether the target storage page is an empty page in the management area is updated to an empty page. At the same time, the data packet sequence number of the data packet stored in the target storage page is recorded. Then, the next storage page to be read is found according to the data packet sequence number of the distance. And it is determined whether the next storage page to be read is the last page. If it is the last page, the data of the last page is read, and the data of the page is erased, and the corresponding status information is updated to an empty page. If it is not the last page, the storage page is determined as the target storage page, the data is read again, the data is erased, and the next storage page to be read is determined, until the next storage page to be read is the last page.

[0079] As can be seen, in this embodiment, after each memory page is read, the next memory page to be read is determined based on the data packet sequence number, eliminating the need to shift subsequent pages of data forward page by page, thereby reducing RAM overhead and CPU usage. Furthermore, since data does not need to be migrated, the number of ineffective erase and write operations is reduced, reducing memory wear and extending the memory's service life.

[0080] In a possible embodiment, the management area is divided into multiple byte groups, each byte group is used to store 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; wherein, 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 the data in the storage page is subpacketed; the value of the third flag bit is used to indicate the type of data packet in the storage page, and the data includes a first packet, an intermediate packet or a tail packet; the value of the fourth flag bit is used to indicate whether the data stored in the storage page is urgent 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 erase and write times of the storage page.

[0081] Each byte group in the management area can be 4 bytes, with each 4 bytes corresponding to the status information of a storage page. For example, the 128 bytes of page 0 in the management area record the status of each page in the data area from 32 to 63. The 128 bytes of page 1 in the management area record the status of each page in the data area from 64 to 95. Similarly, the 128 bytes of page 15 in the management area record the status of each page in the data area from 480 to 511.

[0082] The correspondence between every 4 bytes of the management area and the data page is shown in Table 1 below.

[0083] Table 1

[0084]

[0085] In specific implementation, these 4 bytes can be used to mark the status of the corresponding frame by bit or bits combined. The function of each bit of the 4 bytes is described in Table 2 below:

[0086] Table 2

[0087]

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

[0089] The second flag bit, bit 1, indicates whether the data on this page is sub-packed. 0 means no sub-packaging, 1 means sub-packaging.

[0090] The third flag bit, bit 2-bit 3: indicates the packet type, 00-first packet, 01-middle packet, 02-last packet. The default value is 00 if no packet is split.

[0091] The fourth flag bit, bit 4: data urgency, 0 - normal data, 1 - urgent data. Urgent data needs to be read out and processed as soon as possible.

[0092] The fifth flag bit, bit5: bad page flag. 1-bad page, 0-normal

[0093] bit6: Reserved

[0094] The sixth flag bit, bit 7-bit 15: The sequence number of the data packet when it is stored in the memory. This sequence number can be used as the basis for the data processing order.

[0095] The seventh flag bit, bit 16-bit 31, is two bytes long and is used to record the number of erase and write cycles for the page, ensuring that each page has an equal number of erase and write cycles to achieve balanced memory usage. When the erase and write cycles for all pages reach 65535, the erase counts are cleared and the count starts again from zero.

[0096] As can be seen, in this embodiment, the status information of each storage page is determined based on the values of the flag bits in the management area, and data read and write operations are performed based on this status information. This ensures data security, provides convenient data access, and reduces memory wear. Furthermore, bad memory pages can be isolated based on the status information, ensuring the integrity and reliability of data storage.

[0097] In a possible embodiment, 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.

[0098] The management zone can be divided into a primary management zone (PMZ) and a backup management zone (BMZ). Specifically, the PMZ can occupy the first 16 pages of memory, while the BMZ can be located on pages 16-31 of memory. The PMZ contents are synchronized in real time using a mirroring mechanism, and a double buffering mechanism is used to ensure data consistency.

[0099] The EEPROM can be divided as shown in Table 3 below.

[0100] Table 3

[0101]

[0102] In practice, a "Copy-on-Write" strategy can be used. Each time the PMZ is updated, the mirror buffer is written to the BMZ first. When the system needs to update the primary PMZ, the modification operation is first written to the BMZ. This ensures that the original data is not immediately overwritten. The modification is not actually applied to the PMZ until it is completed and verified.

[0103] As can be seen, in this embodiment, the redundant management zone design, divided into a primary and backup management zone, prevents single points of failure and allows the primary management zone to be repaired based on the backup zone. Furthermore, updating data in the BMZ first improves data consistency, avoids data loss, and improves performance (by reducing unnecessary operations).

[0104] In a possible embodiment, after executing the target operation corresponding to the operation instruction in the target storage page, the method further includes: obtaining feedback information for the target operation, the feedback information being used to indicate the execution status of the target operation; when the feedback information indicates that the target operation fails to execute, updating the status information of the target storage page, the updated status information indicating that the target storage page is a bad page; performing multiple data write and read 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 and read data are consistent, updating the status information of the target storage page again, the updated status information indicating that the target storage page is a normal page.

[0105] If the target operation instruction instructs to write data to the data area of the EEPROM, and the feedback information indicates that the data write was unsuccessful, the target storage page is temporarily marked as a bad page. If the target operation instruction instructs to read data from the data area of the EEPROM, and the feedback information indicates that the data verification after reading the data was unsuccessful, the target storage page is temporarily marked as a bad page. In a specific implementation, the status information of the target storage page can be updated in the BMZ.

[0106] After the status information of the target storage data is updated, multiple (for example, 5) data read and write verification operations can be performed continuously without obtaining the next operation instruction (that is, there is no normal read and write operation task), that is, each time the data is first written to the target storage page, and then the data is read from the target storage page, and then the written data and the read data are compared to see if they are consistent. If the verification results for multiple consecutive times indicate that the written and 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 a verification result indicating inconsistency, the target storage page is determined to be a bad page. In a specific implementation, the update can be an update to the PMZ. 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.

[0107] As can be seen, in this embodiment, bad pages are marked in the memory so that operations are not performed on bad pages during data reading and writing, which can ensure data correctness. Bad pages in the memory are also isolated and processed, ensuring the integrity and reliability of data storage. At the same time, whether the memory page is a bad page is verified, which improves the rigor and accuracy of determining the memory page status information.

[0108] A data reading and writing device for EEPROM provided by the present application is described below. The data reading and writing device for EEPROM described below corresponds to the data reading and writing method for EEPROM described above.

[0109] See also Figure 2 , a data reading and writing device 200 for EEPROM includes: a receiving unit 201, used to receive an operation instruction for EEPROM, the operation instruction instructs to write data to the data area of EEPROM, or read 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 status information of each storage page included in the data area, 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 202, used to read the status information of each storage page stored in the management area according to the operation instruction; a determining unit 203, used to determine the target storage page according to the status information; an executing unit 204, used to execute the 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.

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

[0111] In one possible embodiment, 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 used to: determine the operation type of the target operation, the operation type including packet write or non-packet write; in the case where the operation type is packet write, determine the data packet type and the data packet sequence number corresponding to the target operation, the data packet type including the first packet, the middle packet or the last packet; after the target operation is completed, determine the number of erase and write times of the target storage page plus 1 to obtain the current number of erase and write times of the target storage page; and update the status information of the target storage page according to the operation type, the data packet type, the data packet sequence number and the current number of erase and write times.

[0112] In a possible embodiment, in terms of determining the target storage page based on the status information, the determination unit 203 is specifically used to: determine the data read type of the operation instruction when the operation instruction indicates to read data from the data area of the EEPROM, and the data read type includes packet reading or non-packet reading; when the data read type is packet reading, determine the first reference storage page storing packet data and the first page number of the first reference storage page among the multiple storage pages in the data area according to the status information; determine the first urgency 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 data according to the status information; and determine the target storage page according to the first page number, the first urgency, and whether the data stored in the first reference storage page is the first packet data.

[0113] In a possible embodiment, in terms of determining the target storage page based on the status information, the determination unit 203 is specifically used to: when the data reading type is the non-packetized reading, determine, based on the status 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 multiple storage pages in the data area; determine, based on the status information, a second urgency of the data stored in the second reference storage page; and determine the target storage page based on the second reference storage page and the second urgency.

[0114] In one possible embodiment, in terms of executing 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 used 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, 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; if the next page to be read is not the last page, determine that the next page to be read is the target storage page, and repeat the above steps; if the next page to be read is the last page, read the data stored in the next page to be read, erase the data stored in the next page to be read, and update the status information of the next page to be read, the updated status information indicating that the next page to be read is an empty page.

[0115] In a possible embodiment, the management area includes a main 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 used 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 main management area.

[0116] In a possible embodiment, after executing the target operation corresponding to the operation instruction in the target storage page, the execution unit 204 is further used to: obtain feedback information for the target operation, 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 execute, 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 writing and reading operations on the target storage page, and verify 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 and read data are consistent, update the status information of the target storage page again, and the updated status information indicates that the target storage page is a normal page.

[0117] See also Figure 3 , Figure 3 This is a schematic diagram of the structure of the electronic device provided by this application. Figure 3As shown, the electronic device may include: a processor 310, a communications interface 320, a memory 330, and a communications bus 340, wherein the processor 310, the communications interface 320, and the memory 330 communicate with each other via the communications bus 340. The processor 310 may call logic instructions in the memory 330 to execute a data reading and writing method for an EEPROM. The method includes: receiving an operation instruction for the EEPROM, the operation instruction instructing to write data to a data area of the EEPROM or to read data from the data area of the EEPROM, the EEPROM being divided into a management area and the data area, the management area being used to store status information of each storage page included in the data area, each storage page included in the data area being used to store written data, the status information being 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; determining a target storage page according to the status information; performing a target operation corresponding to the operation instruction on the target storage page, and updating the status information of the target storage page in the management area according to the target operation.

[0118] Furthermore, the logic instructions in the aforementioned memory 330 can be implemented as software functional units and, when sold or used as independent products, can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, or the portion that contributes to the prior art, or a portion of the technical solution, can be embodied in the form of a software product. This computer software product, stored in a storage medium, includes several instructions for enabling a computer device (which can be a personal computer, server, or 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 capable of storing program code, such as a USB flash drive, a mobile hard drive, a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk.

[0119] On the other hand, the present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, is implemented to execute the data reading and writing methods for EEPROM provided by the above-mentioned methods, the method comprising: receiving an operation instruction for EEPROM, the operation instruction instructing to write data to the data area of EEPROM, or to read data from the data area of EEPROM, the EEPROM being divided into a management area and the data area, the management area being used to store status information of each storage page included in the data area, each storage page included in the data area being used to store written data, the status information being 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; determining the target storage page according to the status information; executing 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.

[0120] On the other hand, the present application also provides a computer program product, including a computer program, which, when executed by a processor, implements any of the above-mentioned data reading and writing methods for EEPROM, the method including: receiving an operation instruction for EEPROM, the operation instruction instructing to write data to the data area of EEPROM, or to read data from the data area of EEPROM, the EEPROM being divided into a management area and the data area, the management area being used to store status information of each storage page included in the data area, each storage page included in the data area being used to store written data, the status information being 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; determining the 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.

[0121] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units, i.e., they may be located in one location or distributed across multiple network units. Some or all of the modules may be selected based on actual needs to achieve the objectives of the present embodiment. Persons of ordinary skill in the art will be able to understand and implement the present invention without inventive effort.

[0122] Through the above description of the embodiments, those skilled in the art will clearly understand that each embodiment can be implemented using software plus a necessary general-purpose hardware platform, or of course, hardware. Based on this understanding, the essence of the above technical solution, or the portion that contributes to the prior art, can be embodied in the form of a software product. This computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a magnetic disk, or an optical disk, and includes a number of instructions for causing a computer device (such as a personal computer, server, or network device) to execute the methods described in each embodiment or certain portions of the embodiments.

[0123] 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 it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the various 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, the operation instruction instructing to write data to a data area of the EEPROM or to read data from the data area of the EEPROM, the EEPROM being divided into a management area and the data area, the management area being used to store status information of each storage page included in the data area, each storage page included in the data area being used to store written data, and the status information being used to characterize a data read / write status of each storage page; Reading the status information of each storage page stored in the management area according to the operation instruction; In a case where the operation instruction instructs 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 a 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; determining a target storage page according to the first page sequence number, the first urgency level, and whether the data stored in the first reference storage page is the first packet of data; A target operation corresponding to the operation instruction is executed in the target storage page, and status 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 of the target storage page according to the status information includes: In a case where the operation instruction instructs 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 a number of erase / write times of 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 erase and write times.

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, determining 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 status 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, wherein In a case where the data read type is the non-packetized read, determining, according to the state information, a second reference storage page storing non-packetized data and a second page 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.

5. The method according to claim 1, wherein The performing of 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 data stored in the target storage page, and erasing data stored in the target storage page; Updating status information of the target storage page and obtaining a data packet sequence number of data stored in the target storage page, wherein the updated status information indicates that the target storage page is an empty page; determining a 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 a last page; If 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.

6. The method according to claim 1, characterized in that The management area includes a primary 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, the updated status information in the backup management area is synchronized to the main management area.

7. The method according to any one of claims 1 to 6, characterized in that After executing the target operation corresponding to the operation instruction in the target storage page, the method further includes: Acquiring feedback information for the target operation, where the feedback information is used to indicate an 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 write and read 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.

8. A data reading and writing device for EEPROM, characterized in that: include: a receiving unit, configured to receive an operation instruction for an EEPROM, wherein the operation instruction instructs writing data to a data area of the EEPROM or reading 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 configured to store status information of each storage page included in the data area, and each storage page included in the data area is configured to store written data, and the status information is configured to represent a data read and write 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 determining unit, configured to, when the operation instruction instructs to read data from the data area of the EEPROM, determine a data read type of the operation instruction, the data read type including packet read or non-packet read; and, when the data read type is packet read, determine, based on the status information, a first reference storage page storing packet data among a plurality of storage pages in the data area and a first page number of the first reference storage page; and for 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; and for determining a target storage page according to the first page number, the first urgency level, and whether the data stored in the first reference storage page is the first packet of data; An execution unit is configured to execute a target operation corresponding to the operation instruction in the target storage page, and update status information of the target storage page in the management area according to the target operation.

9. 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 data reading and writing method for the EEPROM according to any one of claims 1 to 7 is implemented.

Citation Information

Patent Citations

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

    CN116893986A