A parameter storage method for embedded devices

By designing multi-level parameter management modules and data structures in embedded devices, the problems of large resource occupation and poor scalability of traditional parameter management modules are solved, flexibility and scalability are improved, and the service life of Flash is extended.

CN114995749BActive Publication Date: 2025-04-04FUJIAN NEBULA ELECTRONICS CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202210568177.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-05-24
Publication Date
2025-04-04
Estimated Expiration
2042-05-24

AI Technical Summary

Technical Problem

The parameter management module of traditional embedded devices has problems such as inconsistent storage structure, resulting in large resource occupation, untrustful entire set of parameters when parameter storage errors, and poor scalability of fixed-length storage.

Method used

The parameter management module consisting of the Parameter layer, KVDB layer, ExtNVM layer and Flash layer is adopted to configure the parameter data structure and sector data structure to achieve flexibility and expansion of parameter storage, and introduce parameter storage status and sector storage status to perform balanced erase and power-down protection.

Benefits of technology

It improves the flexibility and scalability of embedded device parameter storage, reduces resource usage, extends the service life of Flash, and realizes power-down recovery of parameter storage.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114995749B_ABST
    Figure CN114995749B_ABST
Patent Text Reader

Abstract

The present invention provides a parameter storage method for embedded devices in the field of embedded device technology, comprising the following steps: step S10, setting a parameter management module including a Parameter layer, a KVDB layer, an ExtNVM layer and a Flash layer; step S20, configuring a parameter data structure and a sector data structure; step S30, the Parameter layer forwards the acquired parameter storage instruction to the KVDB layer; step S40, after the KVDB layer receives the parameter storage instruction, it verifies the storage space of the Flash sector based on the sector data structure, and forwards the parameter storage instruction to the ExtNVM layer; step S50, the ExtNVM layer stores the parameters to the corresponding Flash sector through the Flash layer based on the parameter data structure and the parameter storage instruction. The advantages of the present invention are: greatly improving the flexibility and extensibility of embedded device parameter storage, and greatly reducing resource occupation.
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 devices, and in particular to a parameter storage method for embedded devices. Background Art

[0002] As IoT applications become more and more popular in our lives, various embedded IoT products emerge in an endless stream. These IoT products (embedded devices) usually store data such as user habits, common function configurations, control parameters, and log records. The storage of these data depends on the parameter management module. A good parameter management module can not only save Flash storage space and reduce hardware costs, but also improve product performance, quickly find and locate problems, and improve user experience. However, traditional parameter management modules for embedded devices have the following disadvantages:

[0003] 1. Due to the variety of data contents that need to be managed and stored, there is no unified storage structure, which results in a large occupation of Flash resources and invisibly reduces the service life of Flash; 2. The conventional parameter management module stores the entire set of parameters as a whole. If one of the parameters is stored incorrectly, it is difficult to identify which parameter is wrong, resulting in the entire set of parameters being unreliable. The only way is to discard the entire set of parameters and restore the default parameters, resulting in a decrease in user experience; 3. Fixed-length storage is used, which has poor scalability. If parameters of other lengths need to be stored, the changes are large and the portability is poor.

[0004] Therefore, how to provide a parameter storage method for embedded devices to improve the flexibility and scalability of embedded device parameter storage and reduce resource usage has become a technical problem that needs to be solved urgently. Summary of the invention

[0005] The technical problem to be solved by the present invention is to provide a parameter storage method for an embedded device, so as to improve the flexibility and scalability of parameter storage of the embedded device and reduce resource occupation.

[0006] The present invention is implemented as follows: a parameter storage method for an embedded device, comprising the following steps:

[0007] Step S10, setting a parameter management module including a Parameter layer, a KVDB layer, an ExtNVM layer and a Flash layer;

[0008] Step S20, configuring a parameter data structure and a sector data structure;

[0009] Step S30: the Parameter layer forwards the acquired parameter storage instruction to the KVDB layer;

[0010] Step S40: After receiving the parameter storage instruction, the KVDB layer verifies the storage space of the Flash sector based on the sector data structure, and forwards the parameter storage instruction to the ExtNVM layer;

[0011] Step S50: The ExtNVM layer stores the parameters in the corresponding Flash sector through the Flash layer based on the parameter data structure and the parameter storage instruction.

[0012] Furthermore, in the step S10, the Parameter layer depends on the KVDB layer, the KVDB layer depends on the ExtNVM layer, and the ExtNVM layer depends on the Flash layer.

[0013] Furthermore, in step S10, the Parameter layer is used to obtain parameter storage instructions of the application layer; the KVDB layer is used to query, store, repair and recycle the parameters stored in the Flash sector in the form of key-value pairs; the ExtNVM layer is used to provide a read interface, a write interface and an erase interface for the Flash sector; the Flash layer is used to provide a read interface and a write interface for the register level corresponding to the physical storage medium.

[0014] Further, in step S20, the parameter data structure includes parameter storage status, check value, parameter type, parameter number, parameter current value, parameter default value, parameter maximum value and parameter minimum value;

[0015] The parameter storage status is ready to write, written, ready to delete or deleted; the check value is the CRC16 calculation value of parameter type, parameter number, parameter current value, parameter default value, parameter maximum value and parameter minimum value; the parameter type is INT8S, UINT8, INT16S, UINT16, INT32S or UINT32; the parameter number ranges from 0 to 65535.

[0016] Further, in the step S20, the sector data structure includes a sector storage state, a dirty state and a version number;

[0017] The sector storage status is empty, in use or full; the dirty status is clean, dirty or recycled; the version number is used to identify the current version of the parameter management module.

[0018] Furthermore, the step S30 is specifically as follows:

[0019] After initializing the parameter management module, the Parameter layer continuously queries the application layer whether there is an input parameter storage instruction, and forwards the obtained parameter storage instruction to the KVDB layer.

[0020] Furthermore, the step S40 specifically includes:

[0021] Step S41, after receiving the parameter storage instruction, the KVDB layer verifies whether the storage space of the allocated Flash sector meets the storage capacity requirement based on the sector data structure. If so, the parameter storage instruction is forwarded to the ExtNVM layer and the process proceeds to step S50; if not, the process proceeds to step S42;

[0022] Step S42: Check the next Flash sector to determine whether the storage space meets the storage capacity requirement. If yes, forward the parameter storage instruction to the ExtNVM layer and proceed to step S50; if no, proceed to step S43;

[0023] Step S43, determine whether the verification of all Flash sectors is completed, if so, perform balanced erasing on the Flash sectors; if not, enter step S42.

[0024] Furthermore, in the step S43, the leveling erase is specifically to move the parameters stored in the Flash sectors whose sector storage status is full and whose dirty status is dirty to other Flash sectors.

[0025] Furthermore, the step S50 is specifically as follows:

[0026] Based on the parameter data structure and the parameter storage instruction, the ExtNVM layer stores the parameters carried by the parameter storage instruction to the corresponding Flash sector through the Flash layer, and updates the parameter data structure and the sector data structure; the parameters are stored in the form of key-value pairs.

[0027] Furthermore, the step S50 further includes: when a power failure occurs during the parameter storage process, after power is restored, performing power failure recovery of parameter storage based on the parameter data structure.

[0028] The advantages of the present invention are:

[0029] 1. By configuring the parameter data structure, the parameter data structure is updated during the parameter storage process. When power failure occurs during the parameter storage process, the parameter storage can be restored based on the parameter data structure after power is restored. That is, power failure recovery is performed through the parameter storage state, without the need to discard the entire set of parameters and then restore the default parameters as traditionally done, thereby greatly improving the flexibility of embedded device parameter storage.

[0030] 2. By dividing the parameter management module into Parameter layer, KVDB layer, ExtNVM layer and Flash layer, each layer implements different functions, has good portability and readability, and is not limited to storing only parameters of fixed length, which ultimately greatly improves the scalability of embedded device parameter storage.

[0031] 3. Due to the storage mechanism of Flash, data can only be modified from 1 to 0, but not from 0 to 1. By configuring the parameter data structure and the sector data structure, the parameter storage state and the sector storage state are introduced to achieve balanced erasing and power-off protection of the Flash sector, which not only reduces resource usage, but also significantly improves the service life of the Flash. BRIEF DESCRIPTION OF THE DRAWINGS

[0032] The present invention will be further described below in conjunction with embodiments with reference to the accompanying drawings.

[0033] Figure 1 The present invention is a flow chart of a parameter storage method for an embedded device.

[0034] Figure 2 It is a structural diagram of the parameter management module of the present invention.

[0035] Figure 3 It is a transition diagram of the parameter storage state of the present invention. DETAILED DESCRIPTION

[0036] The technical solution in the embodiment of the present application has the following overall idea: the parameter management module is divided into Parameter layer, KVDB layer, ExtNVM layer and Flash layer, each layer implements different functions respectively, has good portability and readability, and configures parameter data structure and sector data structure to achieve balanced erasure and power-off protection of Flash sectors, allows individual modification of erroneous parameters, and is not limited to storing only parameters of fixed length, so as to improve the flexibility and scalability of embedded device parameter storage and reduce resource usage.

[0037] Please refer to Figures 1 to 3 As shown, a preferred embodiment of a parameter storage method for an embedded device of the present invention comprises the following steps:

[0038] Step S10, setting a parameter management module including a Parameter layer, a KVDB layer, an ExtNVM layer and a Flash layer;

[0039] Step S20, configuring a parameter data structure and a sector data structure;

[0040] Step S30: the Parameter layer forwards the acquired parameter storage instruction to the KVDB layer;

[0041] Step S40: After receiving the parameter storage instruction, the KVDB layer verifies the storage space of the Flash sector based on the sector data structure, and forwards the parameter storage instruction to the ExtNVM layer;

[0042] Step S50: The ExtNVM layer stores the parameters in the corresponding Flash sector through the Flash layer based on the parameter data structure and the parameter storage instruction.

[0043] In the step S10, the Parameter layer depends on the KVDB layer, the KVDB layer depends on the ExtNVM layer, and the ExtNVM layer depends on the Flash layer. Each layer only completes a specific function and performs its own duties, thereby reducing the coupling between layers and improving the cohesion of the internal code of the layer.

[0044] In step S10, the Parameter layer is used to obtain the parameter storage instruction of the application layer; the KVDB layer is used to query, store, repair and recycle the parameters stored in the Flash sector in a key-value pair manner; the ExtNVM layer is used to provide a read interface, a write interface and an erase interface for the Flash sector; the Flash layer is used to provide a read interface and a write interface for the register level corresponding to the physical storage medium.

[0045] In the step S20, the parameter data structure includes parameter storage status, check value, parameter type, parameter number, parameter current value, parameter default value, parameter maximum value and parameter minimum value;

[0046] The parameter storage status is ready to write (0xFFFC), written (0xFFF0), ready to delete (0xFFC0) or deleted (0xFF00); the check value is the CRC16 calculation value of the parameter type, parameter number, parameter current value, parameter default value, parameter maximum value and parameter minimum value; the parameter type is INT8S, UINT8, INT16S, UINT16, INT32S or UINT32; the parameter number ranges from 0 to 65535.

[0047] In the step S20, the sector data structure includes a sector storage status, a dirty status and a version number;

[0048] The sector storage status is empty (0xFFFC), in use (0xFFF0) or full (0xFFC0); the dirty status is clean (0xFFFC), dirty (0xFFF0) or recycled (0xFFC0); the version number is used to identify the current version of the parameter management module. Clean means that parameters can be stored, dirty means that the parameters stored in the Flash sector have been modified, and recycled means that parameters cannot be stored. During the parameter storage process, the Flash sector with the sector storage status in use is used first, and the Flash sector with the sector storage status empty is used last.

[0049] The step S30 is specifically as follows:

[0050] After initializing the parameter management module, the Parameter layer continuously queries the application layer whether there is an input parameter storage instruction, and forwards the obtained parameter storage instruction to the KVDB layer.

[0051] The step S40 specifically includes:

[0052] Step S41, after receiving the parameter storage instruction, the KVDB layer verifies whether the storage space of the allocated Flash sector meets the storage capacity requirement based on the sector data structure. If so, the parameter storage instruction is forwarded to the ExtNVM layer and the process proceeds to step S50; if not, the process proceeds to step S42;

[0053] Step S42: Check the next Flash sector to determine whether the storage space meets the storage capacity requirement. If yes, forward the parameter storage instruction to the ExtNVM layer and proceed to step S50; if no, proceed to step S43;

[0054] Step S43, determine whether the verification of all Flash sectors is completed, if so, perform balanced erasing on the Flash sectors; if not, enter step S42.

[0055] In the step S43, the leveling erase is specifically to move the parameters stored in the Flash sectors whose sector storage status is full and whose dirty status is dirty to other Flash sectors.

[0056] Assume that sector1, sector2, sector3, and sector4 are four Flash sectors. Sector1 is full, and sector2 has insufficient remaining space to store parameters. Sector3 is full, and the sector storage status of sector4 is empty at this time. The remaining available Flash sectors are 1. If the parameters continue to be stored in sector4, sector recovery will not be possible, and a sector recovery request is triggered at this time.

[0057] Once a sector recycling request is triggered, the KVDB layer will find all Flash sectors whose sector storage status is full and dirty, and move their internal parameters to other locations, so that the Flash sector has no valid parameters, and change the sector storage status of the Flash sector to empty, so that there is an additional Flash sector in the empty state. Similarly, other Flash sectors that meet the recycling conditions will also erase the corresponding Flash sectors. Since each recycling will not only erase the same Flash sector, it will always poll among all Flash sectors, resulting in a more balanced erasure of each Flash sector, that is, balanced erasure.

[0058] The step S50 is specifically as follows:

[0059] Based on the parameter data structure and the parameter storage instruction, the ExtNVM layer stores the parameters carried by the parameter storage instruction to the corresponding Flash sector through the Flash layer, and updates the parameter data structure and the sector data structure; the parameters are stored in the form of key-value pairs.

[0060] That is, after querying the appropriate storage address (Flash sector), write the parameters (key-value pairs). The order of writing parameters is to first write the current parameters to the new address, and then modify its parameter storage status to be ready to write. If there are old parameters, modify the parameter storage status of the old parameters to be ready to delete. Next, modify the parameter storage status of the new parameters to have been written, and finally modify the parameter storage status of the old parameters to have been deleted.

[0061] After writing new parameters and modifying the parameter storage status of the old parameters, you also need to modify the sector storage status. If the current Flash sector is written for the first time, you need to change the sector storage status to in use; if the space of the current Flash sector is full and the new parameters cannot be written, you need to change the sector storage status to full; if the parameter storage status of the previous Flash sector has not been modified, you need to change the dirty status to clean; if the parameter storage status of the current Flash sector has been modified, you need to change the dirty status to dirty; if the current Flash sector needs to be recycled, you need to change the dirty status to recycled.

[0062] Since the characteristic of Flash is that it restores to FF value after erasing, writing can only modify binary bit 1 to 0, and cannot modify 0 to 1. Therefore, the core of being able to modify the parameter storage status of new parameters and old parameters lies in utilizing this characteristic of Flash to configure the parameter storage status: ready to write, written, ready to delete, deleted, and clear the corresponding 2 binary bits to zero each time switching to the next state. Because the parameter storage status cannot change from deleted to written (Flash cannot modify 0 to 1), writing the same-name parameter is written at the new address, and the old parameter is modified to be deleted.

[0063] The step S50 further includes: when a power failure occurs during the parameter storage process, after power is restored, the parameter storage is restored based on the parameter data structure, that is, a local repair can be performed when a parameter storage error occurs.

[0064] refer to Figure 3 , when power is lost in step 1, after power is restored, the parameter storage status of the new parameter is ready to be written, and the parameter storage status of the old parameter is written. You only need to change the parameter storage status of the new parameter to written, and change the parameter storage status of the old parameter to ready to be deleted and deleted in sequence to complete the recovery.

[0065] When power is lost in step 2, after power is restored, the parameter storage status of the new parameters is ready to be written, and the parameter storage status of the old parameters is ready to be deleted. You only need to change the parameter storage status of the new parameters to written and the parameter storage status of the old parameters to deleted to complete the recovery.

[0066] If power is lost in step 3 and power is restored, the parameter storage status of the new parameters is written, and the parameter storage status of the old parameters is ready to be deleted. You only need to change the parameter storage status of the old parameters to deleted to complete the recovery.

[0067] If power is lost in step 4, after power is restored, the parameter storage status of the new parameters is written, and the parameter storage status of the old parameters is deleted. This is a normal state and does not need to be modified.

[0068] In summary, the advantages of the present invention are:

[0069] 1. By configuring the parameter data structure, the parameter data structure is updated during the parameter storage process. When power failure occurs during the parameter storage process, the parameter storage can be restored based on the parameter data structure after power is restored. That is, power failure recovery is performed through the parameter storage state, without the need to discard the entire set of parameters and then restore the default parameters as traditionally done, thereby greatly improving the flexibility of embedded device parameter storage.

[0070] 2. By dividing the parameter management module into Parameter layer, KVDB layer, ExtNVM layer and Flash layer, each layer implements different functions, has good portability and readability, and is not limited to storing only parameters of fixed length, which ultimately greatly improves the scalability of embedded device parameter storage.

[0071] 3. Due to the storage mechanism of Flash, data can only be modified from 1 to 0, but not from 0 to 1. By configuring the parameter data structure and the sector data structure, the parameter storage state and the sector storage state are introduced to achieve balanced erasing and power-off protection of the Flash sector, which not only reduces resource usage, but also significantly improves the service life of the Flash.

[0072] Although the specific implementation modes of the present invention are described above, those skilled in the art should understand that the specific implementation modes described are only illustrative and are not intended to limit the scope of the present invention. Equivalent modifications and changes made by those skilled in the art in accordance with the spirit of the present invention should be included in the scope of protection of the claims of the present invention.

Claims

1. A parameter storage method for an embedded device, characterized in that: The steps include: Step S10, setting a parameter management module including a Parameter layer, a KVDB layer, an ExtNVM layer and a Flash layer; the Parameter layer depends on the KVDB layer, the KVDB layer depends on the ExtNVM layer, and the ExtNVM layer depends on the Flash layer; Step S20, configuring a parameter data structure and a sector data structure; the sector data structure includes a sector storage state, a dirty state and a version number; the sector storage state is empty, in use or full; the dirty state is clean, dirty or recycled; the version number is used to identify the current version of the parameter management module; Step S30: the Parameter layer forwards the acquired parameter storage instruction to the KVDB layer; Step S40: After receiving the parameter storage instruction, the KVDB layer verifies the storage space of the Flash sector based on the sector data structure, and forwards the parameter storage instruction to the ExtNVM layer; Step S50: the ExtNVM layer stores the parameters to the corresponding Flash sector through the Flash layer based on the parameter data structure and the parameter storage instruction; The step S40 specifically includes: Step S41, after receiving the parameter storage instruction, the KVDB layer verifies whether the storage space of the allocated Flash sector meets the storage capacity requirement based on the sector data structure. If so, the parameter storage instruction is forwarded to the ExtNVM layer and the process proceeds to step S50; if not, the process proceeds to step S42; Step S42: Check the next Flash sector to determine whether the storage space meets the storage capacity requirement. If yes, forward the parameter storage instruction to the ExtNVM layer and proceed to step S50; if no, proceed to step S43; Step S43, determine whether the verification of all Flash sectors is completed, if so, perform balanced erasing on the Flash sectors; if not, enter step S42.

2. A parameter storage method for an embedded device as claimed in claim 1, characterized in that: In step S10, the Parameter layer is used to obtain the parameter storage instruction of the application layer; the KVDB layer is used to query, store, repair and recycle the parameters stored in the Flash sector in the form of key-value pairs; the ExtNVM layer is used to provide a read interface, a write interface and an erase interface for the Flash sector; the Flash layer is used to provide a read interface and a write interface corresponding to the register level of the physical storage medium.

3. A parameter storage method for an embedded device as claimed in claim 1, characterized in that: In the step S20, the parameter data structure includes parameter storage status, check value, parameter type, parameter number, parameter current value, parameter default value, parameter maximum value and parameter minimum value; The parameter storage status is ready to write, written, ready to delete or deleted; the check value is the CRC16 calculation value of parameter type, parameter number, parameter current value, parameter default value, parameter maximum value and parameter minimum value; the parameter type is INT8S, UINT8, INT16S, UINT16, INT32S or UINT32; the parameter number ranges from 0 to 65535.

4. A parameter storage method for an embedded device as claimed in claim 1, characterized in that: The step S30 is specifically as follows: After initializing the parameter management module, the Parameter layer continuously queries the application layer whether there is an input parameter storage instruction, and forwards the obtained parameter storage instruction to the KVDB layer.

5. A parameter storage method for an embedded device as claimed in claim 1, characterized in that: In the step S43, the leveling erase is specifically to move the parameters stored in the Flash sectors whose sector storage status is full and whose dirty status is dirty to other Flash sectors.

6. A parameter storage method for an embedded device as claimed in claim 1, characterized in that: The step S50 is specifically as follows: Based on the parameter data structure and the parameter storage instruction, the ExtNVM layer stores the parameters carried by the parameter storage instruction to the corresponding Flash sector through the Flash layer, and updates the parameter data structure and the sector data structure; the parameters are stored in the form of key-value pairs.

7. A parameter storage method for an embedded device as claimed in claim 1, characterized in that: The step S50 further includes: when a power failure occurs during the parameter storage process, after power is restored, performing power failure recovery of parameter storage based on the parameter data structure.

Citation Information

Patent Citations

  • Access method of FLASH parameter of embedded system

    CN103336749A

  • Object-oriented kernel layer database

    CN113342908A