Data reading and writing methods, electronic devices and computer-readable storage media

By determining the data storage address in memory based on index data and memory space size, and performing an erase operation only at the starting address of the smallest write unit, the problem of reduced memory lifespan caused by frequent erases is solved, thus extending the memory's lifespan.

CN115129257BActive Publication Date: 2025-11-14ECOFLOW INC
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202210808127.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-07-08
Publication Date
2025-11-14
Estimated Expiration
2042-07-08

AI Technical Summary

Technical Problem

In existing technologies, frequent data erasure operations on memory lead to a reduction in memory lifespan.

Method used

Based on the latest index data in the memory, the target data to be written, and the space size of the data area in the memory, the data storage address of the target data in the memory is determined. Data erasure is performed when the target data storage address is the starting address of the smallest write unit in the memory, and data is written directly when it is not the starting address.

Benefits of technology

This reduces the number of erase cycles required for the memory and extends its lifespan.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115129257B_ABST
    Figure CN115129257B_ABST
Patent Text Reader

Abstract

This application discloses a data read / write method, an electronic device, and a computer-readable storage medium. The method includes: acquiring the latest index data of the memory; determining the data storage address of the target data in the memory based on the index data, the target data to be written, and the space size of the data storage area in the memory; when the data storage address is the starting address of the smallest write unit of the memory, erasing the data stored in the smallest write unit and writing the target data into the smallest write unit; when the data storage address is not the starting address of the smallest write unit of the memory, writing the target data into the smallest write unit. Compared to erasing storage data every time data is written, the data read / write method disclosed in this application erases storage data when the data storage location of the target data to be written is determined to be the starting address of the smallest write unit in the memory, reducing the number of data erasures and extending the lifespan of the memory.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of computer technology, specifically to a data reading and writing method, an electronic device, and a computer-readable storage medium. Background Technology

[0002] For memory devices with limited storage space, erasing the stored data before writing data is unavoidable. Typically, when writing new data to memory, the entire stored data in the smallest write unit corresponding to the address to be written is read, the stored data in that smallest write unit is erased, and then the new data is written to the erased smallest write unit. This method suffers from the problem of frequent data erasure operations, leading to a reduced lifespan of the memory. Summary of the Invention

[0003] To address the aforementioned technical problems, embodiments of this application provide a data reading and writing method, an electronic device, and a computer-readable storage medium.

[0004] According to one aspect of the embodiments of this application, a data read / write method is provided, the method comprising: acquiring the latest index data of a memory; determining the data storage address of the target data in the memory based on the index data, target data to be written, and the space size of the data storage area in the memory; when the data storage address is the starting address of the minimum write unit of the memory, erasing the data stored in the minimum write unit and writing the target data into the minimum write unit; and when the data storage address is not the starting address of the minimum write unit of the memory, writing the target data into the minimum write unit.

[0005] According to one aspect of the embodiments of this application, a data read / write apparatus is provided, the apparatus comprising: an index data acquisition module configured to acquire the latest index data of a memory; a data storage address determination module configured to determine the data storage address of the target data in the memory based on the index data, target data to be written, and the space size of the data storage area in the memory; an erasure module configured to erase the data stored in the minimum write unit and write the target data into the minimum write unit when the data storage address is the starting address of the minimum write unit of the memory; and a write module configured to write the target data into the minimum write unit when the data storage address is not the starting address of the minimum write unit of the memory.

[0006] According to one aspect of the embodiments of this application, an electronic device is provided, including: a memory storing computer-readable instructions; and a processor reading the computer-readable instructions stored in the memory to execute any of the above data read / write methods.

[0007] According to one aspect of the embodiments of this application, a computer-readable storage medium is provided, on which computer-readable instructions are stored, which, when executed by a computer's processor, cause the computer to perform the data read / write method as described above.

[0008] In the technical solutions provided by the embodiments of this application, compared with erasing the stored data every time data is written, the data read and write method disclosed in this application determines the data storage address of the target data in the memory based on the latest index data of the memory, the target data to be written, and the space size of the data area in the memory. Since the data storage address can reflect the position of the smallest write unit where the target data is written to the memory, when the data storage address of the target data to be written in the memory is the starting address of the smallest write unit of the memory, the stored data in the corresponding smallest write unit is erased. When the data storage address of the target data to be written in the memory is not the starting address of the smallest write unit of the memory, the target data to be written is directly written to the corresponding smallest write unit, thereby reducing the number of times the memory is erased and extending the service life of the memory.

[0009] It should be understood that the above general description and the following detailed description are exemplary and explanatory only, and do not limit this application. Attached Figure Description

[0010] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this application and, together with the description, serve to explain the principles of this application. It is obvious that the drawings described below are merely some embodiments of this application, and those skilled in the art can obtain other drawings based on these drawings without any inventive effort. In the drawings:

[0011] Figure 1 This is a schematic diagram illustrating the implementation environment of a data read / write method in an exemplary embodiment;

[0012] Figure 2 This is a schematic diagram illustrating the implementation environment of a data read / write method as shown in another exemplary embodiment;

[0013] Figure 3 This is a flowchart illustrating a data read / write method in an exemplary embodiment of this application;

[0014] Figure 4 This is a schematic diagram of a data sector in a memory, illustrating an exemplary embodiment of this application;

[0015] Figure 5 This is a schematic diagram of an exemplary data read / write method of this application.

[0016] Figure 6 This is a flowchart illustrating a data read / write method in yet another exemplary embodiment of this application;

[0017] Figure 7 This is a schematic diagram of another exemplary data read / write method of this application.

[0018] Figure 8 This is a block diagram illustrating a data read / write device according to an exemplary embodiment of this application;

[0019] Figure 9 A schematic diagram of the structure of a computer system suitable for implementing the electronic device of the present application is shown. Detailed Implementation

[0020] Exemplary embodiments will now be described in detail, examples of which are illustrated in the accompanying drawings. When the following description relates to the drawings, unless otherwise indicated, the same numbers in different drawings denote the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with this application. Rather, they are merely examples of apparatuses and methods consistent with some aspects of this application as detailed in the appended claims.

[0021] The block diagrams shown in the accompanying drawings are merely functional entities and do not necessarily correspond to physically independent entities. That is, these functional entities can be implemented in software, in one or more hardware modules or integrated circuits, or in different network and / or processor devices and / or microcontroller devices.

[0022] The flowcharts shown in the accompanying drawings are merely illustrative and do not necessarily include all content and operations / steps, nor do they necessarily have to be performed in the described order. For example, some operations / steps can be broken down, while others can be combined or partially combined; therefore, the actual execution order may change depending on the specific circumstances.

[0023] In this application, "multiple" refers to two or more. "And / or" describes the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A alone, A and B simultaneously, or B alone. The character " / " generally indicates that the preceding and following related objects have an "or" relationship.

[0024] First, it's important to clarify that data reading and writing encompasses both the process of writing data to and reading data from memory. More broadly, data reading and writing can be applied to any skill or research involving data processing. The key to data reading and writing lies in the memory used for storage / retrieval, which can range from large to small storage spaces, such as flash memory. For small storage spaces, erasing the stored data before writing it is essential to avoid data loss due to insufficient storage space. The smallest unit of data erasure is often the smallest write unit in the memory, and the size of this smallest write unit varies depending on the storage capacity of different memory types. For example, the smallest erase unit in flash memory is a sector; the size of a sector varies between different flash memory types, with common sector sizes including 1KB, 2KB, and 4KB.

[0025] Furthermore, when writing or modifying new data in the memory, the process involves reading all the stored data in the smallest write unit where the required storage address is located, erasing the stored data in that smallest write unit, and then writing the new data into the erased smallest write unit. This method, due to the frequent erasure operations on the stored data in the memory, leads to a reduction in the memory's lifespan.

[0026] Therefore, to reduce the number of erase cycles and extend the lifespan of the memory, this embodiment determines the data storage address of the target data in the memory based on the latest index data, the target data to be written, and the size of the data area in the memory. Since this data storage address reflects the location of the smallest write unit where the target data is written to the memory, when the data storage address of the target data in the memory is the starting address of the smallest write unit, the data stored in the corresponding smallest write unit is erased. When the data storage address of the target data in the memory is not the starting address of the smallest write unit, the target data is directly written to the corresponding smallest write unit, thereby reducing the number of erase cycles and extending the lifespan of the memory.

[0027] Figure 1 This is a schematic diagram illustrating the implementation environment of a data read / write method in an exemplary embodiment. The implementation environment includes a host computer 110 and an energy storage device 120, with the host computer 110 and the energy storage device 120 having a pre-established wired or wireless network connection.

[0028] like Figure 1As shown, during the data read / write process, in response to a write operation by the target object to the host computer 110, the host computer 110 obtains the target data to be written and sends it to the energy storage device 120. The energy storage device 120 determines the data storage address of the target data in the energy storage device 120 based on the received target data to be written, the latest index data in the energy storage device 120, and the space size of the data storage area in the energy storage device 120. Then, when the data storage address is the starting address of the smallest write unit in the energy storage device 120, the data stored in the corresponding smallest write unit is erased, and the target data is written to the corresponding smallest write unit. When the data storage address is not the starting address of the smallest write unit in the energy storage device 120, the target data is written to the corresponding smallest write unit.

[0029] Figure 2 This is a schematic diagram illustrating the implementation environment of a data read / write method according to another exemplary embodiment. The implementation environment includes a flash memory chip 210 and a battery management system (BMS) 220. Here, both the flash memory chip 210 and the battery management system 220 are configured in an energy storage device, and the flash memory chip 210 and the battery management system 220 are connected.

[0030] like Figure 2 As shown, during the data read / write process, in response to a write operation by the target object to the battery management system 220, the battery management system 220 acquires the target data to be written and sends it to the flash memory chip 210. The flash memory chip 210 determines the data storage address of the target data in its flash memory chip 210 based on the received target data, the latest index data in the flash memory chip 210, and the space size of the data storage area in the flash memory chip 210. Then, when the data storage address is the starting address of the smallest write unit in the flash memory chip 210, the data stored in the corresponding smallest write unit is erased, and the target data is written to the corresponding smallest write unit. When the data storage address is not the starting address of the smallest write unit in the flash memory chip 210, the target data is written to the corresponding smallest write unit. Figure 2 The flash chip 210 shown can be used in any terminal device that supports data reading and writing, such as smartphones, in-vehicle computers, tablets, laptops, or wearable devices, but is not limited to these.

[0031] Figure 1The host computer 110 shown can be a server, such as an independent physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, CDN (Content Delivery Network), and big data and artificial intelligence platforms. There are no restrictions on this. Figure 1 The host computer 110 can communicate with the energy storage device 120 via wireless networks such as 3G (third-generation mobile information technology), 4G (fourth-generation mobile information technology), and 5G (fifth-generation mobile information technology). Figure 2 The battery management system 220 can also communicate with the flash memory chip 210 via wireless networks such as 3G (third-generation mobile information technology), 4G (fourth-generation mobile information technology), and 5G (fifth-generation mobile information technology), and this is not restricted here.

[0032] Please see Figure 3 , Figure 3 This is a flowchart illustrating a data read / write method in an exemplary embodiment of this application. This method can be applied to... Figure 1 or Figure 2 The implementation environment shown is specifically executed by the host computer 110 in that implementation environment or the battery management system 220 in the energy storage device. It should be understood that this method can also be applied to other exemplary implementation environments and executed by devices in other implementation environments. This embodiment does not limit the implementation environment to which this method is applicable.

[0033] The following section will describe in detail the data read / write method proposed in this application embodiment, taking the battery management system in an energy storage device as the specific execution subject.

[0034] like Figure 3 As shown, in an exemplary embodiment, the data read / write method includes at least steps S310 to S340, which are described in detail below:

[0035] Step S310: Obtain the latest index data from the memory.

[0036] In step S310, the index data is used to index the data storage address in the memory, and can also be used to characterize the amount of data written to the memory. It should be noted that there is a correlation between the index data and the read / write data; specifically, there is a one-to-one correspondence between the index data and the read / write data.

[0037] Taking the index data as an example, which refers to the number of data written, when each piece of data is written into the memory, the value of the index data stored in the memory is incremented accordingly.

[0038] The latest index data refers to the current index data obtained before data is written to memory. Specifically, when no data has been written to memory, the value of the latest index data is 0; when data has been written to memory, the index value corresponding to the latest data written to memory is the latest index data.

[0039] As an example, at the first moment, before any data has been written to the data storage area in memory, the latest index data is 0 by default. For instance, if no data has been written to the data storage area in memory at the first moment, and a frame of data is written to the data storage area in memory at the second moment after the first moment, the latest index data obtained at that second moment will be 0.

[0040] Based on the previous example, as another example, when data has already been written to the data storage area in memory, the latest index data is the index data corresponding to the previous written data whose write time is earlier than the target data to be written. For example, at the third time after the second time, since a frame of data has been written to the data storage area in memory, the value of the latest index data obtained at this time is 1.

[0041] Step S320: Determine the data storage address of the target data in the memory based on the index data, the target data to be written, and the space size of the data storage area in the memory.

[0042] In step S320, the target data to be written refers to the data that is about to be written into the memory.

[0043] In this embodiment, the memory includes a data storage area and an index storage area. The data storage area is used to store or retrieve data, and the index storage area is used to store or retrieve index data. The data storage area includes several minimum write units; for example, if the memory is a Flash chip, then the minimum write unit is a data sector.

[0044] See Figure 4 , Figure 4 A schematic diagram of data sectors in memory is shown. As an example, in... Figure 4Data sectors 1, 2, ..., x, ..., n-1, n are arranged sequentially. Each data sector is the same size, and data is stored sequentially in these sectors during read and write operations. For example, if data has been written to data sector 2, and the written address of that data is the second memory address in data sector 2 (assuming each data sector has a total of 5 memory addresses), then the next data write will be written to the third memory address in data sector 2. If the written address of that data is the fifth memory address in data sector 2, then the next data write will be written to data sector 3 after the data has been erased. It should be noted that if the written address of that data is the last memory address of the nth data sector, then the next data write will be written to data sector 1 after the data has been erased. In other words, data storage can be performed cyclically according to the order of the data sectors.

[0045] The index storage area includes several minimum write units. If the memory is a flash memory chip, then the minimum write unit is the index sector.

[0046] The size of a data storage area refers to the total amount of data that the data storage area can store. For example, if the size of a data storage area is 1GB, it means that it can store 1GB of data.

[0047] In all embodiments of this application, the data storage address refers to the write location when target data is written to the data storage area of ​​the memory. For example, the data storage address of the target data to be written may be the second storage location in the third smallest write unit of the data storage area.

[0048] It should be noted that since the latest index data can be used to characterize the amount of data already written in the memory, the address at which the target data is written to the data storage area can be determined by combining the target data to be written with the size of the data storage area in the memory.

[0049] For example, the server determines the data storage address of the target data in the memory based on the latest index data, the target data to be written, and the space size of the data storage area.

[0050] In step S330, when the data storage address is the starting address of the smallest write unit of the memory, the data stored in the smallest write unit is erased, and the target data is written into the smallest write unit.

[0051] In step S330, the starting address of the smallest write unit refers to the first storage location of each smallest write unit in the data storage area.

[0052] In all embodiments of this application, the data storage address is used to indicate the location where the target data is written to the smallest write unit. It is readily understood that writing the target data to the smallest write unit means writing the target data to the specific location within the smallest write unit pointed to by the data storage address.

[0053] For example, when the data storage address is the starting address of the smallest write unit of the memory, the data stored in the smallest write unit is erased, and the target data is written to the starting address of the smallest write unit.

[0054] To avoid frequent erasure of stored data in the minimum write unit, the battery management system determines whether to perform an erasure operation based on the actual storage location of the target data in the memory. Specifically, the battery management system determines whether the data storage address of the target data in the memory is the starting address of the minimum write unit of the memory. If so, the data stored in the corresponding minimum write unit is erased, and the target data is written into the minimum write unit; otherwise, step S340 is executed.

[0055] Step S340: When the data storage address is not the starting address of the smallest write unit of the memory, write the target data into the smallest write unit.

[0056] In step S340, when the battery management system determines that the data storage address of the target data in the memory is not the starting address of the smallest write unit of the memory, it directly writes the target data into the corresponding smallest write unit.

[0057] For example, the data storage address is the middle address of the smallest write unit in the memory, and the target data is written to the middle address of the smallest write unit.

[0058] For example, the data storage address is the end address of the smallest write unit in the memory, and the target data is written to the end address of the smallest write unit.

[0059] As can be seen, compared to erasing stored data every time data is written, the data read / write method disclosed in this application determines the data storage address of the target data in the memory based on the latest index data of the memory, the target data to be written, and the space size of the data area in the memory. Since the data storage address can reflect the position of the smallest write unit where the target data is written to the memory, when the data storage address of the target data to be written in the memory is the starting address of the smallest write unit in the memory, the data storage data of the corresponding smallest write unit is erased. When the data storage address of the target data to be written in the memory is not the starting address of the smallest write unit in the memory, the target data to be written is directly written to the corresponding smallest write unit. This reduces the number of times the memory is erased and extends the service life of the memory.

[0060] Based on the above embodiments, Figure 5 A schematic diagram of an exemplary data read / write method of this application is shown. Figure 5 In this example, taking flash memory chips as the memory and the smallest write unit as the data sector in the flash memory chip, the battery management system obtains the target data to be written, i.e., the new data to be written, and calculates the write address in the flash memory, i.e., the current flash address, based on the space size of the data storage area in the flash memory, the size of the new data, and the index data in the flash memory. Then, it determines whether the current flash address is the starting address of the data sector in the flash memory. If so, the data stored in the corresponding data sector is erased, and the new data is written to the data sector after the data is erased; otherwise, the new data is directly written to the current flash address.

[0061] Based on the above embodiments, the battery management system can determine the maximum data frame storage capacity of the data storage area according to the space size of the data storage area and the length of the unit data frame, and determine the range of stored addresses according to the index data, the maximum data frame storage capacity and the length of the unit data frame. Then, based on the starting address of the data storage area in the memory and the range of stored addresses, the data storage address of the target data in the memory in step S320 can be determined.

[0062] The length of a unit data frame refers to the byte length of a data frame, that is, the size of a data frame. It should be noted that, in order to facilitate the determination of the data storage address, the data size (byte length) is the same each time a data frame is written or read in this embodiment.

[0063] The maximum data frame storage capacity of a data storage area refers to the maximum number of data frames that the data storage area can store.

[0064] The stored address range refers to the size of the memory address space occupied by the stored data. For example, if the storage space size is 1G and the stored address range is 100k, it means that the stored data occupies a memory address range of 100k.

[0065] The starting address of a data storage area refers to the first data storage location within that area, which can also be understood as the first data storage location of the first smallest write unit in the data storage area. For example, using... Figure 4 Taking the data sector in the data storage area of ​​the flash chip shown as an example, the starting address of the data storage area is the first data storage location in data sector 1.

[0066] It should be noted that the maximum data frame storage size is specifically obtained by dividing the space size of the data storage area by the length of the unit data frame. The space size of the data storage area is specifically calculated using the start and end addresses of the data storage area.

[0067] The end address refers to the last data storage location in the data storage area, which can also be understood as the last data storage location of the last minimal write unit in the data storage area.

[0068] For example, if the starting address is represented as start_addr1, the ending address as stop_addr1, the length of a unit data frame as data_size1, and the maximum data frame storage size as max_num1, then the space size of the data storage area is represented as (stop_addr1 - start_addr1), and the maximum data frame storage size is...

[0069] It should be further noted that the battery management system can calculate the first remainder value when the index data is divided by the maximum data storage size, and use the product of the first remainder value and the size of the unit data frame as the range of stored addresses.

[0070] The first remainder value refers to the remainder value of the latest index data relative to the maximum data storage size.

[0071] For example, if the latest index data is represented as Index1, the first remainder value is represented as Index1%max_num1, and the range of stored addresses is represented as Index1%max_num1*data_size1.

[0072] As shown above, the data storage address satisfies the following formula:

[0073] addr1=start_addr1+Index1%max_num1*data_size1

[0074] Where addr1 represents the data storage address, Index1 represents the latest index data, max_num1 represents the maximum data frame storage size, Index1%max_num1 represents the first remainder value, and data_size1 represents the length of a unit data frame.

[0075] As can be seen, the data read / write method of this embodiment calculates the space size of the data storage area by dividing it by the length of a unit data frame, based on the start and end addresses of the data storage area. It then calculates the first remainder value when the index data is divided by the maximum data storage size. The product of this first remainder value and the size of the unit data frame is used as the range of stored addresses. Subsequently, the data storage address is determined based on the obtained start address and the range of stored addresses. This allows the method to determine whether the target data to be written is the first address of the smallest write unit of the memory. When the data storage address is determined to be the first address of the smallest write unit, the stored data in the corresponding smallest write unit is erased, and the target data is written into the smallest write unit after the stored data has been erased. When the data storage address is determined not to be the first address of the smallest write unit, the target data is written directly, reducing the number of data storage operations and extending the lifespan of the memory.

[0076] Based on the above embodiments, this application embodiment can further obtain the size of the smallest write unit in the data storage area, and determine whether the data storage address is the starting address of the smallest write unit of the memory based on the second remainder obtained by dividing the data storage address by the size of the smallest write unit. Specifically, when the battery management system determines that the value of the second remainder is one, it determines that the data storage address is the starting address of the smallest write unit of the memory.

[0077] The second remainder refers to the remainder value of the data storage address relative to the smallest write unit size.

[0078] As can be seen, the data writing method of this application embodiment determines the specific storage location in the minimum writing unit where the data storage address is located based on the data storage address and the size of the minimum writing unit. Then, when the specific storage location is determined to be the first storage location of the minimum writing unit, the data storage address is determined to be the starting address of the minimum writing unit of the memory. This can accurately determine whether the calculated data storage address is the starting address of the data storage area, avoiding the problem of target data storage error caused by incorrect determination of the starting address.

[0079] As one embodiment, prior to the step of erasing the data stored in the smallest write unit, the method further includes:

[0080] Determine whether the starting address has been written with data; if the starting address has been written with data, execute the step of erasing the data stored in the minimum write unit; if the starting address has not been written with data, do not execute the step of erasing the data stored in the minimum write unit, and execute the step of writing the target data into the minimum write unit.

[0081] In this embodiment, in order to further reduce the erasure operation of the memory, before the step of erasing the data stored in the smallest write unit, the starting address of the data storage address is the starting address of the smallest write unit of the memory, and the step of erasing the data stored in the smallest write unit can be determined by judging whether the starting address has data written, and then deciding whether to perform a data erasure operation on the smallest write unit.

[0082] In the actual implementation, to determine whether the starting address has been written with data, a data reading operation can be performed based on the starting address. If data is read from the starting address, it is determined that the starting address has been written with data. If no data is read from the starting address, such as when the read content is empty, it is determined that the starting address has not been written with data.

[0083] This embodiment ensures that the target data can be successfully written to the starting address of the minimum write unit by performing the step of erasing the data stored in the minimum write unit when the starting address has already been written with data. When the starting address has not been written with data, the target data can be directly written to the starting address of the minimum write unit without performing the step of erasing the data stored in the minimum write unit, thus further reducing the number of times the memory is erased.

[0084] Figure 6 This is a flowchart illustrating a data read / write method in yet another exemplary embodiment of this application. For example... Figure 6 As shown, in an exemplary embodiment, after the step of writing the target data into the smallest writing unit, the data writing method of this application embodiment further includes at least steps S610 to S630, which are described in detail below:

[0085] Step S610: Update the index data to obtain the updated index data.

[0086] In step S610, the updated index data corresponds to the target data. After the updated index data is written into the index storage area of ​​the memory, it can be used to index the corresponding target data from the memory.

[0087] After determining the minimum write unit for the target data, the battery management system updates the index data stored in the memory to obtain the updated index data. It should be noted that the index data is stored in the minimum write unit within the index storage area of ​​the memory. For example, if the memory is Flash memory, the index data is stored in the index sector of the index storage area.

[0088] Step S620: Determine the index storage address in memory for the updated index data.

[0089] In step S620, the index storage address refers to the storage location of the updated index data in the index storage area of ​​the memory, specifically the storage location in the smallest write unit of the index storage area.

[0090] The battery management system calculates the index storage address of the updated index data in memory based on the updated index data.

[0091] In step S630, when the index storage address is the starting address of the smallest write unit in the memory, the index data in the previous smallest write unit is erased, and the updated index data is written to the index storage address.

[0092] In step S630, the previous smallest write unit refers to the smallest write unit of the index data that was written earlier than the updated index data. For example, if the index storage address of the updated index data is the starting address of the fourth smallest write unit in the index storage area, then the previous smallest write unit is the third smallest write unit in the index storage area. As another example, if the index storage address of the updated index data is the starting address of the first smallest write unit in the index storage area, then the previous smallest write unit is the first smallest write unit in the index storage area.

[0093] Considering that only one minimum write unit stores index data in the index storage area, in order to protect the index storage area and avoid frequent erasure of other minimum write units in the index storage area, the server in this application embodiment erases the index data stored in the previous minimum write unit and writes the updated index data to the index storage address when it determines that the obtained index storage address is the starting address of the minimum write unit in the index storage area.

[0094] As can be seen, the data writing method of this application, after determining the minimum write unit corresponding to the target data to be written, updates the index data in the index storage area and determines the index storage address of the updated index data in the memory. When the index storage address is the starting address of the index storage area of ​​the memory, the index data in the previous minimum write unit is erased, and the updated index data is written to the index storage address. This can protect the index storage area and avoid the problem of other minimum write units in the index storage area that do not store index data being frequently erased, thereby improving the service life of the memory.

[0095] Based on the above embodiments, the battery management system determines the maximum index data storage volume of the index storage area according to the space size of the index storage area and the size of the unit index data, and determines the stored address range according to the index data, the maximum index data storage volume and the size of the unit index data. Then, it determines the index storage address of the updated index data in the memory in step 620 according to the starting address of the index storage area in the memory and the stored address range.

[0096] The size of the index storage area refers to the total amount of index data that the index storage area can store.

[0097] The size of the unit index data refers to the preset size of the index data. It should be noted that in this embodiment, the data size is the same each time the index data is written or read.

[0098] The maximum index data storage capacity of an index storage area refers to the maximum amount of index data that the index storage area can store.

[0099] The stored address range refers to the size of the storage address space occupied by the stored index data in memory.

[0100] The starting address of the index storage area refers to the first index storage location in the index storage area, which can also be understood as the first index storage location of the first smallest write unit in the index storage area.

[0101] Specifically, the index storage address satisfies the following formula:

[0102] addr2=start_addr2+Index2%max_num2*data_size2

[0103] Where addr2 represents the index storage address, Index2 represents the updated index data, max_num2 represents the maximum index data frame storage size, Index2%max_num2 represents the second remainder value, and data_size2 represents the size of a unit of index data.

[0104] Based on the above embodiments, Figure 7 A schematic diagram of another exemplary data read / write method of this application is shown. Figure 7 In this example, taking a flash memory chip as the memory and an index sector in the flash memory chip as the smallest write unit, the battery management system obtains the latest index data from the flash memory chip. When the latest index data needs to be written, it calculates the index storage address of the latest index data in the memory based on the latest index data, the maximum index data storage size, and the size of the unit index data. Then, it determines whether the calculated index storage address is the starting address of the smallest write unit of the index storage area. If so, it erases the index data in the previous smallest write unit and writes the latest index data to the index storage address; otherwise, it directly writes the latest index data to the index storage address.

[0105] The latest index data refers to the index data updated after the data is written to the data storage area. Alternatively, the latest index data obtained from the flash memory can also be obtained after the battery management system is powered on. Specifically, after power-on, the battery management system retrieves the initial index data from the flash memory and determines whether the retrieved initial index data is equal to the preset index data. If so, the initial index data is used as the latest index data; otherwise, the index data in the index storage area is erased, and the initial index data is used as the latest index data.

[0106] Initial index data refers to the index values ​​read from the index storage area after the battery management system is powered on.

[0107] Preset index data refers to pre-set index values. Specifically, the preset index data can be 0.

[0108] As can be seen, the read / write method in this application determines whether the acquired initial index data is equal to the preset index data. If so, the index data in the index storage area is erased, and the initial index data is used as the latest index data. If not, the initial index data is used as the latest index data. Thus, after power-on initialization, the latest index data can be determined based on the acquired initial index data, avoiding the increase in acquisition time by traversing the index storage area of ​​the memory to obtain the latest index data.

[0109] After writing the updated index data to the index storage address, the battery management system can verify the written data to ensure its accuracy. For example, the battery management system can determine a data difference based on the data storage address of the first written data corresponding to the updated index data in memory, the data storage address of the second written data corresponding to the updated index data in memory, and the updated index data. When the data difference equals one, the updated index data is determined to be the latest index data. Specifically, the battery management system uses the difference between the data storage address of the first written data and the data storage address of the second written data as the region address offset, calculates the ratio between the region address offset and the byte length of the updated index data, and then uses the difference between the updated index data and this ratio as the data difference.

[0110] The first written data corresponds to the updated index data. That is, when the first written data is written into the memory, the index value stored in the index storage area of ​​the memory is incremented by one to obtain the updated index data.

[0111] The second written data corresponds to the current index data stored in the index storage area of ​​the memory, which is also the updated index data. After the current index data is updated, the updated index data corresponding to the first written data is obtained. Therefore, the second written data refers to the data written at the write time preceding the write time of the first written data. For example, if the second written data is written at time n, then the first written data is written at time n+1 after time n.

[0112] The updated index data refers to the current index data stored in the index storage area of ​​the memory. Continuing with the above example, after writing the second write data at time n, the index storage area of ​​the memory stores the updated index data. Then, after writing the first write data at time n+1, the updated index data stored in the index storage area of ​​the memory is updated to obtain the updated index data corresponding to the first write data.

[0113] The region address offset refers to the difference between the data storage address where the first written data is located and the data storage address where the second written data is located.

[0114] The byte length of the updated index data refers to the size of the updated index data.

[0115] The ratio refers to the ratio between the area address offset and the size of the unit index data.

[0116] The data difference refers to the difference between the updated index data and the ratio.

[0117] It should be noted that the data difference satisfies the following formula:

[0118]

[0119] Where Flash_offset represents the region address offset, sizeof(index) represents the byte length of the updated index data, and index represents the updated index data.

[0120] As can be seen, the data read / write method of this application determines the data difference based on the data storage address where the first written data is located, the data storage address where the second written data is located, and the updated index data. Then, it verifies whether the updated index data is the latest index data in the memory based on the data difference, thereby improving the accuracy of obtaining the latest index data.

[0121] Figure 8 This is a block diagram illustrating a data read / write device according to an exemplary embodiment of this application. This data read / write device can be applied to... Figure 1 or Figure 2The implementation environment shown is not limited to this embodiment. This data read / write device can also be applied to other exemplary implementation environments and specifically configured in other devices. This embodiment does not limit the implementation environment to which the device is applicable.

[0122] like Figure 8 As shown, the exemplary data read / write device 800 includes: an index data acquisition module 810, a data storage address determination module 820, an erasure module 830, and a write module 840. Specifically:

[0123] The index data acquisition module 810 is configured to acquire the latest index data from the memory.

[0124] The data storage address determination module 820 is configured to determine the data storage address of the target data in the memory based on the index data, the target data to be written, and the space size of the data storage area in the memory.

[0125] The erase module 830 is configured to erase the data stored in the minimum write unit and write the target data into the minimum write unit when the data storage address is the starting address of the minimum write unit of the memory.

[0126] The write module 840 is configured to write the target data into the smallest write unit when the data storage address is not the starting address of the smallest write unit of the memory.

[0127] In this exemplary data read / write device, compared to erasing stored data every time data is written, the data read / write method disclosed in this application determines the data storage address of the target data in the memory based on the latest index data of the memory, the target data to be written, and the space size of the data area in the memory. Since the data storage address can reflect the position of the smallest write unit where the target data is written to the memory, when the data storage address of the target data to be written in the memory is the starting address of the smallest write unit of the memory, the stored data in the corresponding smallest write unit is erased. When the data storage address of the target data to be written in the memory is not the starting address of the smallest write unit of the memory, the target data to be written is directly written to the corresponding smallest write unit, thereby reducing the number of erase operations of the memory and extending the service life of the memory.

[0128] It should be noted that the data read / write device and the data read / write method provided in the above embodiments belong to the same concept. The specific ways in which each module and unit performs operations have been described in detail in the method embodiments, and will not be repeated here. In practical applications, the data read / write device provided in the above embodiments can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above, and this is not a limitation here.

[0129] Embodiments of this application also provide an electronic device, including: one or more processors; and a storage device for storing one or more programs, which, when executed by the one or more processors, cause the electronic device to implement the data read / write methods provided in the above embodiments.

[0130] Figure 9 A schematic diagram of a computer system suitable for implementing the embodiments of this application is shown. It should be noted that... Figure 9 The computer system 900 of the electronic device shown is merely an example and should not impose any limitation on the functionality and scope of use of the embodiments of this application.

[0131] like Figure 9 As shown, the computer system 900 includes a Central Processing Unit (CPU) 901, which can perform various appropriate actions and processes based on programs stored in Read-Only Memory (ROM) 902 or programs loaded from storage portion 908 into Random Access Memory (RAM) 903, such as executing the data read / write methods described in the above embodiments. The RAM 903 also stores various programs and data required for system operation. The CPU 901, ROM 902, and RAM 903 are interconnected via a bus 904. An Input / Output (I / O) interface 905 is also connected to the bus 904.

[0132] The following components are connected to I / O interface 905: an input section 906 including a keyboard, mouse, etc.; an output section 907 including a cathode ray tube (CRT), liquid crystal display (LCD), etc., and speakers, etc.; a storage section 908 including a hard disk, etc.; and a communication section 909 including a network interface card such as a LAN (Local Area Network) card, modem, etc. The communication section 909 performs communication processing via a network such as the Internet. A drive 910 is also connected to I / O interface 905 as needed. Removable media 911, such as a disk, optical disk, magneto-optical disk, semiconductor memory, etc., are installed on drive 910 as needed so that computer programs read from them can be installed into storage section 908 as needed.

[0133] Specifically, according to embodiments of this application, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, embodiments of this application include a computer program product comprising a computer program carried on a computer-readable medium, the computer program including a computer program for performing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via communication section 909, and / or installed from removable medium 911. When the computer program is executed by central processing unit (CPU) 901, it performs various functions defined in the system of this application.

[0134] It should be noted that the computer-readable medium shown in the embodiments of this application can be a computer-readable signal medium or a computer-readable storage medium, or any combination of the two. A computer-readable storage medium can be, for example, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples of a computer-readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM), flash memory, optical fiber, portable compact disc read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination thereof. In this application, a computer-readable signal medium may include a data signal propagated in baseband or as part of a carrier wave, carrying a computer-readable computer program. Such propagated data signals can take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. Computer-readable signal media can also be any computer-readable medium other than computer-readable storage media, which can send, propagate, or transmit a program for use by or in connection with an instruction execution system, apparatus, or device. The computer program contained on the computer-readable medium can be transmitted using any suitable medium, including but not limited to wireless, wired, etc., or any suitable combination thereof.

[0135] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of this application. Each block in a flowchart or block diagram may represent a module, segment, or portion of code, which contains one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions indicated in the blocks may occur in a different order than those indicated in the drawings. For example, two consecutively indicated blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in a block diagram or flowchart, and combinations of blocks in a block diagram or flowchart, can be implemented using a dedicated hardware-based system that performs the specified function or operation, or using a combination of dedicated hardware and computer instructions.

[0136] The units described in the embodiments of this application can be implemented in software or hardware, and the described units can also be located in a processor. The names of these units do not necessarily limit the specific unit itself.

[0137] Another aspect of this application provides a computer-readable storage medium storing a computer program thereon, which, when executed by a processor, implements the flash memory-based read / write method as described above. This computer-readable storage medium may be included in the electronic device described in the above embodiments, or it may exist independently and not assembled into the electronic device.

[0138] Another aspect of this application provides a computer program product or computer program including computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the computer device to perform the flash memory-based read / write method provided in the various embodiments described above.

[0139] The above description is merely a preferred exemplary embodiment of this application and is not intended to limit the implementation of this application. Those skilled in the art can easily make corresponding modifications or alterations based on the main concept and spirit of this application. Therefore, the scope of protection of this application should be determined by the scope of protection claimed in the claims.

Claims

1. A data read / write method, characterized in that, include: Retrieve the latest index data from the memory; The data storage address of the target data in the memory is determined based on the index data, the target data to be written, and the space size of the data storage area in the memory. When the data storage address is the starting address of the smallest write unit of the memory, the data stored in the smallest write unit is erased, and the target data is written into the smallest write unit; When the data storage address is not the starting address of the minimum write unit of the memory, the target data is written into the minimum write unit; The process of determining the data storage address of the target data in the memory based on the index data, the target data to be written, and the space size of the data storage area in the memory includes: Obtain the starting address of the data storage area in the memory; The maximum data frame storage capacity of the data storage area is determined based on the spatial size of the data storage area and the length of a unit data frame. The range of stored addresses is determined based on the index data, the maximum data frame storage size, and the length of the unit data frame, and the data storage address is determined based on the starting address and the range of stored addresses.

2. The method according to claim 1, characterized in that, The step of determining the maximum data frame storage capacity of the data storage area based on the space size of the data storage area and the length of a unit data frame includes: Calculate the size of the data storage area based on the start and end addresses of the data storage area; The maximum data frame storage capacity is obtained by dividing the size of the data storage area by the length of the unit data frame.

3. The method according to claim 1, characterized in that, The step of determining the range of stored addresses based on the index data, the maximum data frame storage size, and the length of the unit data frame includes: Calculate the first remainder value when the index data is divided by the maximum data frame storage size; The product of the first remainder value and the size of the unit data frame is taken as the stored address range.

4. The method according to claim 1, characterized in that, The method further includes: Obtain the size of the smallest write unit in the data storage area; Calculate the second remainder obtained by dividing the data storage address by the size of the smallest write unit; When the value of the second remainder is one, the data storage address is confirmed as the starting address of the smallest write unit of the memory.

5. The method according to claim 1, characterized in that, After the step of writing the target data into the smallest write unit, the method further includes: Update the index data to obtain updated index data, wherein the updated index data corresponds to the target data; Determine the index storage address of the updated index data in the memory; When the index storage address is the starting address of the smallest write unit in the memory, the index data in the previous smallest write unit is erased, and the updated index data is written to the index storage address.

6. The method according to claim 5, characterized in that, The step of determining the index storage address of the updated index data in the memory includes: Obtain the starting address of the index storage area in the memory; The maximum index data storage capacity of the index storage area is determined based on the space size of the index storage area and the size of the unit index data. The range of stored addresses is determined based on the index data, the maximum index data storage size, and the size of the unit index data; and The index storage address is determined based on the starting address and the range of already stored addresses.

7. The method according to claim 1, characterized in that, Prior to the step of erasing the data stored in the smallest write unit, the method further includes: Determine whether the starting address has already been written with data; When data has already been written to the starting address, the step of erasing the data stored in the smallest write unit is performed; When no data is written to the first address, the step of erasing the data stored in the minimum write unit is not performed, and the step of writing the target data into the minimum write unit is performed instead.

8. An electronic device, characterized in that, include: Memory, which stores computer-readable instructions; A processor reads computer-readable instructions stored in memory to perform the method described in any one of claims 1-7.

9. A computer-readable storage medium, characterized in that, It stores computer-readable instructions that, when executed by the processor of a computer, cause the computer to perform the method described in any one of claims 1-7.

Citation Information

Patent Citations

  • Write-in method and read method for log information of circulation movement of financial equipment

    CN106408790A

  • Data storage method, device and equipment for optimizing service life of FLASH and medium

    CN114035741A