CN115129257A - Data reading and writing method, electronic equipment and computer readable storage medium - Google Patents

Data reading and writing method, electronic equipment and computer readable storage medium Download PDF

Info

Publication number
CN115129257A
CN115129257A CN202210808127.0A CN202210808127A CN115129257A CN 115129257 A CN115129257 A CN 115129257A CN 202210808127 A CN202210808127 A CN 202210808127A CN 115129257 A CN115129257 A CN 115129257A
Authority
CN
China
Prior art keywords
data
address
index
memory
unit
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202210808127.0A
Other languages
Chinese (zh)
Inventor
陈熙
陈玉光
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Ecoflow Technology Ltd
Original Assignee
Ecoflow Technology Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Ecoflow Technology Ltd filed Critical Ecoflow Technology Ltd
Priority to CN202210808127.0A priority Critical patent/CN115129257A/en
Publication of CN115129257A publication Critical patent/CN115129257A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F3/00Input arrangements for transferring data to be processed into a form capable of being handled by the computer; Output arrangements for transferring data from processing unit to output unit, e.g. interface arrangements
    • G06F3/06Digital input from, or digital output to, record carriers, e.g. RAID, emulated record carriers or networked record carriers
    • G06F3/0601Interfaces specially adapted for storage systems
    • G06F3/0602Interfaces specially adapted for storage systems specifically adapted to achieve a particular effect
    • G06F3/0614Improving the reliability of storage systems
    • G06F3/0616Improving the reliability of storage systems in relation to life time, e.g. increasing Mean Time Between Failures [MTBF]
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F3/00Input arrangements for transferring data to be processed into a form capable of being handled by the computer; Output arrangements for transferring data from processing unit to output unit, e.g. interface arrangements
    • G06F3/06Digital input from, or digital output to, record carriers, e.g. RAID, emulated record carriers or networked record carriers
    • G06F3/0601Interfaces specially adapted for storage systems
    • G06F3/0628Interfaces specially adapted for storage systems making use of a particular technique
    • G06F3/0638Organizing or formatting or addressing of data
    • G06F3/0644Management of space entities, e.g. partitions, extents, pools
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F3/00Input arrangements for transferring data to be processed into a form capable of being handled by the computer; Output arrangements for transferring data from processing unit to output unit, e.g. interface arrangements
    • G06F3/06Digital input from, or digital output to, record carriers, e.g. RAID, emulated record carriers or networked record carriers
    • G06F3/0601Interfaces specially adapted for storage systems
    • G06F3/0628Interfaces specially adapted for storage systems making use of a particular technique
    • G06F3/0646Horizontal data movement in storage systems, i.e. moving data in between storage devices or systems
    • G06F3/0652Erasing, e.g. deleting, data cleaning, moving of data to a wastebasket
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F3/00Input arrangements for transferring data to be processed into a form capable of being handled by the computer; Output arrangements for transferring data from processing unit to output unit, e.g. interface arrangements
    • G06F3/06Digital input from, or digital output to, record carriers, e.g. RAID, emulated record carriers or networked record carriers
    • G06F3/0601Interfaces specially adapted for storage systems
    • G06F3/0668Interfaces specially adapted for storage systems adopting a particular infrastructure
    • G06F3/0671In-line storage system
    • G06F3/0673Single storage device
    • G06F3/0679Non-volatile semiconductor memory device, e.g. flash memory, one time programmable memory [OTP]

Abstract

The application discloses a data reading and writing method, electronic equipment and a computer readable storage medium. The method comprises the following steps: acquiring the latest index data of a memory; determining a data storage address of the target data in the memory according to the index data, the target data to be written and the space size of a data storage area in the memory; when the data storage address is the first address of the minimum writing unit of the memory, erasing the data stored in the minimum writing unit, and writing the target data into the minimum writing unit; and when the data storage address is not the first address of the minimum writing unit of the memory, writing the target data into the minimum writing unit. Compared with the method for erasing the stored data when the data is written every time, the data reading and writing method disclosed by the application can erase the stored data when the data storage position of the target data to be written is determined to be the first address of the minimum writing unit in the memory, so that the erasing times of the stored data are reduced, and the service life of the memory is prolonged.

Description

Data reading and writing method, electronic equipment and computer readable storage medium
Technical Field
The present application relates to the field of computer technologies, and in particular, to a data reading and writing method, an electronic device, and a computer-readable storage medium.
Background
For a memory with a small storage space, erasing of stored data before writing data is avoided. Generally, when new data is written into a memory, all the stored data of the minimum writing unit where the new data to be stored in the memory is located is read, the stored data in the minimum writing unit where the new data is located is erased, and the new data is written into the minimum writing unit where the stored data is erased. The method has the problems that the storage data of the memory is frequently erased, the service life of the memory is reduced, and the like.
Disclosure of Invention
In order to solve the above technical problem, embodiments of the present application provide a data reading and writing method, an electronic device, and a computer-readable storage medium.
According to an aspect of an embodiment of the present application, there is provided a data reading and writing method, including: acquiring the latest index data of a memory; determining a data storage address of the target data in the memory according to the index data, the target data to be written and the space size of a data storage area in the memory; when the data storage address is the head address of the minimum writing unit of the memory, erasing the data stored in the minimum writing unit, and writing the target data into the minimum writing unit; and when the data storage address is not the head address of the minimum writing unit of the memory, writing the target data into the minimum writing unit.
According to an aspect of an embodiment of the present application, there is provided a data reading and writing apparatus, including: the index data acquisition module is configured to acquire the latest index data of the memory; the data storage address determining module is configured to determine a data storage address of the target data in the memory according to the index data, the target data to be written and the space size of a data storage area in the memory; the erasing module is configured to erase the data stored in the minimum writing unit and write the target data into the minimum writing unit when the data storage address is the head address of the minimum writing unit of the memory; and the writing module is configured to write the target data into the minimum writing unit when the data storage address is not the head address of the minimum writing unit of the memory.
According to an aspect of an embodiment of the present application, there is provided an electronic device including: a memory storing computer readable instructions; and the processor reads the computer readable instructions stored in the memory to execute the data reading and writing method of any one of the above methods.
According to an aspect of embodiments of the present application, there is provided a computer-readable storage medium having stored thereon computer-readable instructions, which, when executed by a processor of a computer, cause the computer to execute a data reading and writing method as described above.
In the technical solution provided in the embodiment of the present application, compared with erasing stored data every time data is written, the data reading and writing method disclosed in the present application determines the data storage address of the target data in the memory according to the latest index data of the memory, the target data to be written, and the space size of the data area in the memory, and since the data storage address can represent the position of the minimum write unit where the target data is written in the memory, when the data storage address of the target data to be written in the memory is the head address of the minimum write unit in the memory, the data erasing operation is performed on the stored data in the corresponding minimum write unit, and when the data storage address of the target data to be written in the memory is not the head address of the minimum write unit in the memory, the target data to be written is directly written in the corresponding minimum write unit, therefore, the erasing times of the memory are reduced, and the service life of the memory is prolonged.
It is to be understood that both the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the application.
Drawings
The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and together with the description, serve to explain the principles of the application. It is obvious that the drawings in the following description are only some embodiments of the application, and that for a person skilled in the art, other drawings can be derived from them without inventive effort. In the drawings:
FIG. 1 is a schematic diagram of an implementation environment of a data read/write method according to an exemplary embodiment;
FIG. 2 is a schematic diagram of an implementation environment of a data read/write method according to another exemplary embodiment;
FIG. 3 is a flow chart illustrating a method for reading and writing data in accordance with an exemplary embodiment of the present application;
FIG. 4 is a schematic diagram of a data sector in a memory shown in an exemplary embodiment of the present application;
FIG. 5 is a schematic diagram of an overall scheme of an exemplary data read/write method of the present application;
FIG. 6 is a flow chart illustrating a method for reading and writing data in accordance with yet another exemplary embodiment of the present application;
FIG. 7 is a schematic diagram of an overall scheme of another exemplary data read-write method of the present application;
FIG. 8 is a block diagram representation of a data read/write apparatus shown in an exemplary embodiment of the present application;
FIG. 9 illustrates a schematic structural diagram of a computer system suitable for use to implement the electronic device of the embodiments of the subject application.
Detailed Description
Reference will now be made in detail to the exemplary embodiments, examples of which are illustrated in the accompanying drawings. When the following description refers to the accompanying drawings, like numbers in different drawings represent the same or similar elements unless otherwise indicated. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present application. Rather, they are merely examples of apparatus and methods consistent with certain aspects of the present application, as detailed in the appended claims.
The block diagrams shown in the figures are functional entities only and do not necessarily correspond to physically separate entities. I.e. these functional entities may be implemented in the form of software, or in one or more hardware modules or integrated circuits, or in different networks and/or processor means and/or microcontroller means.
The flow charts shown in the drawings are merely illustrative and do not necessarily include all of the contents and operations/steps, nor do they necessarily have to be performed in the order described. For example, some operations/steps may be decomposed, and some operations/steps may be combined or partially combined, so that the actual execution sequence may be changed according to the actual situation.
Reference to "a plurality" in this application means two or more. "and/or" describe the association relationship of the associated objects, meaning that there may be three relationships, e.g., A and/or B may mean: a exists alone, A and B exist simultaneously, and B exists alone. The character "/" generally indicates that the former and latter associated objects are in an "or" relationship.
It should be noted that, reading and writing data includes writing data into the memory and reading data from the memory. In a broader sense, data reading and writing may be applied to any skill or research involving data reading and writing. The key of data reading and writing is the memory required to be stored/read, and the memory comprises a memory with a large storage space and a memory with a small storage space, such as Flash. For a memory with a small storage space, erasing of stored data before writing data is avoided, so that the problem of storage data loss caused by insufficient data storage space is avoided. The minimum unit for storing data erasure is often the minimum write unit in the memory, and the minimum write unit has different sizes due to different memory storage spaces. For example, the minimum erase unit in a flash memory is a sector, and different flash memories have different sizes of a sector, and common sector sizes include 1k (byte), 2k (byte), and 4k (byte).
Further, when new data is written or modified into the memory, all the stored data of the minimum writing unit where the required storage address in the memory is located are read, the stored data in the minimum writing unit where the new data is located are erased, and then the new data are written into the minimum writing unit where the stored data are erased. The method has the problem that the service life of the memory is reduced due to frequent erasing operation on the stored data in the memory.
Based on this, in order to reduce the number of times of erasing data stored in the memory and improve the service life of the memory, in the embodiment of the present application, a data storage address of target data in the memory is determined according to the latest index data of the memory, target data to be written, and the space size of a data area in the memory. The data storage address can represent the position of the minimum writing unit of the memory where the target data is written, so when the data storage address of the target data in the memory is the first address of the minimum writing unit of the memory, the data in the corresponding minimum writing unit is erased. When the data storage address of the target data in the memory is not the first address of the minimum writing unit of the memory, the target data is directly written into the corresponding minimum writing unit, so that the erasing times of the memory are reduced, and the service life of the memory is prolonged.
Fig. 1 is a schematic diagram of an implementation environment of a data read-write method according to an exemplary embodiment. The implementation environment comprises an upper computer 110 and an energy storage device 120, wherein the upper computer 110 and the energy storage device 120 are in wired or wireless network connection in advance.
As shown in fig. 1, in the data reading and writing process, in response to a writing operation of a target object to the upper computer 110, the upper computer 110 obtains target data to be written, and sends the target data to be written to the energy storage device 120, and the energy storage device 120 determines a data storage address of the target data in the energy storage device 120 according to the received target data to be written, the latest index data in the energy storage device 120, and a space size of a data storage area in the energy storage device 120. Then, when the data storage address is the head address of the minimum write unit in the energy storage device 120, the data stored in the corresponding minimum write unit is erased, and the target data is written into the corresponding minimum write unit, and when the data storage address is not the head address of the minimum write unit in the energy storage device 120, the target data is written into the corresponding minimum write unit.
Fig. 2 is a schematic diagram of an implementation environment of a data reading and writing method according to another exemplary embodiment. The implementation environment includes a Flash memory Flash chip 210 and a battery Management system bms (battery Management system) 220. Here, the Flash memory Flash chip 210 and the battery management system 220 are both configured in the energy storage device, and the Flash memory Flash chip 210 and the battery management system 220 are connected.
As shown in fig. 2, in the data reading and writing process, in response to the write operation of the target object to the battery management system 220, the battery management system 220 obtains target data to be written, and sends the target data to be written to the Flash memory Flash chip 210, and the Flash memory Flash chip 210 determines a data storage address of the target data in the Flash memory Flash chip 210 according to the received target data to be written, the latest index data in the Flash memory Flash chip 210, and the space size of the data storage area in the Flash memory Flash chip 210. And then, when the data storage address is the head address of the minimum write-in unit in the Flash memory Flash chip 210, erasing the data stored in the corresponding minimum write-in unit, writing the target data into the corresponding minimum write-in unit, and when the data storage address is not the head address of the minimum write-in unit of the Flash memory Flash chip 210, writing the target data into the corresponding minimum write-in unit. The Flash memory Flash chip 210 shown in fig. 2 may be applied to any terminal device supporting data reading and writing, such as a smart phone, a vehicle-mounted computer, a tablet computer, a notebook computer, or a wearable device, but is not limited thereto.
The upper computer 110 shown in fig. 1 may be a server, for example, an independent physical server, a server cluster or a distributed system formed by a plurality of physical servers, or a cloud server providing basic cloud computing services such as a cloud service, a cloud database, cloud computing, a cloud function, cloud storage, a Network service, cloud communication, a middleware service, a domain name service, a security service, a CDN (Content Delivery Network), a big data and artificial intelligence platform, and is not limited herein. The upper computer 110 in fig. 1 may communicate with the energy storage device 120 through a wireless network such as a 3G (third generation mobile information technology), a 4G (fourth generation mobile information technology), or a 5G (fifth generation mobile information technology), and the battery management system 220 in fig. 2 may also communicate with the Flash memory Flash chip 210 through a wireless network such as a 3G (third generation mobile information technology), a 4G (fourth generation mobile information technology), or a 5G (fifth generation mobile information technology), which is not limited herein.
Referring to fig. 3, fig. 3 is a flowchart illustrating a data reading and writing method according to an exemplary embodiment of the present application. The method may be applied to the implementation environment shown in fig. 1 or fig. 2, and is specifically executed by the upper computer 110 or the battery management system 220 in the energy storage device in the implementation environment. It should be understood that the method may be applied to other exemplary implementation environments and is specifically executed by devices in other implementation environments, and the embodiment does not limit the implementation environment to which the method is applied.
The following describes the data reading and writing method provided in the embodiment of the present application in detail by taking a battery management system in an energy storage device as a specific execution subject.
As shown in fig. 3, in an exemplary embodiment, the data reading and writing method at least includes steps S310 to S340, which are described in detail as follows:
in step S310, the latest index data of the memory is acquired.
In step S310, the index data is used to index the data storage address of the data in the memory, and may also be used to characterize the amount of written data in the memory. It should be noted that the index data and the read-write data have an association relationship, and specifically, the index data and the read-write data correspond to each other one to one.
Taking the index data as the number of the written data as an example, when one piece of data is written into the memory, the value of the index data stored in the memory is correspondingly added by one.
The latest index data refers to the current index data acquired before writing data to the memory. When the data is written into the memory, the index value corresponding to the data written into the memory is the latest index data.
As an example, at the first time, when data has not been written to the data storage area in the memory, the latest index data defaults to 0. For example, when data is not written into the data storage area in the memory at a first time, and during the process of writing one frame of data into the data storage area in the memory at a second time after the first time, the latest index data acquired at the second time is 0.
Based on the above example, as another example, when data has been written in a data storage area in the memory, the newest index data is index data corresponding to previously written data whose writing time is earlier than that of target data to be written. For example, at a third time after the second time, since one frame of data has been written into the data storage area in the memory, the value of the latest index data acquired at this time is 1.
Step S320, determining a data storage address of the target data in the memory according to the index data, the target data to be written, and the space size of the data storage area in the memory.
In step S320, the target data to be written refers to data to be written into the memory.
In this embodiment, the memory includes a data storage area for storing or reading data and an index storage area for storing or reading index data. The data storage area includes a plurality of minimum write units, and illustratively, if the memory is a Flash memory chip, the minimum write unit at this time is a data sector.
Referring to fig. 4, fig. 4 shows a schematic diagram of a data sector in a memory. As an example, in fig. 4, a data sector 1, a data sector 2 …, a data sector x …, a data sector n-1, and a data sector n are sequentially arranged, each data sector has the same size, and data is sequentially stored in the data sectors during data reading and writing. For example, if data is written in data sector 2 and the written location of the written data is the second storage address in data sector 2 (5 storage addresses are set for each data sector), the next write data is written in the third storage address in data sector 2 in sequence; if the written data writing position is the fifth storage address in the data sector 2, the next write data is written in the data sector 3 after the storage data is erased in sequence. It should be noted that, if the written data writing position is the last storage position of the nth data sector, the data is written into the data sector 1 after the data is erased when the data is written next time, that is, the data storage may perform the circular storage according to the sequence of the data sectors.
The index storage area comprises a plurality of minimum write-in units, and if the memory is a Flash memory chip, the minimum write-in unit at the moment is an index sector.
The size of the space of the data storage area refers to the total amount of storage that the data storage area can store data. For example, if the space size of the data storage area is 1G, it indicates that it can store 1G data.
In all embodiments of the present application, the data storage address refers to a write location when target data is written to a 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 minimum writing unit in the data storage area.
It should be noted that, since the latest index data can be used to represent the number of written data in the memory, the address for writing the target data into the data storage area can be determined by combining the target data to be written and the space size of the data storage area in the memory.
Illustratively, the server determines the data storage address of the target data in the memory according to the latest index data, the target data to be written and the space size of the data storage area.
Step S330, when the data storage address is the first 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.
In step S330, the head address of the minimum write unit refers to the first storage location of each minimum write unit in the data storage area.
In all embodiments of the present application, the data storage address is used to indicate where the target data is written to the minimum write unit. It will be readily appreciated that the target data is written to the minimum write unit, i.e. the target data is written to a specific location in the minimum write unit to which the data storage address points.
Illustratively, when the data storage address is the head address of the minimum write unit of the memory, the data stored in the minimum write unit is erased, and the target data is written into the head address of the minimum write unit.
In order to avoid frequent erasure of the stored data in the minimum write unit, the battery management system determines whether to perform an erase operation based on the actual storage location of the target data in the memory. Specifically, the battery management system judges whether a data storage address of target data in the memory is a first address of a minimum writing unit of the memory, if so, erases data stored in the corresponding minimum writing unit, and writes the target data in the minimum writing unit; if not, go to step S340.
Step S340, when the data storage address is not the head address of the minimum write unit of the memory, writing the target data into the minimum write unit.
In step S340, when determining that the data storage address of the target data in the memory is not the head address of the minimum write unit of the memory, the battery management system directly writes the target data in the corresponding minimum write unit.
For example, the data storage address is an intermediate address of a minimum write unit of the memory, and the target data is written to the intermediate address of the minimum write unit.
For another example, the data storage address is an end address of the minimum write unit of the memory, and the target data is written into the end address of the minimum write unit.
It can be seen that, compared with the method for reading and writing data that performs stored data erasure each time data is written, the method for reading and writing data disclosed in this embodiment determines the data storage address of the target data in the memory according to the latest index data of the memory, the target data to be written, and the space size of the data area in the memory, and since the data storage address can represent the position of the minimum write unit where the target data is written in the memory, when the data storage address of the target data to be written in the memory is the head address of the minimum write unit in the memory, the data erasure operation is performed on the stored data of the corresponding minimum write unit, and when the data storage address of the target data to be written in the memory is not the head address of the minimum write unit in the memory, the target data to be written is directly written in the corresponding minimum write unit, therefore, the erasing times of the memory can be reduced, and the service life of the memory is prolonged.
Based on the foregoing embodiments, fig. 5 shows an overall schematic diagram of an exemplary data reading and writing method of the present application. In fig. 5, taking a memory as a flash memory flash chip and a minimum write-in unit as a data sector in the flash memory flash chip as an example, a battery management system obtains target data to be written, that is, new data to be written, and calculates a write address, that is, a current flash address, at which the new data is written in the flash memory flash according to a space size of a data storage area in the flash memory flash, a size of the new data, and index data in the flash memory flash, and further determines whether the current flash address is a first address of the data sector in the flash memory flash, if so, erases data stored in the corresponding data sector, and writes the new data in the data sector from which the data is erased; if not, directly writing the new data into the current false address.
Based on the above embodiment, the battery management system may determine the maximum data frame storage amount of the data storage area according to the space size of the data storage area and the length of the unit data frame, determine the stored address range according to the index data, the maximum data frame storage amount, and the length of the unit data frame, and further determine the data storage address of the target data in the memory in step S320 according to the obtained start address of the data storage area in the memory and the stored address range.
The length of a unit data frame refers to the length of a byte of a frame of data, that is, the size of a frame of data. It should be noted that, in order to determine the data storage address, the data size (byte length) is the same for each writing or reading of one frame of data in the embodiments of the present application.
The maximum data frame storage amount of the data storage area refers to the number of data frames which can be stored in the data storage area at most.
The stored address range refers to the size of the storage address occupied by the stored data in the memory. Illustratively, the size of the storage space is 1G, and the stored address range is 100k, which indicates that the stored data occupies the storage address range of 100 k.
The start address of the data storage area refers to the first data storage location of the data storage area, i.e. the first data storage location that can be understood as the first smallest write unit in the data storage area. For example, the data sector in the data storage area of the flash memory chip shown in fig. 4 is taken as an example for explanation, and the start address of the data storage area at this time is the first data storage location in the data sector 1.
It should be noted that the maximum data frame storage amount is specifically obtained by dividing the space size of the data storage area by the length of the unit data frame. The size of the space of the data storage area is calculated by the starting address and the ending address of the data storage area.
The ending address refers to the last data storage location of the data storage area, that is, the last data storage location of the last write-minimizing unit in the data storage area can be understood.
Illustratively, if the start address is denoted as start _ addr 1 The end address is denoted stop _ addr 1 The length of a unit data frame is expressed as data _ size 1 The maximum data frame storage is denoted as max _ num 1 Then the spatial size of the data storage area is represented as (stop _ addr) 1 -start_addr 1 ) Maximum data frame storage
Figure BDA0003737464770000091
It is further noted that the battery management system may be configured to calculate a first remainder value of the index data divided by the maximum data storage amount, and to take a product of the first remainder value and a size of a unit data frame as the stored address range.
The first remainder value refers to a remainder value of the latest index data relative to the maximum data storage amount.
Illustratively, if the latest Index data is expressed as Index 1 The first remainder value is expressed as Index 1 %max_num 1 Where the stored address range is denoted Index 1 %max_num 1 *data_size 1
From the above, the data storage address satisfies the following equation:
addr 1 =start_addr 1 +Index 1 %max_num 1 *data_size 1
wherein addr 1 Indicating the data storage address, Index 1 Denotes the latest index data, max _ num 1 Indicates the maximum data frame storage, Index 1 %max_num 1 Denotes a first remainder value, data _ size 1 Indicating the length of a unit data frame.
It can be seen that, in the data reading and writing method of this embodiment, the maximum data frame storage amount is obtained by dividing the space size of the data storage area obtained by calculating the start address and the end address of the data storage area by the length of a unit data frame, and calculating the first remainder value of the index data by the maximum data storage amount, and further taking the product of the first remainder value and the size of the unit data frame as the stored address range, and then determining the data storage address according to the obtained start address and the stored address range, so that it can be determined whether the target data to be written is the head address of the minimum writing unit of the memory according to the calculated data storage address, and when the data storage address is determined to be the head address of the minimum writing unit, the storage data corresponding to the minimum writing unit is erased, and the target data is written into the minimum writing unit after the storage data is erased, when the data storage address is determined not to be the first address of the minimum write-in unit, the target data is directly written in, so that the data storage frequency is reduced, and the service life of the memory is prolonged.
On the basis of the above embodiment, the embodiment of the present application may further obtain the size of the minimum write unit in the data storage area, and determine whether the data storage address is the first address of the minimum write unit of the memory according to a second remainder obtained by dividing the data storage address by the size of the minimum write unit. Specifically, when the battery management system determines that the value of the second remainder is one, the battery management system determines that the data storage address is the first address of the minimum write unit of the memory.
The second remainder is a remainder value of the data storage address relative to the minimum write unit size.
It can be seen that, in the data writing method according to the embodiment of the present application, the specific storage location in the minimum writing unit where the data storage address is located is determined according to the data storage address and the size of the minimum writing unit, and then when the specific storage location is determined to be the first storage location of the minimum writing unit where the specific storage location is located, the data storage address is determined to be the head address of the minimum writing unit of the memory, so that whether the calculated data storage address is the head address of the data storage area can be accurately determined, and the problem of target data storage errors caused by head address determination errors is avoided.
As an embodiment, before the step of erasing the data stored in the minimum write unit, the method further includes:
judging whether the first address is written with data or not; when the head address has been written with data, performing the step of erasing the data stored in the minimum write unit; when the head address is not written with data, the step of erasing the data stored in the minimum write unit is not performed, and the step of writing the target data in the minimum write unit is performed.
In this embodiment, in order to further reduce the erasing operation on the memory, before the step of erasing the data stored in the minimum writing unit, whether the data is written in the first address is determined by determining whether the data is written in the first address, so as to determine whether to erase the data in the minimum writing unit.
In a specific implementation, whether the head address has written data is judged, data reading operation can be performed according to the head address, if the data is read from the head address, the head address is judged to have written data, and if the data is not read from the head address, if the read content is empty, the head address is judged not to have written data.
In the embodiment, when the head address is written with data, the step of erasing the data stored in the minimum writing unit is performed, so that the target data can be smoothly written into the head address of the minimum writing unit.
Fig. 6 is a flowchart illustrating a data read/write method according to still another exemplary embodiment of the present application. As shown in fig. 6, in an exemplary embodiment, after the step of writing the target data into the minimum write unit, the data writing method of the embodiment of the present application further includes at least steps S610 to S630, which are described in detail as follows:
step S610, updating the index data to obtain updated index data.
In step S610, the updated index data corresponds to the target data, and after the updated index data is written into the index storage area of the memory, the updated index data can be used to index the corresponding target data from the memory.
And after determining that the target data is written into the minimum writing unit, the battery management system updates the index data stored in the memory to obtain updated index data. Note that the index data is stored in the smallest write unit in the index storage area of the memory. Illustratively, if the memory is a Flash memory Flash, the index data is stored in an index sector of the index storage area.
Step S620, determining an index storage address of the updated index data in the memory.
In step S620, the index storage address refers to a storage location of the updated index data in the index storage area of the memory, and specifically may be a storage location in a minimum write unit of the index storage area.
And the battery management system calculates the index storage address of the updated index data in the memory according to the updated index data.
Step S630, when the index storage address is the first address of the minimum write unit in the memory, erasing the index data in the last minimum write unit, and writing the updated index data into the index storage address.
In step S630, the last minimum writing unit is the minimum writing unit in which the index data is located before the updated index data. For example, if the index storage address of the updated index data is the head address of the fourth minimum write unit in the index storage area, the last minimum write unit is the third minimum write unit in the index storage area. For another example, if the index storage address of the updated index data is the first address of the first minimum write unit in the index storage area, the last minimum write unit is the first minimum write unit in the index storage area.
Considering that only one minimum writing unit in the index storage area stores the index data, in order to protect the index storage area and avoid frequent erasure of other minimum writing units in the index storage area, the server in the embodiment of the application erases the index data stored in the last minimum writing unit and writes the updated index data into the index storage address when determining that the obtained index storage address is the head address of the minimum writing unit in the index storage area.
It can be seen that, in the data writing method according to the embodiment of the present application, after it is determined that the target data is written into the corresponding minimum writing unit, the index data in the index storage area is updated, and the index storage address of the updated index data in the memory is determined, when the index storage address is the first address of the index storage area of the memory, the index data in the last minimum writing unit is erased, and the updated index data is written into the index storage address, so that the index storage area can be protected, the problem that other minimum writing units in the index storage area, in which the index data is not stored, are frequently erased is avoided, and the service life of the memory is further prolonged.
On the basis of the above embodiment, the battery management system determines the maximum index data storage amount of the index storage area according to the space size of the index storage area and the size of the unit index data, determines the stored address range according to the index data, the maximum index data storage amount and the size of the unit index data, and further determines the index storage address of the index data updated in step 620 in the memory according to the acquired start address of the index storage area in the memory and the stored address range.
The space size of the index storage area refers to the total storage amount of the index storage area capable of storing index data.
The size of the unit index data refers to the size of preset index data. It should be noted that, in the embodiments of the present application, the data size is the same each time the index data is written or read.
The maximum index data storage amount of the index storage area refers to the number of index data that can be stored in the index storage area at most.
The stored address range refers to the size of the storage address occupied by the stored index data in the memory.
The start address of the index storage area refers to the first index storage location of the index storage area, that is, the first index storage location of the first minimum write unit in the index storage area.
Specifically, the index storage address satisfies the following formula:
addr 2 =start_addr 2 +Index 2 %max_num 2 *data_size 2
wherein addr 2 Indicating the Index storage address, Index 2 Denotes the updated index data, max _ num 2 Indicates the maximum Index data frame storage, Index 2 %max_num 2 Indicating a second remainder value, data _ size 2 Indicating the size of the unit index data.
Based on the above embodiments, fig. 7 shows an overall schematic diagram of another exemplary data read/write method of the present application. In fig. 7, taking the example that the memory is a flash memory flash chip and the minimum write-in unit is an index sector in the flash memory flash chip, the battery management system obtains the latest index data from the flash memory flash chip, calculates an index storage address of the latest index data in the memory according to the latest index data, the maximum index data storage amount, and the size of the unit index data when the latest index data needs to be written, and further determines whether the calculated index storage address is the head address of the minimum write-in unit of the index storage area, if so, erases the index data in the last minimum write-in unit, and writes the latest index data in the index storage address; if not, directly writing the latest index data into the index storage address.
The latest index data is index data updated after data is written in the data storage area. Specifically, the battery management system obtains initial index data from the flash memory after being powered on, and judges whether the obtained initial index data is equal to preset index data, if so, the initial index data is used as the latest index data, and if not, the index data in the index storage area is erased, and the initial index data is used as the latest index data.
The initial index data refers to an index value read from the index storage area after the battery management system is powered on.
The preset index data refers to a preset index value. Specifically, the preset index data may be 0.
The reading and writing method of the embodiment of the application can be seen by judging whether the obtained initial index data is equal to the preset index data, if so, erasing the index data in the index storage area, and taking the initial index data as the latest index data; if not, the initial index data is used as the latest index data, so that the latest index data can be determined based on the acquired initial index data after power-on initialization, and the phenomenon that the acquisition time is increased by traversing the index storage area of the memory to acquire the latest index data is avoided.
After the process of writing the updated index data to the index storage address, the battery management system may perform a verification process on the written data in order to ensure the accuracy of the written data. For example, the battery management system may determine a data difference value according to a data storage address where first written data corresponding to the updated index data in the memory is located, a data storage address where second written data corresponding to the updated index data in the memory is located, and the updated index data, and determine that the updated index data is the latest index data when the data difference value is equal to one. Specifically, the battery management system takes a difference between a data storage address where the first written data is located and a data storage address where the second written data is located as an area address offset, calculates a ratio between the area address offset and a byte length of the updated index data, and then takes a difference between the updated index data and the ratio as a data difference.
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.
The second written data is the current index data stored in the index storage area of the memory corresponding to the second written data, that is, the updated index data, and the updated index data corresponding to the first written data is obtained after the current index data is updated, so that the second written data is the data written at the previous writing time of the first written data. For example, if the second write data is written at the nth time, the first write data is written at the n +1 th time after the nth time.
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 the second write data is written at the nth time, the updated index data is stored in the index storage area of the memory, and then after the first write data is written at the (n + 1) th time, the updated index data stored in the index storage area of the memory is updated, so as to obtain the updated index data corresponding to the first write data.
The local address offset is a difference between a data storage address where the first written data is located and a data storage address where the second written data is located.
The byte length of the updated index data refers to the size of the updated index data.
The ratio refers to a ratio between the area address offset and the size of the unit index data.
The data difference refers to a difference between the updated index data and the ratio.
It should be noted that the data difference satisfies the following formula:
Figure BDA0003737464770000141
where Flash _ offset represents an area address offset amount, sizeof (index) represents a byte length of the updated index data, and index represents the updated index data.
Therefore, the data reading and writing method of the embodiment of the application determines the data difference value according to 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, and further verifies whether the updated index data is the latest index data in the memory according to the data difference value, so that the acquisition accuracy of the latest index data is improved.
Fig. 8 is a block diagram illustrating a data read/write apparatus according to an exemplary embodiment of the present application. The data read-write device can be applied to the implementation environment shown in fig. 1 or fig. 2. The data reading and writing device may also be applied to other exemplary implementation environments, and is specifically configured in other devices, and this embodiment does not limit the implementation environment to which the device is applied.
As shown in fig. 8, the exemplary data read/write apparatus 800 includes: an index data acquisition module 810, a data storage address determination module 820, an erase module 830, and a write module 840. Specifically, the method comprises the following steps:
an index data obtaining module 810 is configured to obtain the latest index data of the memory.
And a data storage address determining module 820 configured to determine a data storage address of the target data in the memory according to the index data, the target data to be written, and a space size of a data storage area in the memory.
The erasing module 830 is configured to erase the data stored in the minimum writing unit and write the target data into the minimum writing unit when the data storage address is a head address of the minimum writing unit of the memory.
The writing module 840 is configured to write the target data into the minimum writing unit when the data storage address is not the head address of the minimum writing unit of the memory.
In the exemplary data reading and writing device, compared with the case of erasing the stored data every time the data is written, the data reading and writing method disclosed by the application determines the data storage address of the target data in the memory according to the latest index data of the memory, the target data to be written and the space size of the data area in the memory, and since the data storage address can represent the position of the minimum writing unit of the target data written in the memory, when the data storage address of the target data to be written in the memory is the first address of the minimum writing unit of the memory, the data erasing operation is performed on the stored data in the corresponding minimum writing unit, and when the data storage address of the target data to be written in the memory is not the first address of the minimum writing unit in the memory, the target data to be written is directly written in the corresponding minimum writing unit, therefore, the erasing times of the memory are reduced, and the service life of the memory is prolonged.
It should be noted that the data reading and writing apparatus provided in the foregoing embodiment and the data reading and writing method provided in the foregoing embodiment belong to the same concept, and specific ways of performing operations by each module and unit have been described in detail in the method embodiment, and are not described herein again. In practical applications, the data reading and writing device provided in the above embodiment may distribute the above functions through different functional modules according to needs, that is, the internal structure of the device is divided into different functional modules to complete all or part of the above described functions, which is not limited herein.
An embodiment of the present application further provides an electronic device, including: one or more processors; a storage device, configured to store one or more programs, and when the one or more programs are executed by the one or more processors, enable the electronic device to implement the data reading and writing method provided in each of the above embodiments.
FIG. 9 illustrates a schematic structural diagram of a computer system suitable for use in implementing the electronic device of an embodiment of the present application. It should be noted that the computer system 900 of the electronic device shown in fig. 9 is only an example, and should not bring any limitation to the functions and the scope of the application of the embodiments.
As shown in fig. 9, the computer system 900 includes a Central Processing Unit (CPU)901, which can perform various appropriate actions and processes, such as performing the data Read-write method described in the above embodiments, according to a program stored in a Read-Only Memory (ROM) 902 or a program loaded from a storage portion 908 into a Random Access Memory (RAM) 903. In the RAM 903, various programs and data necessary for system operation are also stored. The CPU 901, ROM 902, and RAM 903 are connected to each other via a bus 904. An Input/Output (I/O) interface 905 is also connected to bus 904.
The following components are connected to the I/O interface 905: an input portion 906 including a keyboard, a mouse, and the like; an output section 907 including a Cathode Ray Tube (CRT), a Liquid Crystal Display (LCD), and the like, a speaker, and the like; a storage portion 908 including a hard disk and the like; and a communication section 909 including a Network interface card such as a LAN (Local Area Network) card, a modem, or the like. The communication section 909 performs communication processing via a network such as the internet. The drive 910 is also connected to the I/O interface 905 as necessary. A removable medium 911 such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, or the like is mounted on the drive 910 as necessary, so that a computer program read out therefrom is mounted into the storage section 908 as necessary.
In particular, according to embodiments of the present application, the processes described above with reference to the flow diagrams may be implemented as computer software programs. For example, embodiments of the present application include a computer program product comprising a computer program embodied on a computer readable medium, the computer program comprising a computer program for performing the method illustrated by the flow chart. In such an embodiment, the computer program may be downloaded and installed from a network through the communication section 909, and/or installed from the removable medium 911. The computer program executes various functions defined in the system of the present application when executed by a Central Processing Unit (CPU) 901.
It should be noted that the computer readable medium shown in the embodiments of the present application may be a computer readable signal medium or a computer readable storage medium or any combination of the two. The computer readable storage medium may be, for example, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the foregoing. More specific examples of the computer readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a Read-Only Memory (ROM), an Erasable Programmable Read-Only Memory (EPROM), a flash Memory, an optical fiber, a portable Compact Disc Read-Only Memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the present application, a computer-readable signal medium may comprise a propagated data signal with a computer-readable computer program embodied therein, either in baseband or as part of a carrier wave. Such a propagated data signal may take many forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device. The computer program embodied on the computer readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wired, etc., or any suitable combination of the foregoing.
The flowchart and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present application. Each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams or flowchart illustration, and combinations of blocks in the block diagrams or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
The units described in the embodiments of the present application may be implemented by software, or may be implemented by hardware, and the described units may also be disposed in a processor. Wherein the names of the elements do not in some way constitute a limitation on the elements themselves.
Another aspect of the present application also provides a computer-readable storage medium, on which a computer program is stored, which, when executed by a processor, implements the flash memory based read-write method as described above. The computer-readable storage medium may be included in the electronic device described in the above embodiment, or may exist alone without being assembled into the electronic device.
Another aspect of the application also provides a computer program product or computer program comprising computer instructions stored in a computer readable storage medium. The processor of the computer device reads the computer instructions from the computer-readable storage medium, and executes the computer instructions, so that the computer device executes the flash memory based read-write method provided in the above embodiments.
The above description is only a preferred exemplary embodiment of the present application, and is not intended to limit the embodiments of the present application, and one of ordinary skill in the art can easily make various changes and modifications according to the main concept and spirit of the present application, so that the protection scope of the present application shall be subject to the protection scope of the claims.

Claims (10)

1. A method for reading and writing data, comprising:
acquiring the latest index data of a memory;
determining a data storage address of the target data in the memory according to the index data, the target data to be written and the space size of a data storage area in the memory;
when the data storage address is the head address of the minimum writing unit of the memory, erasing the data stored in the minimum writing unit, and writing the target data into the minimum writing unit;
and when the data storage address is not the head address of the minimum writing unit of the memory, writing the target data into the minimum writing unit.
2. The method according to claim 1, wherein the step of determining the data storage address of the target data in the memory according to the index data, the target data to be written and the space size of the data storage area comprises:
acquiring a starting address of a data storage area in the memory;
determining 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 a unit data frame;
determining a stored address range according to the index data, the maximum data frame storage capacity and the length of the unit data frame; and
determining the data storage address according to the start address and the stored address range.
3. The method of claim 2, wherein the step of determining 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 a unit data frame comprises:
calculating the space size of the data storage area according to the starting address and the ending address of the data storage area;
and dividing the space size of the data storage area by the length of the unit data frame to obtain the maximum data frame storage capacity.
4. The method of claim 2, wherein determining the stored address range based on the index data, the maximum data frame storage amount, and the length of the unit data frame comprises:
calculating a first remainder value of the index data divided by the maximum data storage amount;
taking a product between the first remainder value and the size of the unit frame of data as the stored address range.
5. The method of claim 2, further comprising:
acquiring the size of the minimum writing unit in the data storage area;
calculating a second remainder obtained by dividing the data storage address by the size of the minimum writing unit;
and when the value of the second remainder is one, confirming that the data storage address is the first address of the minimum writing unit of the memory.
6. The method of claim 1, wherein after the step of writing the target data into the minimum write unit, the method further comprises:
updating the index data to obtain updated index data, wherein the updated index data corresponds to the target data;
determining an index storage address of the updated index data in the memory;
and when the index storage address is the first address of the minimum writing unit in the memory, erasing the index data in the last minimum writing unit, and writing the updated index data into the index storage address.
7. The method of claim 6, wherein the step of determining the index storage address of the updated index data in the memory comprises:
acquiring a starting address of an index storage area in the memory;
determining the maximum index data storage capacity of the index storage area according to the space size of the index storage area and the size of unit index data;
determining a stored address range according to the index data, the maximum index data storage capacity and the size of the unit index data; and
and determining the index storage address according to the starting address and the stored address range.
8. The method of claim 1, further comprising, prior to the step of erasing the data stored in the minimum write unit:
judging whether the first address is written with data or not;
when the head address has been written with data, performing the step of erasing the data stored in the minimum write unit;
when the head address is not written with data, the step of erasing the data stored in the minimum write unit is not performed, and the step of writing the target data in the minimum write unit is performed.
9. An electronic device, comprising:
a memory storing computer readable instructions;
a processor to read computer readable instructions stored by the memory to perform the method of any of claims 1-8.
10. A computer-readable storage medium having computer-readable instructions stored thereon, which, when executed by a processor of a computer, cause the computer to perform the method of any one of claims 1-8.
CN202210808127.0A 2022-07-08 2022-07-08 Data reading and writing method, electronic equipment and computer readable storage medium Pending CN115129257A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202210808127.0A CN115129257A (en) 2022-07-08 2022-07-08 Data reading and writing method, electronic equipment and computer readable storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202210808127.0A CN115129257A (en) 2022-07-08 2022-07-08 Data reading and writing method, electronic equipment and computer readable storage medium

Publications (1)

Publication Number Publication Date
CN115129257A true CN115129257A (en) 2022-09-30

Family

ID=83383574

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202210808127.0A Pending CN115129257A (en) 2022-07-08 2022-07-08 Data reading and writing method, electronic equipment and computer readable storage medium

Country Status (1)

Country Link
CN (1) CN115129257A (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116149577A (en) * 2023-04-24 2023-05-23 杭州炬华科技股份有限公司 Data processing method, system and readable storage medium based on rotary pool
CN117093541A (en) * 2023-08-18 2023-11-21 北京天华星航科技有限公司 Data extraction and archiving system for remote sensing data

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116149577A (en) * 2023-04-24 2023-05-23 杭州炬华科技股份有限公司 Data processing method, system and readable storage medium based on rotary pool
CN116149577B (en) * 2023-04-24 2023-07-07 杭州炬华科技股份有限公司 Data processing method, system and readable storage medium based on rotary pool
CN117093541A (en) * 2023-08-18 2023-11-21 北京天华星航科技有限公司 Data extraction and archiving system for remote sensing data
CN117093541B (en) * 2023-08-18 2024-02-23 北京天华星航科技有限公司 Data extraction and archiving system for remote sensing data

Similar Documents

Publication Publication Date Title
CN111090628B (en) Data processing method and device, storage medium and electronic equipment
CN115129257A (en) Data reading and writing method, electronic equipment and computer readable storage medium
CN109766362B (en) Data processing method and device
CN110765076B (en) Data storage method, device, electronic equipment and storage medium
CN108255989B (en) Picture storage method and device, terminal equipment and computer storage medium
CN108932286B (en) Data query method and device
CN110046175B (en) Cache updating and data returning method and device
CN111177143A (en) Key value data storage method and device, storage medium and electronic equipment
CN109918381B (en) Method and apparatus for storing data
CN105653539A (en) Index distributed storage implement method and device
CN114461691A (en) Control method and device of state machine, electronic equipment and storage medium
CN106156038B (en) Date storage method and device
CN111143240B (en) Image storage method, system and terminal equipment
CN113064919A (en) Data processing method, data storage system, computer device and storage medium
CN110674050B (en) Memory out-of-range detection method and device, electronic equipment and computer storage medium
CN107257281B (en) Method, apparatus and computer readable storage medium for NOR F L ASH storage key record
CN115576484A (en) Data reading and writing method and device, electronic equipment and storage medium
CN113127438B (en) Method, apparatus, server and medium for storing data
CN110045929B (en) Mounting point management method and related device
CN110070479B (en) Method and device for positioning image deformation dragging point
CN112882659A (en) Information obtaining method and device, electronic equipment and storage medium
CN110390291B (en) Data processing method and device and electronic equipment
CN110648208B (en) Group identification method and device and electronic equipment
CN109491620B (en) Storage data rewriting method, device, server and storage medium
CN112291276B (en) Flow alarm method and device and electronic equipment

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination