Embedded data storage method and device, terminal equipment and storage medium

By dividing the storage space into a data area, a mapping area, an index area and a backup index area, the time-consuming problem of Flash memory when powering on and the problem of read and write imbalance is solved, dynamic storage and data verification are realized, and the efficiency and reliability of the memory are improved.

CN120353386AActive Publication Date: 2025-07-22SUNLUX IOT TECHNOLOGY (GUANGDONG) INC

Patent Information

Application Number
CN202510391457.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-03-31
Publication Date
2025-07-22
Estimated Expiration
2045-03-31

AI Technical Summary

Technical Problem

When the existing Flash memory is powered on, it takes a long time to traverse the entire storage space to find the latest cache area, and it is unbalanced in reading and writing, and cannot adapt to the dynamic changes in storage needs. There are problems of spatial redundancy and partition fragmentation, and the lack of data verification mechanism, resulting in complex management and inefficient efficiency.

Method used

The storage space is divided into a data area, a mapping area, an index area and a backup index area. The index area is used to record data status information and the mapping area is used to record data storage information. The write position is quickly positioned through the index area, and dynamic storage and balanced distribution are realized, and data verification is performed during writing.

Benefits of technology

It improves the startup speed after power-on memory, realizes fast indexing and balanced storage of data, extends the service life of the device, and ensures data accuracy and integrity.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120353386A_ABST
    Figure CN120353386A_ABST
Patent Text Reader

Abstract

The invention provides an embedded data storage method and device, terminal equipment and a storage medium, and the method comprises the steps: dividing the storage space of a memory into a plurality of functional regions located in different sectors when the memory is started for the first time; whenever the memory is powered on, acquiring data state record information of the index area, and acquiring a data write-in position of a previous data write-in instruction and a next data write-in address based on the data state record information; when a data writing instruction uploaded by a user is received, updating the data state information of the index area and the mapping area, synchronously updating the data state updating information of the index area to the backup index area, and writing a corresponding data block in the data area according to a next data writing address; verifying the written data block according to the data storage information; and when the data verification result of the data block is passed, judging that the data is written successfully. According to the invention, the data storage efficiency and reliability can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of embedded systems, and particularly to an embedded data storage method, device, terminal device and storage medium. Background Art

[0002] Flash Memory (hereinafter referred to as Flash memory for short) is a non-volatile storage medium based on a floating gate transistor structure, which realizes the persistent storage of data through charge storage. In the embedded field, when facing the situation of a large amount of data that needs to be saved when the power is off and needs to be read and written frequently, the mainstream method is to use Flash memory. Its storage capacity ranges from 1MB to 1GB, and the read speed can reach more than 100Mbps. When the memory is powered on, it will divide the storage space into N areas according to the required area and the actual size. First, it obtains the base address of the first area, and the addresses of the remaining areas are obtained by offsetting the base address. In terms of data management, specific small spaces are respectively divided at the beginning and end of each area. The front end is used to store the data size of the current area, and the back end stores the check code of the data in the current area. When performing read and write operations, the storage segment to be read and written is determined based on the index number, and then directly offset to the corresponding address for reading and writing.

[0003] However, there are also many disadvantages in the existing usage methods of Flash memory. First, when powered on, it is necessary to traverse the entire storage space to find the latest cache area, which takes a long time. Second, in the case of frequent read and write, it is impossible to judge the usage of data, which easily leads to unbalanced read and write. Third, the problem of space redundancy is prominent. Fixed-size partitions cannot adapt to the dynamic changes of storage requirements, and the efficiency is lower when storing a large number of small data, and it is impossible to realize the dynamic change storage of data length. Fourth, there is a lack of mutual verification mechanism, and it is difficult to identify bad points of a certain data. Fifth, the maintenance and management are complex. When there are many partitions in the Flash memory, additional management mechanisms are required to avoid overcrowding or idleness of partitions, and the checksum and index management of each partition will increase the code complexity, especially when there is partition fragmentation. Summary of the Invention

[0004] The present invention aims to provide an embedded data storage method, device, terminal device and storage medium to solve the above technical problems and improve the efficiency and reliability of data storage.

[0005] To solve the above technical problems, the present invention provides an embedded data storage method applied to a flash memory, including:

[0006] When the memory is powered on for the first time, divide the storage space of the memory into several functional areas located in different sectors; wherein, the types of the functional areas include a data area, a mapping area, an index area and a backup index area;

[0007] When the memory is powered on, obtain the data status record information of the index area, and based on the data status record information, obtain the data writing position of the previous data writing instruction and the next data writing address; wherein, the index area is used to record the data status information in the mapping area, the mapping area is used to record the data storage information of each data block in the data area, and the data storage information includes the data status information.

[0008] When a data writing instruction uploaded by a user is received, update the data status information of the index area and the mapping area, and synchronously update the data status update information of the index area to the backup index area. Write the corresponding data block in the data area according to the next data writing address; perform verification on the written data block according to the data storage information; when the data verification result of the data block passes, determine that the data writing is successful; wherein, the backup index area is used to perform backup storage on the index area.

[0009] In the above solution, when the device is powered on for the first time, the storage space is divided into functional areas such as a data area, a mapping area, an index area, and a backup index area. The data area can dynamically allocate space according to the actual data volume and is no longer restricted by fixed partitions. The mapping area records the data storage information of each data block. Regardless of how the data block length changes, it can accurately record its storage position in the data area, realizing dynamic storage of data lengths. The partition concept of the index area is introduced. When the memory is powered on, the data status record information can be directly obtained from the index area, so as to quickly determine the data writing position of the previous data writing instruction and the next data writing address. The index area plays a role in quickly indexing the data storage position, avoiding blind traversal of the entire storage space, shortening the time to find the latest cache area after power-on, and effectively improving the startup speed of the system. Further, the index area and the mapping area work together. The index area records the data status information of the mapping area, and the mapping area records the data storage information of each data block in the data area. When a new data writing instruction is received, the data can be reasonably written to the appropriate position according to the data status information, avoiding over-reading and over-writing in some areas, realizing an even distribution of read and write operations, and extending the service life of the storage device. During the data writing process, the written data block is verified according to the data storage information recorded in the mapping area. Only when the data verification result of the data block passes is it determined that the data writing is successful. This verification mechanism can timely detect possible errors in the data during transmission or storage, ensuring the accuracy and integrity of the data.

[0010] In one implementation, when the storage is powered on, obtaining the data status record information of the index area specifically includes:

[0011] When the memory is powered on, initialize the interface of the memory and determine the data storage status of the index area;

[0012] If the index area is not empty and the data status record information does not conform to the preset data storage rules, erase the current stored content of the index area, copy the content stored in the backup index area to the index area, and update the index area;

[0013] Read the data status information recorded in the index area to obtain the data status record information.

[0014] In one implementation, the mapping area is used to record the data storage information of each data block in the data area, specifically:

[0015] The data storage information includes the starting address of the data block in the data area, the length of the data block, and the data status information of the data block; where the data status information includes unused, written but unread, and read.

[0016] In one implementation, when receiving a data write instruction uploaded by the user, update the data status information of the index area and the mapping area, and write the corresponding data block in the data area according to the next data write address, specifically including:

[0017] Based on the data write instruction, update the data status information of the index area and the mapping area to written but unread, and record the starting address of the data block in the mapping area;

[0018] Use the next data write address as the starting address, and write the corresponding data block in the data area based on the starting address.

[0019] In one implementation, verify the written data block according to the data storage information; when the data verification result of the data block passes, determine that the data write is successful, specifically including:

[0020] After writing the data block, generate a parity check byte as the last data byte of the data block based on the preset check rule; where the preset check rule is to use the sum byte obtained by adding each byte of the data block one by one as the check code of the data block;

[0021] Obtain the starting address and data length of the data block, and generate a check code based on the preset check rule;

[0022] When the data byte is consistent with the check code, determine that the data block is successfully written.

[0023] In one implementation, the backup index area is used to back up and store the index area, and further includes:

[0024] Real-time detect the data storage space of the index area. When the data storage space of the index area is full, copy the data status record information of the index area to the backup index area and erase the stored content of the index area;

[0025] Read the data status record information copied in the backup index area and clear the record information with the data status information being read, and rewrite the cleared data status record information into the index area.

[0026] In one implementation, the embedded data storage method further includes:

[0027] When receiving a data reading instruction uploaded by a user, update the data status information of the index area and the mapping area to read, and obtain the starting address recorded in the mapping area of the read target data block of the reading instruction;

[0028] Based on the data length of the read target data block, control the pointer to offset at the starting address to implement the reading of the read target data block.

[0029] In a second aspect, the present application further provides an embedded data storage device, which is applied to a flash memory and includes: a function partitioning module, a data recording module, and a data writing module;

[0030] The function partitioning module is used to divide the storage space of the memory into several function areas located in different sectors when the memory is powered on for the first time; wherein, the types of the function areas include a data area, a mapping area, an index area, and a backup index area;

[0031] The data recording module is used to obtain the data status record information of the index area whenever the memory is powered on, and obtain the data writing position of the previous data writing instruction and the next data writing address based on the data status record information; wherein, the index area is used to record the data status information in the mapping area, the mapping area is used to record the data storage information of each data block in the data area, and the data storage information includes the data status information;

[0032] The data writing module is used to update the data status information of the indexed area and the mapping area when receiving a data writing instruction uploaded by a user, synchronously update the data status update information of the indexed area to the backup indexed area, write a corresponding data block to the data area according to the next data writing address; verify the written data block according to the data storage information; when the data verification result of the data block passes, determine that the data writing is successful; wherein, the backup indexed area is used for backup storage of the indexed area.

[0033] In the above solution, when the storage space is powered on for the first time, it is divided into functional areas such as a data area, a mapping area, an indexed area, and a backup indexed area. The data area can dynamically allocate space according to the actual data volume and is no longer restricted by fixed partitions. The mapping area records the data storage information of each data block. No matter how the data block length changes, it can accurately record its storage location in the data area, realizing dynamic storage of the data length. The partition concept of the indexed area is introduced. When the memory is powered on, the data status record information can be directly obtained from the indexed area, so that the data writing location of the previous data writing instruction and the next data writing address can be quickly determined. The indexed area plays a role in quickly indexing the data storage location, avoiding blind traversal of the entire storage space, shortening the time to find the latest cache area after power-on, and effectively improving the startup speed of the system. Further, by using the indexed area and the mapping area to work together, the indexed area records the data status information of the mapping area, and the mapping area records the data storage information of each data block in the data area. When a new data writing instruction is received, the data can be reasonably written to a suitable location according to the data status information, avoiding excessive reading and writing in some areas, realizing an even distribution of read and write operations, and prolonging the service life of the storage device. During the data writing process, the written data block is verified according to the data storage information recorded in the mapping area. Only when the data verification result of the data block passes is it determined that the data writing is successful. This verification mechanism can timely detect possible errors in the data during transmission or storage, ensuring the accuracy and integrity of the data.

[0034] In one implementation manner, the data recording module is used to obtain the data status record information of the indexed area whenever the memory is powered on, specifically including:

[0035] When the memory is powered on, initialize the interface of the memory and judge the data storage status of the indexed area;

[0036] If the indexed area is not empty and the data status record information does not conform to the preset data storage rule, erase the current stored content of the indexed area, copy the content stored in the backup indexed area to the indexed area, and update the indexed area;

[0037] Read the data status information recorded in the index area to obtain the data status record information.

[0038] In one implementation, the mapping area is used to record the data storage information of each data block in the data area, specifically:

[0039] The data storage information includes the starting address of the data block in the data area, the length of the data block, and the data status information of the data block; where the data status information includes unused, written but unread, and read.

[0040] In one implementation, the data writing module is used to update the data status information of the index area and the mapping area when receiving a data writing instruction uploaded by a user, and write the corresponding data block in the data area according to the next data writing address, specifically including:

[0041] Based on the data writing instruction, update the data status information of the index area and the mapping area to written but unread, and record the starting address of the data block in the mapping area;

[0042] Take the next data writing address as the starting address, and write the corresponding data block in the data area based on the starting address.

[0043] In one implementation, verify the written data block according to the data storage information; when the data verification result of the data block passes, determine that the data writing is successful, specifically including:

[0044] After writing the data block, generate a parity check byte as the last data byte of the data block based on a preset check rule; where the preset check rule is to use the sum byte obtained by adding each byte of the data block one by one as the check code of the data block;

[0045] Obtain the starting address and data length of the data block, and generate a check code based on the preset check rule;

[0046] When the data byte is consistent with the check code, determine that the data block is written successfully.

[0047] In one implementation, the backup index area is used to back up and store the index area, and further includes:

[0048] Real-time detect the data storage space of the index area. When the data storage space of the index area is full, copy the data status record information of the index area to the backup index area and erase the stored content of the index area;

[0049] Read the data status record information in the copied backup index area, clear the record information with the data status information being read, and rewrite the cleared data status record information into the index area.

[0050] In one implementation, the embedded data storage device further includes:

[0051] When receiving a data reading instruction uploaded by a user, update the data status information of the index area and the mapping area to read, and obtain the starting address recorded in the mapping area for the read target data block of the reading instruction;

[0052] Based on the data length of the read target data block, control the pointer to offset at the starting address to implement the reading of the read target data block.

[0053] In a third aspect, the present application further provides a terminal device, including a processor, a memory, and a computer program stored in the memory and configured to be executed by the processor. When the processor executes the computer program, the above-mentioned embedded data storage method is implemented.

[0054] In a fourth aspect, the present application further provides a computer-readable storage medium. The computer-readable storage medium includes a stored computer program. Among them, when the computer program runs, it controls the device where the computer-readable storage medium is located to execute the above-mentioned embedded data storage method. Description of the Drawings

[0055] Figure 1 It is a schematic flowchart of an embedded data storage method provided in an embodiment of the present invention;

[0056] Figure 2 It is a schematic module diagram of an embedded data storage device provided in an embodiment of the present invention. Detailed Embodiments

[0057] The following combines the drawings and embodiments to further describe in detail the specific embodiments of the present invention. The following embodiments are used to illustrate the present invention, but are not used to limit the scope of the present invention.

[0058] The terms "first" and "second" in the specification, claims, and drawings of the present application are used to distinguish different objects, rather than to describe a specific order. In addition, the terms "include" and "have" and any variations thereof are intended to cover non-exclusive inclusion. For example, a process, method, system, product, or device that includes a series of steps or units is not limited to the listed steps or units, but optionally further includes steps or units not listed, or optionally further includes other steps or units inherent to these processes, methods, products, or devices.

[0059] References herein to "embodiments" mean that a particular feature, structure, or characteristic described in connection with the embodiments can be included in at least one embodiment of the present application. The phrase appears in various places in the specification and does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment mutually exclusive with other embodiments. Those skilled in the art will explicitly and implicitly understand that the embodiments described herein can be combined with other embodiments.

[0060] Embodiment 1

[0061] See Figure 1 , Figure 1 which is a schematic flowchart of an embedded data storage method provided in an embodiment of the present invention. The embodiments of the present invention provide the method, which includes steps 101 to 103. The specific steps are as follows:

[0062] Step 101: When the memory is powered on for the first time, divide the storage space of the memory into several functional areas located in different sectors; wherein, the types of the functional areas include a data area, a mapping area, an index area, and a backup index area.

[0063] In the embodiments of the present invention, a partitioning operation is performed when the flash memory is powered on for the first time. Since the erase and write operations of the flash memory are performed in units of sectors, in order to ensure that each functional area can be erased and updated independently, the four areas of the data area, the mapping area, the index area, and the backup index area must be allocated to different sectors. The space sizes of each functional area are fixedly allocated in advance and can be set according to specific requirements. Exemplarily, each of the index area and the backup index area is 4K bytes, the mapping area is 512K bytes, and the data area is 1400K bytes. Such a partitioning mechanism can effectively ensure the efficiency, reliability, and flexibility of storage.

[0064] Step 102: Whenever the memory is powered on, obtain the data status record information of the index area, and obtain the data write position of the previous data write instruction and the next data write address based on the data status record information; wherein, the index area is used to record the data status information in the mapping area, the mapping area is used to record the data storage information of each data block in the data area, and the data storage information includes the data status information.

[0065] Each time the memory is powered on, the index area is first operated on. The index area records the data status information of the mapping area, and the status is divided into three types: unused, written but unread, and read. By reading the data status record information in the index area, the data writing position of the previous data writing instruction can be quickly located, and at the same time, the address of the next data writing can also be determined. The mapping area records the detailed information of each data block in the data area, such as the starting address, length, and usage status of the data block. This information can help the system manage the storage of the data area more efficiently.

[0066] In one embodiment, when obtaining the data status record information of the index area each time the memory is powered on, it specifically includes: when the memory is powered on, initializing the interface of the memory and judging the data storage status of the index area; if the index area is not empty and the data status record information does not conform to the preset data storage rule, erasing the current stored content of the index area, and copying the content stored in the backup index area to the index area to update the index area; reading the data status information recorded in the index area to obtain the data status record information.

[0067] In the embodiment of the present invention, after the memory is powered on, the interface of the memory is first initialized to ensure that the interface can work properly. The data storage status of the index area is judged. Due to the characteristics of Flash, only 1 in binary can be written as 0. When erasing, the storage space is all 0xff, and after writing data, it becomes 0x55, and after reading data, it becomes 0x00. Reading and writing data are in order. If the data rule in the index area does not conform to the order of 0xff -> 0x55 -> 0x00, then the data is determined to be abnormal. If the index area is not empty and the data status machine i-channel information conforms to the preset data storage rule, then direct reading can be performed. If the index area is not empty and the data does not conform to the preset storage rule, first erase the current stored content of the index area. Because the Flash erase operation is necessary, only after erasing can data be rewritten. Then, copy the content stored in the backup index area to the index area to restore the data in the index area. After that, update the index area to ensure that the data in the index area is accurate and effective. After completing the above operations, read the data status information recorded in the index area. Since each index in the index area is 1 byte and the space size is 4K bytes, that is, there are 4096 indexes, read these indexes in order to obtain the complete data status record information, providing a basis for subsequent data operations. It should be noted that the preset storage rule in the embodiment of the present invention is illustrated by the device storage basic requirements of the flash memory, and can also be further customized according to user requirements, which is not limited here.

[0068] In one embodiment, the mapping area is used to record the data storage information of each data block in the data area, specifically: the data storage information includes the starting address of the data block in the data area, the length of the data block, and the data status information of the data block; wherein the data status information includes unused, written but unread, and read.

[0069] In the embodiment of the present invention, the main function of the mapping area is to index the storage structure of the data area. The data storage information it records includes the starting address of the data block in the data area, the length of the data block, and the data status information of the data block. The starting address of the data block can help quickly locate the data in the data area, and the length of the data block clarifies the size of the data. The data status information is divided into three types: unused, written but unread, and read. Through these status information, the data in the data area can be efficiently managed, direct operations on the data area can be avoided, and the stability and performance of the system can be improved. Exemplarily, the data format of the mapping area can also be preset, that is, the start address of the data block occupies 3 bytes, the data length occupies 1.5 bytes, and the data usage flag occupies 0.5 bytes (0xf represents unused, 0x5 represents written, 0x0 represents read), and the size of each mapping is constant at 5 bytes.

[0070] Step 103: When receiving a data write instruction uploaded by the user, update the data status information of the indexed area and the mapping area, and synchronously update the data status update information of the indexed area to the backup indexed area. Write the corresponding data block in the data area according to the next data write address; perform verification on the written data block according to the data storage information; when the data verification result of the data block passes, determine that the data write is successful; wherein, the backup indexed area is used to backup and store the indexed area.

[0071] In one embodiment, when receiving a data write instruction uploaded by the user, updating the data status information of the indexed area and the mapping area, and writing the corresponding data block in the data area according to the next data write address specifically includes: based on the data write instruction, updating the data status information of the indexed area and the mapping area to written but unread, and recording the starting address of the data block in the mapping area; using the next data write address as the starting address, and writing the corresponding data block in the data area based on the starting address.

[0072] In an embodiment of the present invention, after receiving a user's data writing instruction, the data status information in the index area and the mapping area is immediately updated. The data status in these two areas is updated to "written but unread", indicating that the data has been written but not yet read. At the same time, the starting address of the data block is recorded in the mapping area, and this starting address is the next data writing address determined previously. In this way, when reading data subsequently, the location of the data in the data area can be accurately found through the mapping area. The next data writing address determined at startup is used as the starting address of the data block, and then the corresponding data block is written in the data area according to this starting address. During the writing process, the data is written sequentially according to the length of the data block to ensure that the data is accurately stored in the data area. If it is not the just-started state at this time, the next data writing address can also be directly obtained by querying the data status record information in the index area.

[0073] In one embodiment, the written data block is verified according to the data storage information; when the data verification result of the data block passes, it is determined that the data writing is successful, which specifically includes: after the data block is written, a parity check byte is generated based on a preset parity check rule as the last data byte of the data block; wherein, the preset parity check rule is to use the sum byte obtained by adding each byte of the data block one by one as the check code of the data block; the starting address and data length of the data block are obtained, and a check code is generated based on the preset parity check rule; when the data byte is consistent with the check code, it is determined that the data block is written successfully.

[0074] In an embodiment of the present invention, after the data block is written, a check code is generated according to a preset parity check rule. The specific method is to add each byte of the data block one by one to obtain a sum byte, and this sum byte is the check code. Then, this check code is stored as the last data byte of the data block in the data area. In this way, when reading data subsequently, the integrity of the data can be verified by recalculating the check code and comparing it with the stored check code. To perform data verification, the starting address and data length of the data block are obtained from the mapping area. Then, the data block is read from the data area according to this information, and a check code is regenerated according to the preset parity check rule (adding each byte). The regenerated check code is compared with the last byte of the data block (i.e., the stored check code). If the two are consistent, it indicates that there is no error in the data during the writing process and the data block is written successfully; if they are inconsistent, it indicates that there may be an error in the data during the writing process, and a rewrite operation is performed to ensure the accuracy and integrity of the data.

[0075] In one embodiment, the backup index area is used to back up and store the index area, and further includes: real-time detecting the data storage space of the index area, and when the data storage space of the index area is full, copying the data status record information of the index area to the backup index area and erasing the stored content of the index area; reading the copied data status record information in the backup index area and clearing the record information with the data status information being read, and rewriting the cleared data status record information into the index area.

[0076] In an embodiment of the present invention, the data storage space of the index area is monitored in real time. Since each index in the index area is 1 byte and the space size is 4K bytes, that is, there is a storage limit of 4096 indexes. When the number of indexes in the index area reaches 4096, it indicates that the data storage space of the index area is full. At this time, the data status record information of the index area is copied to the backup index area to prevent data loss. Then, the stored content of the index area is erased to free up space for subsequent data writing. After copying the data in the index area to the backup index area and erasing the content of the index area, the copied data status record information is read from the backup index area. Then, these information are sorted out, and the record information with the data status information being "read" is cleared. Because these read data records may no longer be needed subsequently, clearing them can save the storage space of the index area. Finally, the cleared record information is rewritten into the index area to complete the update of the index area.

[0077] In one embodiment, the embedded data storage method further includes: when receiving a data reading instruction uploaded by a user, updating the data status information of the index area and the mapping area to read, and obtaining the starting address recorded in the mapping area of the read target data block of the reading instruction; controlling the pointer to offset at the starting address based on the data length of the read target data block to implement the reading of the read target data block.

[0078] In an embodiment of the present invention, when a data reading instruction from a user is received, the data status information in the index area and the mapping area is first updated to "read", indicating that the data block has been read. Then, the starting address of the target data block to be read is obtained from the mapping area. Since the mapping area records the starting address of each data block in the data area, the position of the target data block in the data area can be quickly located through this address. After obtaining the starting address of the target data block, the data length of the data block is also obtained from the mapping area. Then, according to the data length, the pointer is controlled to be offset at the starting address, and each byte in the data block is read in sequence until the entire data block is read. Preferably, after the reading is completed, the read data can be verified. The sum checksum of the read data is obtained by adding each byte of the read data and compared with the sum checksum during writing. If they are consistent, it means the data is correct and can be used safely; if they are inconsistent, it means that an error may have occurred during the reading process, and the invalid data is discarded and a warning is issued.

[0079] In an embodiment of the present invention, an embedded data storage device is further provided, including a processor, a memory, and a computer program stored in the memory and configured to be executed by the processor. When the processor executes the computer program, the above-mentioned embedded data storage method is implemented.

[0080] In an embodiment of the present invention, a computer-readable storage medium is further provided. The computer-readable storage medium includes a stored computer program, wherein when the computer program runs, it controls the device where the computer-readable storage medium is located to execute the above-mentioned embedded data storage method.

[0081] Exemplarily, the computer program can be divided into one or more modules. One or more modules are stored in the memory and executed by the processor to complete the present invention. One or more modules can be a series of computer program instruction segments capable of performing specific functions, and these instruction segments are used to describe the execution process of the computer program in the embedded data storage device.

[0082] The embedded data storage device can be a computing device such as a desktop computer, a notebook, a palm computer, and a cloud server. The embedded data storage device may include, but is not limited to, a processor, a memory, and a display. Those skilled in the art can understand that the above components are only examples of the embedded data storage device and do not constitute a limitation on the embedded data storage device. It may include more or fewer components than those described, or combine some components, or have different components. For example, the embedded data storage device may further include input / output devices, network access devices, a bus, etc.

[0083] The so-called processor may be a Central Processing Unit (CPU), or it may also be other general-purpose processors, Digital Signal Processors (DSPs), Application Specific Integrated Circuits (ASICs), Field-Programmable Gate Arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc. The processor is the control center of the embedded data storage device, and connects all parts of the entire embedded data storage device through various interfaces and lines.

[0084] The memory can be used to store computer programs and / or modules. By running or executing the computer programs and / or modules stored in the memory, and by invoking the data stored in the memory, the processor realizes various functions of the embedded data storage device. The memory mainly includes a program storage area and a data storage area. Among them, the program storage area can store an operating system, application programs required for at least one function (such as a sound playback function, a text conversion function, etc.); the data storage area can store data created according to the use of the mobile phone (such as audio data, text message data, etc.). In addition, the memory may include high-speed random access memory, and may also include non-volatile memory, such as a hard disk, a memory, a plug-in hard disk, a Smart Media Card (SMC), a Secure Digital (SD) card, a FlashCard, at least one magnetic disk storage device, a flash memory device, or other volatile solid-state storage devices.

[0085] Among them, when the module based on embedded data storage is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on such an understanding, to implement all or part of the processes in the above method embodiments of the present invention, it can also be completed by instructing relevant hardware through a computer program. The computer program can be stored in a computer-readable storage medium. When the computer program is executed by a processor, the steps of the above method embodiments can be implemented. Among them, the computer program includes computer program code, and the computer program code can be in the form of source code, object code, executable file or some intermediate form, etc. The computer-readable medium can include: any entity or device capable of carrying computer program code, recording medium, USB flash drive, mobile hard disk, magnetic disk, optical disc, computer memory, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), electrical carrier signal, telecommunication signal, and software distribution medium, etc. Those of ordinary skill in the art can understand and implement it without creative work.

[0086] The embodiment of the present invention provides an embedded data storage method. When the device is powered on for the first time, the storage space is divided into functional areas such as a data area, a mapping area, an index area, and a backup index area. The data area can dynamically allocate space according to the actual data volume and is no longer restricted by fixed partitions. The mapping area records the data storage information of each data block. Regardless of how the length of the data block changes, it can accurately record its storage position in the data area, realizing the dynamic storage of data lengths. The partition concept of the index area is introduced. When the memory is powered on, the data status record information can be directly obtained from the index area, so that the data writing position of the previous data writing instruction and the next data writing address can be quickly determined. The index area plays a role in quickly indexing the data storage position, avoiding blind traversal of the entire storage space, shortening the time to find the latest cache area after power-on, and effectively improving the system startup speed. Further, by using the index area and the mapping area to work together, the index area records the data status information of the mapping area, and the mapping area records the data storage information of each data block in the data area. When a new data writing instruction is received, the data can be reasonably written to the appropriate position according to the data status information, avoiding over-reading and over-writing in some areas, realizing the balanced distribution of read and write operations, and prolonging the service life of the storage device. During the data writing process, the written data block is verified according to the data storage information recorded in the mapping area. Only when the data verification result of the data block passes is it determined that the data writing is successful. This verification mechanism can timely detect possible errors in the data during transmission or storage, ensuring the accuracy and integrity of the data.

[0087] Embodiment 2

[0088] See Figure 2 , Figure 2 Figure 2 is a schematic diagram of modules of an embedded data storage device provided in an embodiment of the present invention. An embodiment of the present invention provides an embedded data storage device, which is applied to a flash memory and includes: a function partition module 201, a data recording module 202, and a data writing module 203;

[0089] The function partition module 201 is used to divide the storage space of the memory into several function areas located in different sectors when the memory is powered on for the first time; wherein, the types of the function areas include a data area, a mapping area, an index area, and a backup index area;

[0090] The data recording module 202 is used to obtain the data status record information of the index area whenever the memory is powered on, and obtain the data writing position of the previous data writing instruction and the next data writing address based on the data status record information; wherein, the index area is used to record the data status information in the mapping area, the mapping area is used to record the data storage information of each data block in the data area, and the data storage information includes the data status information;

[0091] The data writing module 203 is used to update the data status information of the index area and the mapping area when receiving a data writing instruction uploaded by a user, synchronously update the data status update information of the index area to the backup index area, write the corresponding data block in the data area according to the next data writing address; perform verification on the written data block according to the data storage information; when the data verification result of the data block passes, determine that the data writing is successful; wherein, the backup index area is used to perform backup storage on the index area.

[0092] In one embodiment, the data recording module is used to obtain the data status record information of the index area whenever the memory is powered on, and specifically includes: when the memory is powered on, initialize the interface of the memory and judge the data storage status of the index area; if the index area is not empty and the data status record information does not conform to the preset data storage rule, erase the current stored content of the index area, copy the stored content of the backup index area to the index area, and update the index area; read the data status information recorded in the index area to obtain the data status record information.

[0093] In one embodiment, the mapping area is used to record the data storage information of each data block in the data area, specifically: the data storage information includes the starting address of the data block in the data area, the length of the data block, and the data status information of the data block; wherein the data status information includes unused, written but unread, and read.

[0094] In one embodiment, the data writing module is configured to update the data status information of the indexed area and the mapping area when receiving a data writing instruction uploaded by a user, and write a corresponding data block in the data area according to the next data writing address. Specifically, it includes updating the data status information of the indexed area and the mapping area to "written but unread" based on the data writing instruction, and recording the starting address of the data block in the mapping area;

[0095] Using the next data writing address as the starting address, and writing a corresponding data block in the data area based on the starting address.

[0096] In one embodiment, the written data block is verified according to the data storage information; when the data verification result of the data block passes, it is determined that the data writing is successful. Specifically, it includes: after the data block is written, generating a parity check byte as the last data byte of the data block based on a preset verification rule; wherein, the preset verification rule is to use the sum byte obtained by adding each byte of the data block one by one as the check code of the data block; obtaining the starting address and data length of the data block, and generating a check code based on the preset verification rule; when the data byte is consistent with the check code, it is determined that the data block is written successfully.

[0097] In one embodiment, the backup indexed area is used to back up and store the indexed area, and further includes:

[0098] Real-time detecting the data storage space of the indexed area, when the data storage space of the indexed area is full, copying the data status record information of the indexed area to the backup indexed area and erasing the stored content of the indexed area; reading the copied data status record information in the backup indexed area and clearing the record information with the data status information of "read", and rewriting the cleared data status record information into the indexed area.

[0099] In one embodiment, the embedded data storage device further includes: when receiving a data reading instruction uploaded by a user, updating the data status information of the indexed area and the mapping area to "read", and obtaining the starting address recorded in the mapping area of the read target data block of the reading instruction; controlling the pointer to offset at the starting address based on the data length of the read target data block to implement the reading of the read target data block.

[0100] Those skilled in the art can clearly understand that for the convenience and brevity of description, the specific working process of the above-described device can refer to the corresponding process in the foregoing method embodiment, and will not be elaborated herein.

[0101] An embodiment of the present invention provides an embedded data storage device. When powered on for the first time, the storage space is divided into functional areas such as a data area, a mapping area, an index area, and a backup index area. The data area can dynamically allocate space according to the actual data volume and is no longer restricted by fixed partitions. The mapping area records the data storage information of each data block. Regardless of how the length of the data block changes, it can accurately record its storage location in the data area, realizing the dynamic storage of data lengths. The partition concept of the index area is introduced. When the memory is powered on, the data status record information can be directly obtained from the index area, so that the data writing position of the previous data writing instruction and the next data writing address can be quickly determined. The index area plays a role in quickly indexing the data storage location, avoiding blind traversal of the entire storage space, shortening the time to find the latest cache area after power-on, and effectively improving the system startup speed. Further, by using the index area and the mapping area to work together, the index area records the data status information of the mapping area, and the mapping area records the data storage information of each data block in the data area. When a new data writing instruction is received, the data can be reasonably written to a suitable position according to the data status information, avoiding over-reading and over-writing in some areas, realizing an even distribution of read and write operations, and extending the service life of the storage device. During the data writing process, the written data block is verified according to the data storage information recorded in the mapping area. Only when the data verification result of the data block passes is it determined that the data writing is successful. This verification mechanism can timely detect possible errors in the data during transmission or storage, ensuring the accuracy and integrity of the data.

[0102] The above are only the preferred embodiments of the present invention. It should be noted that for those of ordinary skill in the art, without departing from the technical principle of the present invention, several improvements and substitutions can be made, and these improvements and substitutions should also be regarded as the protection scope of the present invention.

Claims

1. An embedded data storage method, applied to a flash memory, characterized in that, Including: When the memory is powered on for the first time, divide the storage space of the memory into several functional areas located in different sectors; among them, the types of the functional areas include a data area, a mapping area, an index area, and a backup index area; Whenever the memory is powered on, obtain the data status record information of the index area, and obtain the data writing position of the previous data writing instruction and the next data writing address based on the data status record information; wherein, the index area is used to record the data status information in the mapping area, and the mapping area is used to record the data storage information of each data block in the data area, and the data storage information includes the data status information; When receiving a data writing instruction uploaded by a user, update the data status information of the index area and the mapping area, and synchronously update the data status update information of the index area to the backup index area, and write the corresponding data block in the data area according to the next data writing address; perform verification on the written data block according to the data storage information; when the data verification result of the data block passes, determine that the data writing is successful; wherein, the backup index area is used to perform backup storage on the index area.

2. The embedded data storage method according to claim 1, wherein The step of obtaining the data status record information of the index area whenever the memory is powered on specifically includes: When the memory is powered on, initialize the interface of the memory and judge the data storage status of the index area; If the index area is not empty and the data status record information does not conform to the preset data storage rule, erase the current stored content of the index area, copy the stored content of the backup index area to the index area, and update the index area; Read the data status information recorded in the index area to obtain the data status record information.

3. An embedded data storage method as claimed in claim 1, wherein The mapping area is used to record the data storage information of each data block in the data area, specifically: The data storage information includes the starting address of the data block in the data area, the length of the data block, and the data status information of the data block; wherein the data status information includes unused, written but unread, and read.

4. An embedded data storage method according to claim 1, characterized in that, The step of updating the data status information of the index area and the mapping area and writing the corresponding data block in the data area according to the next data writing address when receiving a data writing instruction uploaded by a user specifically includes: Based on the data writing instruction, update the data status information of the index area and the mapping area to written but unread, and record the starting address of the data block in the mapping area; Use the next data writing address as the starting address, and write the corresponding data block in the data area based on the starting address.

5. An embedded data storage method according to claim 3, characterized in that, The step of performing verification on the written data block according to the data storage information; when the data verification result of the data block passes, determine that the data writing is successful, specifically includes: After the data block is written, generate a parity byte as the last data byte of the data block based on a preset verification rule; wherein, the preset verification rule is to use the sum byte obtained by adding each byte of the data block one by one as the verification code of the data block; Obtain the starting address and data length of the data block, and generate a check code based on the preset check rule; When the data byte is consistent with the check code, it is determined that the data block is successfully written.

6. An embedded data storage method according to claim 1, characterized in that, The backup index area is used for backup storage of the index area, and further includes: Real-time detect the data storage space of the index area. When the data storage space of the index area is full, copy the data status record information of the index area to the backup index area and erase the stored content of the index area; Read the copied data status record information in the backup index area and clear the record information with the data status information being read, and rewrite the cleared data status record information into the index area.

7. An embedded data storage method according to claim 1, wherein The embedded data storage method further includes: When receiving a data reading instruction uploaded by a user, update the data status information of the index area and the mapping area to read, and obtain the starting address recorded in the mapping area of the reading target data block of the reading instruction; Control the pointer to offset at the starting address based on the data length of the reading target data block to realize the reading of the reading target data block.

8. An embedded data storage device is applied to a flash memory, characterized in that, Includes: A function partitioning module, a data recording module, and a data writing module; The function partitioning module is used to divide the storage space of the memory into several function areas located in different sectors when the memory is powered on for the first time; wherein, the types of the function areas include a data area, a mapping area, an index area, and a backup index area; The data recording module is used to obtain the data status record information of the index area whenever the memory is powered on, and obtain the data writing position of the previous data writing instruction and the next data writing address based on the data status record information; wherein, the index area is used to record the data status information in the mapping area, the mapping area is used to record the data storage information of each data block in the data area, and the data storage information includes the data status information; The data writing module is used to update the data status information of the index area and the mapping area when receiving a data writing instruction uploaded by a user, and synchronously update the data status update information of the index area to the backup index area, write the corresponding data block in the data area according to the next data writing address; perform a check on the written data block according to the data storage information; when the data check result of the data block passes, it is determined that the data is successfully written; wherein, the backup index area is used for backup storage of the index area.

9. A terminal device, characterized in that, Includes a processor, a memory, and a computer program stored in the memory and configured to be executed by the processor. When the processor executes the computer program, it implements the embedded data storage method according to any one of claims 1 to 7.

10. A computer-readable storage medium, characterized in that, The computer-readable storage medium includes a stored computer program, wherein when the computer program runs, it controls the device where the computer-readable storage medium is located to execute the embedded data storage method according to any one of claims 1 to 7.

Citation Information

Patent Citations

  • Train automatic control system data read-write method and device

    CN110941394A

  • Storage wear balancing method and device

    CN119597215A

  • Flash memory and control method

    CN1290014A

  • Memory control apparatus, memory control method and program

    US20060059297A1

  • Hardware supported memory logging

    US20140258777A1

Cited By

  • Data synchronization control method of A-type single-phase Bluetooth prepayment ammeter, storage medium and device

    CN120881548A

  • A data synchronization control method, storage medium and device of a single-phase Bluetooth prepayment electric meter of type A

    CN120881548B