Data storage method of embedded system and single-chip microcomputer system and intelligent terminal
By writing data into the RAM cache area in an embedded system and dividing it into an index area and a data area, dynamically managing and storing data with varying lengths, the problem of inconvenience in storage management in the prior art is solved, efficient data storage and flexible storage expansion are achieved, and the risk of system crashes and maintenance costs are reduced.
Patent Information
- Application Number
- CN202510079392.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-17
- Publication Date
- 2025-05-13
AI Technical Summary
In embedded systems, it is difficult for the prior art to effectively manage and store data with dynamic length changes, resulting in system crashes or waste of resources during product iterations, and the inability to flexibly add new storage projects.
Dynamic management and storage of data are achieved by writing data in the storage medium into a RAM cache area and dividing it into an index area and a data area. The specific steps include applying to create index information of data in the index area, applying for data space of corresponding length in the data area based on the index information, and appropriately deleting and recycling the space when data is updated to meet the length requirements of new data.
It realizes efficient management and storage of data with dynamic length changes in embedded systems, reduces the risk of system crashes and resource waste during product iteration, supports flexible storage requirements, and reduces product maintenance costs.
Smart Images

Figure CN119988253A_ABST
Abstract
Description
Technical Field
[0001] The invention relates to an embedded system and a data storage method of a single-chip computer system and an intelligent terminal, belonging to the technical field of data storage. Background Art
[0002] In embedded systems, some data is very important, such as the card number of the access control system, the device information of smart home devices, the quick list information, etc. Some of this information has a dynamically changing length, some is repeatedly deleted and added during use, and some is added by product software iterations. All of this information needs to be saved in the flash memory and ensured not to be lost during power failure.
[0003] The storage of this data on the Linux system is through database storage, which can meet the needs of dynamic changes in the length of one or some stored data in the storage table and the addition and deletion of some data;
[0004] However, there is no database support in the embedded system, but it is stored according to the old traditional technology, as shown below:
[0005] In traditional products, data storage generally uses a structure to declare a data type. Assume that the data structure type is: typdef struct{char a; short b; int c; char reserve
[100] }Data_t; if single-byte alignment is used, the size of this structure Data_t is 107 bytes and is stored in the order of a, b, c, reserve. This leads to the following problems:
[0006] If we find that the length of data a is not enough and needs to be expanded during subsequent product iterations, we cannot directly change char to short or a longer type, otherwise it will cause errors in data b and c, and even cause the system to crash. If we take out a 2-byte new element from reserve, the storage space of element a will be wasted and cannot be reused.
[0007] When a new storage item is needed during subsequent product iterations, it is not possible to insert between a and b or between b and c. If the R&D personnel do not understand this feature, all data after the insertion position will be wrong, which may even cause the system to crash.
[0008] Since the length of Data_t is defined as 107 bytes when setting the structure, and it is assumed that the flash space behind this storage space stores other data, when new data is needed, if a 5-byte element d is to be added, 5 bytes must be taken out of the reserve space;
[0009] Under the single-byte alignment condition, there are 95 bytes left in reserve, and the structure becomes: typdef struct{chara; short b; int c; char d[5], char reserve
[95] }Data_t. At this time, it is relatively simple to calculate the remaining space. However, under non-single-byte alignment conditions, the remaining space of the structure will not be 95 bytes, and other methods need to be used to calculate the remaining bytes, which increases the cost of subsequent maintenance.
[0010] If enough length is reserved for elements a, b, c, etc. at the very beginning, the reserved space will be wasted, and for small resource systems, flash resources will be insufficient, which will increase the hardware cost of the product. Moreover, it is impossible to determine whether the reserved length is sufficient at the initial R&D stage, and whether the length needs to be increased due to changes in later requirements. Summary of the invention
[0011] In order to solve the above problems in the prior art, the present invention proposes a data storage method for an embedded system and a single-chip microcomputer system and an intelligent terminal.
[0012] The technical solution of the present invention is as follows:
[0013] In one aspect, the present invention provides a data storage method for an embedded system and a single-chip computer system, comprising the following steps:
[0014] Write the data stored in the storage medium into the RAM buffer area and map it and divide it into an index area and a data area;
[0015] When storing unstored data, apply to create index information of the data in the index area, then apply for data space of corresponding length in the data area according to the index information of the data and store the data in the data space;
[0016] When updating the stored data, if the length of the new data is less than or equal to the length of the data space of the stored data, the stored data will be deleted and the data will be updated;
[0017] If the length of the new data is greater than the length of the data space of the stored data, the stored data and its corresponding index information will be deleted and the data space occupied by them will be reclaimed. New index information will be applied for in the index area according to the new data. At the same time, data space of corresponding length will be applied for in the data area according to the new index information and the new data will be stored in the data space.
[0018] After the data processing in the RAM data area is completed, the check value of the RAM is recalculated and updated to the check value of the index area, and all the data in the RAM is rewritten to the storage medium in one go.
[0019] As a preferred implementation of the present invention, the index area includes a data check value and an index table, and the index table is used to store index information.
[0020] As a preferred implementation of the present invention, the index information includes a data name, a data space length, a data length, and an offset address of the data relative to a RAM head address.
[0021] As a preferred embodiment of the present invention, when reading data, the data parameters are matched in the index information items of the index table through the index module, and after the match is successful, the data is read in the data area according to the offset address of the data relative to the RAM header address.
[0022] As a preferred implementation mode of the present invention, when the storage medium is a flash memory, when writing data into the flash memory, all the data in the RAM are directly written into the flash memory at one time.
[0023] When the storage medium is a file system file, when writing data, all the data in the RAM is directly written into the file at once.
[0024] On the other hand, the present invention also provides a data storage system for an embedded system and a single-chip computer system, including a RAM mapping module, a data retrieval module, a data update module and a data storage module;
[0025] The RAM mapping module is used to write the data stored in the storage medium into the RAM buffer area for mapping and dividing it into an index area and a data area;
[0026] The data retrieval module is used to search for corresponding index items from the retrieval table according to the data name keyword and obtain index information;
[0027] The data update module is used to update the stored data. If the length of the new data is less than or equal to the length of the data space of the stored data, the stored data will be deleted and the data will be updated; if the length of the new data is greater than the length of the data space of the stored data, the stored data and its corresponding index information will be deleted and the data space they occupy will be reclaimed, and new index information will be applied for in the index area based on the new data. At the same time, data space of corresponding length will be applied for in the data area based on the new index information and the new data will be stored in the data space.
[0028] The data storage module is used to store the data in the RAM into the flash or the file system after calculating the check value of the data in the RAM and updating the check value of the index table.
[0029] As a preferred embodiment of the present invention, the system further comprises a data reading module, and the data reading module is used to read data in the data area according to the index information after the index information is retrieved by the retrieval module.
[0030] As a preferred implementation mode of the present invention, when the storage medium is a flash memory, when writing data into the flash memory, all the data in the RAM are directly written into the flash memory at one time.
[0031] When the storage medium is a file system file, when writing data, all the data in the RAM is directly written into the file at once.
[0032] On the other hand, the present invention further provides an intelligent terminal, comprising a memory, a processor, a file system, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the method described in any embodiment of the present invention is implemented.
[0033] In yet another aspect, the present invention further provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the method described in any embodiment of the present invention.
[0034] The present invention has the following beneficial effects:
[0035] 1. The present invention supports complex business storage requirements, can implement large system functions on a small-capacity chip, reduce flash space requirements and CPU chip performance requirements, reduce product costs and improve competitiveness.
[0036] 2. The present invention supports multiple storage formats such as single byte, 4 bytes, array, block and string to meet the needs of various scenarios, make full use of storage space, reduce product costs and improve product competitiveness.
[0037] 3. The present invention supports file system storage and direct flash storage, meets storage requirements in various occasions, reduces R&D costs and product costs, and improves product competitiveness.
[0038] 4. The present invention reads data into RAM once and then directly operates on the RAM, which reduces time consumption, improves product data reading and writing efficiency, and operating speed, and improves product competitiveness.
[0039] 5. When the present invention is applied to actual products, when the product is iterated in the later stage, there is no need to change the initialization array even if the storage space requirement increases, there is no data size limit, and the product maintenance cost is reduced; at the same time, when adding new data items, they can be inserted into the initialization array at any position without calculating the remaining space, which reduces the product maintenance cost. BRIEF DESCRIPTION OF THE DRAWINGS
[0040] Figure 1 is a flow chart of the method of the present invention;
[0041] Figure 2 A mapping relationship diagram between the index area and the data area of the present invention;
[0042] Figure 3 The present invention is a flowchart of the intelligent terminal for updating and storing data. DETAILED DESCRIPTION
[0043] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0044] It should be understood that the step numbers used in this document are only for convenience of description and are not intended to limit the order in which the steps are executed.
[0045] It should be understood that the terms used in the present specification are only for the purpose of describing specific embodiments and are not intended to limit the present invention. As used in the present specification and the appended claims, unless the context clearly indicates otherwise, the singular forms "a", "an" and "the" are intended to include plural forms.
[0046] The terms “include” and “comprising” indicate the presence of described features, integers, steps, operations, elements and / or components, but do not exclude the presence or addition of one or more other features, integers, steps, operations, elements, components and / or combinations thereof.
[0047] The term "and / or" means and includes any and all possible combinations of one or more of the associated listed items.
[0048] Embodiment 1:
[0049] See also Figure 1 , a data storage method for an embedded system and a single-chip computer system, comprising the following steps:
[0050] Write the data stored in the storage medium into the RAM buffer area and map it and divide it into an index area and a data area;
[0051] When storing unstored data, apply to create index information of the data in the index area, then apply for data space of corresponding length in the data area according to the index information of the data and store the data in the data space;
[0052] When updating the stored data, if the length of the new data is less than or equal to the length of the data space of the stored data, the stored data will be deleted and the data will be updated;
[0053] If the length of the new data is greater than the length of the data space of the stored data, the stored data and its corresponding index information are deleted and the data space occupied by them is reclaimed (specifically, the unused data space is reclaimed and the subsequent data is replaced, and then the data space is placed at the end of the corresponding area), and new index information is applied for in the index area according to the new data. At the same time, data space of corresponding length is applied for in the data area according to the new index information and the new data is stored in the data space;
[0054] After the data processing in the RAM data area is completed, the data check value in the RAM is calculated and the check value in the index area is updated, and then the data in the RAM data area is rewritten into the storage medium.
[0055] In this embodiment, the storage medium may be a file system storage or a flash memory, and the file system storage is directly written through fwrite, and the flash storage is directly written through write;
[0056] As a preferred implementation of this embodiment, the index area includes a data verification value (used to verify the correctness of data) and an index table, and the index table is used to store index information.
[0057] As a preferred implementation scheme of this embodiment, the index information includes data name (used to identify the uniqueness of data), data space length (indicating the maximum storage length of the current space), data length (indicating the actual storage length of the current space data) and the offset address of the data relative to the RAM head address (indicating the specific position of the data of the storage medium when it is mapped to the RAM data area).
[0058] As a preferred implementation of this embodiment, see Figure 2 When reading data, the data parameters (specifically the data name, data space length, data length, and the offset address of the data relative to the RAM header address) are matched in the index information item of the index table. After the match is successful, the data is read in the data area at the offset address of the data relative to the RAM header address, and the read data is placed in the read cache (RAM cache).
[0059] As a preferred implementation mode of this embodiment, when the storage medium is a flash memory, when writing data to the flash memory, all the data in the RAM are directly written to the flash memory at one time.
[0060] Embodiment 2:
[0061] A data storage system for an embedded system and a single-chip computer system, comprising a RAM mapping module, a data retrieval module, a data updating module and a data storage module;
[0062] The RAM mapping module is used to write the data stored in the storage medium into the RAM buffer area for mapping and dividing it into an index area and a data area;
[0063] The data retrieval module is used to search for corresponding index items from the retrieval table according to the data name keyword and obtain index information;
[0064] The data update module is used to update the stored data. If the length of the new data is less than or equal to the length of the data space of the stored data, the stored data will be deleted and the data will be updated; if the length of the new data is greater than the length of the data space of the stored data, the stored data and its corresponding index information will be deleted and the data space they occupy will be reclaimed, and new index information will be applied for in the index area based on the new data. At the same time, data space of corresponding length will be applied for in the data area based on the new index information and the new data will be stored in the data space.
[0065] The data storage module is used to store the data in the RAM into the flash or the file system after calculating the check value of the data in the RAM and updating the check value of the index table;
[0066] As a preferred implementation of this embodiment, the system further includes a data reading module, and the data reading module is used to read data in the data area according to the index information after the index information is retrieved by the retrieval module.
[0067] As a preferred implementation of this embodiment, when the storage medium is a flash memory, when writing data to the flash memory, all the data in the RAM are directly written to the flash at one time.
[0068] The system is used to implement the method in Example 1, which will not be described in detail here.
[0069] Embodiment three:
[0070] This embodiment provides an intelligent terminal, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the program, the method described in any embodiment of the present invention is implemented. The specific process of updating and storing data is as follows: Figure 3 shown.
[0071] Embodiment 4:
[0072] This embodiment provides a computer-readable storage medium on which a computer program is stored. When the program is executed by a processor, the method described in any embodiment of the present invention is implemented.
[0073] In the embodiments of the present application, "at least one" refers to one or more, and "more than one" refers to two or more. "And / or" describes the association relationship of associated objects, indicating that three relationships may exist. For example, A and / or B can represent the existence of A alone, the existence of A and B at the same time, and the existence of B alone. Among them, A and B can be singular or plural. The character " / " generally indicates that the previous and next associated objects are in an "or" relationship. "At least one of the following" and similar expressions refer to any combination of these items, including any combination of single or plural items. For example, at least one of a, b and c can be represented by: a, b, c, a and b, a and c, b and c, or a and b and c, where a, b, c can be single or multiple.
[0074] Those of ordinary skill in the art will appreciate that the various units and algorithm steps described in the embodiments disclosed herein can be implemented in a combination of electronic hardware, computer software, and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.
[0075] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.
[0076] In several embodiments provided in the present application, if any function 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 this understanding, the technical solution of the present application, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (Read-Only Memory; hereinafter referred to as: ROM), random access memory (Random Access Memory; hereinafter referred to as: RAM), disk or optical disk, and other media that can store program codes.
[0077] The above descriptions are merely embodiments of the present invention and are not intended to limit the patent scope of the present invention. Any equivalent structure or equivalent process transformation made using the contents of the present invention specification and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present invention.
Claims
1. A data storage method for an embedded system and a single-chip microcomputer system, characterized in that: The following steps are involved: Writing the data stored in the storage medium into the RAM buffer area, and then mapping the RAM buffer area into an index area and a data area; When storing unstored data, apply for and create index information of the data in the index area, then apply for data space of corresponding length in the data area according to the index information of the data and store the data in the data space; When updating the stored data, if the length of the new data is less than or equal to the length of the data space of the stored data, the stored data will be deleted and the data and index information will be updated; If the length of the new data is greater than the length of the data space of the stored data, the stored data and its corresponding index information will be deleted and the data space occupied by them will be reclaimed. New index information will be applied for in the index area according to the new data. At the same time, data space of corresponding length will be applied for in the data area according to the new index information and the new data will be stored in the data space. After the data processing of the RAM data area is completed, the data of the RAM data area is rewritten into the storage medium.
2. The data storage method of an embedded system and a single-chip computer system according to claim 1, characterized in that: The index area includes a data check value and an index table, and the index table is used to store index information.
3. The data storage method of an embedded system and a single chip computer system according to claim 2, characterized in that: The index information includes data name, data space length, data length, and offset address of the data relative to the RAM head address.
4. The data storage method for embedded systems and single-chip microcomputer systems according to claim 1, characterized in that: When reading data, the data parameters are matched in the index information item of the index table. After the match is successful, the data is read in the data area according to the offset address of the data relative to the RAM header address.
5. The data storage method of an embedded system and a single-chip computer system according to claim 1, characterized in that: When the storage medium is a flash memory, when writing data to the flash memory, all the data in the RAM are directly written to the flash memory at one time. When the storage medium is a file system file, all data in the RAM are directly written into the file at once during writing.
6. A data storage system for an embedded system and a single-chip microcomputer system, characterized in that: It includes a RAM mapping module, a data retrieval module, a data updating module and a data storage module; The RAM mapping module is used to write the data stored in the storage medium into the RAM buffer area, and then map the RAM buffer area into an index area and a data area; The data retrieval module is used to search for corresponding index items from the retrieval table according to the data name keyword and obtain index information; The data update module is used to update the stored data. If the length of the new data is less than or equal to the length of the data space of the stored data, the stored data will be deleted and the data will be updated; if the length of the new data is greater than the length of the data space of the stored data, the stored data and its corresponding index information will be deleted and the data space they occupy will be reclaimed, and new index information will be applied for in the index area based on the new data. At the same time, data space of corresponding length will be applied for in the data area based on the new index information and the new data will be stored in the data space. The data storage module is used to calculate the check value of the data in the RAM, and store the data in the RAM to the storage medium after updating the check value of the index table.
7. The data storage system of an embedded system and a single-chip computer system according to claim 6, characterized in that: The system further comprises a data reading module, wherein the data reading module is used to read data in the data area according to the index information after the index information is retrieved by the retrieval module.
8. The data storage system of an embedded system and a single-chip computer system according to claim 6, characterized in that: When the storage medium is a flash memory, when writing data to the flash memory, all the data in the RAM are directly written to the flash memory at one time. When the storage medium is a file system file, all data in the RAM are directly written into the file at once during writing.
9. An intelligent terminal, comprising a memory, a processor, a file system, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the program, the method according to any one of claims 1 to 5 is implemented.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method according to any one of claims 1 to 5 is implemented.