Background technology
At present, along with the development of electronic technology, embedded system is being controlled the electronic product widespread uses such as class, consumer, communication class more and more, and embedded technology is also more and more combined closely with people's life.The Flash storer is a kind of non-volatile solid state memory, and it is complete nonvolatile memory, and reliable data cut-off protection can be provided; And it can write online, access speed is fast, is a kind of high reliability, highdensity solid storage device, current, and various Flash storeies become topmost memory device in embedded system gradually.
Very high to data storage security and reliability requirement, on the exigent embedded device in the aspects such as cost and power consumption, Nor Flash has a wide range of applications simultaneously.Randomness due to the distribution of bad piece of Nand Flash, and the uncertainty of bad piece and instability make it use the support that must introduce file system, but file system need to take many system resources space, in cost, power consumption, field that reliability requirement is higher, the introducing of file system will cause the sharply increase of cost.
Nor Flash only has erasing and writing life 100,000 times, when using Nor Flash as storage medium, how to guarantee reliability and the erasing and writing life of data, normally used method, the characteristics for data to be stored, design, avoid frequent erasable the same area targetedly, causes because of the life problems loss of data, in addition, be aided with polylith Flash chip and backup each other, prevent from causing loss of data because of system exception in erasable process.This method does not possess reusability, and cost is relatively high simultaneously.Each new equipment all needs to redesign storage scheme, and new design each time all can bring new unreliable factor, need to again accumulate operating experience, for exploitation, the maintenance of embedded device, need to pay extra fringe cost.
Summary of the invention
The objective of the invention is when adopting Nor Flash as storage medium in embedded device, the problem that the data storage management cost is high, do not possess reusability, propose the highly reliable Nor Flash data storage and management method of a kind of Universal efficient.
Technical scheme of the present invention is:
The Nor Flash data storage and management method that a kind of Universal efficient is highly reliable, it is divided into the Liang Ge district by Nor Flash, comprise storage administration district and user data area, set up the MDR table in described storage administration district, user data is described in the mode of file, the management information that file is relevant is stored in storage administration district MDR table, and user data content is stored in user data area.
The MDR table in storage administration of the present invention district adopts the double copies structure with CRC check, and in the MDR table, each user file information has independent CRC check, if one of them MDR shows all or part of corrupted data, can repair by other MDR table.
In user data area of the present invention, for each user data content, adopt slip storage administration mode, set up continuous subscriber data file storage space, according to sliding window size, the circulation storage, while each time the renewal of data content being preserved, all will select next slip address to be preserved, when the subscriber data file storage space is used completely, be circulated to first address and preserved, preserved to next one slip address successively.
In the present invention, when the user creates a data file, will in the MDR table, increase a file record, the CRC check of content include file name, file size, creation-time, data storage start address and file record; When the user deletes a data file, corresponding file record in the MDR table will be deleted; While upgrading the MDR table, first upgrade main MDR table, then upgrade backup MDR table.
In the present invention, when the user data area content is damaged, will roll back to the last correct content, the rollback number of times can be set.
Beneficial effect of the present invention:
Method of the present invention has reusability, has reduced exploitation, the maintenance cost of new product; Simultaneously, take into account efficient, high reliability, the erasable equilibrium of flash, there is very high application and popularization value.
The memory management method that the present invention proposes, to the establishment of data file, delete, open, the reading and writing operation, method is simple, execution efficiency is high, user interface part only consists of these five operations, simple, easy-to-use.This method has taken into full account in system and has occurred that the data under any abnormal conditions recover (reparation) automatically, has fully represented efficient, highly reliable characteristics.Simultaneously, this memory management method has deeply abstraction, irrelevant with concrete application, is a kind of general data storage and management method, goes for different embedded device field of data storage, has very high practicality and promotional value.
Embodiment
Below in conjunction with drawings and Examples, the present invention is further illustrated.
As shown in Fig. 1-6, a kind of general Nor Flash data storage and management method, the method does not rely on concrete application scenario, can adapt to different embedded devices, the storage demand of different data format, possesses reusability.
This memory management method, be divided into the Liang Ge district by Nor Flash, storage administration district and user data area.User's data are described in the mode of file, and different data sets, describe with different files.Each file is identified by unique filename.The management information that file is relevant, be stored in " storage administration district ", and file content is stored in " user data area ".
" storage administration district " consists of the active and standby two parts MDR tables that carry CRC check, and the MDR table consists of all user file information recordings, and the MDR table carries CRC check, and each file record has independent CRC check; If any one MDR table damages, will show by other MDR to repair the MDR table of damage.If the MDR table is normal, only certain file record damages, and can repair the file record of current damage by corresponding record in other MDR table equally.The CRC algorithm adopts CRC16-CCITT, and generator polynomial is x16+x12+x5+1.
When the user creates or deletes a file, will upgrade the MDR table in storage administration district, the renewal operation of user to the data file, do not relate to and upgrade the MDR table.When the user creates a data file, a file information recording will be added in the MDR table, and this document information recording comprises: the CRC check code of filename, file size, storage space start address, creation-time and this record; When deleting a file, will from the MDR table, delete the fileinfo record of corresponding this filename; To the renewal operation of MDR table, first upgrade main MDR table, then upgrade backup MDR table.
The content of subscriber data file, be stored in the user data area of Nor Flash.When creating this document, according to MDR table content, distribute to storage space start address of current file.The storage of user data content, adopt slip storage administration mode, according to sliding window size, and the circulation storage.While each time the renewal of data content being preserved, all will select next slip address to be preserved.Make the erasable probability equilibrium in each sector of flash, extended to greatest extent the serviceable life of flash.
The content territory of data file, be comprised of file header and data, and file header is partly for the final updating time of storing current content, the CRC check that adds up update times, file content.When each up-to-date is preserved, the change final updating time, the accumulative total update times adds 1, recalculates the CRC check of file content, according to upgrading the cumulative number calculating memory addresses, carries out the Flash write operation, preserves file.The memory address computing method:
Address=file storage start address+(the sliding window size that accumulative total update times % slides and stores) * file size.
During user's read data files, by filename, obtain the storage space start address from the MDR table, according to the sliding window size of the storage of sliding, read successively the file header of each slip memory point, find out the effectively record of (CRC check is correct) up-to-date (accumulative total update times maximum).If certain measuring point is damaged, auto back is rolled into to the last correct content, according to accumulative total update times inverted order, read successively, until find a up-to-date effective document record, the worst situation of subscriber data file is to lose certain content of once upgrading, and can not cause the All Files content all to be lost, the sliding window size of storage but the rollback number of times slides, can need to be set according to application.
The read-write operation of content data file, do not need extra addressing algorithm, is direct address, and read operation, according to the given off-set value of user, is directly read; Write operation, all standing of first level address is erasable, and memory usage is extremely low and efficiency is higher.
Embodiment mono-:
Nor Flash is divided into to the Liang Ge district, storage administration district and user data area, front four sectors are the storage administration district, remaining space is as user data area.The storage administration district comprises active and standby two parts of MDR table, and main MDR epi-position is in first, second sector, and backup MDR epi-position is in the 3rd, the 4th sector.512 bytes between every sector null.
The MDR table consists of gauge outfit and fileinfo record, and gauge outfit is fixed as 32 bytes, and gauge outfit comprises: file record number, whole MDR show CRC check; Every the file recorded information comprises: filename, file size, creation-time, storage start address, CRC check, the length of file record information is fixed as 26 bytes.
When the user creates a new data file, retrieve main MDR table, if (main MDR table damages, retrieval backup MDR table, if backup MDR table is normal, now will backs up MDR table content and be covered to main MDR table, repair the main MDR table damaged), apply for space size according to the user, obtain a storage start address, upgrade active and standby MDR table simultaneously.
When the user needs the reading and writing content data file, the filename at first provided according to the user, retrieval MDR table, find corresponding fileinfo record; The start address of storage from the fileinfo record, according to the sliding window size of the storage of sliding (in the present embodiment, sliding window size gets 5), read successively the file header of each memory point, find out up-to-date data recording, if latest document content CRC check mistake, rollback automatically, continue to find time new record file, until the file content CRC check found is correct, take this file as up-to-date benchmark, and the underproof file record of CRC check will be dropped, but maximum rollback number of times is 5.After file content is revised, carry out while preserving operation, the final updating time in the updating file head, accumulative total update times add 1, recalculate CRC check, and then calculating memory addresses, carry out the Flash write operation, completes file content and preserve.
When the user deletes a file operation, retrieval MDR table, find corresponding record, from the MDR table, deletes this record, upgrades MDR gauge outfit (file record number, CRC check), first upgrades main MDR table, and then upgrade backup MDR table.
The part that the present invention does not relate to all prior art that maybe can adopt same as the prior art is realized.