CN106407050B - Data storage method - Google Patents

Data storage method Download PDF

Info

Publication number
CN106407050B
CN106407050B CN201610910741.2A CN201610910741A CN106407050B CN 106407050 B CN106407050 B CN 106407050B CN 201610910741 A CN201610910741 A CN 201610910741A CN 106407050 B CN106407050 B CN 106407050B
Authority
CN
China
Prior art keywords
data
storage area
area
backup
storage
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.)
Active
Application number
CN201610910741.2A
Other languages
Chinese (zh)
Other versions
CN106407050A (en
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.)
Kehua Data Co Ltd
Xiamen Kehua Digital Energy Tech Co Ltd
Original Assignee
Xiamen Kehua Hengsheng Co 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 Xiamen Kehua Hengsheng Co Ltd filed Critical Xiamen Kehua Hengsheng Co Ltd
Priority to CN201610910741.2A priority Critical patent/CN106407050B/en
Publication of CN106407050A publication Critical patent/CN106407050A/en
Application granted granted Critical
Publication of CN106407050B publication Critical patent/CN106407050B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/07Responding to the occurrence of a fault, e.g. fault tolerance
    • G06F11/14Error detection or correction of the data by redundancy in operation
    • G06F11/1402Saving, restoring, recovering or retrying
    • G06F11/1446Point-in-time backing up or restoration of persistent data
    • G06F11/1448Management of the data involved in backup or backup restore
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/07Responding to the occurrence of a fault, e.g. fault tolerance
    • G06F11/08Error detection or correction by redundancy in data representation, e.g. by using checking codes
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/07Responding to the occurrence of a fault, e.g. fault tolerance
    • G06F11/14Error detection or correction of the data by redundancy in operation
    • G06F11/1402Saving, restoring, recovering or retrying
    • G06F11/1446Point-in-time backing up or restoration of persistent data
    • G06F11/1458Management of the backup or restore process
    • G06F11/1469Backup restoration techniques
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F12/00Accessing, addressing or allocating within memory systems or architectures
    • G06F12/02Addressing or allocation; Relocation
    • G06F12/0223User address space allocation, e.g. contiguous or non contiguous base addressing
    • G06F12/023Free address space management
    • G06F12/0238Memory management in non-volatile memory, e.g. resistive RAM or ferroelectric memory
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F12/00Accessing, addressing or allocating within memory systems or architectures
    • G06F12/02Addressing or allocation; Relocation
    • G06F12/06Addressing a physical block of locations, e.g. base addressing, module addressing, memory dedication
    • G06F12/0646Configuration or reconfiguration

Abstract

The invention relates to a data storage method, which comprises the steps of providing a main storage area, a backup storage area, an index area, a data temporary storage area, a time temporary storage area, a main check area and a backup check area; the method comprises the following steps: erasing the main storage area and the backup storage area, writing current time information in the time temporary storage area, and writing an initial offset in a current index unit in the index area; writing the acquired data to be stored into a data temporary storage area; calculating a storage offset corresponding to the current time information; calculating a write address of the data to be stored in the main storage area, and writing the data to be stored in the main storage area: and calculating the backup address stored in the backup storage area by mapping the writing address, and writing the data to be stored into the backup storage area according to the backup address. The data storage method provided by the invention realizes data storage, real-time updating and regular storage with large data volume.

Description

Data storage method
Technical Field
The invention relates to the field of electric digital data processing, in particular to a data storage method.
Background
In industrial production, various parameters are required to be continuously recorded and stored, continuous historical data is generated, and technical and management personnel are provided with data for analyzing and researching. However, many working conditions and environments are not good, and the data storage process is interrupted due to the inevitable accidental power failure of the memory in the storage process, and particularly for the flash memory used as a storage medium, the accidental power failure may cause errors of the stored historical data. The flash memory is a common storage medium and has the characteristics of power-down storage, large storage space and low cost. The steps of the repeated write operation to the flash memory are generally: the method comprises the steps of firstly obtaining data of a sector where a destination address is located, then replacing the data of the destination address in the whole sector with data to be written, integrating old data and the data to be written, and finally writing the integrated data into a flash memory. Because the read-write speed of the flash memory is slow and the flash memory is subjected to the operation of erasing first and then writing, if abnormal conditions such as unexpected power failure and the like occur in the writing process, the original data can be damaged. In addition, the flash memory has a limited erasing life, some memory blocks become unstable or fail to store gradually as the number of times of erasing increases, and the flash memory is limited by the service life when data needs to be stored in real time. In order to realize real-time data storage, a ferroelectric memory with high writing speed and unlimited erasing times is generally adopted for data storage, but the cost of the memory is high, and when a large amount of data needs to be stored, the cost is greatly increased.
In industrial application, all real-time data is not required to be recorded and reserved at many times, and parameters are sampled and recorded at a certain sampling period. Some parameters are sampled in real time, but the stored data are stored after the sampled data in a certain period are processed. For example, a photovoltaic grid-connected inverter is concerned about daily power generation more than the change situation of real-time power generation, so that real-time sampling and statistics of power generation are required, and the statistical daily power generation is stored at the end of each day. The data volume of the photovoltaic grid-connected inverter is basically required to be guaranteed for 20-25 years, and the data volume is not small. The invention provides a data storage device and a data storage method which are suitable for data storage devices which need to be updated in real time and are stored regularly and have large data volumes.
Disclosure of Invention
The invention aims to provide a data storage method to overcome the defects in the prior art.
In order to achieve the purpose, the technical scheme of the invention is as follows: a data storage method, provide a main memory area including multiple memory blocks, a backup memory area used for backing up the data of the said main memory area, an index area including at least one index unit, a data temporary storage area used for temporarily storing the data to be stored; the method is realized according to the following steps:
step S12: acquiring data to be stored, and writing the data into the data temporary storage area;
step S13: calculating a storage offset corresponding to the current time information;
step S14: calculating a write address of the data to be stored in the main storage area according to the following mode, and writing the data to be stored in the main storage area according to the write address:
the write address = the starting address of the main memory area + the starting offset stored in the current index unit + the storage offset;
step S15: calculating the backup address of the writing address mapping in the backup storage area according to the following mode, and writing the data to be stored into the backup storage area according to the backup address:
the backup address = the starting address of the backup storage area + the starting offset stored in the current index unit + the storage offset;
the index unit is configured to store a start offset of the storage block, and the current time information includes a storage tag used to tag a storage period and a time tag used to tag a sampling time sequence number corresponding to the data to be stored.
Further, before data storage is performed by initial power-on, initialization is performed according to the following steps S110 to S113:
step S110: erasing the main storage area and the backup storage area;
step S111: reading the initial address of a storage block of the main storage area, which is not written with data, and writing a storage mark of the current time information into the initial address;
step S112: calculating the initial offset of the initial address of the current storage block of the main storage area relative to the initial address of the main storage area, and writing the initial offset into the current index unit;
step S113: calculating the backup address of the backup storage area mapped by the starting address of the current storage block of the main storage area as follows, and writing the storage mark into the backup address:
backup address = the starting address of the backup storage area + the starting offset stored by the current index unit.
Further, a time buffer for storing time information is provided, and the step S110 further includes:
acquiring current time information and writing the current time information into a time temporary storage area;
after the step S15, the method further includes the following steps:
step S16: and acquiring the current time information and writing the current time information into a time temporary storage area.
Further, the step S12 specifically includes the following steps S121 to S122:
step S121: judging whether the storage flag of the current time information is consistent with the storage flag of the time information stored in the time temporary storage area, if so, executing step S122, otherwise, jumping to execute the steps S13 to S16, and executing the steps S111 to S113 after step S16;
step S122: judging whether the time stamp of the current time information is consistent with the time stamp of the time information stored in the time temporary storage area, if so, acquiring the data to be stored, writing the data into the data temporary storage area, and repeatedly executing the step S122; otherwise, jumping to execute the step S13 to the step S16.
Further, a main check area for storing the check code of the main storage area and a backup check area for storing the check code of the backup storage area are also provided;
in step S14, writing the data to be stored into the write address, or in step S111, writing the current storage flag into the start address, and further calculating a check code of the primary storage area; if the check is correct, writing the check code into the main check area, otherwise erasing the main storage area and the main check area, writing the data stored in the backup storage area into the corresponding address of the main storage area, and writing the check code of the backup check area into the main check area;
in step S15, writing the data to be stored into a backup address, or in step S113, writing a current storage flag into a backup address, and further calculating a check code of the backup storage area; if the check is correct, the check code is written into the backup check area, otherwise, the backup storage area and the backup check area are erased, the data stored in the main storage area is written into the corresponding address of the backup storage area, and the check code of the main check area is written into the backup check area.
Further, the index unit points to the next index unit in a circular circulation mode.
Further, in step S13, the method of calculating the storage offset corresponding to the current time information is as follows: storage offset = n1+ n2 (timestamp-1) +1, where n1 is the byte length of the storage marker, n2 is the byte length of the data to be stored, and n1, n2 are both positive integers.
Further, the time information includes year, month and date, the storage flag is year, and the time flag = month × 31+ date.
Further, the main storage area and the backup storage area adopt nor flash memories, and the index area, the data temporary storage area and the time temporary storage area adopt ferroelectric memories; and the main verification area and the backup verification area both adopt ferroelectric memories.
Further, when the storage process is interrupted unexpectedly, the data storage method after power-on is implemented according to the following steps S21 to S24:
step S21: reading the data stored in the main storage area, and recalculating the check code of the main storage area;
step S22: judging whether the recalculated check code is consistent with the check code stored in the main check area, if so, erasing the backup storage area and the backup check area, writing the data stored in the main storage area into the corresponding address of the backup storage area, writing the check code in the main check area into the backup check area, and skipping to execute the step S12 to continue to store the data; if not, go to step S23;
step S23: reading the data stored in the backup storage area, and recalculating the check code of the backup storage area;
step S24: judging whether the recalculated check code is consistent with the check code stored in the backup check area, if so, erasing the main storage area and the main check area, writing the data stored in the backup storage area into the corresponding address of the main storage area, writing the check code which is the backup check area into the main check area, skipping to execute the step S12, and continuing to store the data; if the data are inconsistent, the data cannot be recovered, and initialization is carried out according to the steps during initial power-on storage.
Compared with the prior art, the invention has the following beneficial effects:
(1) the storage address of the data in the main storage area or the backup storage area is closely related to the sampling time of the data, the sampling time corresponding to the data stored in any storage unit can be acquired by reverse-pushing according to the calculation rule of the storage offset, the written data does not contain specific sampling time, the storage space is saved, and meanwhile, the reading and the restoring of the data are not influenced. Taking time information including year, month and date as an example, storing all data in one year in the same storage block by taking the year as a storage mark, and writing the year information into the storage block; the data of every other day is transferred to the corresponding storage address of the main storage area or the backup storage area according to the month and the date of the current time, the storage address corresponding to the main storage area/the backup storage area in a certain day is fixed, when the data of the year is read, the storage block corresponding to the year is read in the main storage area, the month and the date corresponding to the data can be restored according to the storage address of the certain data, the specific month and date do not need to be written, the storage space is saved, and the later data restoration is not influenced.
(2) The invention adopts two identical but independent sectors of a main storage area and a backup storage area to store data in a time-sharing way, the data are firstly stored in the main storage area and then written into the backup storage area, the main storage area and the backup storage area form identical storage data which are mutually backed up, power is cut off at any time in the erasing and writing process of the sectors, the data stored in at least the main storage area or the backup storage area are ensured to be effective, one storage area can be used for carrying out data recovery on the other storage area, and a data structure that the main storage area and the backup storage area are mutually backed up is reestablished.
(3) The invention adopts the ferroelectric memory and the Nor Flash memory at the same time, utilizes the characteristics that the ferroelectric memory is erased and written for unlimited times and can be stored in a power-down mode to carry out real-time storage, makes up the defect that the Nor Flash memory is erased and written for limited times, utilizes the characteristics that the Nor Flash memory has large storage space and low cost to carry out large-data-volume storage, makes up the defect that the Nor Flash memory has high cost, and can simultaneously meet the requirements of real-time storage and large-data-volume storage by complementing the Nor Flash memory and the.
(4) And a check area is respectively configured for the main storage area and the backup storage area, and each write-in data is checked when being written into the main storage area or the backup storage area, so that each write-in data is correct, and meanwhile, whether the data stored in the main storage area or the backup storage area is wrong can be judged by using a check code stored in the check area.
Drawings
FIG. 1 is a schematic diagram of a data storage device of the present invention.
FIG. 2 is a flow chart of a data storage method according to the present invention.
Detailed Description
The technical scheme of the invention is specifically explained below with reference to the accompanying drawings.
In the present embodiment, the data storage device and the storage method proposed by the present invention are described in detail by taking the daily power generation amount of the photovoltaic system as an example, so as to make the inventive concept of the present invention more clearly and clearly understood by those skilled in the art.
The invention provides a data storage method and also provides a data storage device, as shown in fig. 1, comprising a main storage area, a backup storage area, an index area, a data temporary storage area, a time temporary storage area, a main check area and a backup check area. The main storage area and the backup storage area adopt a nor flash memory and are used for storing data which are acquired by a sensor or other modes and need to be stored for a long time. In this embodiment, the daily power generation amount is the daily power generation amount of the photovoltaic system; the index area, the data temporary storage area, the time temporary storage area, the main verification area and the backup verification area adopt ferroelectric memories which are used for storing data which needs to be continuously updated and repeatedly erased in the whole data acquisition period.
Further, in this embodiment, the main storage area includes a plurality of storage blocks with the same address length, the backup storage area and the main storage area form a storage block structure with the same address length, and the storage blocks are used for storing data to be stored in one storage cycle. In this embodiment, each storage block is used to store sampled data in a time period of year, and the address length of each storage block is greater than the maximum address length required by data to be stored in a year, so that the data block is not covered, and all data in the year can be completely reproduced.
Further, in this embodiment, the index area includes at least one index unit, the index unit is configured to store a start offset of a start address of a storage block of the main storage area relative to a start address of the main storage area, and the index unit points to a next index unit in a circular loop manner; in this embodiment, 20 index units are provided, which are respectively used for writing the start addresses of 20 memory blocks in the main memory area, and can overwrite the start addresses of different memory blocks.
Further, in this embodiment, the data temporary storage area is used for temporarily storing the data to be stored. In this embodiment, the data to be stored is the daily power generation amount accumulated at the current time.
Further, in this embodiment, the time buffer is used to store time information of the sampling time corresponding to the data to be stored. It should be noted that the sampling time may include information of year, month, date, hour, minute, second, etc., or even smaller time units according to actual needs, and the time information stored in the time buffer includes a storage flag for marking one storage period and a time flag for marking a sampling time serial number of the current data to be stored. In this embodiment, the storage period is one year, the storage flag is a corresponding year, the sampling period is 1 day, and the time flag is a month and a date, and more specifically, the current date may correspond to the number of days in the year. The sampling time sequence number represents a sequence number of a sampling period corresponding to the current data to be stored in the storage period, that is, represents that the current data to be stored is the data sampled for the second time.
Further, in this embodiment, the main verification area and the backup verification area are respectively used for storing the verification code of the main storage area and the verification code of the backup storage area.
Further, in this embodiment, the storage units that need to be erased repeatedly, such as the index area, the data temporary storage area, the time temporary storage area, the main verification area, the backup verification area, and the like, adopt a ferroelectric memory, the main storage area and the backup storage area are used for storing a large number of data storage units and adopt a Nor Flash memory, the characteristics that the ferroelectric memory is erased for unlimited times and can be stored in a power-down mode are used for real-time storage, the defect that the erasing times of the Nor Flash memory are limited is overcome, the characteristics that the Nor Flash memory is large in storage space and low in cost are used for large-volume data storage, the defect that the Nor Flash memory is high in cost is overcome, the advantages of the two are combined, the defects are complemented, and the cost is controlled on the premise.
Further, in this embodiment, the data storage method provided by the present invention, as shown in fig. 2, specifically includes the following steps:
it should be noted that the following time information includes a storage flag and a time flag, in this embodiment, the daily power generation amount of the photovoltaic system is used as a storage object, the time information includes a year, a month, and a date, where the year is the storage flag, and the time flag includes the month and the date, for example, the current date is 2016, 9, 20, and the storage flag is 2016, and the time flag is month 31+ date, specifically 9 × 31+20= 299. It should be noted that the default month is calculated by 31 days per month to simplify the calculation and ensure that each sampling time has a corresponding memory cell, ensuring data integrity.
Before data storage is carried out by initial power-on, initialization is carried out according to the following steps S110 to S113:
step S110: erasing the main storage area and the backup storage area; acquiring current time information and writing the current time information into a time temporary storage area;
step S111: reading the initial address of a storage block of the main storage area, wherein data is not written in the storage block, and writing the current storage mark, namely the current year, into the initial address; assuming that the memory block is the first data block of the main memory area, and the start address of the memory block is Ox0000, that is, the start address of the main memory area, the current year is written into the memory unit with the address of Ox 0000;
step S112: calculating the initial offset of the initial address of the current storage block of the main storage area relative to the initial address of the main storage area, and writing the initial offset into the current index unit; based on step S111, the calculated starting offset amount is 0;
step S113, mapping the initial address of the current storage block of the main storage area to the backup address of the backup storage area, wherein the backup address = the initial address of the backup storage area + the initial offset stored in the current index unit, and writing the storage mark into the backup address; assuming that the starting address of the backup storage area is Ox8000, the backup address is Ox 8000;
the initialization process of the initial power-on is completed.
Step S12: acquiring data to be stored, and writing the data into a data temporary storage area;
step S12 specifically includes the following steps S121 to S122:
step S121: judging whether the storage mark of the current time information is consistent with the storage mark of the time information stored in the time temporary storage area, if so, executing step S122, namely, reacquiring the data to be stored, writing the data into the data temporary storage area and acquiring the corresponding time information; otherwise, the jump is executed from step S13 to step S16 to complete the storage of the data to be stored, and after step S16, the jump is executed from step S111 to step S113 to re-read one of the storage blocks of the primary storage area where no data is written, complete the storage of the storage marks in the primary storage area and the backup storage area, and write the start offset in the next index unit to prepare for writing the data to be stored into the new storage block.
Step S122: judging whether the time mark of the current time information is consistent with the time mark of the time information stored in the time temporary storage area, if so, indicating that the next sampling time is not reached, in this embodiment, that is, the day is not finished, acquiring the data to be stored, writing the data into the data temporary storage area, and repeatedly executing the step S122; otherwise, the step S13 is skipped.
As in the above steps S111 to S113, writing of the storage mark to the start address of one of the storage blocks of the main/backup storage areas is realized, and in S121 to S122, it is ensured that the data having the same storage mark is stored in the same storage block, facilitating the reading and restoring of the data.
Step S13: calculating a storage offset corresponding to the current time information; preferably, the storage offset = n1+ n2 (month 31+ date-1) +1, where n1 is the byte length of the storage flag, n2 is the byte length of the data to be stored, and n1 and n2 are both positive integers.
The storage address of the data in the main storage area or the backup storage area is related to the sampling time of the data, the sampling time corresponding to the data stored in any storage unit can be acquired by reverse-pushing according to the calculation rule of the storage offset, the written data does not contain specific sampling time, the storage space is saved, and meanwhile, the reading and the restoring of the data are not influenced. Taking time information including year, month and date as an example, the year is a storage mark, the month and the date are used as time marks, all data in the same year are stored in the same storage block, the storage block only stores data of one year, and the year information is written into the storage block; the month and the date are used as time marks, the data of every other day are transferred to the main storage area or the backup storage area, the writing address of each data in the main storage area is related to the corresponding month and date, the storage address corresponding to the main storage area/the backup storage area in a certain day of the year is fixed, when the data of the year is read, the storage block corresponding to the year is read in the main storage area, the month and the date corresponding to the data can be restored according to the storage address of the certain data, the specific month and date do not need to be written, the storage space is saved, and the data restoration in the later period is not influenced.
Step S14: calculating a write address of the current data to be stored in the main storage area, wherein the write address = an initial address of the main storage area + an initial offset stored in the current index unit + a storage offset, and writing the data to be stored in the write address;
step S15: calculating a backup address stored in a backup storage area by the current data to be stored, wherein the backup address = an initial address of the backup storage area + an initial offset stored in a current index unit + a storage offset, and writing the data to be stored in the backup address;
step S16: acquiring the current time information, writing the current time information into the time temporary storage area, erasing the data temporary storage area, and jumping to execute step S12 to start storing the next data to be stored.
As in the above S11-S16, writing data into the primary storage area for storage and writing the data into the backup address of the backup storage area for data backup storage are realized. Before data storage, the main storage area and the backup storage area are two storage areas with completely same storage block structures and empty contents, and after data storage, the main storage area and the backup storage area can form two storage areas with same stored data contents.
As in S14, writing the data to be stored into the write address or writing the current storage flag into the start address in S111, calculating the check code of the main storage area, writing the check code into the main check area if the check is correct, otherwise erasing the main storage area and the main check area, writing the data content stored in the backup storage area into the corresponding address of the main storage area, so that the main storage area forms the data content completely consistent with the backup storage area, and writing the check code stored in the backup check area into the main check area. The specific correspondence relationship of the data content stored in the backup storage area at the corresponding address of the main storage area is as follows: the corresponding address of the main storage area = backup address of the backup storage area- (start address of backup storage area-start address of main storage area).
As in S15, writing the data to be stored into the backup address or writing the current storage flag into the backup address in S113, calculating the check code of the backup storage area, writing the check code into the backup check area if the check is correct, or erasing the backup storage area and the backup check area, writing the data content stored in the main storage area into the corresponding address of the backup storage area, so that the backup storage area forms a data structure completely consistent with the main storage area, and writing the check code stored in the main check area into the backup check area. The specific correspondence relationship of the data content stored in the main storage area at the corresponding address of the backup storage area is as follows: the corresponding address of the backup memory area = backup address + of the main memory area (starting address of the backup memory area-starting address of the main memory area).
When data is written in the main storage area/the backup storage area, the written data is verified every time, and it is guaranteed that each written data is correct. In this embodiment, the verification is performed by calculating the sum of the data in the main storage area and the data in the backup storage area. Taking the write address of the data to be stored written into the main storage area as an example, the verification method is as follows: before the data to be stored is written in, the check code in the check area is taken out, an original check code is calculated with the data to be stored for standby, and after the data to be stored is written in, the data in the main storage area is read out to calculate a new check code; if the two check codes are consistent, the check codes are correctly checked and written into the check area, otherwise, the check is wrong, namely, the data writing process is wrong. The verification mode when writing data in the backup storage area is the same as the above verification mode.
When the storage process is interrupted unexpectedly, the data storage method after power-up is realized according to the following steps S21 to S24:
step S21: reading data stored in the main storage area and recalculating the check code of the main storage area; the method for calculating the check code is consistent with the method for calculating the check code when data is written
Step S22: judging whether the recalculated check code is consistent with the check code stored in the main check area, if so, indicating that the data stored in the main memory area is valid, erasing the backup memory area and the backup check area, writing the data stored in the main memory area into the corresponding address of the backup memory area, writing the check code in the main check area into the backup check area, and skipping to execute the step S12 to continue to store the data; if the data in the main storage area is not consistent with the data in the main storage area, the step S23 is executed;
step S23: reading data stored in the backup storage area and recalculating the check code of the backup storage area;
step S24: judging whether the recalculated check code is consistent with the check code stored in the backup check area, if so, indicating that the data stored in the main storage area is valid, erasing the main storage area and the main check area, writing the data stored in the backup storage area into the corresponding address of the main storage area, writing the check code of the backup check area into the main check area, and skipping to execute the step S12 to continue to store the data; if the data in the main storage area and the data in the backup storage area are inconsistent, the data in the main storage area and the data in the backup storage area are both damaged, and the data cannot be recovered by adopting a software mode, but the occurrence probability of the situation is extremely low; if this occurs, initialization may be performed according to the procedure when the memory was first powered up.
In this embodiment, after the power is turned on again, the check code is recalculated in the same check mode as that in the case where the data is written into the main storage area or the backup storage area, and the check code is compared with the check code stored in the main check area or the backup check area, to verify whether the data is destroyed due to storage interruption, and perform data recovery of the storage area according to the data of the other storage area, and reestablish two data to complete the same storage area. And ensuring that the data of the main storage area and the backup storage area are consistent and then storing new data.
The above is a preferred embodiment of the present invention, and all changes made according to the technical scheme of the present invention, such as modifying the above-mentioned data stored every other day to be stored once in 1 hour or 2 days or in other time periods, or modifying the above-mentioned one storage block to be used for storing data of one year to be stored in other time periods, or using the data storage device or the data storage method of the present invention in other fields to store other parameters, belong to the protection scope of the present invention when the generated functional effects do not exceed the scope of the technical scheme of the present invention.

Claims (9)

1. A data storage method is characterized in that a main storage area comprising a plurality of storage blocks, a backup storage area for backing up data of the main storage area, an index area comprising at least one index unit and a data temporary storage area for temporarily storing data to be stored are provided, the main storage area and the backup storage area are two same and independent sectors, and the storage blocks of the main storage area and the storage blocks of the backup storage area are completely the same and are in one-to-one correspondence; the method is realized according to the following steps:
step S12: acquiring data to be stored, and writing the data into the data temporary storage area;
step S13: calculating a storage offset corresponding to the current time information;
step S14: calculating a write address of the data to be stored in the main storage area according to the following mode, and writing the data to be stored in the main storage area according to the write address:
the write address = the starting address of the main memory area + the starting offset stored in the current index unit + the storage offset;
step S15: calculating the backup address of the writing address mapping in the backup storage area according to the following mode, and writing the data to be stored into the backup storage area according to the backup address:
the backup address = the starting address of the backup storage area + the starting offset stored in the current index unit + the storage offset;
the index unit is used for storing the initial offset of the storage block, and the current time information comprises a storage mark for marking a storage period and a time mark for marking a sampling time sequence number corresponding to the data to be stored;
the index area, the data temporary storage area, the time temporary storage area, the main verification area and the backup verification area adopt memories which are unlimited in times and can be stored in a power-down mode, and the main storage area and the backup storage area adopt memories which are large in storage space and low in cost;
in step S13, the method of calculating the storage offset corresponding to the current time information is as follows: storage offset = n1+ n2 (timestamp-1) +1, where n1 is the byte length of the storage marker, n2 is the byte length of the data to be stored, and n1, n2 are both positive integers.
2. A data storage method as claimed in claim 1, wherein before the data storage is performed by first powering on, the initialization is performed according to the following steps:
step S110: erasing the main storage area and the backup storage area;
step S111: reading the initial address of a storage block of the main storage area, which is not written with data, and writing a storage mark of the current time information into the initial address;
step S112: calculating the initial offset of the initial address of the current storage block of the main storage area relative to the initial address of the main storage area, and writing the initial offset into the current index unit;
step S113: calculating the backup address of the backup storage area mapped by the starting address of the current storage block of the main storage area as follows, and writing the storage mark into the backup address:
backup address = the starting address of the backup storage area + the starting offset stored by the current index unit.
3. A data storage method as claimed in claim 2, wherein a time buffer for storing time information is further provided, said step S110 further comprises:
acquiring current time information and writing the current time information into a time temporary storage area;
after the step S15, the method further includes the following steps:
step S16: and acquiring the current time information and writing the current time information into a time temporary storage area.
4. The data storage method according to claim 3, wherein the step S12 specifically includes the following steps:
step S121: judging whether the storage flag of the current time information is consistent with the storage flag of the time information stored in the time temporary storage area, if so, executing step S122, otherwise, jumping to execute the steps S13 to S16, and executing the steps S111 to S113 after step S16;
step S122: judging whether the time stamp of the current time information is consistent with the time stamp of the time information stored in the time temporary storage area, if so, acquiring the data to be stored, writing the data into the data temporary storage area, and repeatedly executing the step S122; otherwise, jumping to execute the step S13 to the step S16.
5. A data storage method according to claim 2, 3 or 4, wherein a primary check area for storing a primary storage area check code and a backup check area for storing a backup storage area check code are further provided;
in step S14, writing the data to be stored into the write address, or in step S111, writing the current storage flag into the start address, and further calculating a check code of the primary storage area; if the check is correct, writing the check code into the main check area, otherwise erasing the main storage area and the main check area, writing the data stored in the backup storage area into the corresponding address of the main storage area, and writing the check code of the backup check area into the main check area;
in step S15, writing the data to be stored into a backup address, or in step S113, writing a current storage flag into a backup address, and further calculating a check code of the backup storage area; if the check is correct, the check code is written into the backup check area, otherwise, the backup storage area and the backup check area are erased, the data stored in the main storage area is written into the corresponding address of the backup storage area, and the check code of the main check area is written into the backup check area.
6. A data storage method according to claim 1, wherein said index units are directed to the next index unit in a circular loop.
7. A data storage method according to claim 6, wherein said time information includes year, month and date, said storage marker is year, and said time marker = month x 31+ date.
8. The data storage method of claim 5, wherein the main memory area and the backup memory area use nor flash memories, and the index area, the data temporary storage area and the time temporary storage area use ferroelectric memories; and the main verification area and the backup verification area both adopt ferroelectric memories.
9. A data storage method according to claim 5, wherein: after the unexpected interruption in the storage process, the data storage method after the power is turned on again is as follows:
step S21: reading the data stored in the main storage area, and recalculating the check code of the main storage area;
step S22: judging whether the recalculated check code is consistent with the check code stored in the main check area, if so, erasing the backup storage area and the backup check area, writing the data stored in the main storage area into the corresponding address of the backup storage area, writing the check code in the main check area into the backup check area, and skipping to execute the step S12 to continue to store the data; if not, go to step S23;
step S23: reading the data stored in the backup storage area, and recalculating the check code of the backup storage area;
step S24: judging whether the recalculated check code is consistent with the check code stored in the backup check area, if so, erasing the main storage area and the main check area, writing the data stored in the backup storage area into the corresponding address of the main storage area, writing the check code which is the backup check area into the main check area, skipping to execute the step S12, and continuing to store the data; if the data are inconsistent, the data cannot be recovered, and initialization is carried out according to the steps during initial power-on storage.
CN201610910741.2A 2016-10-20 2016-10-20 Data storage method Active CN106407050B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201610910741.2A CN106407050B (en) 2016-10-20 2016-10-20 Data storage method

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201610910741.2A CN106407050B (en) 2016-10-20 2016-10-20 Data storage method

Publications (2)

Publication Number Publication Date
CN106407050A CN106407050A (en) 2017-02-15
CN106407050B true CN106407050B (en) 2020-11-10

Family

ID=58012769

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201610910741.2A Active CN106407050B (en) 2016-10-20 2016-10-20 Data storage method

Country Status (1)

Country Link
CN (1) CN106407050B (en)

Families Citing this family (16)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109521960A (en) * 2018-11-02 2019-03-26 格力电器(合肥)有限公司 Data read-write method, device and system
CN109542350A (en) * 2018-11-20 2019-03-29 大连理工大学 A kind of SD card rapid access method based on time index
CN109918228B (en) * 2019-01-28 2021-01-12 浙江中控技术股份有限公司 Data power failure maintaining method and system
CN111367844B (en) * 2019-03-13 2020-12-15 苏州库瀚信息科技有限公司 System, method and apparatus for a storage controller having multiple heterogeneous network interface ports
CN110162573B (en) * 2019-05-05 2021-04-30 中国银行股份有限公司 Distributed sequence generation method, device and system
CN110515544B (en) * 2019-08-06 2022-10-21 科华数据股份有限公司 Data storage method and terminal equipment
CN110764695A (en) * 2019-09-23 2020-02-07 合肥富煌君达高科信息技术有限公司 Storage method and system based on high-speed acquisition
CN110781026A (en) * 2019-10-25 2020-02-11 宁波三星医疗电气股份有限公司 Embedded equipment data storage and repair method and device and embedded equipment
CN110941394A (en) * 2019-11-13 2020-03-31 通号城市轨道交通技术有限公司 Data reading and writing method and device for automatic train control system
CN111143240B (en) * 2019-12-31 2022-07-05 科华恒盛股份有限公司 Image storage method, system and terminal equipment
CN111666046B (en) * 2020-05-20 2023-07-25 西安奥卡云数据科技有限公司 Data storage method, device and equipment
CN112326684B (en) * 2020-10-21 2022-05-24 阳光电源股份有限公司 Photovoltaic module dust accumulation detection method, device, equipment and storage medium
CN113885795B (en) * 2021-09-23 2024-01-19 惠州Tcl移动通信有限公司 Data storage method, device, terminal equipment and storage medium
CN114661722A (en) * 2022-03-23 2022-06-24 天津同阳科技发展有限公司 Data storage method, data indexing method and device
CN114647534B (en) * 2022-05-24 2022-09-20 国网山东省电力公司营销服务中心(计量中心) Data storage method and device based on digital control equipment
CN115086168B (en) * 2022-08-19 2022-11-22 北京全路通信信号研究设计院集团有限公司 Vehicle-mounted equipment communication parameter updating and storing method and system

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101216790A (en) * 2008-01-17 2008-07-09 四川大学 Backup data sharing storage method irrespective to source structure
CN102508782A (en) * 2011-09-29 2012-06-20 北京星网锐捷网络技术有限公司 Data read-write method, data read-write device, memory bank and network equipment
CN103914393A (en) * 2014-04-11 2014-07-09 四川华拓光通信股份有限公司 MCU-based (microprogrammed control unit-based) non-loss FLASH storage update method
CN104268225A (en) * 2014-09-26 2015-01-07 山西达鑫核科技有限公司 File system architecture for addressing in multidimensional degree of freedom, as well as generating and accessing mode thereof
US20150154086A1 (en) * 2013-12-03 2015-06-04 Samsung Electronics Co., Ltd. Method and apparatus for updating firmware

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102662852B (en) * 2012-03-20 2015-05-27 山东省科学院自动化研究所 Method for storing nonvolatile data by using MCU internal data Flash

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101216790A (en) * 2008-01-17 2008-07-09 四川大学 Backup data sharing storage method irrespective to source structure
CN102508782A (en) * 2011-09-29 2012-06-20 北京星网锐捷网络技术有限公司 Data read-write method, data read-write device, memory bank and network equipment
US20150154086A1 (en) * 2013-12-03 2015-06-04 Samsung Electronics Co., Ltd. Method and apparatus for updating firmware
CN103914393A (en) * 2014-04-11 2014-07-09 四川华拓光通信股份有限公司 MCU-based (microprogrammed control unit-based) non-loss FLASH storage update method
CN104268225A (en) * 2014-09-26 2015-01-07 山西达鑫核科技有限公司 File system architecture for addressing in multidimensional degree of freedom, as well as generating and accessing mode thereof

Also Published As

Publication number Publication date
CN106407050A (en) 2017-02-15

Similar Documents

Publication Publication Date Title
CN106407050B (en) Data storage method
TWI546666B (en) Data storage device and flash memory control method
US7065608B2 (en) Apparatus for recording data and method for writing data to flash memory
JP4339244B2 (en) Using flash memory to store measurement data
US9612954B2 (en) Recovery for non-volatile memory after power loss
CN102541676B (en) Method for detecting and mapping states of NAND FLASH
JPH09330273A (en) Memory card, and error correcting method therefor
CN102081577A (en) Data storage structure of Flash memory and data manipulation mode thereof
JP2008198310A (en) Method for repairing bit error and information processing system
TW201428757A (en) Back-up and restoration of data between volatile and flash memory
US20190095276A1 (en) Method for Processing Data Stored in a Memory Device and a Data Storage Device Utilizing the Same
CN110795044B (en) Bad block management method and system of NAND Flash memory
US9465538B2 (en) Flash memory control chip and data storage device and flash memory control method
CN103176920A (en) Nor flash power down protection method and Nor flash power down protection device
CN105204958A (en) Coding method for prolonging NAND Flash data reliable storage time
US20130219244A1 (en) Storage device
CN103425546A (en) General high-efficient reliable Nor Flash data memory management method
JP2011103077A (en) Memory device
CN102789813B (en) Method and device for controlling use of non-least significant bit page in storage device
CN105022695A (en) Data storage method, memorizer control circuit unit and memorizer storage device
CN102063342A (en) Method and system for managing data of flash memory storage equipment
CN113434086B (en) Data storage method, device, nonvolatile memory device and memory
CN113625947B (en) Data error correction method, device, equipment and computer readable storage medium
CN112416246B (en) High-resolution method for storing electric energy data
CN103716693A (en) Setting method of MAC address and smart television

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
CB02 Change of applicant information
CB02 Change of applicant information

Address after: 361006 torch garden, torch high tech Zone, Xiamen, Fujian 457

Applicant after: XIAMEN KEHUAHENGSHENG LIMITED BY SHARE Ltd.

Address before: 361006 torch garden, torch high tech Zone, Xiamen, Fujian 457

Applicant before: XIAMEN KEHUA HENGSHENG Co.,Ltd.

GR01 Patent grant
GR01 Patent grant
CP01 Change in the name or title of a patent holder
CP01 Change in the name or title of a patent holder

Address after: 361006 torch garden, torch high tech Zone, Xiamen, Fujian 457

Patentee after: Kehua Data Co.,Ltd.

Address before: 361006 torch garden, torch high tech Zone, Xiamen, Fujian 457

Patentee before: XIAMEN KEHUAHENGSHENG LIMITED BY SHARE Ltd.

TR01 Transfer of patent right
TR01 Transfer of patent right

Effective date of registration: 20231206

Address after: Room 208-38, Hengye Building, No. 100 Xiangxing Road, Xiang'an Industrial Zone, Xiamen Torch High tech Zone, Xiamen, Fujian Province, 361000

Patentee after: Xiamen Kehua shuneng Technology Co.,Ltd.

Address before: 361006 torch garden, torch high tech Zone, Xiamen, Fujian 457

Patentee before: Kehua Data Co.,Ltd.