Storage method for storing user data into Flash and read method

A user data and data technology, applied in the direction of memory system, electrical digital data processing, memory address/allocation/relocation, etc., can solve the problems of data loss, data Flash usage time is not long, etc., to achieve the effect of improving the service life

Active Publication Date: 2016-03-23
浙江卓奥科技股份有限公司
3 Cites 6 Cited by

AI-Extracted Technical Summary

Problems solved by technology

[0003] The technical problem to be solved by the present invention is to provide a storage method and a reading method for storing user data in the Flash for the above-mentioned prior art, which can well avoid the problem of sporadic loss of data in the storage process of user data; the...
View more

Abstract

The present invention relates to a storage method for storing user data into a Flash and a read method. The storage method is characterized in that: N to-be-stored user data with a fixed length are packaged into data packets, each data packet comprises a peltier, N user data and a check code from the front to the rear sequentially, and the data packets are sequentially stored in the Flash. The storage method provided by the present invention adopts a method of erasing one block for one time, and then dividing the block into partitions, and storing the user data sequentially, and when the partitions are full of the user data, erasing a block again, and sequentially storing the user data according to the partitions again, and according to such a cycle, the service life of the flash is greatly improved. Compared with the prior art, the present invention has the advantages that: the storage method provided by the present invention can preferably avoid an accidental loss existing in user data storage or avoid a premature failure of storage units, and can also correctly and quickly identify the last stored user data.

Application Domain

Memory adressing/allocation/relocation

Technology Topic

Storage cellPremature failure +4

Image

  • Storage method for storing user data into Flash and read method
  • Storage method for storing user data into Flash and read method
  • Storage method for storing user data into Flash and read method

Examples

  • Experimental program(1)

Example Embodiment

[0034] Example one
[0035] The storage method and reading method for storing user data in Flash in this embodiment are used to store user data with a fixed length that needs to be saved on the electrical terminal control board in the Flash space of the single-chip microcomputer in the electrical terminal control board. The stored N user data with a fixed length are packaged into data in the following way. Each data packet includes the header, N user data and check code from front to back; when the length of the user data is not fixed, each data packet From front to back, it includes the post header, M user data, reserved characters, end of post and check code; M changes within a predetermined range, M is less than or equal to the predetermined length of the longest user data N, the header or end of the post can be It is used to judge the integrity of the data link. We agree that the length of the stored data packet is fixed, so we agree to 1 byte length of post header and 1 byte length of post end. The content of post header and end of post is defined by the user, or only one of them , The check code adopts the cyclic redundancy check code CRC, which is 8 bits, and the polynomial adopts X8+X4+X3+1; in order to improve the efficiency, the CRC is obtained by the look-up table method; use the Flash that comes with the microcontroller The free part of the space is divided into several storage blocks according to the address order, see figure 1 Shown
[0036] For the data packet in the header, fixed-length N user data and check code format, the storage method for storing the packaged data packet in Flash is:
[0037] First define an array variable user_data[data_size], where data_size=frame header length+user data length N+check code length, unit byte, make user_data[0]=post header, and then save N user data with a fixed length to user_data [1]~user_data[N], N=data_size-2, user_data[data_size-1]=check code; define a pointer to const, unsignedcharconst*write_addr, make write_addr point to the first address of memory block a, and store the block The storage space of a is divided into several areas with data_size as the length. Before storing new data packets, check the storage block a by area. When checking the space, you only need to query the frame header of each area. The header is just the first address of each area. When the first empty area header address is found, that is, the frame header of the area is empty, start to write the packed data packet. After the data writing operation is over, The written data is verified whether it has been written successfully. If the write is not successful, the write operation is performed again; if the write operation is executed M times and the write operation is not successful, the next free area is searched and the above write operation is performed. , It is allowed to replace X areas at most to perform write operations. If X areas cannot be written successfully, it is considered that storage block a is damaged and the storage operation is exited; in this embodiment, M=5, X=50;
[0038] The specific steps are:
[0039] Step (1), judge whether the user data storage function is allowed to be called, that is: judge the user data storage flag bsave=true? If yes, go to step (2), if no, end;
[0040] Step (2), set user_data[0]=post header; then save the user data in user_data[1]~user_data[N];
[0041] Step (3), obtain the check code of the data packet;
[0042] Step (4), let user_data[data_size-1]=check code;
[0043] Step (5): Let write_addr=block_a, block_a is the first address of storage block a, and block_a_end is the end address of storage block a;
[0044] Step (6), the zone change counter y is cleared, that is, y=0;
[0045] Step (7), judge y <50? If yes, go to step (8), if not end;
[0046] Step (8), judge write_addr
[0047] Step (9). Determine whether the area pointed to by write_addr is empty? If yes, execute step (10), if not, point the address pointer to the next area, that is, write_addr+=data_size, and then execute step (8);
[0048] Step (10), judge (write_addr == block_a)? ,
[0049] Or (write_addr> (block_a_end-data_size)))? , If yes, go to step (11), if not, go to step (13);
[0050] Step (11), erase the block_a~block_a_end area; that is, erase the storage block a "empty" once when the user data is saved for the first time or the address overflows;
[0051] Step (12), set write_addr=block_a;
[0052] Step (13), clear the number n of writes to the same area, that is, n=0;
[0053] Step (14), judge whether the number of writes in the same area n is less than 5, if yes, execute step (15), if not, set y++, write_addr+=data_size, and then return to step (7);
[0054] Step (15), write the array user_data[] into the Flash space pointed to by write_addr;
[0055] Step (16), verify whether the writing is successful, if yes, end, if not, let n++, return to step (14).
[0056] The reading method for reading user data stored in Flash is:
[0057] Set a pointer to const, unsignedcharconst*P, and set the value of the flash space of the microcontroller to be "empty" to 0xff;
[0058] Step 1. Let P=block_a;
[0059] Step 2. Determine whether P is less than block_a_end, if yes, go to step 3, if not, end;
[0060] Step 3. Determine P[0] == header, and P[data_size] == 0xff? If yes, go to step 4, if not, set P+=data_size, and return to step 2;
[0061] Step 4. Find the check code of P[0]~P[data_size-2];
[0062] Step 5. Determine whether P[data_size-1] is equal to the check code? If yes, perform step 6, if not, initialize user data, set the save user data flag = true, and end;
[0063] Step 6. Recall the user data, save it to RAM, and end.
[0064] For the data packet in the format of header, variable-length user data M, trailer and check code, the storage method for storing the packaged data packet in Flash is:
[0065] First define an array variable user_data[data_size], data_size=predetermined maximum number of users N+3, make user_data[0]=post header, and then save M user data with variable length to user_data[1]~user_data In [N], user_data[data_size-2]=end of post, user_data[data_size-1]=check code, and the rest are cleared; define a pointer to const, unsignedcharconst*write_addr, to make Write_addr point to the first address of memory block a , Divide the storage space of storage block a into several areas with data_size as the length. Before storing new data packets, first check the storage block a by area to check "empty", and find the first address closest to storage block a After the "empty" area of ​​the first address, start to write the packaged data packet. After the action of writing data is finished, verify whether the written data has been written successfully. If the write is not successful, perform another write Action; if the write action is executed M times and it is not successful, then find the next "empty" area, and then execute the above write operation. Up to X areas are allowed to be replaced to perform the write operation. If none of the X areas can be written successfully , It is considered that the storage block a is damaged, and the storage operation is exited; in this embodiment, M=5, X=50; the specific writing operation principle is the same as the above detailed steps;
[0066] The reading method for reading user data stored in Flash is:
[0067] Set a pointer to const, unsignedcharconst*P, and set the value of the flash space of the microcontroller to be 0xff after erasing;
[0068] Step 1. Let P=block_a;
[0069] Step 2. Determine whether P is less than block_a_end, if yes, go to step 3, if not, end;
[0070] Step 3. Determine P[0] == header, and P[data_size] == 0xff? If yes, go to step 4, if not, set P+=data_size, and return to step 2;
[0071] Step 4. Determine P[data_size-2] == End of post? If yes, go to step 5, if not, go to step 7;
[0072] Step 5. Find the check code of P[0]~P[data_size-2];
[0073] Step 6. Determine whether P[data_size-1] is equal to the check code? If yes, go to step 8, if not, go to step 7;
[0074] Step 7. Initialize user data, set the save user data flag = true, and end;
[0075] Step 8. Recall the user data, save it to RAM, and end.

PUM

no PUM

Description & Claims & Application Information

We can also present the details of the Description, Claims and Application information to help users get a comprehensive understanding of the technical details of the patent, such as background art, summary of invention, brief description of drawings, description of embodiments, and other original content. On the other hand, users can also determine the specific scope of protection of the technology through the list of claims; as well as understand the changes in the life cycle of the technology with the presentation of the patent timeline. Login to view more.

Similar technology patents

Glomerocryst cubic boron nitride composite sheet and preparation method for same

ActiveCN103158287AExtended service lifeIncreased depth of cut
Owner:ZHENGZHOU BERLT HARD MATERIALS

Sleep assistance mattress

ActiveCN106842979AReduce data processing pressureExtended service life
Owner:DONGGUAN UNIV OF TECH

Application of epoxy cardanol as bio-based hindered phenolic antioxidant

InactiveCN105219458AGood antioxidant propertiesExtended service life
Owner:INST OF CHEM IND OF FOREST PROD CHINESE ACAD OF FORESTRY

Classification and recommendation of technical efficacy words

Who we serve
  • R&D Engineer
  • R&D Manager
  • IP Professional
Why Eureka
  • Industry Leading Data Capabilities
  • Powerful AI technology
  • Patent DNA Extraction
Social media
Try Eureka
PatSnap group products