Lightweight two-way double-linked list data storage method for single-chip microcomputer
By building a two-way and two-dimensional linked list structure in the Flash space of the microcontroller, the problem of rolling storage of measurement data under the limitation of microcontroller resources is solved, efficient and low-cost data management is achieved, and the system's needs for fast writes and query are met.
Patent Information
- Application Number
- CN202510562850.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-30
- Publication Date
- 2025-08-12
AI Technical Summary
In microcontrollers with limited resources, how to achieve efficient and scalable rolling storage of measurement data without adding additional costs to meet the system's needs for fast writes and queries, and avoid waste of space and insufficient performance in traditional storage methods.
The address number information storage area and the measurement data information storage area are divided in the readable and writeable Flash space of the microcontroller, and a data storage structure that supports two-way and two-dimensional retrieval is built, including address index and time index, forming a two-way linked list of address dimensions and time dimensions, and realizing efficient two-dimensional management of data.
The microcontroller's own ROM space is equipped with efficient rolling storage of measurement data, which reduces implementation costs, improves data access efficiency, avoids the waste of space in traditional storage methods, and meets the needs of low-cost systems.
Smart Images

Figure HDA0005385103320000011 
Figure HDA0005385103320000021 
Figure HDA0005385103320000031
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of embedded system data storage, and in particular to a lightweight bidirectional double-linked list data storage method for a single-chip computer. Background Art
[0002] In applications such as mines, where multi-channel, high-frequency, and low-cost rolling measurements are required, continuous storage and management of measurement data is often required. In most practical projects, each set of measurement data typically does not exceed 64 bytes, with the maximum number of rolling storage groups being approximately 1,000, keeping the total required storage space within 64KB. To reduce system costs, low-cost microcontrollers are often selected as the control core while meeting project requirements. However, these microcontrollers have limited program memory (ROM) and RAM (RAM) resources, resulting in numerous challenges in achieving efficient rolling data storage.
[0003] Currently, there are two common implementation methods:
[0004] 1. Integrate a lightweight file system (such as FATFS): Although FATFS is designed for resource-constrained systems, its simplest implementation still requires approximately 15KB of ROM space and has a certain reliance on RAM during operation. With limited resources, it is difficult to meet the system stability and responsiveness requirements of embedded projects.
[0005] 2. Introducing external storage chips: such as Flash chips, SD cards, or EEPROM. While this solution expands storage capacity, it also incurs additional hardware costs, defeating the purpose of a low-cost system design. Furthermore, storage devices like Flash or SD cards typically have page or sector write granularity limitations (e.g., 512 bytes or 4KB), resulting in significant space waste when storing small data blocks. Although EEPROM can be written byte by byte, its average maximum write rate (approximately 10 Mbit / s) is insufficient to meet the system's requirements for fast writes and queries.
[0006] Considering the small size of measurement data and the low overall capacity requirements, if the ROM area (i.e., on-chip Flash) within the microcontroller can be fully utilized, it is expected that the system's requirements for data rolling storage can be met without adding additional costs. In particular, the AHB bus speed of current low-power microcontrollers can generally reach at least 80MHz, which can basically meet the high-frequency rolling read and write rates of measurement data even at this main frequency. Therefore, how to achieve efficient and scalable data rolling storage without the need for external storage chips or file system support, while fully utilizing the limited ROM and RAM resources built into the microcontroller, has become a technical problem that urgently needs to be solved in this field. Summary of the Invention
[0007] In view of the above-mentioned deficiencies in the prior art, the technical problem to be solved by the present invention is: how to provide a bidirectional double-linked list data storage method in a lightweight non-file system presentation mode that can realize rolling storage of measurement data on the ROM space of the microcontroller, which can not only meet project requirements but also reduce implementation costs.
[0008] In order to solve the above technical problems, the present invention adopts the following technical solutions:
[0009] A lightweight bidirectional double-linked list data storage method for a single-chip microcomputer is characterized in that before storing data, a data storage structure supporting bidirectional and bidimensional retrieval is first established, and then data storage is performed; the steps of establishing the data storage structure are:
[0010] An address number information storage area and a measurement data information storage area are divided in the readable and writable Flash space of the single-chip computer; the address number information storage area is used to store index information corresponding to the address number of each measurement sensor; the measurement data information storage area is used to store measurement data nodes;
[0011] In the address number information storage area, an address index structure is established for each address number, the address index structure including the address number, the first address index of the measurement data node corresponding to the address number in the measurement data information storage area, and an address free page linked list index for managing unused address index items;
[0012] In the measurement data information storage area, each measurement data node includes a forward index and a backward index according to the address dimension, an actual measurement data field, a forward index and a backward index according to the time dimension, and a data free page linked list index for managing free data node space;
[0013] A bidirectional linked list of the address dimension is established by the first address index of the measurement data node corresponding to the address number in the measurement data information storage area, and the forward index and backward index of the address dimension. A bidirectional linked list of the time dimension is established by the forward index and backward index of the time dimension in the measurement data information storage area, thereby forming a data storage structure that supports bidirectional and dual-dimensional retrieval.
[0014] Furthermore, when adding data by time dimension, the following steps are taken:
[0015] S11, obtaining an idle storage unit Pe in the measurement data information storage area;
[0016] S12. Obtain the last data storage unit Pt in the bidirectional linked list of the time dimension in the measurement data information storage area, point the backward index of the data storage unit Pt in the time dimension to the free storage unit Pe, point the forward index of the free storage unit Pe in the time dimension to the data storage unit Pt, initialize the backward index of the free storage unit Pe in the time dimension to null, and update the data free page linked list index;
[0017] S13. Store the measurement data into the free storage unit Pe.
[0018] Furthermore, when adding data by address dimension, the following steps are taken:
[0019] S21, obtaining an idle storage unit Pe in the measurement data information storage area;
[0020] S22, querying the corresponding address number in the address number information storage area according to the address number of the sensor;
[0021] S23, obtaining the last data storage unit Pi under the address number in the bidirectional linked list of the address dimension of the measurement data information storage area, and obtaining the last data storage unit Pt under the bidirectional linked list of the time dimension of the measurement data information storage area;
[0022] S24. Point the backward index of data storage unit Pi in the address dimension to the free storage unit Pe, and point the backward index of data storage unit Pt in the time dimension to the free storage unit Pe; point the forward index of free storage unit Pe in the address dimension and time dimension to data storage unit Pi and data storage unit Pt respectively, initialize the backward index of free storage unit Pe in the address dimension and time dimension to null respectively, and update the data free page linked list index;
[0023] S25. Store the measurement data into the free storage unit Pe.
[0024] Furthermore, in step S22, if the queried address number does not exist, an idle storage unit PAe is obtained in the address number information storage area, and the address number of the sensor is stored in the idle storage unit PAe, and the address idle page linked list index is updated; the first address index of the idle storage unit PAe is pointed to the idle storage unit Pe.
[0025] Furthermore, when deleting data, the following steps are taken:
[0026] S31, searching for the data storage unit Pd to be deleted in the measurement data information storage area, and searching for the address storage unit PAa corresponding to the data storage unit Pd in the address number information storage area according to the bidirectional linked list of the address dimension;
[0027] S32. Delete the data storage unit Pd in the measurement data information storage area, and update the data free page linked list index; delete the address storage unit PAa in the address number information storage area, and update the address free page linked list index.
[0028] Furthermore, in step S32, the step of updating the data free page linked list index is:
[0029] S321. In the doubly linked list of the time dimension, search for the previous data storage unit Ptr according to the forward index of the data storage unit Pd, and search for the next data storage unit Ptn according to the backward index of the data storage unit Pd;
[0030] S322. If both the data storage unit Ptr and the data storage unit Ptn exist, point the backward index of the data storage unit Ptr in the time dimension to the data storage unit Ptn, and point the forward index of the data storage unit Ptn in the time dimension to the data storage unit Ptr.
[0031] If only the data storage unit Ptr exists, the backward index of the data storage unit Ptr in the time dimension is initialized to empty;
[0032] If only the data storage unit Ptn exists, the forward index of the data storage unit Ptn in the time dimension is initialized to empty.
[0033] Furthermore, in step S32, the step of updating the address free page linked list index is:
[0034] S32a, searching for the corresponding previous data storage unit Pr and next data storage unit Pn in the measurement data information storage area according to the forward index and backward index of the data storage unit Pd on the bidirectional linked list of the address dimension;
[0035] S32b, if both the data storage unit Pr and the data storage unit Pn exist, point the backward index of the data storage unit Pr in the address dimension to the data storage unit Pn, and point the forward index of the data storage unit Pn in the address dimension to the data storage unit Pr;
[0036] If there is only data storage unit Pr, the backward index of the data storage unit Pr in the address dimension is initialized to empty;
[0037] If only data storage unit Pn exists, the forward index of data storage unit Pn in the address dimension is initialized to empty;
[0038] If the data storage unit Pr and the data storage unit Pn do not exist, the first address index of the address storage unit PAa is initialized to empty, and all information stored in the address storage unit PAa is cleared.
[0039] In summary, the present invention has the advantages of being able to realize rolling storage of measurement data in the ROM space of the single-chip microcomputer, which can not only meet project requirements but also reduce implementation costs. BRIEF DESCRIPTION OF THE DRAWINGS
[0040] Figure 1 This is a schematic diagram of the Flash storage space division of the present invention.
[0041] Figure 2 Represents intent for a single-dimensional (time) chain.
[0042] Figure 3 Indicates the intention for a two-dimensional chain.
[0043] Figure 4 Add a flow chart to your data.
[0044] Figure 5 The following is a flowchart of data deletion.
[0045] Figure 6 Modify the flowchart for the data.
[0046] Figure 7 This is a data query flow chart. DETAILED DESCRIPTION
[0047] The present invention is further described in detail below with reference to an embodiment of a bidirectional double-linked list data storage method in a lightweight non-file system presentation mode suitable for use in a single-chip microcomputer.
[0048] In this embodiment, the project required the lowest cost solution, so a very low-cost single-chip microcomputer was selected. This low-cost microcontroller results in limited resource sizes for program storage space (ROM) (on-chip Flash) and runtime space (RAM). To implement the measurement data storage function, the space occupied by each set of measurement data must be ≤ 64 bytes. Rolling storage of up to approximately 1,000 sets of data (the actual project situation) is required, so the total storage space does not exceed 64KB. The stored data needs to be rapidly added, deleted, modified, and checked in the order of the address number (such as Key1) and the storage time (such as Key2) in the measurement data.
[0049] The actual problem is that, due to cost considerations, it's impossible to add additional external storage chips (such as EEPROM memory chips, NandFlash chips, NorFlash chips, SD cards, TF cards, etc.) that meet the storage space requirements. Even if cost is not a concern and external storage chips are used, the minimum page (or sector) size of Flash chips and SD cards (typically 512B or 4KB) still results in wasted space. While using EEPROM chips does not waste space, the maximum storage speed (market average of 10Mbit / s) cannot meet the required fast storage and query functions. Furthermore, because the extremely low-cost microcontroller is selected, its ROM (program space) and RAM (runtime space) are limited, making it impossible to integrate even a lightweight FATFS file system driver. The average ROM program space occupied by a conventional minimalist FATFS file system suitable for microcontrollers is approximately 15KB. Furthermore, considering that the file system also requires limited RAM space (a major drawback), using a simplified third-party file system to achieve the required functions is impossible.
[0050] Based on the above, the implementation scheme considered in this embodiment is as follows: the storage medium uses the ROM space (user-readable and writable Flash) of the microcontroller to allocate a specific area for storing measurement data. At the same time, the read and write speed is mainly determined by the maximum main frequency of the microcontroller. Although the actual low-power and low-cost microcontroller used is a low-power and low-cost microcontroller, the actual AHB bus speed can reach at least 80MHz, which can meet the project's measurement data read and write speed requirements. At the same time, in the mainstream implementation of linked list file systems (such as the FAT series file systems), it is generally implemented in a bidirectional single linked list manner (such as index nodes, etc.); the actual requirement of this embodiment is to require a two-dimensional index to realize the addition, deletion, modification, and query of data of different dimensions.
[0051] Specifically, the embodiment of the present invention is a lightweight non-file system presentation method for a single chip microcomputer using a bidirectional double linked list data storage method, firstly establishing a data storage structure that supports bidirectional and dual-dimensional retrieval, such as Figures 1 to 3 As shown, the address number information storage area and the measurement data information storage area are divided in the readable and writable Flash space of the single chip microcomputer; the address number information storage area is used to store the index information corresponding to the address number of each measurement sensor; the measurement data information storage area is used to store the measurement data node.
[0052] In the address number information storage area, an address index structure is established for each address number, and the address index structure includes the address number, the first address index of the measurement data node corresponding to the address number in the measurement data information storage area, and an address free page linked list index for managing unused address index items.
[0053] In the measurement data information storage area, each measurement data node includes a forward index and a backward index according to the address dimension, an actual measurement data field, a forward index and a backward index according to the time dimension, and a data free page linked list index for managing free data node space.
[0054] A bidirectional linked list of the address dimension is established by the first address index of the measurement data node corresponding to the address number in the measurement data information storage area, and the forward index and backward index of the address dimension. A bidirectional linked list of the time dimension is established by the forward index and backward index of the time dimension in the measurement data information storage area, thereby forming a data storage structure that supports bidirectional and dual-dimensional retrieval.
[0055] like Figure 4 As shown, in this embodiment, data can be added according to the time dimension or the address dimension. When adding data according to the time dimension, the following steps are adopted:
[0056] S11, obtaining an idle storage unit Pe in the measurement data information storage area;
[0057] S12. Obtain the last data storage unit Pt in the bidirectional linked list of the time dimension in the measurement data information storage area, point the backward index of the data storage unit Pt in the time dimension to the free storage unit Pe, point the forward index of the free storage unit Pe in the time dimension to the data storage unit Pt, initialize the backward index of the free storage unit Pe in the time dimension to null, and update the data free page linked list index;
[0058] S13. Store the measurement data into the free storage unit Pe.
[0059] When adding data by address dimension, use the following steps:
[0060] S21, obtaining an idle storage unit Pe in the measurement data information storage area;
[0061] S22, querying the corresponding address number in the address number information storage area according to the address number of the sensor;
[0062] S23, obtaining the last data storage unit Pi under the address number in the bidirectional linked list of the address dimension of the measurement data information storage area, and obtaining the last data storage unit Pt under the bidirectional linked list of the time dimension of the measurement data information storage area;
[0063] S24. Point the backward index of data storage unit Pi in the address dimension to the free storage unit Pe, and point the backward index of data storage unit Pt in the time dimension to the free storage unit Pe; point the forward index of free storage unit Pe in the address dimension and time dimension to data storage unit Pi and data storage unit Pt respectively, initialize the backward index of free storage unit Pe in the address dimension and time dimension to null respectively, and update the data free page linked list index;
[0064] S25. Store the measurement data into the free storage unit Pe.
[0065] like Figure 5 As shown, the steps for deleting data in this embodiment are:
[0066] S31, searching for the data storage unit Pd to be deleted in the measurement data information storage area, and searching for the address storage unit PAa corresponding to the data storage unit Pd in the address number information storage area according to the bidirectional linked list of the address dimension;
[0067] S32. Delete the data storage unit Pd in the measurement data information storage area, and update the data free page linked list index; delete the address storage unit PAa in the address number information storage area, and update the address free page linked list index.
[0068] The steps for updating the data free page linked list index are:
[0069] S321. In the doubly linked list of the time dimension, search for the previous data storage unit Ptr according to the forward index of the data storage unit Pd, and search for the next data storage unit Ptn according to the backward index of the data storage unit Pd;
[0070] S322. If both the data storage unit Ptr and the data storage unit Ptn exist, point the backward index of the data storage unit Ptr in the time dimension to the data storage unit Ptn, and point the forward index of the data storage unit Ptn in the time dimension to the data storage unit Ptr.
[0071] If only the data storage unit Ptr exists, the backward index of the data storage unit Ptr in the time dimension is initialized to empty;
[0072] If only the data storage unit Ptn exists, the forward index of the data storage unit Ptn in the time dimension is initialized to empty.
[0073] The steps to update the address free page list index are:
[0074] S32a, searching for the corresponding previous data storage unit Pr and next data storage unit Pn in the measurement data information storage area according to the forward index and backward index of the data storage unit Pd on the bidirectional linked list of the address dimension;
[0075] S32b, if both the data storage unit Pr and the data storage unit Pn exist, point the backward index of the data storage unit Pr in the address dimension to the data storage unit Pn, and point the forward index of the data storage unit Pn in the address dimension to the data storage unit Pr;
[0076] If there is only data storage unit Pr, the backward index of the data storage unit Pr in the address dimension is initialized to empty;
[0077] If only data storage unit Pn exists, the forward index of data storage unit Pn in the address dimension is initialized to empty;
[0078] If the data storage unit Pr and the data storage unit Pn do not exist, the first address index of the address storage unit PAa is initialized to empty, and all information stored in the address storage unit PAa is cleared.
[0079] like Figure 6 As shown, this embodiment can modify data according to the time dimension or the address dimension. The steps for modifying data according to the time dimension are as follows: under the bidirectional linked list of the time dimension, search the data storage unit Ptm that needs to be modified in the measurement data information storage area according to the key data information, and modify the data information of the data storage unit Ptm.
[0080] The steps for modifying data according to the address dimension are as follows: search for the address number of the modified data in the address number information storage area, and choose whether to modify the address information as needed; search for the data storage unit Pm that needs to be modified in the measurement data information storage area according to the key data information under the bidirectional linked list of the address dimension, and modify the data information of the data storage unit Pm.
[0081] like Figure 7 As shown, this embodiment can perform data query according to the time dimension and the address dimension. The steps for querying data according to the time dimension are: under the bidirectional linked list of the time dimension, according to the key data information, search for the data storage unit Pts to be queried in the measurement data information storage area, and read the data information of the data storage unit Pts.
[0082] The steps for querying data according to the address dimension are: searching for the address number of the query data in the address number information storage area, reading the address information, searching for the data storage unit Ps to be queried in the measurement data information storage area according to the key data information under the bidirectional linked list of the address dimension, and reading the data information of the data storage unit Ps.
[0083] This embodiment, in a resource-constrained single-chip microcomputer environment, eliminates the need for external memory chips and file system support. Instead, it relies solely on the microcontroller's built-in Flash memory to partition the address number information storage area and the measurement data information storage area, constructing a bidirectional, dual-dimensional linked list structure for efficient rolling storage and management of measurement data. By establishing linked lists based on address numbers and time dimensions, data can be quickly inserted, queried, deleted, and modified, improving data access efficiency.
[0084] Compared to traditional file systems, this solution is more lightweight and doesn't rely on systems like FATFS, which consume large amounts of ROM and RAM resources. It's particularly suitable for low-cost, low-power embedded applications. Each data node is small and clearly structured, and reusable space is centrally managed through a free list, effectively improving Flash memory utilization and avoiding the space waste associated with traditional memory chips at the page or sector level.
[0085] The above description is only a preferred embodiment of the present invention and does not limit the present invention. Any modifications, equivalent substitutions and improvements made within the spirit and principles of the present invention should be included in the scope of protection of the present invention.
Claims
1. A lightweight bidirectional double-linked list data storage method for a single-chip microcomputer, characterized in that: Before storing data, a data storage structure that supports bidirectional and bi-dimensional retrieval is first established, and then data is stored; the steps for establishing the data storage structure are: An address number information storage area and a measurement data information storage area are divided in the readable and writable Flash space of the single-chip computer; the address number information storage area is used to store index information corresponding to the address number of each measurement sensor; the measurement data information storage area is used to store measurement data nodes; In the address number information storage area, an address index structure is established for each address number, the address index structure including the address number, the first address index of the measurement data node corresponding to the address number in the measurement data information storage area, and an address free page linked list index for managing unused address index items; In the measurement data information storage area, each measurement data node includes a forward index and a backward index according to the address dimension, an actual measurement data field, a forward index and a backward index according to the time dimension, and a data free page linked list index for managing free data node space; A bidirectional linked list of the address dimension is established by the first address index of the measurement data node corresponding to the address number in the measurement data information storage area, and the forward index and backward index of the address dimension. A bidirectional linked list of the time dimension is established by the forward index and backward index of the time dimension in the measurement data information storage area, thereby forming a data storage structure that supports bidirectional and dual-dimensional retrieval.
2. The lightweight bidirectional double-linked list data storage method for a single-chip microcomputer according to claim 1, characterized in that: When adding data by time dimension, use the following steps: S11, obtaining an idle storage unit Pe in the measurement data information storage area; S12. Obtain the last data storage unit Pt in the bidirectional linked list of the time dimension in the measurement data information storage area, point the backward index of the data storage unit Pt in the time dimension to the free storage unit Pe, point the forward index of the free storage unit Pe in the time dimension to the data storage unit Pt, initialize the backward index of the free storage unit Pe in the time dimension to null, and update the data free page linked list index; S13. Store the measurement data into the free storage unit Pe.
3. The lightweight bidirectional double-linked list data storage method for a single-chip microcomputer according to claim 2, wherein: When adding data by address dimension, use the following steps: S21, obtaining an idle storage unit Pe in the measurement data information storage area; S22, querying the corresponding address number in the address number information storage area according to the address number of the sensor; S23, obtaining the last data storage unit Pi under the address number in the bidirectional linked list of the address dimension of the measurement data information storage area, and obtaining the last data storage unit Pt under the bidirectional linked list of the time dimension in the measurement data information storage area; S24. Point the backward index of data storage unit Pi in the address dimension to the free storage unit Pe, and point the backward index of data storage unit Pt in the time dimension to the free storage unit Pe; point the forward index of free storage unit Pe in the address dimension and time dimension to data storage unit Pi and data storage unit Pt respectively, initialize the backward index of free storage unit Pe in the address dimension and time dimension to null respectively, and update the data free page linked list index; S25. Store the measurement data into the free storage unit Pe.
4. The lightweight bidirectional double-linked list data storage method for a single-chip microcomputer according to claim 3, characterized in that: In step S22, if the queried address number does not exist, the free storage unit PAe is obtained in the address number information storage area, the address number of the sensor is stored in the free storage unit PAe, and the address free page linked list index is updated; the first address index of the free storage unit PAe is pointed to the free storage unit Pe.
5. The lightweight bidirectional double-linked list data storage method for a single-chip microcomputer according to claim 1, wherein: To delete data, follow these steps: S31, searching for the data storage unit Pd to be deleted in the measurement data information storage area, and searching for the address storage unit PAa corresponding to the data storage unit Pd in the address number information storage area according to the bidirectional linked list of the address dimension; S32. Delete the data storage unit Pd in the measurement data information storage area, and update the data free page linked list index; delete the address storage unit PAa in the address number information storage area, and update the address free page linked list index.
6. The lightweight bidirectional double-linked list data storage method for a single-chip microcomputer according to claim 5, characterized in that: In step S32, the steps of updating the data free page linked list index are: S321. In the doubly linked list of the time dimension, search for the previous data storage unit Ptr according to the forward index of the data storage unit Pd, and search for the next data storage unit Ptn according to the backward index of the data storage unit Pd; S322. If both the data storage unit Ptr and the data storage unit Ptn exist, point the backward index of the data storage unit Ptr in the time dimension to the data storage unit Ptn, and point the forward index of the data storage unit Ptn in the time dimension to the data storage unit Ptr. If only the data storage unit Ptr exists, the backward index of the data storage unit Ptr in the time dimension is initialized to empty; If only the data storage unit Ptn exists, the forward index of the data storage unit Ptn in the time dimension is initialized to empty.
7. The lightweight bidirectional double-linked list data storage method for a single-chip microcomputer according to claim 5, characterized in that: In step S32, the steps of updating the address free page linked list index are: S32a, searching for the corresponding previous data storage unit Pr and next data storage unit Pn in the measurement data information storage area according to the forward index and backward index of the data storage unit Pd on the bidirectional linked list of the address dimension; S32b, if both the data storage unit Pr and the data storage unit Pn exist, point the backward index of the data storage unit Pr in the address dimension to the data storage unit Pn, and point the forward index of the data storage unit Pn in the address dimension to the data storage unit Pr; If there is only data storage unit Pr, the backward index of the data storage unit Pr in the address dimension is initialized to empty; If only data storage unit Pn exists, the forward index of data storage unit Pn in the address dimension is initialized to empty; If the data storage unit Pr and the data storage unit Pn do not exist, the first address index of the address storage unit PAa is initialized to empty, and all information stored in the address storage unit PAa is cleared.