Summary of the invention
The purpose of this invention is to provide a kind of Miniature data backup method of data acquisition system based on FLASH ROM, use this method Backup Data occupying system resources few, it is little to take code space.
A kind of Miniature data backup method of data acquisition system based on FLASH ROM, wherein: comprise the steps:
A), enter and regularly interrupt the initialization flow process, simultaneously, enter serial ports and interrupt initialization flow process, serial ports buffering initialization flow process;
B), enter data backup initialization of variable flow process;
C), judge whether to receive the data acquisition message signale, if the current data that collect of reception data acquisition unit enter step d) afterwards; If not, directly enter step d);
D), judge whether to receive the data backup message signale, if the current data that backup receives after backup actions is finished, enters step e); If not, directly enter step e);
E), judge whether to receive and set up the data directory message signale, if, set up Backup Data piece index, enter step f) afterwards; If not, directly return step f);
F), enter the system command treatment scheme;
G), return step c).
Described Miniature data backup method of data acquisition system based on FLASH ROM, wherein: comprise the steps: in its data backup initialization of variable step a)
B1), set up that effective sector number is 0, interim flowing water variable is 0, interim sector pointers is 0, interim page pointer is 0;
B2), in the internal memory of data acquisition system (DAS) processor, set up first data buffering;
B3), read FLASH ROM sector index that interim sector pointers points to step b2) in first data buffering of foundation;
B4), from this first data buffering, read current sector data sign and judge whether this sector is effective;
B5), if current sector effective, with effective sector number+1, and from above-mentioned first data buffering, read current sector serial number; If current sector is invalid, enter step b8);
B6), judge that current sector serial number is whether greater than interim flowing water variable, if enter step b7), if not, enter step b8);
B7), described current sector serial number is written to interim flowing water variable, current sector pointers is pointed to interim sector pointers;
B8), with interim sector pointers+1;
B9), judge that interim sector pointers is whether greater than the sector number of FLASH ROM device, if enter step b10), if not, return step b3);
B10), judge whether effective sector number is 0, if enter step b18), if not, enter step b11);
B11), read the sector bitmap of current sector pointers sensing to first data buffering;
B12), from first data buffering, read the data bitmap that interim page pointer is pointed to;
B13), judge according to data bitmap whether this data bitmap corresponding page is empty, if step b12 will be returned behind interim page pointer+1); If not, enter step b14);
B14), with the interim page pointer of current page pointed;
B15), judge that interim page pointer is whether greater than the sector number of FLASH ROM device, if enter step b16), if not, enter step b21);
B16), with current sector pointers+1;
B17), carrying out FLASH ROM device boundaries handles;
B18), wipe current sector;
B19), rebulid sector index;
B20), the current page pointer is made as 1;
B21), set up the data block index;
B22), set up page index;
B23), current offset pointer moves, and skips the current page index;
B24), finish initialization.
Described Miniature data backup method of data acquisition system based on FLASH ROM, wherein: it enters in the step a) of regularly interrupting flow process and comprises the steps:
A1), the timer of data acquisition system (DAS) picks up counting;
A2), whether judgment data gather timing cycle and expire, if send the data acquisition message signale, enter step a3 afterwards), if not, directly enter step a3);
A3), whether judgment data backup timing cycle expire, if send the data backup message signale, enter step a4 afterwards), if not, directly enter step a4);
A4), whether judgment data index timing cycle expire, if send the data directory message signale, enter step a5 afterwards), if not, directly enter step a5);
A5), regularly interrupting flow process finishes.
Described Miniature data backup method of data acquisition system based on FLASH ROM, wherein: " current data that backup receives " in its step d) comprises the following steps:
D1), set up FLASH ROM operation buffering;
D2), current data is write in this operation buffering;
D3), the data that will operate in the buffering write FLASH ROM;
D4), current offset pointer moves the length of the FLASH ROM data that write;
D5), enter current page bounds checking flow process;
D6), the Backup Data flow process finishes.
Described Miniature data backup method of data acquisition system based on FLASH ROM, wherein: the flow process that enters the current page bounds checking its steps d 5) comprises the steps:
D5I), judge whether to arrive the border of current page, if enter steps d 5II), if not, enter steps d 5IV);
D5II), enter the flow process of upgrading the work at present page;
D5III), after the renewal of the page, set up the index of current page;
D5IV), the page boundary inspection finishes.
Described Miniature data backup method of data acquisition system based on FLASH ROM, wherein: enter the flow process of upgrading the work at present page its steps d 5II) and comprise the steps:
D5II is 1.), judge whether to arrive the border of current sector, if enter steps d 5II 2.), if not, the current page pointer added 1 after, enter steps d 5II 6.);
D5II is 2.), current sector serial number is added 1;
D5II is 3.), the search minimum serial number the sector as current sector;
D5II is 4.), wipe the data in the current sector;
D5II is 5.), set up the index of current sector;
D5II is 6.), in the bitmap of sector the mark current page;
D5II is 7.), set up page index;
D5II is 8.), upgrade current page and finish.
Described Miniature data backup method of data acquisition system based on FLASH ROM, wherein: its steps d 5II is 5.) in set up the index of current sector flow process comprise the steps:
D5II is i 5.), in the internal memory of data acquisition system (DAS) processor, set up second data buffering;
D5II 5. ii), will have serial number, the current time of the sign of no datat, current sector to write in this second data buffering;
D5II 5. iii), the data in second data buffering are written to the homepage of the current sector of FLASH ROM;
D5II 5. iv), set up the index of the data block write;
D5II 5. v), set up sector index and finish.
Described Miniature data backup method of data acquisition system based on FLASH ROM, wherein: its steps d 5II 5. flow process of setting up institute's writing data blocks index described in iv) comprises the steps:
D5II is iv1. 5.) in the data acquisition system (DAS) processor memory, set up the 3rd data buffering;
D5II is iv2. 5.) current time, the work at present page etc. is write the 3rd data buffering;
D5II is iv3. 5.) search lowest address index space in the homepage of the current sector of FLASH ROM;
D5II is iv4. 5.) data in the 3rd data buffering are written in this index space;
D5II is iv5. 5.) set up the data block index and finish.
Described Miniature data backup method of data acquisition system based on FLASH ROM, wherein: the flow process of setting up the current page index described steps d 5III) comprises the steps:
D5III is 1.), in the data acquisition system (DAS) processor memory, set up the 4th data buffering;
D5III is 2.), current time, current Backup Data kind are write the 4th data buffering;
D5III is 3.), with the data in the 4th data buffering be written to current page begin the place;
D5III is 4.), set up page index and finish.
Described Miniature data backup method of data acquisition system based on FLASH ROM, wherein: the flow process of serial ports Interrupt Process described in its step a) comprises the steps:
A1 '), whether judgment data acquisition system serial ports interrupt processed command arrive, if this processing command byte is write in the order buffering of processor, enter step a2 ' afterwards); If not, directly enter step a2 ');
A2 '), rs 232 serial interface signal sends and handles;
A3 '), serial ports Interrupt Process flow process finishes.
Described Miniature data backup method of data acquisition system based on FLASH ROM, wherein: enter the system command treatment scheme in its step f) and comprise the steps:
F1), judge whether command format effective, if enter step f2), if not, enter step f4);
F2), the judgment data reading order mates that (this coupling refers to what and what coupling? how to mate? if), enter step f3); If not, enter step f5);
F3), carry out historical data and read treatment scheme;
F4), send the wrong cue of order, and data in the clear command buffering;
F5), the system command processing finishes.
Described Miniature data backup method of data acquisition system based on FLASH ROM, wherein: historical data its step f3) reads treatment scheme and comprises the steps:
F3I), in the data acquisition system (DAS) processor memory, set up the 5th data buffering;
F3II), the storage time of from the order buffering of processor, reading historical data;
F3III), according to the storage time of the historical data that reads, enter the data query flow process;
F3IV), judge whether inquiry hits, if enter step f3V), if not, enter step f3VII);
F3V), from FLASH ROM, read historical data to the five data bufferings;
F3VI), the data in the 5th data buffering are sent to host computer by serial ports;
F3VII), send the query missed information;
F3VIII), historical data reads the treatment scheme end.
Described Miniature data backup method of data acquisition system based on FLASH ROM, wherein: the data query flow process step f3III) comprises the steps:
F3III1.), search sector count;
F3III2.), judge whether the sector of search effective, if enter step f3III3.), if not, enter step f3III10.);
F3III3.), the search data blocks index count, after searching, enter step f3III4.);
F3III4.), judge the data block index date search whether with the time coupling of the historical data that requires, if enter step f3III5.), if not, enter step f3III9.);
F3III5.), searched page counting;
F3III6.), page index time of judging search whether with the time coupling of the historical data that requires, if return hiting signal, finish the data query flow process, if not, enter step f3III7.);
F3III7.), judge whether this sector page has been searched for, if enter step f3III8.), if not, return step f3III3.);
F3III8.), judge whether this sector data piece index has been searched for, if enter step f3III9.), if not, return step f3III1.),
F3III9.), judge whether whole sectors to have been searched for, if enter step f3III10.), if not, return step f3III1.);
F3III10.), return miss signal, end data query flow process.
The present invention adopts technique scheme will reach following technique effect:
A kind of Miniature data backup method of data acquisition system provided by the invention based on FLASH ROM, be the characteristics that data traffic is little when having utilized miniature data backup, data have the strict time order, be operating unit with the sector during data storage, all there is similar storage organization each sector, order before and after differentiating by serial number and index; When a sector is filled with data, search used the earliest sector, remove this sector, it as the work at present sector, so can be realized uniform wear.
Each sector all is made up of index and data field, and index comprises sector index and page or leaf index.Sector index is positioned at the sector homepage, comprise sector valid data sign, serial number, page operating position bitmap, data block index, its data block index comprises data block Start Date, time and sector, and its cycle of setting up is set up according to balances such as data traffic, sector-size and data query times by the user; The page or leaf index comprises date that page data begins, time, data backup type, data backup cycle etc.; The space of page or leaf index back is exactly the data field, and the data layout in the data field is defined according to application demand by the user.
Data acquisition system (DAS) when work, according to cycle and the kind set data backup is stored among the FLASHROM, as requested form is set up sector index and page index in the process of storage.
When data query, first search data blocks index, the corresponding page or leaf index of search after the date hits, this two-stage index can define the driftlessness data very soon.
To sum up, this method occupying system resources seldom only need the code of several kilobyte to realize, and it is also very little to take the variable internal memory, is well suited for miniature data backup and uses; From the sector use as can be seen, this method has realized uniform wear; In addition, two-stage index can realize quick search.
Embodiment
Embodiment:
A kind of Miniature data backup method of data acquisition system based on FLASH ROM, the data collector structural drawing that is applied to visiometer as shown in figure 14, this data collector comprises acquired signal and conversion of signals is become the sensor of data-signal, processor CPU, FLASH ROM and host computer, processor CPU adopts chip AT89C51ED2, sensor is connected with processor CPU by sensor interface, it is M24P16 that FLASH ROM adopts model, it is the 16Mbits device of a SPI interface, it is connected with processor CPU by the SPI interface, processor CPU also is connected with host computer (PC) by the RS232 interface, processor CPU pick-up transducers signal, after the processing signal is sent to PC by the RS232 mouth, and cycle as requested and form with signal storage in FLASH ROM, realize data backup.When PC sends the Backup Data reading requirement by order to processor CPU, after the inquiry of processor CPU process,, just from FLASH ROM, read this data, and form in accordance with regulations sends to PC if there are the data that require.
Before method is implemented, at first need definition sector index, page index form, the sector index that defines in the present embodiment, page index form are as follows:
The sector index form
The offset byte number is defined as usefulness
01 data have or not sign, and: 0x59 has data 0xFF no datat other (as 0x00 0x01 0xF0 are illegal, promptly do not meet the mistake of this method) to be used for flag data to have or not
11 keep ...
44 serial numbers are used to judge data storage order between the sector from small to large
84 keep ...
12 3 keep ...
15 1 keep ...
16 32 bitmap for every page are used to judge whether the page has data
Fast 1 index of 48 4 date date datas begins
52 3 time times
The page or leaf that 55 1 page data begin
Fast 2 index of 56 4 date date datas begin
60 3 time times
The page or leaf that 63 1 page data begin
...... ...... ....... ......
The page index form
The offset byte number is defined as usefulness
The date that 04 these page datas of date dat recorder begin
The time that 43 these page datas of time time keeping begin
The kind of 71 these page datas of backup type records
The workflow of data acquisition system (DAS) as shown in Figure 1, it comprises the steps:
A), enter and regularly interrupt flow process, enter serial ports Interrupt Process flow process simultaneously;
B), enter data backup initialization of variable flow process;
C), judge whether to receive the data acquisition message signale, if the current data that collect of reception data acquisition unit enter step d) afterwards; If not, directly enter step d);
D), judge whether to receive the data backup message signale, if the current data that backup receives after backup actions is finished, enters step e); If not, directly enter step e);
E), judge whether to receive and set up the data directory message signale, if, set up Backup Data piece index, enter step f) afterwards; If not, directly return step f);
F), enter the system command treatment scheme;
G), return step c).
Wherein, as shown in Figure 2, the data backup initialization of variable flow process in the described step a) comprises the steps:
B1), set up that effective sector number is 0, interim flowing water variable is 0, interim sector pointers is 0, interim page pointer is 0; (effectively the sector refers to and stores the signal data that collects, and indexed format meets the above-mentioned definition of present embodiment to it in this sector, and effectively sector number is based upon in the CPU internal memory, is global variable; Described several temporary variable all is a local variable, is based upon in the CPU internal memory, and temporary variable only works in initialize routine, is the intermediate variable that calculates initializing variable.)
B2), in the internal memory of data acquisition system (DAS) processor, set up first data buffering (this first data buffering is the ephemeral data buffering, and this buffering promptly was released after initialize routine executed, and is clear for describing, and it is labeled as first data buffering here);
B3), read FLASH ROM sector index that interim sector pointers points to step b2) in first data buffering of foundation;
B4), reading current sector data sign from this first data buffering (is that data have or not sign, see the sector index form for details), and judge this sector whether effectively (whether effectively refer to and whether meet the identification data 0x59 that defines in the present embodiment sector index form);
B5), if current sector is effective, with effective sector number+1, and (described sector serial number is 4 byte integer of stipulating in the sector index form from small to large to read current sector serial number from above-mentioned first data buffering, be used for judging the front and back order of different sectors data storage, it can guarantee still can judge the order of Backup Data when system clock is disorderly); If current sector is invalid, enter step b8);
B6), judge that current sector serial number is whether greater than interim flowing water variable, if enter step b7), if not, enter step b8);
B7), described current sector serial number is written to interim flowing water variable, current sector pointers is pointed to interim sector pointers;
B8), with interim sector pointers+1;
B9), judge that interim sector pointers is whether greater than the sector number of FLASH ROM device, if enter step b10), if not, return step b3);
B10), judge whether effective sector number is 0, if enter step b18), if not, enter step b11);
B11), read the sector bitmap of current sector pointers sensing to first data buffering; (the sector bitmap is used for whether the page is empty in the mark sector, represents a page with a position, is defined as in the present embodiment: 0 this page data with existing of expression, and 1 this page of expression is empty; Can determine the page vacant in the current page rapidly by bitmap, also provide foundation) for search data
B12), from first data buffering, read the data bitmap that interim page pointer is pointed to;
B13), judge whether data bitmap is 1, if step b12 will be returned behind interim page pointer+1); If not, enter step b14);
B14), with the interim page pointer of current page pointed; (initialized purpose that Here it is is given suitable value with several key variables such as sector pointers, page pointer, offset pointer);
B15), judge that interim page pointer is whether greater than the sector number (interim page pointer is a temporary variable, and initialization finishes and promptly is released, and is used for judging the page situation of respective sectors) of FLASH ROM device, if, enter step b16), if not, enter step b21);
B16), with current sector pointers+1;
B17), carrying out FLASH ROM device boundaries handles;
B18), wipe current sector; Add in (the current sector here is step b16) 1 the operation after the sector)
B19), rebulid sector index;
B20), the current page pointer is made as 1;
B21), set up the data block index; (because of it is the index of setting up in initialization procedure, so also be initial index, the process of specifically setting up is seen Fig. 8)
B22), set up page index; (process such as Fig. 9 are set up in page index, and the page index after the foundation is one the 8 byte data piece that meets the page index form of present embodiment definition)
B23), make current offset pointer=8, even current offset pointer is skipped page index; (offset pointer is indicated the position of current Backup Data in FLASH ROM with sector pointers, page pointer, makes offset pointer=8th, in order to skip the page index of 8 bytes.)
B24), finish initialization.
Described step a) enters regularly interrupts flow process, sees shown in Figure 3ly, comprises the steps:
A1), the timer of data acquisition system (DAS) picks up counting; (timer of data acquisition system (DAS) is the impulse meter that has utilized among the CPU AT89C51 in the present embodiment)
A2), whether judgment data gather timing cycle and expire, if send the data acquisition message signale, enter step a3 afterwards), if not, directly enter step a3);
A3), whether judgment data backup timing cycle expire, if send the data backup message signale, enter step a4 afterwards), if not, directly enter step a4);
A4), whether judgment data index timing cycle expire, if send the data directory message signale, enter step a5 afterwards), if not, directly enter step a5);
A5), regularly interrupting flow process finishes.
Described Miniature data backup method of data acquisition system based on FLASH ROM, the flow process of the current data that the backup in its step d) receives comprises the following steps: as shown in Figure 4
D1), set up FLASH ROM operation buffering;
D2), current data is write in this operation buffering;
D3), the data that will operate in the buffering write FLASH ROM;
D4), current offset pointer moves the length of the FLASH ROM data that write; (moving the current offset pointer in back and be the end of the total length that points to the page index of having set up in the FLASH ROM current page and already present data)
D5), enter current page bounds checking flow process;
D6), the Backup Data flow process finishes.
Above-mentioned steps d5) enters the flow process of current page bounds checking in, as shown in Figure 5, comprise the steps:
D5I), judge whether to arrive the border of current page, if enter steps d 5II), if not, enter steps d 5IV);
D5II), enter the flow process of upgrading the work at present page;
D5III), after the renewal of the page, set up the index of current page;
D5IV), the page boundary inspection finishes.
Above-mentioned steps d5II) enters the flow process of upgrading the work at present page in,, comprise the steps: as Fig. 6
D5II is 1.), judge whether to arrive the border of current sector, if enter steps d 5II 2.), if not, the current page pointer added 1 after, enter steps d 5II 6.);
D5II is 2.), current sector serial number is added 1;
D5II is 3.), the search minimum serial number the sector as current sector;
D5II is 4.), wipe the data in the current sector;
D5II is 5.), set up the index of current sector;
D5II is 6.), in the bitmap of sector the mark current page;
D5II is 7.), set up page index; The flow process of page index (set up also as shown in Figure 9)
D5II is 8.), upgrade current page and finish.
Above-mentioned steps d5II is 5.) in set up current sector index flow process as shown in Figure 7, comprise the steps:
D5II is i 5.), in the internal memory of data acquisition system (DAS) processor, set up second data buffering; (this second data buffering also is the ephemeral data buffering, and sector index promptly is released after setting up and finishing, and describes for clear, it is expressed as second data buffering here.)
D5II 5. ii), will have serial number, the current time of the sign of no datat, current sector to write in this second data buffering;
D5II 5. iii), the data in second data buffering are written to the homepage of the current sector of FLASH ROM;
D5II 5. iv), set up the index of the data block write; (the data block here is meant the data of specified period period stored.)
D5II 5. v), set up sector index and finish.
Above-mentioned steps d5II is the flow process of setting up institute's writing data blocks index described in iv) 5., as shown in Figure 8, comprises the steps:
D5II is iv 1. 5.) in the data acquisition system (DAS) processor memory, set up the 3rd data buffering;
D5II is iv 2. 5.) current time, the work at present page etc. is write the 3rd data buffering;
D5II is iv 3. 5.) search lowest address index space in the homepage of the current sector of FLASH ROM;
D5II is iv 4. 5.) data in the 3rd data buffering are written in this index space;
D5II is iv 5. 5.) set up the data block index and finish.
Above-mentioned steps d5III) sets up the flow process of current page index in, as shown in Figure 9, comprise the steps:
D5III is 1.), in the data acquisition system (DAS) processor memory, set up the 4th data buffering;
D5III is 2.), current time, current Backup Data kind are write the 4th data buffering;
D5III is 3.), with the data in the 4th data buffering be written to current page begin the place;
D5III is 4.), set up page index and finish.
Above-mentioned steps d5II is 7.) in set up page index flow process also as shown in Figure 9, repeat no more here.
Described Miniature data backup method of data acquisition system based on FLASH ROM, wherein, the serial ports Interrupt Process flow process described in the step a) as shown in figure 10, comprises the steps:
A1 '), whether judgment data acquisition system serial ports interrupt processed command arrive, if this processing command byte is write in the order buffering of processor, enter step a2 ' afterwards); If not, directly enter step a2 ');
A2 '), rs 232 serial interface signal sends and handles;
A3 '), serial ports Interrupt Process flow process finishes.
Enter the system command treatment scheme in its step f), as shown in figure 11, comprise the steps:
F1), judge whether command format effective, if enter step f2), if not, enter step f4);
F2), judgment data reading order character string whether with the string matching of predetermined data reading order, (the command string definition repeats no more here) coupling is if enter step f3); If not, enter step f5);
F3), carry out historical data and read treatment scheme;
F4), send the wrong cue of order, and data in the clear command buffering;
F5), the system command processing finishes.
Above-mentioned steps f3) historical data reads treatment scheme described in, as shown in figure 12, comprises the steps:
F3I), in the data acquisition system (DAS) processor memory, set up the 5th data buffering;
Time when f3II), from the order of processor buffering, reading historical data and be stored; (this method be with the time as the index foundation.)
F3III), the time when being stored according to the historical data that reads, enter the data query flow process;
F3IV), judge whether inquiry hits, if enter step f3V), if not, enter step f3VII);
F3V), from FLASH ROM, read historical data to the five data bufferings;
F3VI), the data in the 5th data buffering are sent to host computer by serial ports;
F3VII), send the query missed information;
F3VIII), historical data reads the treatment scheme end.
Above-mentioned steps f3III) the data query flow process described in comprises the steps: as shown in figure 13
F3III1.), search sector count; (this sector count is a temporary variable, is used to calculate the sector number of searching for, and judges whether that with it all sectors have all searched for)
F3III2.), judge whether the sector of search effective, if enter step f3III3.), if not, enter step f3III10.);
F3III3.), search data blocks index count (the data block index count also is a temporary variable, is used to calculate the quantity of the data block index of searching for, and judges whether that with it all data block index have all searched for), after searching, enter step f3III4.);
F3III4.), judge the data block index date search whether with the time coupling of the historical data that requires, if enter step f3III5.), if not, enter step f3III9.);
F3III5.), searched page counting;
F3III6.), page index time of judging search whether with the time coupling of the historical data that requires, if return hiting signal, finish the data query flow process, if not, enter step f3III7.);
F3III7.), judge whether this sector page has been searched for, if enter step f3III8.), if not, return step f3III3.);
F3III8.), judge whether this sector data piece index has been searched for, if enter step f3III9.), if not, return step f3III1.),
F3III9.), judge whether whole sectors to have been searched for, if enter step f3III10.), if not, return step f3III1.);
F3III10.), return miss signal, end data query flow process.