CN114860164A - Embedded system data storage structure and power failure data recovery method - Google Patents

Embedded system data storage structure and power failure data recovery method Download PDF

Info

Publication number
CN114860164A
CN114860164A CN202210451003.1A CN202210451003A CN114860164A CN 114860164 A CN114860164 A CN 114860164A CN 202210451003 A CN202210451003 A CN 202210451003A CN 114860164 A CN114860164 A CN 114860164A
Authority
CN
China
Prior art keywords
data
sector
recording area
index
backup
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
CN202210451003.1A
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.)
Zhejiang Yankon Group Co Ltd
Zhejiang Yankon Mega Lighting Co Ltd
Original Assignee
Zhejiang Yankon Group Co Ltd
Zhejiang Yankon Mega Lighting 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 Zhejiang Yankon Group Co Ltd, Zhejiang Yankon Mega Lighting Co Ltd filed Critical Zhejiang Yankon Group Co Ltd
Priority to CN202210451003.1A priority Critical patent/CN114860164A/en
Publication of CN114860164A publication Critical patent/CN114860164A/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/062Securing storage systems
    • 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/1471Saving, restoring, recovering or retrying involving logging of persistent data for recovery
    • 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
    • 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]
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Abstract

The invention provides an embedded system data storage structure and a power failure data recovery method, which relate to the technical field of data storage, and comprise a FLASH memory, wherein the FLASH memory is used for: setting a plurality of data storage sectors and a backup domain sector, wherein each data storage sector is provided with a plurality of data recording areas, and each data recording area stores one piece of recording data; when the data recording area is full, temporarily storing the next recording data to the backup area sector, then erasing the recording data of the data recording area, and storing the recording data of the backup area sector to the data recording area; an index pointer to: pointing to a data recording area or a backup area sector according to the index value; and moving up and down between different data recording areas to perform indexing. The invention delays the erasing time period in the FLASH by setting the data storage structure, thereby prolonging the service life; by setting data storage winding and backup, the function state before power failure can still be recovered after the equipment is restarted after power failure.

Description

Embedded system data storage structure and power failure data recovery method
Technical Field
The invention relates to the technical field of data storage, in particular to a data storage structure of an embedded system and a power failure data recovery method.
Background
Many embedded systems all need to save information such as a series of data and parameter in real time at the operation in-process, if the intelligent lamp uses the lamp pearl of different colour temperatures or uses the lamp pearl in-process of different colours to need to save the lamp pearl colour temperature or the colour that the user used at present in real time to equipment still can show the lamp pearl colour temperature or the colour state that the user used at present when powering on again after the power failure.
At present, most storage media of an embedded system are stored by using FLASH, real-time data are directly stored in a sector, original data stored in the sector are erased before data are stored, then the data are stored in the erased sector, when the data need to be stored again or refreshed, the last data need to be erased, and the above steps are repeated in a circulating manner.
Because the FLASH memory does not divide the inside of the sector, the stored data only occupies a part of the sector, the original data needs to be erased in advance during each storage, and the FLASH memory is limited by the erasing times, so that the service life is reduced due to frequent operation. In addition, in the FLASH storage mode, when abnormal power failure occurs, for example, after sector data is erased, the abnormal power failure occurs before new data is stored, which may cause data loss and cause abnormal device functions.
Disclosure of Invention
Aiming at the problems, the invention provides an embedded system data storage structure and a power failure data recovery method, through setting the data storage structure, the time period of erasing in FLASH is delayed, the service life is prolonged, and through setting data storage winding and backup, the functional state before power failure can still be recovered after the equipment is restarted after power failure.
In order to achieve the above object, the present invention provides an embedded system data storage structure, including: a FLASH memory and an index pointer;
the FLASH memory is used for:
setting a plurality of data storage sectors and a backup domain sector, wherein a plurality of data recording areas are arranged in each data storage sector;
each data recording area stores one piece of recording data;
when the data recording area is full, temporarily storing the next piece of recording data to the backup area sector, erasing the recording data of all the data recording areas, and then storing the recording data of the backup area sector to the data recording area;
the index pointer is used for:
pointing to the data recording area or the backup area sector according to the index value;
and moving up and down between different data recording areas to store and read recorded data.
As a further improvement of the invention, a plurality of sectors are arranged in the FLASH memory, and partial sectors are used for power-down data storage and comprise a plurality of data storage sectors and a backup domain sector.
As a further improvement of the present invention, the index pointer is set in the RAM, and different index values are set for the indication position of the index pointer;
at the beginning, the index pointer points to the first data recording area from the position indicated by the initialized index value, and the recorded data is stored in the data recording area;
and after the storage is finished, adding 1 to the index value, pointing an index pointer to the next data recording area, and storing the recorded data in the data recording area until the data recording area indicated by the last index value is stored.
As a further improvement of the present invention, when all the data storage sectors have stored the record data and the record data needs to be stored next time, the method transfers the index value to the backup domain sector, and specifically includes:
storing the recorded data into a backup domain sector;
erasing all recorded data in the data storage sector;
storing the recording data of the backup domain sector to a first data recording area indicated by an initialized index value position, and adding 1 to the index value;
and finally, erasing the recorded data of the backup domain sector.
As a further improvement of the present invention, the storing process of the record data includes:
calculating a corresponding check code according to the user data to be stored, and storing the check code and the user data to be stored together as recording data in the data recording area or the backup area sector;
if the stored index value corresponding to the data recording area is smaller than the maximum value, after the recorded data is stored in the data recording area, adding 1 to the index value to continue to store the data in the data recording area pointed by the index value;
if the index value corresponding to the stored data recording area is equal to the maximum value, the data of the sector of the backup area is erased after the recorded data is stored in the data recording area pointed by the maximum index value;
if the index value corresponding to the stored data recording area is larger than the maximum value, the data is stored in the backup area sector, all recorded data in the data storage sector is erased, the index value is initialized, and the data in the backup area sector is stored in the data recording area pointed by the index value.
The invention also provides a method for recovering the data of the embedded system in case of power failure, which comprises the following steps:
powering on the equipment, initializing an index value, enabling an index pointer to point to a first data recording area, gradually adding 1 to the index value, and moving the index pointer to sequentially read and verify the recorded data of each data recording area;
in the process, if the recorded data of all the data recording areas are successfully verified, the index pointer points to the sector of the backup area;
if the recorded data of the backup domain sector is successfully verified, erasing the recorded data of all the data recording areas, storing the recorded data of the backup domain sector into the data recording area corresponding to the initialized index value, and completing power failure data recovery by using the recorded data;
if the recorded data of the backup domain sector fails to be verified, completing power failure data recovery by using the recorded data of the last data recording area pointed by the index pointer, and pointing the index pointer to the backup domain sector;
in the process, if the recorded data in any data recording area fails to be verified, whether the index position is an initialized index value is judged, if not, an index pointer points to the data recording area with the index position minus 1, and the power failure data recovery is completed by the recorded data in the data recording area;
if so, pointing the index pointer to a backup domain sector, and reading and verifying the recorded data of the backup domain sector;
if the recorded data of the backup domain sector is successfully verified, the recorded data of the backup domain sector is stored in a data recording area corresponding to the initialized index value, and the recorded data is used for completing power failure data recovery;
and if the recorded data of the sector of the backup domain fails to be verified, loading default data into the data recording area corresponding to the initialization index value to finish power failure data recovery by the default data.
As a further improvement of the present invention, the recorded data includes user data and a check code;
when the recorded data is read and verified, the user data and the check code are read together, and the integrity of the user data is judged through the check code.
Compared with the prior art, the invention has the beneficial effects that:
the FLASH is set into a plurality of data storage sectors and a backup domain sector, each data storage sector is internally provided with a plurality of data recording areas, and each data recording area can store one piece of recorded data, so that the erasing time period in the FLASH is delayed, the service life is prolonged, and the functional state before power failure can still be recovered after the equipment is restarted after power failure by setting a data storage winding and backup method, thereby ensuring the normal work of the product.
The power failure data recovery method has clear logic, can accurately acquire correct power failure storage data when the equipment is started for the first time or restarted after power failure, and can normally store the data in the subsequent operation process of the equipment.
Drawings
FIG. 1 is a schematic diagram of a data storage structure of an embedded system according to an embodiment of the present invention;
FIG. 2 is a flowchart illustrating recovery of power-down data of an embedded system according to an embodiment of the present invention;
FIG. 3 is a flowchart illustrating data saving of a data storage structure of an embedded system according to an embodiment of the present invention;
FIG. 4 is a data reading and verifying process of the data storage structure of the embedded system according to an embodiment of the present invention;
FIG. 5 is a flow chart illustrating a power down of the disclosed apparatus during data storage wrap-around in accordance with one embodiment of the present invention.
Detailed Description
In order to make the objects, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are some, but not all, embodiments of the present invention. All other embodiments, which can be obtained by a person skilled in the art without any inventive step based on the embodiments of the present invention, are within the scope of the present invention.
The invention is described in further detail below with reference to the attached drawing figures:
as shown in fig. 1, the data storage structure of an embedded system provided by the present invention includes: a FLASH memory and an index pointer;
wherein the content of the first and second substances,
(1) the FLASH memory is internally provided with different numbers of sectors according to different chip specifications, part of the sectors are used for power-down data storage and are set into a plurality of data storage sectors and a backup domain sector, and each data storage sector is internally provided with a plurality of data recording areas;
each data recording area stores one piece of recording data;
when the data recording area is full, temporarily storing the next recording data to the backup area sector, erasing the recording data of all the data recording areas, and then storing the recording data of the backup area sector to the data recording area;
such as: using K sectors in the FLASH memory as data storage sectors and one sector as a backup domain sector, namely using K +1 sectors as a power-down data storage function, wherein each data storage sector is provided with a plurality of data recording areas, for example, each data storage sector is provided with n data recording areas, wherein the larger the K, n value is, the longer the interval time of FLASH erasing is, so that the cycle of data storage winding is prolonged; the longer the erase interval time, the longer the life of the FLASH. For example, a sector of general FLASH is 4096 bytes, and when the size of one piece of recording data is 100 bytes, 40 pieces of recording data can be stored in each sector. Of course, the number of the recording data may be set differently according to the size of the recording data.
(2) Setting an index pointer in the RAM, and setting different index values aiming at the indication position of the index pointer; an index pointer to:
pointing to a data recording area or a backup area sector according to the index value;
and moving up and down between different data recording areas to store and read the recorded data.
Further, in the above-mentioned case,
at the beginning, the index pointer points to the first data recording area from the position indicated by the initialized index value, and the recorded data is stored in the data recording area;
and after the storage is finished, adding 1 to the index value, pointing to the next data recording area by the index pointer, and storing the recorded data in the data recording area until the data recording area indicated by the last index value is stored.
When all the data storage sectors have stored the recording data and the recording data needs to be stored next time, the index value is transferred to the backup domain sector, which includes:
1) storing the recorded data into a backup domain sector;
2) erasing all recorded data in the data storage sector;
3) storing the recording data of the sector of the backup domain into a first data recording area indicated by the position of the initialized index value, and adding 1 to the index value;
4) and finally, erasing the recorded data of the sector of the backup domain.
For example:
setting the initial position of the index pointer to be 0, starting to store data by the index pointer from the position of the index value of 0 to the first data recording area after the equipment is powered on for the first time, after the first piece of recorded data is stored, adding 1 to the index value, namely, storing data in the second data recording area pointed by the position of the index value 1 until the data in the last data recording area pointed by the last index value (index is max) is stored, and at this time, the index value is not added with 1 any more and is converted to the backup area address.
When the data is stored again next time, the data is stored in the backup area, the data in the data storage sector is erased, then the data in the backup area is stored in the first data recording area pointed by the index value 0 (index is 0), and finally the data in the backup area is erased, at this time, only the first recorded data in the first data recording area in the data storage sector is complete, and the data in the data recording areas pointed by the other indexes and the data in the backup area are incomplete. And then a loop operation is performed according to the above logic. It should be noted that, if the size of a piece of recorded data is close to the size of a data storage sector, the operation condition is the same as that of the conventional FLASH, and thus the method is not suitable for the operation method of the present method.
In addition, the first and second substrates are,
(1) in the present invention, a specific storage process of the recorded data is shown in fig. 3, and includes:
1) calculating corresponding check codes according to the user data to be stored, and storing the check codes and the user data to be stored in a data recording area or a backup area sector as recording data;
2) if the index value corresponding to the stored data recording area is smaller than the maximum value, after the recorded data is stored in the data recording area, adding 1 to the index value to continue to execute data storage in the data recording area pointed by the index value;
3) if the index value corresponding to the stored data recording area is equal to the maximum value, the data of the sector of the backup area is erased after the recorded data is stored in the data recording area pointed by the maximum index value;
4) if the index value corresponding to the stored data recording area is larger than the maximum value, the data is stored in the backup area sector, the recorded data in all the data storage sectors is erased, the index value is initialized, and the data in the backup area sector is stored in the data recording area pointed by the index value.
The recorded data includes user data and a check code, the check code is set to ensure integrity of the stored user data, and the check code may be obtained through different check algorithms, including but not limited to common methods such as CRC32, checksun (checksum), and xor.
For example: taking checksun as an example, if the data stored by the user is 1, 2, 3, 4, 5, the check code obtained by the checksun method is 15 (the sum of all data), and the user data (1, 2, 3, 4, 5) and the check code (15) are stored into a data area of the FLASH as a whole record data during storage;
(2) in the present invention, a specific process of reading recorded data is shown in fig. 4, and includes:
1) corresponding recorded data according to the index pointing to the data recording area, and performing data verification according to user data and a verification code in the recorded data;
2) if the verification fails, returning error information;
3) if the check passes, the check of the next set of data continues.
When the recorded data is read, the user data and the check code are read together, and the integrity of the data is judged through the check code.
For example: for the example of the recording process, when the integrity of the data is judged by the check code, the sum of the user data is calculated, in this case, 1, 2, 3, 4 and 5 are accumulated to obtain a value 15, and the value 15 is compared with the read check code 15, if the value is equal, the data is complete; if the read user data is 0, 2, 3, 4, 5, and the obtained value 14 is not equal to the read check code 15, the data is incomplete. On the contrary, if the check code is abnormal, for example, the check code changes from 15 to 16, the read record data will not pass.
As shown in fig. 2, the present invention provides a method for recovering power-down data of an embedded system, which comprises the following steps:
the equipment is powered on, an index value is initialized, an index pointer points to a first data recording area, the index value is added by 1 one by one, and the index pointer is moved to read and verify the recorded data of each data recording area in sequence;
(1) in the process, if the recorded data of all the data recording areas are successfully verified, the index pointer points to the sector of the backup area;
1) if the recorded data of the backup domain sector is successfully verified, power failure is indicated when data storage is wound, specifically, after the recorded data is stored in the backup domain sector, power failure occurs before the recorded data of the previous data recording area is erased, and the recorded data of the backup domain sector is correct power failure stored data of a user; therefore, erasing the recorded data of all the data recording areas, and storing the recorded data of the sector of the backup area into the data recording area corresponding to the initialized index value, so as to complete the power failure data recovery by the recorded data;
2) if the recorded data of the sector of the backup domain fails to be verified, the data is just stored in the data recording area pointed by the last index value, no winding occurs or the user data is stored in the backup domain in a power-down mode when the winding occurs, so that the user data in the backup domain is incomplete, the recorded data of the last data recording area pointed by the index pointer is the correct power-down stored data of the user, the power-down data recovery is completed by the data, and the index pointer points to the sector of the backup domain;
(2) in the process, if the recorded data verification of any data recording area fails, whether the index position is an initialized index value is judged; 1) if not, indicating that the power failure occurs when no data storage is wound, pointing the index pointer to a data recording area with the index position minus 1, wherein the recorded data of the data recording area is the correct power failure storage data of the user, and completing power failure data recovery by using the recorded data of the data recording area;
2) if so, pointing the index pointer to the sector of the backup domain, and reading and verifying the recorded data of the sector of the backup domain;
if the recorded data of the sector of the backup domain is successfully verified, the power failure of the device occurs during winding, specifically, after the recorded data of the previous data recording area is erased, the sector of the data storage sector is completely erased, so that the data in the sector is incomplete. Therefore, the recorded data of the sector of the backup domain is the correct power-down stored data of the user, the recorded data of the sector of the backup domain is stored in the data recording area corresponding to the initialized index value, and the power-down data recovery is completed by the recorded data;
if the recorded data of the backup domain sector fails to be verified, the device is powered on for the first time, the data storage sector and the backup domain sector are in an initialized state, all data are 0xFF according to the characteristics of FLASH, and the data in the position of the data recording area and the data in the backup area are incomplete, which is equivalent to the data recording area pointed by 0 as index; at this time, the default data is loaded into the data recording area corresponding to the initialization index value, and the power failure data recovery (initial power-on of the device) is completed with the default data.
Example (b):
in the above process, the power-down situations are divided into the following cases:
1. the device is powered on for the first time, the data storage sector and the backup domain sector are in an initialized state, all data are 0xFF according to the characteristics of FLASH, the data in the position of the data recording area pointed by the index 0 and the data in the backup area are incomplete, at this time, the device adopts default parameters, the default parameters are stored in the position of the data recording area pointed by the index 0, and after the storage is finished, the index +1 is stored, namely the index is 1.
2. The power failure occurs when there is no winding, i.e. the case of 0< index < max before power failure, is divided into two cases: one is in the process of data storage, and the other is after the data storage is finished; if the device is powered down when storing the 4 th recorded data, at this time, the data check codes of index is 0, the data check codes of 1, 2 and 3 are all complete, but the data of index is 4 is incomplete, then when the device is powered down and then powered up, the device will sequentially read data from the data recording area position pointed by index 0, and perform integrity check every time one piece of data is read from the address pointed by index, if the check is passed, continue to read the next piece of data until the data of which the integrity is not passed, that is, index is 4, so that it can be inferred that the last power down of the device occurs when the third piece of data is stored, so the device will use the data of index 3 just read as the correct power down stored data of the user, and assign index 4 for subsequent data storage. If the power is off when the 4 th recorded data is stored in the device, the device is powered on after the power is off, and the recorded data with index of 4 points to the device can be used as the correct power-off storage data of the user.
3. When the device is powered off, namely when the index is not wound, namely before the power off, the index is max, after the device is powered on again, the data is read sequentially from the data recording area pointed by the index being 0 until the data recording pointed by the index being max is complete, and then the data in the sector of the backup area is read, wherein the integrity of the data is not passed at the moment, so that the device takes the data correspondingly read by the index being max as the correct power off storage data of the user, and points the index to the backup address for subsequent data storage.
4. As shown in FIG. 5, the power down of the device occurs during the winding process, since the winding process is composed of a series of operations, and the power down of each link is discussed separately below
(1) Power down 1 #:
power down occurs after saving data to a backup sector and before erasing a previous data storage sector, where the data is complete because the data storage sector is not erased. When the user powers on again and reads the data pointed by the index of 0 in sequence, all the data are complete, and the data in the backup domain are also complete, at this time, the device only needs to erase all the data in the previous data storage sector, and stores the data read from the backup domain to the data position pointed by the index of 0, which is equivalent to continuously completing the winding work before power failure.
(2) Power down 2 #:
the power down occurs after erasing the preceding data storage sector and before saving the backup domain data to the location with index equal to 0. Since the data storage sector has been completely erased, the data inside is incomplete. When the device is powered on again to sequentially read the data pointed by the index of 0, the data pointed by the index of 0 is found to be incomplete, then the data in the backup domain is read, and the data in the backup domain is complete, at this time, the device only needs to store the data read from the backup domain to the position of the data recording area pointed by the index of 0, which is equivalent to continuously completing the winding work before the power failure.
The invention has the advantages that:
(1) the FLASH is set into a plurality of data storage sectors and a backup domain sector, each data storage sector is internally provided with a plurality of data recording areas, and each data recording area can store one piece of recording data, so that the time period of erasing in the FLASH is delayed, the service life is prolonged, and the functional state before power failure can still be recovered after the equipment is restarted after power failure by setting a data storage winding and backup method, thereby ensuring the normal work of the product.
(2) The power failure data recovery method has clear logic, can accurately acquire correct power failure storage data when the equipment is started for the first time or restarted after power failure, and can normally store the data in the subsequent operation process of the equipment.
The above is only a preferred embodiment of the present invention, and is not intended to limit the present invention, and various modifications and changes will occur to those skilled in the art. Any modification, equivalent replacement, or improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.

Claims (7)

1. An embedded system data storage structure, comprising: a FLASH memory and an index pointer;
the FLASH memory is used for:
setting a plurality of data storage sectors and a backup domain sector, wherein a plurality of data recording areas are arranged in each data storage sector;
each data recording area stores one piece of recording data;
when the data recording area is full, temporarily storing the next piece of recording data to the backup area sector, erasing the recording data of all the data recording areas, and then storing the recording data of the backup area sector to the data recording area;
the index pointer is used for:
pointing to the data recording area or the backup area sector according to the index value;
and moving up and down between different data recording areas to store and read recorded data.
2. The data storage structure of claim 1, wherein: the FLASH memory is internally provided with a plurality of sectors, and part of the sectors are used for storing power-down data and comprise a plurality of data storage sectors and a backup domain sector.
3. The data storage structure of claim 1, wherein: setting the index pointer in the RAM, and setting different index values aiming at the indication position of the index pointer;
at the beginning, the index pointer points to the first data recording area from the position indicated by the initialized index value, and the recorded data is stored in the data recording area;
and after the storage is finished, adding 1 to the index value, pointing to the next data recording area by an index pointer, and storing the recording data in the data recording area until the data recording area indicated by the last index value is stored.
4. The data storage structure of claim 1, wherein: when all the data storage sectors have stored recording data and the recording data needs to be stored next time, transferring the index value to the backup domain sector, specifically comprising:
storing the recorded data into a backup domain sector;
erasing all recorded data in the data storage sector;
storing the recording data of the sector of the backup domain into a first data recording area indicated by an initialized index value position, and adding 1 to the index value;
and finally, erasing the recorded data of the backup domain sector.
5. The data storage structure of claim 1, wherein: the storage process of the recorded data comprises the following steps:
calculating a corresponding check code according to the user data to be stored, and storing the check code and the user data to be stored together as recording data in the data recording area or the backup area sector;
if the stored index value corresponding to the data recording area is smaller than the maximum value, after the recorded data is stored in the data recording area, adding 1 to the index value to continue to store the data in the data recording area pointed by the index value;
if the index value corresponding to the stored data recording area is equal to the maximum value, the data of the sector of the backup area is erased after the recorded data is stored in the data recording area pointed by the maximum index value;
if the index value corresponding to the stored data recording area is larger than the maximum value, the data is stored in the backup area sector, all recorded data in the data storage sector is erased, the index value is initialized, and the data in the backup area sector is stored in the data recording area pointed by the index value.
6. A power failure data recovery method based on the embedded system data storage structure of any one of claims 1 to 5, characterized by comprising:
powering on the equipment, initializing an index value, enabling an index pointer to point to a first data recording area, gradually adding 1 to the index value, and moving the index pointer to sequentially read and verify the recorded data of each data recording area;
in the process, if the recorded data of all the data recording areas are successfully verified, the index pointer points to the sector of the backup area;
if the recorded data of the backup domain sector is successfully verified, erasing the recorded data of all the data recording areas, storing the recorded data of the backup domain sector into the data recording area corresponding to the initialized index value, and completing power failure data recovery by using the recorded data;
if the recorded data of the backup domain sector fails to be verified, completing power failure data recovery by using the recorded data of the last data recording area pointed by the index pointer, and pointing the index pointer to the backup domain sector;
in the process, if the recorded data in any data recording area fails to be verified, whether the index position is an initialized index value is judged, if not, an index pointer points to the data recording area with the index position minus 1, and the power failure data recovery is completed by the recorded data in the data recording area;
if so, pointing the index pointer to a backup domain sector, and reading and verifying the recorded data of the backup domain sector;
if the recorded data of the backup domain sector is successfully verified, the recorded data of the backup domain sector is stored in a data recording area corresponding to the initialized index value, and the recorded data is used for completing power failure data recovery;
and if the recorded data of the sector of the backup domain fails to be verified, loading default data into the data recording area corresponding to the initialization index value to finish power failure data recovery by the default data.
7. The method for recovering lost power data according to claim 6, wherein: the recorded data comprises user data and a check code;
when the recorded data is read and verified, the user data and the check code are read together, and the integrity of the user data is judged through the check code.
CN202210451003.1A 2022-04-27 2022-04-27 Embedded system data storage structure and power failure data recovery method Pending CN114860164A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202210451003.1A CN114860164A (en) 2022-04-27 2022-04-27 Embedded system data storage structure and power failure data recovery method

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202210451003.1A CN114860164A (en) 2022-04-27 2022-04-27 Embedded system data storage structure and power failure data recovery method

Publications (1)

Publication Number Publication Date
CN114860164A true CN114860164A (en) 2022-08-05

Family

ID=82633206

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202210451003.1A Pending CN114860164A (en) 2022-04-27 2022-04-27 Embedded system data storage structure and power failure data recovery method

Country Status (1)

Country Link
CN (1) CN114860164A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116303481A (en) * 2023-05-22 2023-06-23 深圳市首航新能源股份有限公司 Storage method, device, equipment and storage medium for fault wave recording data

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116303481A (en) * 2023-05-22 2023-06-23 深圳市首航新能源股份有限公司 Storage method, device, equipment and storage medium for fault wave recording data
CN116303481B (en) * 2023-05-22 2023-09-12 深圳市首航新能源股份有限公司 Storage method, device, equipment and storage medium for fault wave recording data

Similar Documents

Publication Publication Date Title
US7065608B2 (en) Apparatus for recording data and method for writing data to flash memory
US7725646B2 (en) Method of using a flash memory for a circular buffer
US7774382B2 (en) Method and apparatus for configuring a control device, and corresponding control device
US8060684B2 (en) Memory control apparatus, memory control method and program
CN108646982B (en) Automatic data restoration method and device based on UBIFS
CN106227680B (en) A kind of data processing and power fail preventing data guard method
CN102081577A (en) Data storage structure of Flash memory and data manipulation mode thereof
JP2002351685A (en) Data updating method and controller for nonvolatile memory
US9524212B2 (en) Method, device and operating system for processing and using burn data of NAND flash
CN110399247B (en) Data recovery method, device and equipment and computer readable storage medium
US20070091697A1 (en) Device recoverable purge for flash storage device
CN112817527A (en) Power failure data storage method, single chip microcomputer and computer readable storage medium
CN114860164A (en) Embedded system data storage structure and power failure data recovery method
CN116880782B (en) Embedded memory and testing method thereof
CN112397128A (en) Control method and device for Flash memory
CN116880781B (en) Storage device and control method thereof
CN109445982A (en) Realize the data storage device of data reliable read write
CN116185563A (en) Software simulation algorithm based on vehicle-gauge microcontroller data flash memory
CN111737058A (en) IC card and power-down prevention data backup method or data recovery method thereof
CN103744746A (en) Index-based smart card record backup and recovery method
CN105404475A (en) Storage management system and method for small-capacity flash in MCU chip
JP2002318732A (en) Device and method for processing file in case of recovery
CN108053861A (en) Firmware self-regeneration method in intelligent memory device
US20070101049A1 (en) Redundant purge for flash storage device
US20070088905A1 (en) System and method for purging a flash storage device

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