Data storage method and storage device
By dividing the main storage sector and the backup storage sector in the storage device, and using the verification value comparison method of the structure array, the reading error problem caused by data bit jump in a strong electromagnetic interference environment is solved, and data storage is improved stability and reliability.
Patent Information
- Application Number
- CN202411265335.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-10
- Publication Date
- 2025-02-11
AI Technical Summary
In an environment with strong electromagnetic interference, the stored data is prone to bit jumps, resulting in reading of incorrect parameters and causing incorrect judgments.
The data storage method is adopted to divide the data into main storage sectors and backup storage sectors, and data is read by comparing the verification values of the structure array to ensure the stability and reliability of the data.
It effectively improves the stability and reliability of data storage and prevents data loss or system failure caused by partial bit jumps.
Smart Images

Figure CN119415012A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of data storage, and more specifically, to a data storage method and a storage device. Background Art
[0002] At present, we usually use the master-slave storage method, that is, the master storage sector stores one set of parameters and the backup storage sector stores one set of parameters. This method is fine in most cases, but in some environments with strong electromagnetic interference, the stored data is prone to bit jumps. If the storage unit bit jumps and the jump does not affect our check value, then we will get the wrong parameters when reading, which will lead to some wrong judgments. Summary of the invention
[0003] In view of the deficiencies in the prior art, the present invention innovatively provides a data storage method and a storage device, which can solve the above technical problems.
[0004] To achieve the above technical objectives, the present invention discloses, in a first aspect, a data storage method for a storage device, wherein the storage device includes a primary storage sector and a backup storage sector, and the storage method includes:
[0005] Data organization, establishing a structure array, each of the structure arrays includes N storage data, where N is a positive integer greater than or equal to 3;
[0006] storing data, calculating a check value of the stored data,
[0007] Storing the structure array into the main storage sector and the backup storage sector respectively;
[0008] Data reading, reading the check values of the N stored data in the same structure array, and taking any two of the check values for comparison, when the check values are the same, the comparison is successful, otherwise the comparison fails;
[0009] Data processing: when the number of successful comparisons of the two structure arrays is equal to 0, data reading fails; when the number of successful comparisons of any one of the structure arrays is greater than 0, data reading succeeds.
[0010] Furthermore, in the data processing step, the structure array in the main storage sector is first read. When the number of successful comparisons of the structure array in the main storage sector is equal to 0, the structure array in the backup storage sector is read again. When the number of successful comparisons of the structure array in the backup storage sector is equal to 0, it is determined that the data reading has failed.
[0011] Furthermore, when data reading fails, the stored data is reloaded.
[0012] Furthermore, when the number of successful comparisons of the structure array in the backup storage sector is greater than 0, the structure array in the primary storage sector is updated.
[0013] Furthermore, when the number of successful comparisons of the structure array is greater than 0 and less than Then there is an error in at least one set of the stored data.
[0014] Further, the stored data with errors is updated, or,
[0015] Update the structure array.
[0016] Furthermore, the structure array includes three structures, each of which stores a set of storage data.
[0017] In a first aspect of the present invention, a storage device is disclosed, comprising a primary storage sector and a backup storage sector, wherein the storage device applies the above data storage method to process storage data.
[0018] Furthermore, the structure array includes three structures, and each structure stores one storage data.
[0019] The beneficial effects of the present invention are:
[0020] The present invention divides the storage device into a main storage sector and a backup storage sector, and stores multiple data in each of the main storage sector and the backup storage sector, and then reads the data by comparing the check values in pairs, which can effectively improve the stability and reliability of data storage and prevent data loss or system failure due to partial bit jumps. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] Figure 1 A schematic diagram showing a flow chart of a data storage method according to an embodiment of the present invention is shown;
[0022] Figure 2 A schematic diagram of the data processing flow of an embodiment of the present invention is shown (N takes a value of 3). DETAILED DESCRIPTION
[0023] The data storage method and storage device provided by the present invention are explained and illustrated in detail below in conjunction with the accompanying drawings of the specification.
[0024] The present invention divides the storage device into a main storage sector and a backup storage sector, and stores multiple data in each of the main storage sector and the backup storage sector, and then reads the data by comparing the check values in pairs, which can effectively improve the stability and reliability of data storage and prevent data loss or system failure caused by partial bit jumps. The present invention is described in detail below in conjunction with specific embodiments:
[0025] According to a first aspect of the present invention, there is provided a data storage method for a storage device, the storage device comprising a primary storage sector and a backup storage sector, such as Figure 1 As shown, the storage method includes:
[0026] Data organization, establishing a structure array, each structure array includes N storage data, where N is a positive integer greater than or equal to 3;
[0027] Data storage, calculation of checksums for stored data,
[0028] Store the structure array into the primary storage sector and the backup storage sector respectively;
[0029] Data reading, read the check values of N stored data in the same structure array, and compare any two of them. If the check values are the same, the comparison is successful, otherwise the comparison fails;
[0030] Data processing: When the number of successful comparisons of two structure arrays is equal to 0, data reading fails; when the number of successful comparisons of any structure array is greater than 0, data reading succeeds.
[0031] Optionally, in the data processing step, the structure array in the main storage sector is first read, and when the number of successful comparisons of the structure array in the main storage sector is equal to 0, the structure array in the backup storage sector is read again, and when the number of successful comparisons of the structure array in the backup storage sector is equal to 0, it is determined that the data reading fails. When the data reading fails, the storage data is reloaded. When the number of successful comparisons of the structure array in the backup storage sector is greater than 0, the structure array in the main storage sector is updated.
[0032] When the number of successful comparisons of the structure array is greater than 0 and less than At least one set of stored data is wrong. Update the stored data with errors, or update the structure array.
[0033] In one embodiment, N=3, that is, a structure array includes 3 storage data. Optionally, a structure is established, each structure stores a storage data, and the three structures constitute a structure array. In this embodiment, the structure array is defined as follows:
[0034]
[0035] Among them, short parameter1, short parameter2 and short parameter3 define three short integer member variables respectively, which are used to store three storage data. unsigned int XOR defines an unsigned integer member variable, which may be used to store the check value or the result obtained by the XOR operation. Data data1 is used to store the default parameter. Data data2[3], which is an array containing 3 Data type elements, is usually used to store three storage data.
[0036] In one embodiment, in data storage, the check value in the structure is calculated, the check value is assigned to each corresponding bit in the structure array, and then the structure array is stored in the main and backup storage areas, that is, 3 main storage sectors and 3 backup storage sectors. The storage process is:
[0037] Data pParam = data1;
[0038] pParam.XOR = crc16table();
[0039] data2[0] = pParam;
[0040] data2[1] = pParam;
[0041] data2[2] = pParam;
[0042] Datawrite(data2[0],1);
[0043] Datawrite(data2[1],1);
[0044] Datawrite(data2[2],1);
[0045] Datawrite(data2[0],2);
[0046] Datawrite(data2[1],2);
[0047] Datawrite(data2[2],2);
[0048] Among them, Data pParam = data1: assign the value of data1 to the new variable pParam,
[0049] pParam.XOR = crc16table(); Call the crc16table() function and assign the return value to the XOR member of pParam. Then copy the data into three copies and store them in the primary storage sector and the backup storage sector respectively.
[0050] In one embodiment, during data reading, three copies of stored data are read respectively and the check value of each copy is calculated, and then the data bodies and check values are compared two by two. Each time the comparison is successful, the success value is increased by 1 and the success value is returned. The processing process is:
[0051]
[0052] In one embodiment, Figure 2 As shown, in data processing, each time when the parameters need to be read, the main storage area is read first, and then the read success return value is judged. If the return value is greater than 0, it is considered that the read is successful. If the return value is less than 3, it is considered that one of the three stored data in the main storage area is wrong, and the correct data read is rewritten to the main storage area; if the read success return value of the main storage area is equal to 0, then the three parameters in the main storage area are all wrong, and then the backup storage area is read. If the read success return value is greater than 0, it is considered that the read is successful. If the return value is less than 3, it is considered that one of the three parameters in the backup storage area is wrong, and the correct data read is rewritten to the backup storage area; if the read success return value of the main storage area is equal to 0, then the three parameters in the backup storage area are all wrong, and the default parameters are loaded;
[0053] SuccessNum=ReadMainArea(0) reads three copies of data in the main storage area
[0054] SuccessNum is greater than 0. Successfully read the main storage area
[0055] SuccessNum is greater than 0 but less than 3, indicating that one of the three copies of data in the primary storage area has a problem.
[0056] WriteMainArea(0) reassigns the correct data read to the main storage area
[0057] SuccessNum is less than 0. Failed to read the main storage area.
[0058] SuccessNum=ReadMainArea(1) The main storage area fails to be read, and the three copies of data in the backup storage area are read.
[0059] SuccessNum is greater than 0. Read the backup storage area successfully.
[0060] SuccessNum is greater than 0 but less than 3, indicating that one of the three copies of data in the backup storage area has a problem.
[0061] WriteMainArea(1) reassigns the correct data read to the backup storage area
[0062] SuccessNum is less than 0. Failed to read the backup storage area.
[0063] AdddefaultParameter(); Load default parameters and re-update the primary and backup storage areas
[0064] According to a second aspect of the present invention, a storage device is provided, comprising a main storage sector and a backup storage sector, and the storage device applies the above data storage method to process storage data. Optionally, the storage space of each sector is 4k, that is, the storage space of the main storage sector and the backup storage sector is 4k, and each structure array is defined to include three connector bodies, that is, to store three copies of storage data, so as to avoid insufficient storage space and data overflow.
[0065] In the description of the present invention, it is to be understood that the terms “center”, “longitudinal”, “lateral”, “length”, “width”, “thickness”, “up”, “down”, “front”, “back”, “left”, “right”, “vertical”, “horizontal”, “top”, “bottom”, “inside”, “outside”, “clockwise”, “counterclockwise”, “axial”, “radial”, “circumferential”, etc., indicating orientations or positional relationships based on the orientations or positional relationships shown in the accompanying drawings, are only for the convenience of describing the present invention and simplifying the description, and do not indicate or imply that the referred device or element must have a specific orientation, be constructed and operated in a specific orientation, and therefore should not be understood as limiting the present invention.
[0066] In the present invention, unless otherwise clearly specified and limited, the terms "installed", "connected", "connected", "fixed" and the like should be understood in a broad sense, for example, it can be a fixed connection, a detachable connection, or an integral connection; it can be a mechanical connection or an electrical connection; it can be a direct connection or an indirect connection through an intermediate medium, it can be the internal connection of two elements or the interaction relationship between two elements, unless otherwise clearly defined. For ordinary technicians in this field, the specific meanings of the above terms in the present invention can be understood according to specific circumstances.
[0067] In the description of this specification, the description with reference to the terms "this embodiment", "one embodiment", "some embodiments", "example", "specific example", or "some examples" means that the specific features, structures, materials or characteristics described in conjunction with the embodiment or example are included in at least one embodiment or example of the present invention. In this specification, the schematic representations of the above terms do not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials or characteristics described may be combined in a suitable manner in any at least one embodiment or example. In addition, those skilled in the art may combine and combine different embodiments or examples described in this specification and the features of different embodiments or examples, unless they are contradictory.
[0068] In addition, the terms "first" and "second" are used for descriptive purposes only and should not be understood as indicating or implying relative importance or implicitly indicating the number of the indicated technical features. Therefore, the features defined as "first" and "second" may explicitly or implicitly include at least one of the features. In the description of the present invention, the meaning of "plurality" is at least two, such as two, three, etc., unless otherwise clearly and specifically defined.
[0069] The above are only preferred embodiments of the present invention and are not intended to limit the present invention. Any modifications, equivalent substitutions and simple improvements made to the essential contents of the present invention should be included in the protection scope of the present invention.
Claims
1. A data storage method, used for a storage device, wherein the storage device includes a primary storage sector and a backup storage sector, characterized in that: The storage method comprises: Data organization, establishing a structure array, each of the structure arrays includes N storage data, where N is a positive integer greater than or equal to 3; storing data, calculating a check value of the stored data, Storing the structure array into the main storage sector and the backup storage sector respectively; Data reading, reading the check values of the N stored data in the same structure array, and taking any two of the check values for comparison, when the check values are the same, the comparison is successful, otherwise the comparison fails; Data processing: when the number of successful comparisons of the two structure arrays is equal to 0, data reading fails; when the number of successful comparisons of any one of the structure arrays is greater than 0, data reading succeeds.
2. The data storage method according to claim 1, characterized in that: In the data processing step, the structure array in the main storage sector is first read. When the number of successful comparisons of the structure array in the main storage sector is equal to 0, the structure array in the backup storage sector is read again. When the number of successful comparisons of the structure array in the backup storage sector is equal to 0, it is determined that the data reading has failed.
3. The data storage method according to claim 2, characterized in that: When data reading fails, the stored data is reloaded.
4. The data storage method according to claim 2, characterized in that: When the number of successful comparisons of the structure array in the backup storage sector is greater than 0, the structure array in the primary storage sector is updated.
5. The data storage method according to claim 2, characterized in that: When the number of successful comparisons of the structure array is greater than 0 and less than Then there is an error in at least one set of the stored data.
6. The data storage method according to claim 5, characterized in that: updating the stored data that has errors, or Update the structure array.
7. The data storage method according to any one of claims 1 to 6, characterized in that: The structure array includes three structures, each of which stores a group of storage data.
8. A storage device, characterized in that: Comprising a primary storage sector and a backup storage sector, the storage device applies the data storage method according to any one of claims 1 to 7 to process and store data.
9. The storage device according to claim 8, characterized in that: The structure array includes three structures, and each structure stores one storage data.