Summary of the invention
It is an object of the invention to provide life-span method for early warning and the device of a kind of NAND flash storage, the remaining life of NAND flash storage cannot be known, user data loss when causing NAND flash storage to lose efficacy, the technical problem that cannot recover with solution user.
First aspect present invention provides the life-span method for early warning of a kind of NAND flash storage, and the method includes:
Obtain the maximum write data volume of NAND flash storage;
Obtain the accumulative erased block data volume in NAND flash storage work process;
According to described maximum write data volume and described accumulative erased block data volume, calculate the residue erasable blocks of data amount of NAND flash storage;
When judging that described residue erasable blocks of data amount reaches predetermined threshold value, generate alarm command;
According to described alarm command, show warning message to user.
Wherein, the maximum write data volume of described acquisition NAND flash storage includes:
Described NAND flash storage is carried out bad block detection, obtains active block quantity;
The erasable number of times of maximum according to active block quantity and active block, it is thus achieved that the maximum write data volume of NAND flash storage.
Wherein, the accumulative erased block data volume obtained in NAND flash storage work process includes:
Obtain accumulative erased block quantity and the capacity of each active block;
According to accumulative erased block quantity and the capacity of each active block, obtain the accumulative erased block data volume of NAND flash storage.
Wherein, the erasable process of described NAND flash storage includes:
Travel through all active blocks of described NAND flash storage, obtain the accumulative erasing times of each active block;
Obtain the active block that accumulative erasing times is minimum, this active block is carried out erasable operation.
Wherein, described NAND flash storage is arranged in video camera, described according to described alarm command, shows that warning message includes to user:
According to described alarm command, on the display screen of described video camera, NAND flash storage life-span overdue warning message described in pop-up display;Or,
According to described alarm command, by changing the color of the display lamp arranged on described video camera or making described display lamp flash, show warning message to user;Or,
According to described alarm command, by the voice output of described video camera, send specific caution sound, show warning message to user.
Wherein, described NAND flash storage is arranged in video camera, and described video camera and an external display device are connected, described according to described alarm command, shows that warning message includes to user:
According to described alarm command, on the display screen of described external display device, NAND flash storage life-span overdue warning message described in pop-up display;Or,
According to described alarm command, by the voice output of described external display device, send specific caution sound, show warning message to user.
Present invention offers following beneficial effect: embodiments provide the life-span method for early warning of a kind of NAND flash storage, the method can be accurate, detect the accumulative erased block quantity of NAND flash storage rapidly, obtain the residue erasable blocks of data amount of NAND flash storage, and when remaining erasable blocks of data amount and reaching predetermined threshold value, warning message is shown to user, user is avoided to be unable to estimate the erasable blocks of data amount of NAND flash storage, user data loss when causing NAND flash storage to lose efficacy, the generation of unfavorable condition such as cannot recover, ensure that the data safety of user.
Second aspect present invention provides the life-span prior-warning device of a kind of NAND flash storage, and this device includes:
Acquisition module, obtains the maximum accumulative erased block data volume write in data volume and described NAND flash storage work process of described NAND flash storage;
Computing module, according to described maximum write data volume and described accumulative erased block data volume, calculates the residue erasable blocks of data amount of NAND flash storage;
Processing module, when determining described residue erasable blocks of data amount and reaching predetermined threshold value, generates alarm command;
Alarm module, according to described alarm command, shows warning message to user.
Wherein, described acquisition module includes:
Bad block detector unit, for described NAND flash storage carries out bad block detection, obtains active block quantity;
Maximum write data volume administrative unit, for the erasable number of times of maximum according to active block quantity and active block, it is thus achieved that the maximum write data volume of NAND flash storage.
Wherein, described acquisition module also includes:
Accumulative erased block data volume administrative unit, for obtaining accumulative erased block quantity and the capacity of each active block, and according to accumulative erased block quantity and the capacity of each active block, obtains the accumulative erased block data volume of NAND flash storage.
Wherein, this device also includes:
Erasable module, for traveling through all active blocks of described NAND flash storage, obtains the accumulative erasing times of each active block, and obtains the active block that accumulative erasing times is minimum, this active block is carried out erasable operation.
Wherein, described alarm module is according to described alarm command, on the display screen of video camera, and NAND flash storage life-span overdue warning message described in pop-up display;Or according to described alarm command, by changing the color of the display lamp arranged on described video camera or making described display lamp flash, show warning message to user;Or according to described alarm command, by the voice output of described video camera, send specific caution sound.
Wherein, described device and an external display device are connected, and described alarm module is according to described alarm command, on the display screen of described external display device, and NAND flash storage life-span overdue warning message described in pop-up display;Or according to described alarm command, by the voice output of described external display device, send specific caution sound.
Other features and advantages of the present invention will illustrate in the following description, and, partly become apparent from description, or understand by implementing the present invention.The purpose of the present invention and other advantages can be realized by structure specifically noted in description, claims and accompanying drawing and be obtained.
Detailed description of the invention
Describing embodiments of the present invention in detail below with reference to drawings and Examples, to the present invention, how application technology means solve technical problem whereby, and the process that realizes reaching technique effect can fully understand and implement according to this.As long as it should be noted that do not constitute conflict, each embodiment in the present invention and each feature in each embodiment can be combined with each other, and the technical scheme formed is all within protection scope of the present invention.
Embodiments provide the life-span method for early warning of a kind of NAND flash storage, be applied to install the video camera of NAND flash storage, as it is shown in figure 1, the method includes:
Step S101, the maximum write data volume of acquisition NAND flash storage.
Each NAND flash storage is made up of a block array.Each block is exactly the set of the memory element of a series of entitled page (page).Video camera is before writing data into the memory element of NAND flash storage, it is necessary to wipe this memory element, in order to can carry out data write.Minimum erasing unit is block (block), and minimum write or reading unit are page (page).
Erasing operation allows all of position (bit) in a block be become 1 from 0 exactly, the block of clean " a wiping " state restart to write data.After one page inside block or several pages become 0, only wipe whole piece and this page could be allowed to become 1.
Therefore, the maximum write data volume of NAND flash storage depends on the quantity of its internal active block.When using NAND flash storage, it is only necessary to the bad block in detection NAND flash storage, learn bad number of blocks, active block quantity can be obtained.
Then, according to the erasable number of times of the maximum of active block quantity and each piece, in conjunction with the capacity of active block, the maximum write data volume of NAND flash storage can be obtained.Once the write data volume of NAND flash storage approaches or arrives at maximum write data volume, the end of having arrived the service life of NAND flash storage.Therefore, the maximum write data volume of NAND flash storage represents the terminal life of NAND flash storage.
For the NAND flash storage that have employed erasable equalization algorithm, only need when running first, in scanning NAND flash storage each piece, obtain the quantity of the bad block of NAND flash storage, the quantity of the remaining active block of this NAND flash storage can be learnt, thus according to the erasable number of times of maximum of each piece and the capacity of block, learn the maximum write data volume of this NAND flash storage, and then learn the terminal life of this NAND flash storage.
Step S102, the accumulative erased block data volume obtained in NAND flash storage work process.
Accumulative erased block data volume represents the service life of NAND flash storage.Accumulative erased block data volume is mainly by obtaining accumulative erased block quantity and the capacity of each active block, and obtain according to the procurement of reserve capacity of accumulative erased block quantity and each active block.
In the work process of NAND flash storage, except the erasable operation performed under user operation can increase accumulative erased block quantity, the garbage reclamation mechanism that NAND flash storage itself performs also can increase accumulative erased block quantity.Take due to NAND flash storage is strange land update mechanism, and As time goes on, the quantity of the free block in NAND flash storage can constantly reduce.In order to be able to there are enough free spaces for user, this is accomplished by wiping those physical blocks comprising invalid data page to obtain new free block, and this is the effect of garbage reclamation mechanism.
During garbage reclamation mechanism performs, often moving the data in a block and wipe a block, accumulative erased block quantity adds one, automatically until a garbage reclamation mechanism is finished.
It addition, for NAND flash storage, it has write and amplifies the function of (Write amplification is called for short WA), and the physical message amount being i.e. actually written into is many times of the amount of logic that will write.Owing to the block of NAND flash storage must first carry out erasing operation before can re-writing data, and the granularity wiping operation is much lower compared with write operation, performs these operations and will repeatedly move (or rewriting) user data.This working method of NAND flash storage, make the flash parts that must wipe rewriting more much bigger than what new data was actually needed, this multiplier effect can increase the number of times of request write, shorten the life-span of NAND flash storage, thus reduce the time of the reliability service of NAND flash storage.
Therefore, NAND flash storage generally uses erasable equilibrium (Wear-Leveling) algorithm, i.e. every time erasing/write operation circulate, be equally distributed in all of active block rather than repeatedly wipe for same or several active blocks, write operation.Concrete, have employed the NAND flash storage of erasable equalization algorithm every time before carrying out erasing operation, all of active block can be traveled through, obtain the accumulative erasing times of each active block, and the accumulative active block that erasing times is minimum is performed erasing operation.Use this erasable equalization algorithm so that the accumulative erasing times of each active block in NAND flash storage is roughly equal.Therefore when obtaining accumulative erased block data volume, can arbitrarily obtain the accumulative erasing times of an active block, the product of this accumulative erasing times with active block quantity is added up the inconvenient degree of erased block data volume as accumulative erased block data volume, reduction statistics.
Step S103, according to maximum write data volume and accumulative erased block data volume, calculate the residue erasable blocks of data amount of NAND flash storage.
The loss of data causing user to prevent NAND flash storage to lose efficacy, situation about cannot recover occur, and the life detecting method of the NAND flash storage that the embodiment of the present invention provides also includes:
Step S104, when judge remain erasable blocks of data amount reach predetermined threshold value time, generate alarm command.
Step S105, according to alarm command, show warning message to user.
When the residue of NAND flash storage erasable blocks of data amount reaches predetermined threshold value, warning message will be shown to user, and remind user to change NAND flash storage and avoid loss of data.
As a example by NAND flash storage is arranged in video camera, now, the display screen of available video camera, pop-up display NAND flash storage life-span overdue warning message.After most NAND flash storage is changed by user by the life-span, this warning message disappears from display screen.
Or, can load near in place of NAND flash storage at video camera, the display lamp of the state being specifically designed to displaying NAND flash storage is set.If NAND flash storage normally work and add up erased block data volume less time, display lamp is for green or do not work;And when the NAND flash storage life-span is by time to the greatest extent, and display lamp is shown in red or starts acutely flicker, call user's attention.
Additionally, it is possible to by the voice output of video camera, making video camera or external equipment send caution sound that pre-set, specific, this caution sound may be configured as the most sharp-pointed, rapid sound, to cause the attention of user, changes NAND flash storage in time.
When this video camera connects external display device, it is possible on the display screen of external display device, pop-up display NAND flash storage life-span overdue warning message;Or by the voice output of external display device, send specific caution sound, show warning message to user.Enrich the life-span early warning approach of NAND flash storage, be more convenient for allowing user understand in time, changing NAND flash storage.
To sum up, embodiments provide the life-span method for early warning of a kind of NAND flash storage, the method can be accurate, detect the accumulative erased block quantity of NAND flash storage rapidly, obtain the residue erasable blocks of data amount of NAND flash storage, and when remaining erasable blocks of data amount and reaching predetermined threshold value, warning message is shown to user, user is avoided to be unable to estimate the erasable blocks of data amount of NAND flash storage, user data loss when causing NAND flash storage to lose efficacy, the generation of unfavorable condition such as cannot recover, ensure that the data safety of user.
Concrete, for being provided with the video camera of SD card or Micro SD card, as in figure 2 it is shown, video camera is as main frame, its master control system sends instruction by SD interface to SD card or Micro SD card, operates in the firmware program in the controller of SD card.The Flash interface instructed by connecting NAND flash storage that the firmware program of SD controller sends according to video camera, carries out the operations such as digital independent, write and acquisition of information to NAND flash storage.
The master control system of video camera is by a reserve statement transmission information in SD instruction set, SD card or Micro SD card return according to the reserve statement that master control system is sent and remain the information such as erasable blocks of data amount, write amplification quantity, active block quantity, bad number of blocks, and the state of SD card or Micro SD card is estimated by the master control system of auxiliary camera.
Concrete, SD card or Micro SD are stuck in after receiving the instruction that the master control system from video camera sends, and calculate and write amplification quantity.Owing to minimum erasing unit is block (block), minimum write or reading unit are page (pages), and the physical message amount being i.e. actually written into is many times of the amount of logic that will write.Therefore video camera needs to obtain write amplification quantity, i.e. write data volume and the ratio of erasing blocks of data amount, calculates the filling proportion of the active block of NAND flash storage in SD card or Micro SD card, as this SD card of assessment or a parameter of Micro SD card.
It addition, during as it is shown on figure 3, SD card or Micro SD card run after dispatching from the factory first, the firmware program on SD controller can carry out bad block detection, mark bad block.Afterwards, according to remaining active block quantity after removing bad block and some reserved block, in conjunction with the erasable number of times of maximum determined by the dielectric property of NAND flash storage and the capacity of block, i.e. can obtain the maximum write data volume of this SD card or Micro SD card, this information is saved in SD card or Micro SD card, it is simple to the master control system of video camera is extracted, called.
Mentioning in the preceding article, in order to extend the service life of NAND flash storage, NAND flash storage can use erasable equalization algorithm.As shown in Figure 4, in ablation process, in order to erasable loss is uniformly distributed to each physical block, select a free block being suitable for write by erasable equilibrium.Concrete, when a write request occurs in the master control system of video camera, each piece in NAND flash storage can be browsed by this erasable equalization algorithm, finds a minimum module unit of erasing count value.Once find satisfactory piece, if this block internal memory contains data, just the valid data in this block are moved, this block is wiped totally, then write data into.If there is no data in this block, so that it may directly this block is performed write operation.If the process of write occurs in that erasing operation, then in SD card or Micro SD card, the accumulative erased block quantity of storage will be cumulatively added, occur that erasing operation, accumulative erased block quantity are required for adding up each time.
Additionally, as shown in Figure 5, if the invalid physical block of this NAND flash storage is too much or the quantity of free block is less than certain threshold value, the garbage reclamation mechanism of NAND flash storage is activated, garbage reclamation mechanism can select the invalid physical block needing to be recovered, useful data in invalid physical block is copied in other blocks, then block erasing will be reclaimed, become free block.Obviously, during garbage reclamation mechanism, accumulative erased block quantity should also be as together changing, to guarantee to be correctly detected the residue erasable blocks of data amount of NAND flash storage.
Effect due to erasable equalization algorithm, the erasable number of times of each physical block is closely, so available accumulative erased block quantity weigh whole SD card or Micro SD card objectively use the life-span, thus obtain the residue erasable blocks of data amount of accurate SD card or Micro SD card, the most whole SD card or the residual life of Micro SD card.
As shown in Figure 6, the master control system of video camera can be at interval of certain time, and from SD card or Micro SD card read status information and record log blocks, SD controller calculates and remains erasable blocks of data amount and also feed back to master control system;After master control system receives the erasable blocks of data amount of residue, determine whether to need to report to the police.Concrete; when SD card or when remaining the predetermined threshold value that erasable blocks of data amount reaches corresponding of Micro SD card, master control system is reported to the police to user, it is proposed that user changes card in time to avoid loss of data; avoid the loss of data that will cause to the greatest extent because of SD card or Micro SD card life-span, protect data safety.
Further, the embodiment of the present invention additionally provides the life-span prior-warning device of a kind of NAND flash storage, as it is shown in fig. 7, this device includes:
Acquisition module, obtains the maximum accumulative erased block data volume write in data volume and NAND flash storage work process of NAND flash storage.
Computing module, according to maximum write data volume and accumulative erased block data volume, calculates the residue erasable blocks of data amount of NAND flash storage.
Processing module, when determining the erasable blocks of data amount of residue and reaching predetermined threshold value, generates alarm command.
In order to coordinate NAND flash storage to realize warning function, the alarm command that the alarm module in this device can generate according to processing module, show warning message to user.
Concrete, as shown in Figure 8, the acquisition module in NAND flash storage includes:
Bad block detector unit, for described NAND flash storage carries out bad block detection, obtains active block quantity.
Maximum write data volume administrative unit, for the erasable number of times of maximum according to active block quantity and active block, it is thus achieved that the maximum write data volume of NAND flash storage.
Additionally, acquisition module also includes:
Accumulative erased block data volume administrative unit, for obtaining accumulative erased block quantity and the capacity of each active block, and according to accumulative erased block quantity and the capacity of each active block, obtains the accumulative erased block data volume of NAND flash storage.
Concrete, if this NAND Flash life-span prior-warning device is video camera or time in video camera, alarm module can be according to alarm command, on the display screen of video camera, NAND flash storage life-span overdue warning message described in pop-up display;Or according to alarm command, by changing the color of the display lamp arranged on video camera or making display lamp flash, show warning message to user;Or according to alarm command, by the voice output of video camera, send specific caution sound, show warning message to user.
It addition, when this NAND Flash life-span prior-warning device and an external display device are connected, alarm module can be according to described alarm command, on the display screen of external display device, pop-up display NAND flash storage life-span overdue warning message;Or according to alarm command, by the voice output of external display device, send specific caution sound, show warning message to user.
Further, the life-span prior-warning device of this NAND flash storage also includes: erasable module, for traveling through all active blocks of described NAND flash storage, obtain the accumulative erasing times of each active block, and obtain the active block that accumulative erasing times is minimum, this active block is carried out erasable operation.
Erasable module can change the accumulative erased block data volume needed for acquisition module, and after the work of each erasable module, acquisition module is required for reacquiring accumulative erased block data volume, are exactly carried out early warning the life-span of NAND Flash.
While it is disclosed that embodiment as above, but described content is only to facilitate the embodiment that understands the present invention and use, is not limited to the present invention.Technical staff in any the technical field of the invention; on the premise of without departing from spirit and scope disclosed in this invention; in form and any amendment and change can be made in details implement; but the scope of patent protection of the present invention, still must be defined in the range of standard with appending claims.