Summary of the invention
The invention provides a kind of method for writing data and a kind of data transfer apparatus, write fashionable to solve the data of using the FAT file system to carry out repeatedly flash memory, because of zone of repeatable operation, cause the whole BLOCK at this place, zone to be judged as bad piece, waste is the memory property of flash memory repeatedly, can't give full play to repeatedly the problem of the potential storage capacity of flash memory.
In order to address the above problem, the invention discloses a kind of method for writing data, comprise: receive to the data of flash memory data writing repeatedly and write instruction, write the first data block that data to be written in the described repeatedly flash memory are determined in instruction according to described data; Obtain the number of times of wiping/writing of described the first data block, and when the number of times of wiping/writing of described the first data block reached setting threshold, selective erasing from other data block of described repeatedly flash memory/number of times that writes did not reach the second data block of described setting threshold; Data in data in described the first data block and described the second data block are exchanged; Write instruction to described the second data block data writing that carries out after the exchanges data according to described data.
Preferably, write according to described data after the step of the described second data block data writing of instruction after carrying out exchanges data, also comprise: the number of times of wiping/writing that upgrades the notebook data piece that the outer data OOB district of band of described the second data block records.
Preferably, the described step of obtaining the number of times of wiping/writing of described the first data block comprises: the number of times of wiping/writing that reads the OOB district record of described the first data block.
Preferably, after the step of the number of times of wiping/writing of the notebook data piece of the outer data OOB district of the band of described the second data block of described renewal record, also comprise: according to the number of times of wiping/writing of described the second data block after upgrading, the number of times that described the second data block is moved to described wiping/write is less than or equal to after the data block of the number of times of wiping/writing of described the second data block, forms the data block chained list that links from small to large according to the number of times of wiping/writing.
Preferably, the step that the number of times of described selective erasing from other data block of described repeatedly flash memory/write does not reach the second data block of described setting threshold comprises: when the number of times of wiping/writing of the data block of the gauge outfit of described data block chained list does not reach described setting threshold, the data block of the gauge outfit of described data block chained list is defined as the second data block.
Preferably, the step that the number of times of described selective erasing from other data block of described repeatedly flash memory/write does not reach the second data block of described setting threshold comprises: obtain described wiping/number of times that writes and do not reach the information of the data block of described setting threshold from the data block information table, wherein, store the number of times of wiping/writing of each data block of described repeatedly flash memory in the described data block information table; Selecting a data block from data block corresponding to the information of the described data block obtained is the second data block.
In order to address the above problem, the invention also discloses a kind of data transfer apparatus, comprise: determination module, be used for to receive to the data of flash memory data writing repeatedly and write instruction, write the first data block that data to be written in the described repeatedly flash memory are determined in instruction according to described data; Acquisition module, be used for obtaining the number of times of wiping/writing of described the first data block, and when the number of times of wiping/writing of described the first data block reached setting threshold, selective erasing from other data block of described repeatedly flash memory/number of times that writes did not reach the second data block of described setting threshold; Execution module is used for the data of described the first data block and the data in described the second data block are exchanged; Write instruction to described the second data block data writing that carries out after the exchanges data according to described data.
Preferably, described data transfer apparatus also comprises: logging modle, be used for described execution module writes the described second data block data writing of instruction after carrying out exchanges data according to described data after, upgrade the number of times of wiping/writing of the notebook data piece that the outer data OOB district of band of described the second data block records.
Preferably, described acquisition module reads the number of times of wiping/writing of the OOB district record of described the first data block when obtaining the number of times of wiping/writing of described the first data block.
Preferably, described data transfer apparatus also comprises: processing module, after the number of times of wiping/writing for the notebook data piece of data OOB district record outside the band that upgrades described the second data block in described logging modle, the number of times of wiping/writing according to described the second data block after upgrading, the number of times that described the second data block is moved to described wiping/write is less than or equal to after the data block of the number of times of wiping/writing of described the second data block, forms the data block chained list that links from small to large according to the number of times of wiping/writing.
Preferably, when described acquisition module does not reach the second data block of described setting threshold at the number of times of selective erasing from other data block of described repeatedly flash memory/write, when the number of times of wiping/writing of the data block of the gauge outfit of described data block chained list does not reach described setting threshold, the data block of the gauge outfit of described data block chained list is defined as the second data block.
Preferably, when described acquisition module does not reach the second data block of described setting threshold at the number of times of selective erasing from other data block of described repeatedly flash memory/write, from the data block information table, obtain described wiping/number of times that writes and do not reach the information of the data block of described setting threshold, wherein, store the number of times of wiping/writing of each data block of described repeatedly flash memory in the described data block information table; Selecting a data block from data block corresponding to the information of the described data block obtained is the second data block.
Compared with prior art, the present invention has the following advantages:
The present invention is repeatedly the threshold value that each data block of flash memory is set the number of times of wiping/writing, to flash memory data writing repeatedly the time, the number of times of wiping/writing of determining first the first data block of data to be written reaches setting threshold, then, select the second new data block to carry out exchanges data, after exchanges data, data to be written are write the second new data block.Behind setting threshold, can look for again the data block of " suitable " to replace in a data block " wearing and tearing ".Change like this, just can utilize as much as possible repeatedly each data block in the flash memory, " wearing and tearing " on average in each data block, thereby avoided the wearing and tearing of individual data piece excessive, cause bad piece.By the present invention, having solved the data of using the FAT file system to carry out repeatedly flash memory writes fashionable, because of zone of repeatable operation, cause the whole BLOCK at this place, zone to be judged as bad piece, waste is the memory property of flash memory repeatedly, can't give full play to repeatedly the problem of the potential storage capacity of flash memory, reach the repeatedly effect of flash memory memory property of effective utilization.
Embodiment
For above-mentioned purpose of the present invention, feature and advantage can be become apparent more, the present invention is further detailed explanation below in conjunction with the drawings and specific embodiments.
Embodiment one
With reference to Fig. 1, show the flow chart of steps according to a kind of method for writing data of the embodiment of the invention one.
The method for writing data of the present embodiment may further comprise the steps:
Step S102: receive to the data of flash memory data writing repeatedly and write instruction, write the first data block that data to be written in the flash memory are determined repeatedly in instruction according to data.
Data write the data block address that usually includes data to be written in the instruction, such as the logical address of data block to be written, and then can determine the physical address of corresponding data block according to this logical address.
Step S104: the number of times of wiping/writing that obtains the first data block, and when the number of times of wiping/writing of the first data block reached setting threshold, selective erasing/number of times that writes did not reach the second data block of setting threshold from other data block of flash memory repeatedly.
Repeatedly preserve the number of times of wiping/writing of each data block in the flash memory, when to the data block data writing, judge first whether the number of times of wiping/writing of this data block reaches setting threshold.Wherein, setting threshold is frequently wiped/is write for fear of certain data block, and other data block might be left unused always, causes data block to utilize inhomogeneous, avoids producing the bad data piece and the threshold value that arranges.
When selecting the second data block, can be according to certain rule, as according to sequencing, select or other suitable selective rule at random, selective erasing/number of times that writes does not reach the data block of setting threshold.
Step S106: the data in the data in the first data block and the second data block are exchanged.
The number of times of wiping/writing of the second data block of selecting is less, after the exchanges data in the data in the first data block and the second data block, data writing in the second data block again, can balanced utilization the data block in the flash memory repeatedly, effectively avoid because a data block is frequently wiped/write, cause the situation of bad data blocks to occur.
Step S108: write instruction to the second data block data writing that carries out after the exchanges data according to data.
After data write the flow process end, the number of times of wiping/writing of the data block of repeatedly preserving in the flash memory upgraded.As, when all recording the number of times of wiping/writing of notebook data piece in every blocks of data piece, after data write, namely the indegree of wiping/write of notebook data increased counting, carry out real-time update; For another example, if when the number of times of wiping/writing of every blocks of data piece of flash memory adopts centralized record repeatedly, as when using the number of times of wiping/writing of file or each data block of charting, can be after data write, the number of times of corresponding the wiping of this data block in file or the form/write is upgraded.Certainly, be not limited to this, in actual applications, those skilled in the art also can adopt other appropriate ways record and the number of times of wiping/writing of new data block more.
Pass through the present embodiment, set the threshold value of the number of times of wiping/writing for each data block of flash memory repeatedly, to flash memory data writing repeatedly the time, the number of times of wiping/writing of determining first the first data block of data to be written reaches setting threshold, then, select the second new data block to carry out exchanges data, after exchanges data, data to be written are write the second new data block.Behind setting threshold, can look for again the data block of " suitable " to replace in a data block " wearing and tearing ".Change like this, just can utilize as much as possible repeatedly each data block in the flash memory, " wearing and tearing " on average in each data block, thereby avoided the wearing and tearing of individual data piece excessive, cause bad piece.Pass through the present embodiment, having solved the data of using the FAT file system to carry out repeatedly flash memory writes fashionable, because of zone of repeatable operation, cause the whole BLOCK at this place, zone to be judged as bad piece, waste is the memory property of flash memory repeatedly, can't give full play to repeatedly the problem of the potential storage capacity of flash memory, reach the repeatedly effect of flash memory memory property of effective utilization.
Embodiment two
With reference to Fig. 2, show the flow chart of steps according to a kind of method for writing data of the embodiment of the invention two.
In the present embodiment, take can be repeatedly erasable nand memory as example, use the chained list mode to link each data block of nand memory, at the OOB(Out of each data block Of Band, be with outer data) distinguish the number of times of wiping/writing of minute book data block.According to the number of times of wiping/writing of each data block of nand memory, use from small to large each data block of chained list link nand memory; When behind the data block data writing, according to the number of times of wiping/writing of the data block of data writing, the data block of data writing is moved to the number of times of wiping/writing be less than or equal to after the data block of the number of times of wiping/writing of data block of data writing.
Below with a simple example linked list data piece of nand memory is carried out exemplary illustration, as set nand memory A, B, C, four data blocks of D are arranged, when initial, list structure is A(0)-〉 B(0)-〉 C(0)-〉 D(0), wherein, the number of times that data representation notebook data piece in the bracket () is wiped free of/writes is 0 when initial.When behind A data block data writing, list structure becomes B(0)-〉 C(0)-〉 D(0)-〉 A(1); Behind B data block data writing, list structure becomes C(0 again)-〉 D(0)-〉 A(1)-〉 B(1); Behind A data block data writing, list structure becomes C(0 again)-〉 D(0)-〉 B(1)-〉 A(2); Behind D data block data writing, list structure becomes C(0 again)-〉 B(1)-〉 D(1)-〉 A(2), the like.
Based on above structure, the method for writing data of the present embodiment may further comprise the steps:
Step S202: receive to the data of nand memory data writing and write instruction, write the first data block that data to be written are determined in instruction according to data.
Step S204: read the number of times of wiping/writing of the OOB district record of the first data block, judge whether the number of times of wiping/writing of the first data block reaches setting threshold, if, execution in step S206 then; If not, execution in step S212 then.
Step S206: if the number of times of wiping/writing of the first data block reaches setting threshold, judge then whether the number of times of wiping/writing of data block of gauge outfit of the data block chained list of nand memory reaches setting threshold, if do not reach, execution in step S208 then; If reach, then provide prompting, finish this secondary data and write flow process.
In the present embodiment, because adopt list structure to link from small to large the data block of nand memory according to the number of times of wiping/writing of data block, therefore, when needed, directly select the data block of linked list head as the second data block, if this linked list head data block has also reached setting threshold, then illustrate in this chained list not reached the data block of setting threshold, provide corresponding prompting.Therefore but generally, the data block of linked list head can not reach setting threshold, can directly select this linked list head data block as the second new data block, and reach setting threshold the first data block and carry out exchanges data, and then data writing.
Need to prove, the storage organization of the data block of nand memory is not limited to list structure, and those skilled in the art can arrange suitable structure according to the actual requirements.The selection of the second data block also is not limited to the form of above-mentioned use linked list head data block, those skilled in the art can also select other form according to actual conditions.For example, the data block information table is set in nand memory, store the number of times of wiping/writing of each data block of nand memory in this data block information table, certainly, can also store the address information of each data block, like this, when needs are selected data block, can from the data block information table, obtain the information that the number of times of wiping/writing does not reach the data block of setting threshold; And then, according to suitable setting rule (as according to from small to large select progressively of the number of times of wiping/writing, random select etc.), from data block corresponding to the information of the data block obtained, select a data block as the second data block.Further, can according to the address information of second data block of storing in the data block information table, directly access the second data block of this selection.
Step S208: select the data block of gauge outfit of chained list as the second data block, the data in the first data block and data in the second data block of selecting are exchanged.
For example, the setting threshold of the number of times of wiping/writing is to store D1, D2, three data of D3 in 500, the A data block, and the number of times of current wiping/write is 200; Store D5, two data of D6 in the B data block, the number of times of current wiping/write is 500; During then again to B data block data writing, because the number of times of wiping/writing of B data block has reached setting threshold, then select the A data block as new data block.At this moment, temporarily store the data D1 in the A data block, D2, D3 into a scratchpad area (SPA), delete the data in the A data block, and the D5 in the B data block, D6 are copied in the A data block, the number of times of wiping/writing of A data block becomes 201; Then, with the deletion of the data in the B data block, the D1 in the scratchpad area (SPA), D2, D3 are copied in the B data block, the number of times of wiping/writing of B data block becomes 501.As seen, by aforesaid operations, realized the exchanges data of A data block and B data block, because the number of times of wiping/writing of A data block does not also reach setting threshold, therefore can continue the A data block is wiped/write operation, data have been write the A data block.
Step S210: write instruction to the second data block data writing that carries out after the exchanges data, execution in step S214 according to data.
Step S212: if the number of times of wiping/writing of the first data block does not reach setting threshold, then write instruction to this first data block data of writing direct, execution in step S214 according to data.
Step S214: the number of times of wiping/writing of the notebook data piece of the outer data OOB district of the band of the data block of renewal data writing record.
Step S216: according to the number of times of wiping/writing of the data block after upgrading, this data block is moved to the number of times of wiping/writing be less than or equal to after the data block of the number of times of wiping/writing of notebook data piece, form the data block chained list that links from small to large according to the number of times of wiping/writing.
By the present embodiment, effectively prolonged the service time of nand memory+FAT file system, using or test for data card is long-time provides how selectable LOG recording mode; And so that data card uses or during test long-time, the memory property of saving nand memory is given full play to the potential storage capacity of nand memory.
In addition, need to prove, in the present embodiment, at the number of times of wiping/writing of the OOB district of each data block minute book data block, can effectively utilize the OOB district of data block, and realize simply not needing the memory block is set in addition, saved the realization cost.
Embodiment three
With reference to Fig. 3, show the flow chart of steps according to a kind of method for writing data of the embodiment of the invention three.
The file that the present embodiment is stored in the nand memory is described the sector as example, and 512 bytes of this sector can be by frequently erasable, and wearing and tearing can be more serious.The present embodiment records the number of times of wiping/writing of this data block in the OOB district of data block corresponding to this sector, after number of times surpasses setting threshold, this data block and other available data block is exchanged, and makes it become " new data block ".
The method for writing data of the present embodiment may further comprise the steps:
Step S302:LTE data card output LOG information, LTE data card place equipment sends data and writes instruction, and the corresponding software module of LTE data card place equipment is prepared to describe the sector data writing to the file of nand memory.
Step S304: software module writes from data and obtains the logical address that file is described the sector the instruction.
Step S306: the logical address that software module is described the sector according to file determines that file describes the physical address of sector.
Step S308: software module judges that file describes the number of times of wiping/writing of data block at the physical address place of sector and whether reach setting threshold, if, execution in step S310 then; If not, execution in step S316 then.
Wherein, setting threshold can be according to those skilled in the art's experience or test simulation setting, generally can select nand memory erasable/below 90% of write operation life-span number of times, as, if nand memory can repeatedly be wiped/write 100,000 times, then setting threshold can be set to 80,000 times or be 90,000 inferior.Certainly, above only is exemplary illustration, and in actual applications, those skilled in the art can arrange according to actual needs flexibly.
Step S310: software module does not reach from the number of times of wiping/writing selects a data block the data block of setting threshold.
As, the data block of the least number of times of wiping/writing in selection linked list head data block or the selection data block information table.
Step S312: software module is described the data block at place, sector to file data exchange with data in the data block selected.
After the exchange, the data that file is described the sector have stored in the data block of selecting.
Step S314: software module writes instruction according to data, and the file in the data block of selecting is described the sector data writing, finishes this secondary data and writes flow process.
For example, software module writes instruction according to data, and control NAND controller is described the sector data writing to the file in the data block of selecting
Step S316: do not reach setting threshold if file is described the number of times of wiping/writing of data block at the physical address place of sector, then software module writes instruction to this data block data of writing direct according to data, finishes this secondary data and writes flow process.
The present embodiment for the FAT file system to the inhomogeneous and limited problem of the erasable number of times of nand memory of data block utilization factor, a kind of data writing scheme is provided, between logical address to be written and actual NAND physical address, add scheduling (being the scheduling of corresponding software module in the equipment of LTE data card place), this scheduling is after receiving logical address, can reschedule according to erasable number of times, then after shining upon real physical address, carry out read-write operation, thereby reduced as much as possible the unevenness of FAT file system operation, taken full advantage of the potential storage capacity of nand memory.For example, in the present embodiment, the sector is described as example take file, 512 bytes of this sector because of meeting by frequently erasable, wear and tear more serious, the scheme of the present embodiment is in the OOB district of data block corresponding to this sector, record the number of times of wiping/writing of this data block, after number of times surpasses setting threshold, this data block and other data block are exchanged, make it become " new data block ".After this " new data block " may wear to setting threshold, can look for again the data block of " suitable " to replace.Change like this, just can utilize as much as possible each data block in the nand memory, on average in each data block, avoid wearing and tearing the wearing and tearing of individual data piece excessive, cause bad piece.As seen, scheme by the present embodiment, can effectively prolong the service time of nand memory+FAT file system, so that data card is when long-time test, many selectable LOG recording modes, and the memory property of saving nand memory is given full play to the potential storage capacity of nand memory.
Embodiment four
With reference to Fig. 4, show the structured flowchart according to a kind of data transfer apparatus of the embodiment of the invention four.
The data transfer apparatus of the present embodiment four comprises: determination module 402, and be used for to receive to the data of flash memory data writing repeatedly and write instruction, write the first data block that data to be written in the flash memory are determined repeatedly in instruction according to data; Acquisition module 404, be used for obtaining the number of times of wiping/writing of the first data block, and when the number of times of wiping/writing of the first data block reached setting threshold, selective erasing/number of times that writes did not reach the second data block of setting threshold from other data block of flash memory repeatedly; Execution module 406 is used for the data of the first data block and the data in the second data block are exchanged; Write instruction to the second data block data writing that carries out after the exchanges data according to data.
Preferably, the data transfer apparatus of the present embodiment also comprises: logging modle 408, be used for execution module 406 writes the second data block data writing of instruction after carrying out exchanges data according to data after, upgrade the number of times of wiping/writing of the notebook data piece that the OOB district of the second data block records.
Preferably, acquisition module 404 reads the number of times of wiping/writing of the OOB district record of the first data block when obtaining the number of times of wiping/writing of the first data block.
Preferably, the data transfer apparatus of the present embodiment also comprises: processing module 410, be used for after logging modle 408 is upgraded the number of times of wiping/writing of the notebook data piece that the OOB district of the second data block records, the number of times of wiping/writing according to the second data block after upgrading, the second data block is moved to the number of times of wiping/writing be less than or equal to after the data block of the number of times of wiping/writing of the data block of selecting, form the data block chained list that links from small to large according to the number of times of wiping/writing.
Preferably, when acquisition module 404 does not reach the second data block of setting threshold at the number of times of selective erasing from other data block of flash memory repeatedly/write, when the number of times of wiping/writing of the data block of the gauge outfit of data block chained list does not reach setting threshold, the data block of the gauge outfit of data block chained list is defined as the second data block.
Preferably, when acquisition module 404 does not reach the second data block of setting threshold at the number of times of selective erasing from other data block of flash memory repeatedly/write, from the data block information table, obtain the information that the number of times of wiping/writing does not reach the data block of setting threshold, wherein, store repeatedly the number of times of wiping/writing of each data block of flash memory in the data block information table; According to setting rule, from data block corresponding to the information of the data block obtained, select a data block as the second data block.
Preferably, the repeatedly flash memory of the present embodiment is nand memory.
The data transfer apparatus of the present embodiment is used for realizing the corresponding method for writing data of aforementioned a plurality of embodiment of the method, and the beneficial effect with corresponding embodiment of the method, does not repeat them here.
Need to prove, among a plurality of embodiment of the present invention all take nand memory as example, but it should be understood by those skilled in the art that arbitrarily similar with nand memory, can repeatedly wipe/write operation and having wipes/the equal applicable the solution of the present invention of the storer in write operation life-span.
Each embodiment in this instructions all adopts the mode of going forward one by one to describe, and what each embodiment stressed is and the difference of other embodiment that identical similar part is mutually referring to getting final product between each embodiment.For device embodiment because itself and embodiment of the method basic simlarity, so describe fairly simple, relevant part gets final product referring to the part explanation of embodiment of the method.
Above a kind of method for writing data provided by the present invention and device are described in detail, used specific case herein principle of the present invention and embodiment are set forth, the explanation of above embodiment just is used for helping to understand method of the present invention and core concept thereof; Simultaneously, for one of ordinary skill in the art, according to thought of the present invention, all will change in specific embodiments and applications, in sum, this description should not be construed as limitation of the present invention.