Summary of the invention
Fundamental purpose of the present invention is to provide a kind of method solving SD agreement time-out, is intended to solve take-back model in flash memory management and completes the problem that all reclaimer operations time used exceedes the response time specified in agreement.
Another object of the present invention is to provide a kind of device solving SD agreement time-out.
To achieve these goals, the invention provides a kind of method solving SD agreement time-out, comprise following concrete steps: S1, judge whether the residual capacity of spatial cache is greater than the first preset value; If so, in units of page, carry out write operation, after completing the write of current page, response main frame, completes write-once operation; Otherwise, write operation is carried out in units of page, after completing the write of current page, statistics page status table, find out to be recycled piece of minimum valid data and mark reclaims mark, moving in blank page, after having moved to the described valid data being labeled the appointment number of pages of to be recycled piece of upper recovery mark, response main frame, completes write-once operation.
Preferably, also comprise step S10 before step S1: in units of page, carry out write operation, after completing the write of current page, response main frame, completes write-once operation.
Preferably, after step S1, also comprise step S11: judge whether main frame sends stopping data transfer command, if so, terminate all write operations, otherwise, after continuing to receive data to be written from main frame, go to step S10.
Preferably, the method for described solution SD agreement time-out, comprises following concrete steps:
A, from main frame, receive one page data to be written to spatial cache, after a blank page of write current block, judge whether current block is finished, if so, then refresh page state table, gets an empty block as current block, goes to step E; Otherwise go to step B;
B, judge whether to be labeled to be recycled piece that reclaims mark, if so, go to step C; Otherwise, judge whether the residual capacity of spatial cache is greater than the first preset value, if so, proceeds to E, otherwise statistics page status table, find out to be recycled piece of minimum valid data and mark reclaims mark, going to step C;
C, enter reclaimer operation, by the data-moving in the described valid data page being labeled the predetermined number of to be recycled piece reclaiming mark to blank page, be labeled valid data in be recycled piece that reclaims mark described in judgement whether all to move, if so, then this to be recycled piece is wiped, and remove recovery mark, then added to spatial cache, go to step D, otherwise, go to step E;
D, judge whether the residual capacity of spatial cache is greater than the second preset value, if so, goes to step E; Otherwise statistics page status table, finds out to be recycled piece of minimum valid data and after the upper recovery mark of mark, goes to step E;
E, response main frame, complete when previous write operation, judge whether main frame sends stopping data transfer command, if so, terminate all write operations, otherwise after continuing to receive data to be written from main frame, go to step A.
Preferably, in step D, described second preset value is greater than the first preset value.
Solve a device for SD agreement time-out, comprise write operation unit, the first spatial cache reading unit and reclaimer operation unit, wherein,
Described first spatial cache reading unit, for judging whether the residual capacity of spatial cache is greater than the first preset value, if, then enter said write operating unit, otherwise statistics page status table, find out to be recycled piece of minimum valid data and mark reclaims mark, entering described reclaimer operation unit;
Said write operating unit, for carrying out write operation in units of page, after completing the write of current page, response main frame, completes write-once operation;
Described reclaimer operation unit, for carrying out write operation in units of page, after completing the write of current page, move in blank page to the described valid data being labeled the appointment number of pages of to be recycled piece of upper recovery mark, after having moved, response main frame, completes write-once operation.
Preferably, the device of described solution SD agreement time-out also comprises main frame write judging unit, for judging whether main frame sends stopping data transfer command, if so, all write operations are terminated, otherwise, after continuing to receive data to be written from main frame, enter said write operating unit.
Preferably, the device of described solution SD agreement time-out also comprises to be recycled piece of recognition unit, the second spatial cache reading unit and main frame write judging unit; Wherein,
Said write operating unit, specifically for receiving one page data to be written to spatial cache from main frame, after a blank page of write current block, judge whether current block is finished, if so, then refresh page state table, get an empty block as current block, enter described main frame write judging unit; Otherwise enter to be recycled piece of recognition unit;
Described to be recycled piece of recognition unit, being labeled upper to be recycled piece of reclaiming mark for judging whether, if so, entering described reclaimer operation unit; Otherwise, enter the first spatial cache reading unit;
Described first spatial cache reading unit, specifically for judging whether the residual capacity of spatial cache is greater than the first preset value, if, enter described main frame write judging unit, otherwise statistics page status table, find out to be recycled piece of minimum valid data and mark reclaims mark, entering described reclaimer operation unit;
Described reclaimer operation unit, specifically for by described be labeled reclaim mark the predetermined number of to be recycled piece valid data page in data-moving to blank page, be labeled valid data in be recycled piece that reclaims mark described in judgement whether all to move, if so, then this to be recycled piece is wiped, and remove recovery mark, then added to spatial cache, enter described second spatial cache reading unit, otherwise, enter described main frame write judging unit;
Described second spatial cache reading unit, for judging whether the residual capacity of spatial cache is greater than the second preset value, if so, enters described main frame write judging unit; Otherwise statistics page status table, finds out to be recycled piece of minimum valid data and after the upper recovery mark of mark, enters described main frame write judging unit;
Described main frame write judging unit, for judging whether main frame sends stopping data transfer command, if so, terminates all write operations, otherwise, after continuing to receive data to be written from main frame, enter said write operating unit.
The invention provides a kind of method and the device that solve SD agreement time-out.In the data writing process of flash memory, if after judging that the residual capacity of spatial cache is less than the first preset value, need to enter take-back model, the present invention adopts the data often writing a blank page, then to be recycled piece is just obtained, and by specify the valid data of number of pages to move in be recycled piece blank page on, then HOST is responded, complete write-once operation, the several design parameter according to flash memory of specific page of data-moving is arranged, can not TIMEOUT time of specifying of operating protocol to ensure to write in each write operation data and T.T. of number of pages of moving.
Embodiment
Should be appreciated that specific embodiment described herein only in order to explain the present invention, be not intended to limit the present invention.
Solution for embodiment of the invention is mainly: the method and the device that solve SD agreement time-out.In the data writing process of flash memory, if after judging that the residual capacity of spatial cache is less than the first preset value, need to enter take-back model, the present invention adopts the data often writing a blank page, then to be recycled piece is just obtained, and by specify the valid data of number of pages to move in be recycled piece blank page on, then HOST is responded, complete write-once operation, the several design parameter according to flash memory of specific page of data-moving is arranged, can not TIMEOUT time of specifying of operating protocol to ensure to write in each write operation data and T.T. of number of pages of moving.
Please with reference to shown in Fig. 1 to Fig. 2, wherein, Fig. 1 is the workflow diagram of method one embodiment of solution SD agreement time-out of the present invention; Fig. 2 is the structural representation of the device of solution SD agreement time-out of the present invention.The method of solution SD agreement time-out of the present invention comprises following concrete steps:
S1, from main frame, receive one page data to be written to spatial cache (S10), after a blank page (S11) of write current block, judge whether current block is finished (S12), if, then refresh page state table, get an empty block as current block (S13), go to step S5; Otherwise go to step S2;
S2, judge whether to be labeled to be recycled piece (S20) reclaiming mark, if so, go to step S3; Otherwise, judge whether the residual capacity of spatial cache is greater than the first preset value (S21), if, go to step S5, otherwise statistics page status table, finds out to be recycled piece of minimum valid data and mark reclaims mark (S22), going to step S3;
S3, enter reclaimer operation, by the data-moving in the described valid data page being labeled the predetermined number of to be recycled piece reclaiming mark to blank page (S30), be labeled valid data in be recycled piece that reclaims mark described in judgement whether all to move (S31), if so, then this to be recycled piece is wiped, and remove recovery mark, then added to spatial cache (S32), go to step S4, otherwise, go to step S5;
D, judge whether the residual capacity of spatial cache is greater than the second preset value (S40), if so, goes to step S5; Otherwise statistics page status table, finds out to be recycled piece of minimum valid data and after mark reclaims mark (S41), goes to step S5;
S5, response main frame, complete as previous write operation (S50), judge whether main frame sends stopping data transfer command, if so, terminate all write operations (S51), otherwise after continuing to receive data to be written from main frame, go to step S1.
In actual application of the present invention, in step S3, the blank page number of described specified quantity can be arranged according to the design parameter of flash memory, to ensure that the time of the number of pages moved and write data can not the time-out time that specifies of operating protocol at every turn, generally speaking, the blank page number of this specified quantity is 4 pages, and the second preset value is greater than the first preset value.
As shown in Figure 2, one embodiment of the invention proposes a kind of device solving SD agreement time-out, comprises write operation unit 1, to be recycled piece of recognition unit 2, first spatial cache reading unit 3, reclaimer operation unit 4, second spatial cache reading unit 5 and main frame write judging unit 6; Wherein,
Write operation unit 1, for receiving one page data to be written to spatial cache from main frame, after a blank page of write current block, judge whether current block is finished, if so, then refresh page state table, get an empty block as current block, enter main frame write judging unit 6; Otherwise enter to be recycled piece of recognition unit 2.
To be recycled piece of recognition unit 2, being labeled upper to be recycled piece of reclaiming mark for judging whether, if so, entering reclaimer operation unit 4; Otherwise, enter the first spatial cache reading unit 3;
First spatial cache reading unit 3, specifically for judging whether the residual capacity of spatial cache is greater than the first preset value, if, enter main frame write judging unit 6, otherwise statistics page status table, finds out to be recycled piece of minimum valid data and mark reclaims mark, entering reclaimer operation unit 4;
Reclaimer operation unit 4, specifically for will be labeled reclaim mark the predetermined number of to be recycled piece valid data page in data-moving to blank page, be labeled valid data in be recycled piece that reclaims mark described in judgement whether all to move, if so, then this to be recycled piece is wiped, and remove recovery mark, then added to spatial cache, enter the second spatial cache reading unit 5, otherwise, enter main frame write judging unit 6;
Second spatial cache reading unit 5, for judging whether the residual capacity of spatial cache is greater than the second preset value, if so, enters main frame write judging unit 6; Otherwise statistics page status table, finds out to be recycled piece of minimum valid data and after the upper recovery mark of mark, enters main frame write judging unit 6.
Main frame write judging unit 6, for judging whether main frame sends stopping data transfer command, if so, terminates all write operations, otherwise, after continuing to receive data to be written from main frame, enter write operation unit 1.
Shortcoming and defect compared to existing technology, the present invention has following beneficial effect: in the method take-back model of solution SD agreement time-out of the present invention, the time used is controlled, ensure in data write Flash-process, can not cause because of during spatial cache residual capacity deficiency the problem writing time-out.
Should be understood that, the present invention can summarize with other the concrete form without prejudice to spirit of the present invention or principal character.Therefore, no matter from which point, the above embodiment of the present invention can only be thought explanation of the present invention and can not limit the present invention, claims indicate scope of the present invention, and scope of the present invention is not pointed out in above-mentioned explanation, therefore any change in the implication suitable with claims of the present invention and scope, all should think to be included in the scope of claims.