Data writing method and device, electronic equipment and storage medium
By optimizing the EEPROM write strategy, selecting partial or full writing based on the number of differing bytes in the target page, the problems of long EEPROM write time and low efficiency are solved, extending the lifespan of the EEPROM, improving write efficiency and data accuracy, and reducing maintenance costs.
Patent Information
- Application Number
- CN202410568998.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-09
- Publication Date
- 2025-11-11
AI Technical Summary
EEPROM has a long write time, especially when storing long amounts of data, resulting in low storage efficiency.
By determining the number of bytes of difference between the existing data stored in the target byte in each target page and the data to be written, partial writing is performed when the number of bytes of difference is less than 2, and full writing is performed when the number of bytes of difference is greater than or equal to 2, thus optimizing the writing strategy.
It significantly reduces unnecessary write operations, extends the lifespan of EEPROM, improves write efficiency, ensures data integrity and accuracy, balances the load on the EEPROM area, and reduces maintenance costs.
Smart Images

Figure CN120928996A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of data storage technology, and in particular to a data writing method, apparatus, electronic device and storage medium. Background Technology
[0002] EEPROM (Electrically Erasable Programmable Read-Only Memory) is a non-volatile storage device widely used in various electronic devices to store data or program code that needs to be stored for a long time.
[0003] However, due to the characteristics of its internal structure, EEPROM takes a relatively long time to write. Therefore, its storage efficiency is low when storing long amounts of data in a specific EEPROM area. Summary of the Invention
[0004] In view of this, embodiments of this application provide a data writing method, apparatus, electronic device, and storage medium that can improve data writing efficiency.
[0005] The technical solution of this application embodiment is implemented as follows:
[0006] In a first aspect, embodiments of this application provide a data writing method, comprising the following steps:
[0007] Based on the data to be written, at least one target page in the EEPROM is determined to be written to; each target page includes multiple bytes; and...
[0008] When writing to each target page, the number of bytes in each target page that differ from the existing data stored in the target byte is determined. If the number of bytes is less than 2, the bytes that differ are written based on the data to be written. If the number of bytes is greater than or equal to 2, the entire target page is written.
[0009] Secondly, embodiments of this application also provide a data writing device, the device comprising:
[0010] The determining module is configured to determine, based on the data to be written, at least one target page in the EEPROM to which the data to be written is to be written; each target page includes multiple bytes; and,
[0011] The writing module is used to determine the number of bytes in each target page that differ from the existing data stored in the target byte and the data to be written when writing to each target page. When the number of bytes is less than 2, the bytes that differ are written based on the data to be written; when the number of bytes is greater than or equal to 2, the entire target page is written.
[0012] Thirdly, embodiments of this application also provide an electronic device, including: a processor, a storage medium, and a bus, wherein the storage medium stores machine-readable instructions executable by the processor, and when the electronic device is running, the processor communicates with the storage medium via the bus, and the processor executes the machine-readable instructions to perform the data writing method described in any of the first aspects.
[0013] Fourthly, embodiments of this application also provide a computer-readable storage medium storing a computer program, wherein the computer program is executed by a processor to perform the data writing method described in any one of the first aspects.
[0014] The embodiments of this application have the following beneficial effects:
[0015] First, by accurately determining the number of bytes that need to be updated in each target page, and selecting a strategy of partial or full write based on that number, unnecessary write operations can be significantly reduced. This helps reduce the number of write operations to the EEPROM, thereby extending its lifespan and improving the stability and reliability of the entire system.
[0016] Secondly, optimized write strategies reduce data transfer and waiting time. When only a few bytes need to be updated, only these differing data are transferred and written, avoiding the complexity and overhead of erasing and rewriting the entire target page. This improves the efficiency of write operations, making data updates faster and more efficient.
[0017] Furthermore, by precisely controlling the data writing process in the EEPROM, it is ensured that data is correctly written to the designated location, and data overflow or truncation issues are avoided. This improves data integrity and accuracy, reduces the possibility of data writing errors, and further enhances the stability and reliability of the system.
[0018] Finally, optimizing the write strategy also helps balance the write load across different areas of the EEPROM. By distributing write operations more evenly, premature wear in certain areas can be prevented, thereby extending the overall lifespan of the EEPROM.
[0019] In summary, optimizing the EEPROM write strategy can bring significant benefits, including extended lifespan, improved write efficiency, reduced data errors, and balanced write load. These beneficial effects help improve the overall system performance and stability, reduce maintenance costs, and provide better assurance for the long-term use of EEPROM. Attached Figure Description
[0020] To more clearly illustrate the technical solutions of the embodiments of this application, the accompanying drawings used in the embodiments will be briefly introduced below. It should be understood that the following drawings only show some embodiments of this application and should not be regarded as a limitation of the scope. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.
[0021] Figure 1 This is a flowchart illustrating steps S101-S102 provided in the embodiments of this application;
[0022] Figure 2 This is a flowchart illustrating steps S201-S202 provided in the embodiments of this application;
[0023] Figure 3 This is a flowchart illustrating steps S301-S302 provided in the embodiments of this application;
[0024] Figure 4 This is a flowchart illustrating steps S401-S402 provided in the embodiments of this application;
[0025] Figure 5 This is a flowchart illustrating steps S501-S502 provided in the embodiments of this application;
[0026] Figure 6 This is a schematic diagram of the data writing device provided in the embodiments of this application;
[0027] Figure 7 This is a schematic diagram of the composition structure of the electronic device provided in the embodiments of this application. Detailed Implementation
[0028] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. It should be understood that the accompanying drawings in this application are for illustrative and descriptive purposes only and are not intended to limit the scope of protection of this application. Furthermore, it should be understood that the schematic drawings are not drawn to scale. The flowcharts used in this application illustrate operations implemented according to some embodiments of this application. It should be understood that the operations in the flowcharts may not be implemented in sequence, and steps without logical contextual relationships may be reversed or implemented simultaneously. In addition, those skilled in the art, guided by the content of this application, may add one or more other operations to the flowcharts, or remove one or more operations from the flowcharts.
[0029] In the following description, references are made to “some embodiments,” which describe a subset of all possible embodiments. However, it is understood that “some embodiments” may be the same subset or different subsets of all possible embodiments and may be combined with each other without conflict.
[0030] Furthermore, the described embodiments are merely some, not all, of the embodiments of this application. The components of the embodiments of this application described and illustrated herein can typically be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of this application provided in the accompanying drawings is not intended to limit the scope of the claimed application, but merely to illustrate selected embodiments of the application. All other embodiments obtained by those skilled in the art based on the embodiments of this application without inventive effort are within the scope of protection of this application.
[0031] In the following description, the terms "first, second, third" are used merely to distinguish similar objects and do not represent a specific ordering of objects. It is understood that "first, second, third" may be interchanged in a specific order or sequence where permitted, so that the embodiments of this application described herein can be implemented in an order other than that illustrated or described herein.
[0032] It should be noted that the term "comprising" will be used in the embodiments of this application to indicate the presence of the features declared thereafter, but does not exclude the addition of other features.
[0033] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application belongs. The terminology used herein is for the purpose of describing embodiments of this application and is not intended to limit this application.
[0034] See Figure 1 , Figure 1This is a flowchart illustrating steps S101-S102 of the data writing method provided in this application embodiment, which will be combined with... Figure 1 Steps S101-S102 shown will be explained.
[0035] Step S101: Determine at least one target page in the EEPROM where the data to be written is to be written based on the data to be written; each target page includes multiple bytes.
[0036] Step S102: When writing to each target page, determine the number of bytes in each target page where the existing data stored in the target byte differs from the data to be written. When the number of bytes is less than 2, write the bytes that differ based on the data to be written. When the number of bytes is greater than or equal to 2, write the entire target page.
[0037] The exemplary steps described above in the embodiments of this application will be explained below.
[0038] In step S101, at least one target page in the EEPROM is determined based on the data to be written; each target page includes multiple bytes.
[0039] Here, EEPROM typically organizes and manages data in units of pages. Each page contains multiple bytes, which are the smallest addressable unit of data in the EEPROM. When writing data, it is necessary to determine which pages the data to be written should be stored in, which usually depends on the length of the data, the page size of the EEPROM, and the data organization method.
[0040] Determining the target page requires understanding the specific content of the data to be written, including its length, format, and possible organization. This helps determine the storage requirements of the data in the EEPROM. The page size of an EEPROM is fixed, typically a certain number of bytes. This information can be obtained from the EEPROM's specifications or documentation. Knowing the page size helps calculate how many pages the data to be written will occupy. Based on the length of the data to be written and the EEPROM's page size, it's possible to calculate which pages the data needs to be written to. This usually involves simple mathematical operations such as division (to determine the number of complete pages) and modulo (to determine if there is any remaining data to be written to the next page).
[0041] In step S102, when writing to each target page, the number of bytes in each target page where the existing data stored in the target byte differs from the data to be written is determined. When the number of bytes is less than 2, the bytes that differ are written based on the data to be written. When the number of bytes is greater than or equal to 2, the entire target page is written.
[0042] Here, it is necessary to first explain the principle behind the efficiency improvement in this application:
[0043] In this embodiment of the application, the following conditions are met:
[0044] The time T1 for writing a single byte to the EEPROM is equal to the first transmission time plus the first waiting time. The first transmission time represents the transmission time consumed by the I2C communication line when writing a single byte, and the first waiting time represents the time to wait for the EEPROM to complete writing when writing a single byte.
[0045] The time T2 for writing a single target page to the EEPROM is equal to the second transmission time plus the second waiting time. The second transmission time represents the transmission time consumed by the I2C communication line when writing a single target page, and the second waiting time represents the time spent waiting for the EEPROM to complete writing when writing a single target page.
[0046] T1 < T2 < 2T1.
[0047] The first waiting time is equal to the second waiting time; the writing method is based on I2C communication, the I2C communication rate is a preset rate, and at the preset rate, the first waiting time is greater than the first transmission time, and the second waiting time is greater than the second transmission time.
[0048] Specifically, in EEPROM, the actual time consumed for writing a single byte and a single page are as follows:
[0049] The time per byte is Tbyte = Ti2c1 + Twait1;
[0050] The time for a single page is Tpage = Ti²c² + Twait²;
[0051] And there is a time constraint: Tbyte <Tpage<2*Tbyte;
[0052] It should be noted that Ti2c1 represents the transmission time consumption of the I2C communication line when writing a single byte, Twait1 represents the time to wait for the EEPROM to complete writing when writing a single byte, Ti2c2 represents the transmission time consumption of the I2C communication line when writing a single target page, and Twait2 represents the time to wait for the EEPROM to complete writing when writing a single target page. Ti2c1 is less than Ti2c2 because the transmission time consumption of the I2C communication line is determined by the amount of communication byte data. The larger the communication data volume, the more time is consumed.
[0053] Based on the conclusion that Tbyte < Tpage < 2 * Tbyte, the number of bytes to be written in each Page page can be identified. When there is no data change before and after storing the data in the Page page, the time consumption is 0; when there is only one byte change before and after storing the data in the Page page, the time consumption is Tbyte; when there are two or more byte changes before and after storing the data in the Page page, the time consumption is Tpage. Since the time consumption range of each improved page is [0, Tpage], the total time consumption of the index is less than before.
[0054] Based on this principle and step S102, first, considering that the write operation of the EEPROM includes two parts of time consumption: transmitting data and waiting for writing to complete, and the waiting time is usually longer than the transmission time. Therefore, reducing unnecessary write operations, especially reducing the number of writes of the entire target page, is crucial for improving the write efficiency.
[0055] When the number of bytes to be updated in the target page is less than 2, it is reasonable to only write these different bytes. This is because:
[0056] The transmission time (Ti2c) will be significantly reduced because only a small amount of byte data needs to be transmitted.
[0057] The waiting time (Twait) will not change much because the write mechanism of the EEPROM usually does not significantly speed up due to the small number of bytes written.
[0058] However, since only a few bytes are updated, the total time consumption is still relatively small, and this strategy avoids the complexity and overhead of erasing and rewriting the entire target page.
[0059] When the number of bytes to be updated in the target page is greater than or equal to 2, it may be more efficient to write the entire target page as a whole. This is because:
[0060] Although the transmission time (Ti2c2) will increase because more byte data needs to be transmitted, this increase is usually acceptable, especially when compared with the waiting time.
[0061] The wait time (Twait2) still dominates, but because it writes the entire target page at once, it avoids the overhead of writing a few bytes separately multiple times.
[0062] Furthermore, considering the lifespan of EEPROM, frequent individual writes of a few bytes may cause some areas of the target page to wear out prematurely, while overall writing helps to distribute write operations more evenly, thereby extending the lifespan of EEPROM.
[0063] In summary, determining the write strategy based on the number of differing bytes in the target page balances both time efficiency and EEPROM lifespan. When the number of differing bytes is small, partial writing is chosen to reduce unnecessary operations; when the number of differing bytes is large, full writing is chosen to improve write efficiency and data consistency. This flexible strategy optimizes the use of EEPROM, making it more suitable for application scenarios with frequent data updates.
[0064] In some embodiments, see Figure 2 , Figure 2 This is a flowchart illustrating steps S201-S202 provided in an embodiment of this application. The step of determining at least one target page in the EEPROM to be written based on the data to be written can be achieved through steps S201-S202, which will be explained in conjunction with each step.
[0065] In step S201, the starting position for writing the data to be written to the EEPROM is obtained.
[0066] In step S202, at least one target page in the EEPROM is determined based on the starting position and the data length of the data to be written.
[0067] The starting address is the starting address of the data to be written in the EEPROM. This address can be preset or dynamically calculated based on the current usage state of the EEPROM. Determining the starting address typically depends on the EEPROM's memory layout, existing data distribution, and any available free space.
[0068] If the EEPROM is being used for the first time or has undergone an erase operation, the starting address may be the beginning address of the EEPROM. If the EEPROM already contains other data, the starting address needs to be determined based on the location of that data to ensure that new data does not overwrite old data. In some cases, the selection of the starting address may need to consider factors such as data alignment and memory fragmentation to ensure efficient data storage and fast access.
[0069] The length of the data to be written refers to the number of bytes that need to be written to the EEPROM. Once the starting position and data length are determined, it's possible to calculate which pages of the EEPROM this data will span. First, determine the first target page based on the starting position. The page containing the starting address is the first target page. Then, calculate the number of pages to be written based on the data length and the EEPROM page size. If the data length is less than or equal to the page size, only one page needs to be written; if the data length is greater than the page size, multiple pages need to be written, and the end address of the last target page is calculated. Page boundaries can also be considered during this process. If the end position of the data to be written is exactly on a page boundary, then only writing to that boundary is needed. If the end position is inside a page, then the entire page needs to be written, even if the remaining portion of the page is not used. Through these two steps, at least one target page in the EEPROM where the data to be written can be accurately determined, providing clear guidance for subsequent data writing operations.
[0070] In some embodiments, see Figure 3 , Figure 3 This is a flowchart illustrating steps S301-S302 provided in an embodiment of this application. The step of determining at least one target page in the EEPROM to be written based on the starting position and the data length of the data to be written can be achieved through steps S301-S302, which will be explained in conjunction with each step.
[0071] In step S301, the number of pages required to write the data to be written is determined based on the starting position and the data length of the data to be written.
[0072] In step S302, when the number of pages is 1, the target page is determined as the homepage, and the data length to be written to the homepage is calculated; when the number of pages is 2, the first page is determined as the homepage, the second page is determined as the last page, and the data length to be written to the homepage and the last page are calculated respectively; when the number of pages is greater than or equal to 3, the first page is determined as the homepage, the last page is determined as the last page, and each target page between the first page and the last page is determined as a middle page, and the data length to be written to the homepage, the last page, and each middle page is calculated respectively.
[0073] Here, the number of pages required to write the data needs to be determined based on the starting position and the length of the data to be written. When the starting position is the beginning of the page (i.e., there is no offset), the number of pages required can be determined by division. If the remainder of the data length divided by the page size is 0, then the required number of pages is the quotient of the data length divided by the page size. If the remainder is not 0, then the required number of pages is the quotient plus 1, because the last page, even if not full, still needs to be written. In this case, if the number of pages required is 1, it means that only 1 page is needed to fill all the data to be written. This page is usually named the first page, and the length of the data to be written on the first page is the length of the data to be written. If the number of pages required is 2, it means that 2 pages are needed to fill all the data to be written. The first page is usually named the first page, and the second page is named the last page. The length of the data to be written on the first page is the capacity of the current page, and the length of the data to be written on the last page is the length of the data to be written minus the capacity of the first page. The length of the data to be written on the last page can also be determined by the remainder. To determine the length of data to be written, if the remainder is 0, it means the last page is full; if the remainder is not 0, the remainder value is the length of data to be written to the last page. If the number of pages required to write the data is greater than or equal to 3, it means at least 3 pages are needed to fill the page. We still name the first page the first page, the last page the last page, and the pages between the first and last pages the middle pages. Since the writing is continuous, the length of data to be written to all middle pages is the page capacity (which will definitely be full). The first page is also full, and the length of data written is the page capacity. The length of data to be written to the last page can be determined based on the remainder method described above.
[0074] When the starting position is not the beginning of the page (i.e., there is an offset), division cannot be used directly. The situation of the first page needs to be assessed first. Taking a page length of 16 bytes as an example, if the starting position is the 4th byte, the capacity of the first page is only 16 - 4 = 12 bytes. If the length of the data to be written is less than or equal to 12 bytes, the first page alone is sufficient, and the number of pages required is 1. If the length of the data to be written is greater than 12 bytes, other pages are needed after the first page is filled. The number of other pages is calculated using division. The dividend is the length of the data to be written minus the actual writing length of the first page (length of the data to be written - 12 bytes), and the divisor is the page capacity (16 bytes). If the remainder is 0, the number of other pages is the quotient; if the remainder is not 0, the number of other pages is the quotient plus 1. Finally, the number of other pages needs to be increased by 1 (plus the first page) to obtain the final number of pages required for the data to be written.
[0075] When calculating the length of data to be written per page, we need to be careful to avoid data overflow or truncation, ensuring that the data written to each page is complete and accurate. This method allows us to precisely control the data writing process in the EEPROM, ensuring that data is correctly written to the specified location and that the amount of data per page is reasonably allocated. This is beneficial for improving EEPROM efficiency, reducing data write errors, and extending the lifespan of the EEPROM.
[0076] In some embodiments, see Figure 4 , Figure 4 This is a flowchart illustrating steps S401-S402 provided in an embodiment of this application. The step of determining the number of bytes in each target page where the existing data stored in the target byte differs from the data to be written can be achieved through steps S401-S402, which will be explained in conjunction with each step.
[0077] In step S401, the target byte corresponding to the data to be written in each target page is determined.
[0078] In step S402, the target bytes are traversed to determine the difference bytes in the target bytes that are different from those in the data to be written, and the difference bytes are counted to obtain the number of bytes.
[0079] First, it's necessary to determine the target byte corresponding to the data to be written in each target page. This typically involves matching the address of the target page in the EEPROM with the address of the data to be written to determine which bytes will be overwritten by the data. Next, these target bytes are traversed. This traversal can be done byte-by-byte or using more efficient algorithms, such as comparing strings or memory blocks, depending on the EEPROM's access method and the capabilities of the programming language. During traversal, the existing data in the target byte is compared with the corresponding byte in the data to be written. If they differ, that byte is a difference byte. For each difference byte, it needs to be counted to ultimately determine the number of bytes with differences.
[0080] The counting can be achieved using a variable; the value of this variable is incremented by 1 for each differing byte found. After traversing all target bytes, the value of this variable will be the number of differing bytes. It's important to note that during the traversal and comparison process, the data representation (e.g., big-endian or little-endian storage) and any potential memory alignment issues may need to be considered. Furthermore, to improve efficiency, parallel processing or caching techniques can be used to accelerate the comparison and counting process.
[0081] This method accurately determines the number of bytes in each target page where the existing data differs from the data to be written. This provides crucial information for subsequent write strategies, helping to determine whether to perform a partial or full write, thereby optimizing write efficiency and EEPROM lifespan.
[0082] In some embodiments, see Figure 5 , Figure 5 This is a flowchart illustrating steps S501-S502 provided in an embodiment of this application. The step of traversing the target byte to determine the difference byte that is different from the data to be written can be achieved through steps S501-S502, which will be explained in conjunction with each step.
[0083] In step S501, a difference count is defined. For each Byte in the target byte, the data stored in the Byte is compared with the corresponding data in the data to be written. If they are the same, the next Byte is compared; if they are different, the difference count is incremented by one, and the next Byte is compared.
[0084] In step S502, in response to the comparison being completed, the value of the difference count is determined as the number of bytes.
[0085] Here, we need to define a difference count variable to record the number of bytes that differ from the data to be written. This variable is usually initialized to 0. Next, we begin iterating through each byte in the target byte. For each byte, we need to compare its stored data with the corresponding bit in the data to be written. This is usually done by reading the byte value in the target page and the corresponding byte value in the data to be written, and comparing them bit by bit. If the data stored in the current byte is the same as the corresponding bit in the data to be written, it means there is no difference, and we directly proceed to the comparison of the next byte. This usually involves moving the pointer or indexing to the next byte and continuing the comparison process. If the data stored in the current byte is different from the corresponding bit in the data to be written, it means there is a difference, and we need to increment the difference count variable to record this different byte. Then, we similarly proceed to the comparison of the next byte.
[0086] This comparison and counting process continues until all target bytes have been traversed. After the traversal is complete, the value of the difference count variable is the number of bytes we need to determine, that is, the number of difference bytes in the target bytes that are different from the data to be written.
[0087] In this way, we can accurately determine the number of bytes that need to be updated in each target page, providing an important basis for subsequent write strategies. This helps us optimize write operations, reduce unnecessary write operations, and improve the lifespan of the EEPROM and data write efficiency.
[0088] In summary, the embodiments of this application have the following beneficial effects:
[0089] First, by accurately determining the number of bytes that need to be updated in each target page, and selecting a strategy of partial or full write based on that number, unnecessary write operations can be significantly reduced. This helps reduce the number of write operations to the EEPROM, thereby extending its lifespan and improving the stability and reliability of the entire system.
[0090] Secondly, optimized write strategies reduce data transfer and waiting time. When only a few bytes need to be updated, only these differing data are transferred and written, avoiding the complexity and overhead of erasing and rewriting the entire target page. This improves the efficiency of write operations, making data updates faster and more efficient.
[0091] Furthermore, by precisely controlling the data writing process in the EEPROM, it is ensured that data is correctly written to the designated location, and data overflow or truncation issues are avoided. This improves data integrity and accuracy, reduces the possibility of data writing errors, and further enhances the stability and reliability of the system.
[0092] Finally, optimizing the write strategy also helps balance the write load across different areas of the EEPROM. By distributing write operations more evenly, premature wear in certain areas can be prevented, thereby extending the overall lifespan of the EEPROM.
[0093] In summary, optimizing the EEPROM write strategy can bring significant benefits, including extended lifespan, improved write efficiency, reduced data errors, and balanced write load. These beneficial effects help improve the overall system performance and stability, reduce maintenance costs, and provide better assurance for the long-term use of EEPROM.
[0094] Based on the same inventive concept, this application also provides a data writing device corresponding to the data writing method in the first embodiment. Since the principle of the device in this application is similar to the above-mentioned data writing method, the implementation of the device can refer to the implementation of the method, and the repeated parts will not be described again.
[0095] like Figure 6 As shown, Figure 6 This is a schematic diagram of the structure of the data writing device 600 provided in an embodiment of this application. The data writing device 600 includes:
[0096] The determining module 601 is configured to determine, based on the data to be written, at least one target page in the EEPROM to which the data to be written is to be written; each target page includes multiple bytes; and,
[0097] The writing module 602 is used to determine, when writing to each target page, the number of bytes in each target page where the existing data stored in the target byte differs from the data to be written; when the number of bytes is less than 2, the bytes with differences are written based on the data to be written; when the number of bytes is greater than or equal to 2, the entire target page is written.
[0098] Those skilled in the art should understand that Figure 6 The functions of each unit in the data writing device 600 shown can be understood by referring to the relevant description of the aforementioned data writing method. Figure 6 The functions of each unit in the data writing device 600 shown can be implemented by a program running on a processor or by specific logic circuits.
[0099] In one possible implementation, the determining module 601 determines at least one target page in the EEPROM to be written based on the data to be written, including:
[0100] Obtain the starting position for writing the data to be written to the EEPROM;
[0101] Based on the starting position and the data length of the data to be written, at least one target page in the EEPROM is determined to be written to by the data to be written.
[0102] In one possible implementation, the determining module 601 determines at least one target page in the EEPROM to be written to by the data to be written, based on the starting position and the data length of the data to be written, including:
[0103] The number of pages required to write the data to be written is determined based on the starting position and the data length of the data to be written.
[0104] When the number of pages is 1, the target page is designated as the homepage, and the data length to be written to the homepage is calculated. When the number of pages is 2, the first page is designated as the homepage, the second page is designated as the last page, and the data length to be written to the homepage and the last page are calculated respectively. When the number of pages is greater than or equal to 3, the first page is designated as the homepage, the last page is designated as the last page, and each target page between the first and last pages is designated as a middle page, and the data length to be written to the homepage, the last page, and each middle page is calculated respectively.
[0105] In one possible implementation, the write module 602 determines the number of bytes in each target page where the existing data stored in the target byte differs from the data to be written, including:
[0106] Determine the target byte in each target page that corresponds to the data to be written;
[0107] The target bytes are traversed to identify the difference bytes that are different from those in the data to be written, and the difference bytes are counted to obtain the number of bytes.
[0108] In one possible implementation, the writing module 602 traverses the target bytes to determine the difference bytes in the target bytes that are different from those in the data to be written, including:
[0109] Define a difference count. For each byte in the target byte, compare the data stored in the byte with the corresponding data in the data to be written. If they are the same, compare the next byte; if they are different, increment the difference count and compare the next byte.
[0110] In response to the completion of the comparison, the value of the difference count is determined as the number of bytes.
[0111] In one possible implementation, the time T1 for writing a single byte to the EEPROM is equal to the first transmission time plus the first waiting time, where the first transmission time represents the I2C communication line transmission time consumed when writing a single byte, and the first waiting time represents the time for waiting for the EEPROM to complete writing when writing a single byte.
[0112] The time T2 for writing a single target page to the EEPROM is equal to the second transmission time plus the second waiting time. The second transmission time represents the transmission time consumed by the I2C communication line when writing a single target page, and the second waiting time represents the time spent waiting for the EEPROM to complete writing when writing a single target page.
[0113] T1 < T2 < 2T1.
[0114] In one possible implementation, the first waiting time is equal to the second waiting time; the writing method is based on I2C communication, the I2C communication rate is a preset rate, and at the preset rate, the first waiting time is greater than the first transmission time, and the second waiting time is greater than the second transmission time.
[0115] The above-mentioned data writing device has the following beneficial effects:
[0116] First, by accurately determining the number of bytes that need to be updated in each target page, and selecting a strategy of partial or full write based on that number, unnecessary write operations can be significantly reduced. This helps reduce the number of write operations to the EEPROM, thereby extending its lifespan and improving the stability and reliability of the entire system.
[0117] Secondly, optimized write strategies reduce data transfer and waiting time. When only a few bytes need to be updated, only these differing data are transferred and written, avoiding the complexity and overhead of erasing and rewriting the entire target page. This improves the efficiency of write operations, making data updates faster and more efficient.
[0118] Furthermore, by precisely controlling the data writing process in the EEPROM, it is ensured that data is correctly written to the designated location, and data overflow or truncation issues are avoided. This improves data integrity and accuracy, reduces the possibility of data writing errors, and further enhances the stability and reliability of the system.
[0119] Finally, optimizing the write strategy also helps balance the write load across different areas of the EEPROM. By distributing write operations more evenly, premature wear in certain areas can be prevented, thereby extending the overall lifespan of the EEPROM.
[0120] In summary, optimizing the EEPROM write strategy can bring significant benefits, including extended lifespan, improved write efficiency, reduced data errors, and balanced write load. These beneficial effects help improve the overall system performance and stability, reduce maintenance costs, and provide better assurance for the long-term use of EEPROM.
[0121] like Figure 7 As shown, Figure 7 This is a schematic diagram of the composition structure of the electronic device 700 provided in the embodiments of this application. The electronic device 700 includes:
[0122] The device 700 includes a processor 701, a storage medium 702, and a bus 703. The storage medium 702 stores machine-readable instructions that can be executed by the processor 701. When the electronic device 700 is running, the processor 701 communicates with the storage medium 702 via the bus 703. The processor 701 executes the machine-readable instructions to perform the steps of the data writing method described in the embodiments of this application.
[0123] In practical applications, the various components in the electronic device 700 are coupled together via a bus 703. It is understood that the bus 703 is used to achieve communication between these components. In addition to a data bus, the bus 703 also includes a power bus, a control bus, and a status signal bus. However, for clarity, in... Figure 7 The general designated all buses as Bus 703.
[0124] The above-mentioned electronic devices have the following beneficial effects:
[0125] First, by accurately determining the number of bytes that need to be updated in each target page, and selecting a strategy of partial or full write based on that number, unnecessary write operations can be significantly reduced. This helps reduce the number of write operations to the EEPROM, thereby extending its lifespan and improving the stability and reliability of the entire system.
[0126] Secondly, optimized write strategies reduce data transfer and waiting time. When only a few bytes need to be updated, only these differing data are transferred and written, avoiding the complexity and overhead of erasing and rewriting the entire target page. This improves the efficiency of write operations, making data updates faster and more efficient.
[0127] Furthermore, by precisely controlling the data writing process in the EEPROM, it is ensured that data is correctly written to the designated location, and data overflow or truncation issues are avoided. This improves data integrity and accuracy, reduces the possibility of data writing errors, and further enhances the stability and reliability of the system.
[0128] Finally, optimizing the write strategy also helps balance the write load across different areas of the EEPROM. By distributing write operations more evenly, premature wear in certain areas can be prevented, thereby extending the overall lifespan of the EEPROM.
[0129] In summary, optimizing the EEPROM write strategy can bring significant benefits, including extended lifespan, improved write efficiency, reduced data errors, and balanced write load. These beneficial effects help improve the overall system performance and stability, reduce maintenance costs, and provide better assurance for the long-term use of EEPROM.
[0130] This application also provides a computer-readable storage medium storing executable instructions, which, when executed by at least one processor 701, implement the data writing method described in this application.
[0131] In some embodiments, the storage medium may be a magnetic random access memory (FRAM), a read-only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), a flash memory, a magnetic surface memory, an optical disc, or a compact disc read-only memory (CD ROM), etc.; or it may be a device that includes one or any combination of the above-mentioned memories.
[0132] In some embodiments, executable instructions may take the form of a program, software, software module, script, or code, written in any form of programming language (including compiled or interpreted languages, or declarative or procedural languages), and may be deployed in any form, including as a standalone program or as a module, component, subroutine, or other unit suitable for use in a computing environment.
[0133] As an example, executable instructions may, but do not necessarily, correspond to files in the file system. They may be stored as part of a file that holds other programs or data, for example, in one or more scripts in a HyperText Markup Language (HTML) document, in a single file dedicated to the program in question, or in multiple collaborating files (e.g., a file that stores one or more modules, subroutines, or code sections).
[0134] As an example, executable instructions can be deployed to execute on a single computing device, or on multiple computing devices located in one location, or on multiple computing devices distributed across multiple locations and interconnected via a communication network.
[0135] The aforementioned computer-readable storage media have the following beneficial effects:
[0136] First, by accurately determining the number of bytes that need to be updated in each target page, and selecting a strategy of partial or full write based on that number, unnecessary write operations can be significantly reduced. This helps reduce the number of write operations to the EEPROM, thereby extending its lifespan and improving the stability and reliability of the entire system.
[0137] Secondly, optimized write strategies reduce data transfer and waiting time. When only a few bytes need to be updated, only these differing data are transferred and written, avoiding the complexity and overhead of erasing and rewriting the entire target page. This improves the efficiency of write operations, making data updates faster and more efficient.
[0138] Furthermore, by precisely controlling the data writing process in the EEPROM, it is ensured that data is correctly written to the designated location, and data overflow or truncation issues are avoided. This improves data integrity and accuracy, reduces the possibility of data writing errors, and further enhances the stability and reliability of the system.
[0139] Finally, optimizing the write strategy also helps balance the write load across different areas of the EEPROM. By distributing write operations more evenly, premature wear in certain areas can be prevented, thereby extending the overall lifespan of the EEPROM.
[0140] In summary, optimizing the EEPROM write strategy can bring significant benefits, including extended lifespan, improved write efficiency, reduced data errors, and balanced write load. These beneficial effects help improve the overall system performance and stability, reduce maintenance costs, and provide better assurance for the long-term use of EEPROM.
[0141] In the several embodiments provided in this application, it should be understood that the disclosed methods and electronic devices can be implemented in other ways. The device embodiments described above are merely illustrative. For example, the division of units is only a logical functional division, and in actual implementation, there may be other division methods, such as: multiple units or components may be combined, or integrated into another system, or some features may be ignored or not executed. In addition, the coupling, direct coupling, or communication connection between the various components shown or discussed may be through some interfaces, and the indirect coupling or communication connection between devices or units may be electrical, mechanical, or other forms.
[0142] The modules described as separate components may or may not be physically separate. The components shown as modules may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0143] In addition, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit.
[0144] If the aforementioned functions are implemented as software functional units and sold or used as independent products, they can be stored in a processor-executable, non-volatile, computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part 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 is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, a platform server, or a network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, ROM, RAM, magnetic disks, or optical disks.
[0145] The above are merely specific embodiments of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.
Claims
1. A data writing method, characterized in that, Applied to EEPROM, the method includes: Based on the data to be written, at least one target page in the EEPROM is determined to be written to; each target page includes multiple bytes; and... When writing to each target page, the number of bytes in each target page that differ from the existing data stored in the target byte is determined. If the number of bytes is less than 2, the bytes that differ are written based on the data to be written. If the number of bytes is greater than or equal to 2, the entire target page is written.
2. The data writing method according to claim 1, characterized in that, The step of determining at least one target page in the EEPROM to be written based on the data to be written includes: Obtain the starting position for writing the data to be written to the EEPROM; Based on the starting position and the data length of the data to be written, at least one target page in the EEPROM is determined to be written to by the data to be written.
3. The data writing method according to claim 2, characterized in that, Determining at least one target page in the EEPROM to be written to the data to be written based on the starting position and the data length of the data to be written includes: The number of pages required to write the data to be written is determined based on the starting position and the data length of the data to be written. When the number of pages is 1, the target page is designated as the homepage, and the data length to be written to the homepage is calculated. When the number of pages is 2, the first page is designated as the homepage, the second page is designated as the last page, and the data length to be written to the homepage and the last page are calculated respectively. When the number of pages is greater than or equal to 3, the first page is designated as the homepage, the last page is designated as the last page, and each target page between the first and last pages is designated as a middle page, and the data length to be written to the homepage, the last page, and each middle page is calculated respectively.
4. The data writing method according to claim 1, characterized in that, Determining the number of bytes in each target page where the existing data stored in the target byte differs from the data to be written includes: Determine the target byte in each target page that corresponds to the data to be written; The target bytes are traversed to identify the difference bytes that are different from those in the data to be written, and the difference bytes are counted to obtain the number of bytes.
5. The data writing method according to claim 4, characterized in that, The step of traversing the target bytes to determine the difference bytes in the target bytes that are different from those in the data to be written includes: Define a difference count. For each byte in the target byte, compare the data stored in the byte with the corresponding data in the data to be written. If they are the same, compare the next byte; if they are different, increment the difference count and compare the next byte. In response to the completion of the comparison, the value of the difference count is determined as the number of bytes.
6. The data writing method according to claim 1, characterized in that, The time T1 for writing a single byte to the EEPROM is equal to the first transmission time plus the first waiting time. The first transmission time represents the transmission time consumed by the I2C communication line when writing a single byte, and the first waiting time represents the time to wait for the EEPROM to complete writing when writing a single byte. The time T2 for writing a single target page to the EEPROM is equal to the second transmission time plus the second waiting time. The second transmission time represents the transmission time consumed by the I2C communication line when writing a single target page, and the second waiting time represents the time spent waiting for the EEPROM to complete writing when writing a single target page. T1 < T2 < 2T1.
7. The data writing method according to claim 6, characterized in that, The first waiting time is equal to the second waiting time; the writing method is based on I2C communication, the I2C communication rate is a preset rate, and at the preset rate, the first waiting time is greater than the first transmission time, and the second waiting time is greater than the second transmission time.
8. A data writing device, characterized in that, The device, applied to an EEPROM, includes: The determining module is configured to determine, based on the data to be written, at least one target page in the EEPROM to which the data to be written is to be written; each target page includes multiple bytes; and, The writing module is used to determine the number of bytes in each target page that differ from the existing data stored in the target byte and the data to be written when writing to each target page. When the number of bytes is less than 2, the bytes that differ are written based on the data to be written; when the number of bytes is greater than or equal to 2, the entire target page is written.
9. An electronic device, characterized in that, include: The device includes a processor, a storage medium, and a bus, wherein the storage medium stores machine-readable instructions executable by the processor, and when the electronic device is in operation, the processor communicates with the storage medium via the bus, and the processor executes the machine-readable instructions to perform the data writing method as described in any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program, which, when executed by a processor, performs the data writing method as described in any one of claims 1 to 7.