Data reading and writing and erasing method and device, intelligent device and storage medium

By reading historical status parameters from the starting address after the smart device is powered on and updating or erasing the status parameters when the device malfunctions, the problem of reduced lifespan of storage area and microprocessor caused by frequent data read and write is solved, and higher device reliability and storage efficiency are achieved.

CN117891403BActive Publication Date: 2026-08-04ANHUI MEIZHI COMPRESSOR CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
ANHUI MEIZHI COMPRESSOR CO LTD
Filing Date
2024-01-16
Publication Date
2026-08-04

AI Technical Summary

Technical Problem

In existing technologies, frequent data reading, writing, and erasing of smart devices lead to reduced storage utilization and microprocessor lifespan, and may even cause device malfunctions.

Method used

After the smart device is powered on, it reads data from the starting address of the status parameter storage area until it reads the historical status parameters. It updates the status parameters as needed, and when it detects that the device is not operating normally, it obtains the current status parameters, erases or stores the status parameters to optimize storage space usage.

Benefits of technology

This reduces the frequency of data read/write and erase operations, increases the lifespan of the microprocessor and the utilization rate of the status parameter storage area, reduces the probability of device malfunctions, and improves device reliability and storage efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117891403B_ABST
    Figure CN117891403B_ABST
Patent Text Reader

Abstract

The application discloses a data reading and writing and erasing method and device, a computing device and a storage medium, and belongs to the technical field of data processing. The method comprises the following steps: after the smart device is powered on, data is read from the starting storage address of the state parameter storage area until the historical state parameter is read; in the process in which the smart device operates according to the historical state parameter, if a state parameter updating instruction is received, the state parameter is updated; in the case that it is detected that the smart device cannot normally operate, the current state parameter of the smart device is acquired; if the current state parameter is different from the historical state parameter and the remaining capacity of the state parameter storage area is smaller than the data capacity of the current state parameter, the state parameter stored in the target storage area of the state parameter storage area is erased, and the current state parameter is stored from the starting storage address of the target storage area. In this way, the frequency of data reading and writing and erasing is reduced, and the service life of the microprocessor for storing data in the smart device is prolonged.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of data processing technology, and in particular to a data reading, writing and erasing method, apparatus, smart device and storage medium. Background Technology

[0002] With the continuous upgrading of microprocessor performance, smart devices are becoming increasingly functional, and the trends of digitalization and intelligence are becoming more and more obvious. In order to better suit consumers' usage habits, most smart devices now have a power-off memory function. The microprocessor in smart home appliances stores and remembers the user's personalized settings, performance parameters, operating status and other status parameters according to the user's usage habits. When the power is restored, the above status parameters are read, improving the user experience.

[0003] In related technologies, microprocessors are typically used to store code and state parameters. Each time the state parameters are updated, the entire state parameter storage area is erased. This means that the state parameter storage area is frequently read, written, and erased, which reduces the utilization rate of the storage area and the lifespan of the microprocessor, and may even cause the smart device to malfunction. Summary of the Invention

[0004] To address this, the present invention provides a data reading, writing, and erasing method, as well as a data reading, writing, and erasing device, an intelligent device, and a computer-readable storage medium, aiming to at least partially solve the technical problem in related technologies where frequent data reading and writing leads to reduced storage area utilization and microprocessor lifespan.

[0005] To achieve the above objectives, a first aspect of the present invention provides a data reading, writing, and erasing method, comprising: After the smart device is powered on, it starts reading data from the starting storage address of the status parameter storage area until the historical status parameters are read. If a status parameter update command is received while the smart device is operating according to historical status parameters, the status parameters will be updated. When a smart device is detected to be malfunctioning, its current status parameters are obtained. If the current state parameter is different from the historical state parameter, and the remaining capacity of the state parameter storage area is less than the data capacity of the current state parameter, erase the state parameter stored in the target storage area in the state parameter storage area, and start storing the current state parameter from the starting storage address of the target storage area.

[0006] According to one embodiment of the present invention, after the smart device is powered on, it reads data from the starting storage address of the state parameter storage area until historical state parameters are read, including: Read the status parameters stored at each memory address sequentially, starting from the initial memory address, until the default data is read; If the default data is not read at the starting storage address, determine the storage address preceding the storage address where the default data was read; The status parameters read from the previous storage address are determined to be historical status parameters.

[0007] According to one embodiment of the present invention, the method further includes sequentially reading the status parameters stored at each storage address starting from the starting storage address until the default data is read, and then: If the default data is read at the starting storage address, and the initialization state parameters are determined to be historical state parameters, the smart device will operate according to the initialization state parameters.

[0008] According to one embodiment of the present invention, before erasing the state parameters stored in the target storage area in the state parameter storage area, the method further includes: Obtain the minimum erase space capacity and erase efficiency; The target storage area is determined based on the data capacity, remaining capacity, minimum erase space capacity, and erase efficiency, wherein the capacity of the target storage area is greater than or equal to the data capacity.

[0009] According to one embodiment of the present invention, the method further includes: If the current state parameter is different from the historical state parameter, and the remaining capacity of the state parameter storage area is not less than the data capacity of the current state parameter, the current state parameter will be stored in the remaining storage area of ​​the state parameter storage area where no data has been stored.

[0010] According to one embodiment of the present invention, storing the current state parameter to the remaining storage area in the state parameter storage area where no data is stored includes: Determine the next storage address after the storage address where the historical status parameters were read; Store the current status parameters at the next storage address.

[0011] According to one embodiment of the present invention, the method further includes: Before using the state parameter storage area for the first time, erase all data in the state parameter storage area.

[0012] To achieve the above objectives, a second aspect of the present invention provides a data reading, writing, and erasing apparatus, comprising: The reading module is configured to read data from the starting storage address of the status parameter storage area after the smart device is powered on, until the historical status parameters are read. The update module is configured to update the status parameters if a status parameter update instruction is received while the smart device is running according to historical status parameters. The acquisition module is configured to acquire the current status parameters of the smart device when it is detected that the smart device is not functioning properly. The storage module is configured to erase the state parameters stored in the target storage area in the state parameter storage area when the current state parameters are different from the historical state parameters and the remaining capacity of the state parameter storage area is less than the data capacity of the current state parameters, and to store the current state parameters starting from the starting storage address of the target storage area.

[0013] To achieve the above objectives, a third aspect of the present invention provides an intelligent device, including: a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, it implements the data reading, writing, and erasing methods as described in any of the first aspects above.

[0014] To achieve the above objectives, a fourth aspect of the present invention provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the data reading, writing, and erasing methods as described in any of the first aspects above.

[0015] The data reading, writing, and erasing method provided in this embodiment of the invention reads data from the starting storage address of the status parameter storage area after the smart device is powered on, until historical status parameters are read. During the operation of the smart device according to the read historical status parameters, if a status parameter update instruction is received, the status parameters are updated. If the smart device is detected to be unable to operate normally, the current status parameters of the smart device are obtained. If the current status parameters are different from the historical status parameters and the remaining capacity of the status parameter storage area is less than the data capacity of the current status parameters, the status parameters of the target storage area in the status parameter storage area are erased, and the current status parameters are stored from the starting storage address of the target storage area. In the above method, the smart device reads data from the starting storage address after power-on, without hardware or software partitioning or setting index flags, reducing upfront operations. While the smart device updates its status parameters normally during operation, storing these parameters for each update would lead to excessively frequent data read / write operations, impacting the lifespan of the microprocessor storing the data and reducing the utilization rate of the status parameter storage area. Therefore, instead of storing status parameters with each update, the current status parameters are retrieved and prepared for storage when the smart device is detected to be malfunctioning. Furthermore, since the smart device may be reconfigured to match the previously stored status parameters when power is lost, storing the current status parameters only when they differ from historical parameters not only ensures timely memory of status parameters but also reduces the frequency of data read / write and erasure in the status parameter storage area. This improves the lifespan of the microprocessor, the utilization rate of the status parameter storage area, reduces the likelihood of device malfunctions, and enhances the reliability of the smart device. Furthermore, when the remaining capacity of the state parameter storage area is insufficient to store the current state parameters, the state parameters in a portion of the storage area are erased instead of the entire state parameter storage area is erased. Reducing the erasure area can improve data erasure efficiency, thereby improving data storage efficiency.

[0016] Additional aspects and advantages of the invention will be set forth in part in the description which follows, and in part will be obvious from the description, or may be learned by practice of the invention. Attached Figure Description

[0017] Figure 1 This is a flowchart of a data reading, writing, and erasing method provided according to an embodiment of the present invention; Figure 2 This is a schematic diagram of a storage area provided according to an embodiment of the present invention; Figure 3 This is a flowchart of another data reading, writing, and erasing method provided according to an embodiment of the present invention; Figure 4This is a schematic diagram of a data reading, writing, and erasing device according to an embodiment of the present invention; Figure 5 This is a structural schematic diagram of a smart device provided according to an embodiment of the present invention. Detailed Implementation

[0018] Embodiments of the present invention are described in detail below, examples of which are illustrated in the accompanying drawings, wherein the same or similar reference numerals denote the same or similar elements or elements having the same or similar functions throughout. The embodiments described below with reference to the accompanying drawings are exemplary and intended to explain the present invention, and should not be construed as limiting the present invention.

[0019] In related technologies, there are two main methods for storing key user parameters. The first method combines a microprocessor such as an MCU (Microcontroller Unit) with an external EEPROM (Electrically Erasable Programmable Read-Only Memory). The MCU and its internal FLASH memory store the main control program, while the external EEPROM is used for reading, writing, and storing key parameters. However, the external EEPROM not only occupies MCU pin resources but also increases the PCB (Process Control Block) size, resulting in higher costs and hindering product standardization. The second method divides a specified FLASH area into page and block sizes and determines the data read / write location by setting retrieval flags. This software algorithm is more complex. When dealing with large amounts of data, frequent read / write operations increase the microprocessor's load, especially in algorithms requiring fast response, such as motor drives. Frequent read / write operations can lead to program execution malfunctions, crashes, and abnormal shutdowns.

[0020] To address these issues, this invention provides a data reading, writing, and erasing method that solves the aforementioned technical problems. Specific implementation details can be found in the following descriptions of various embodiments.

[0021] The data reading, writing, and erasing methods, apparatuses, smart devices, and storage media provided in embodiments of the present invention are described below with reference to the accompanying drawings.

[0022] Figure 1 This is a flowchart of a data reading, writing, and erasing method provided according to an embodiment of the present invention, which may include the following steps.

[0023] Step 101: After the smart device is powered on, it reads data from the starting storage address of the status parameter storage area until the historical status parameters are read.

[0024] In this embodiment of the invention, the smart device can be any device capable of data storage. For example, a smart device can be a smart home appliance such as an air conditioner, washing machine, refrigerator, or television, or it can be a server, computer, or mobile phone. This embodiment of the invention does not limit the scope of the smart device. Furthermore, the smart device can include a microprocessor, which can be an MCU chip. The microprocessor includes a state parameter storage area for remembering the state parameters of the smart device, facilitating a quick restoration to the previous state after power-on. The microprocessor can also perform data reading, writing, and erasing, and can control the smart device to execute relevant instructions. The data reading, writing, and erasing methods provided in this embodiment of the invention can be applied to smart devices, specifically executed by the microprocessor within the smart device.

[0025] In practical implementation, a full-chip erase of the microprocessor can be performed during the initial code burning to ensure sufficient space for data. Specifically, the status parameter storage area can be completely erased before its first use. Furthermore, during the operation of the smart device, status parameters are generated based on its running state. To ensure that the device can be restored to its previous state each time it is used, these status parameters can be stored in the status parameter storage area when power is off.

[0026] According to one embodiment of the present invention, after the smart device is powered on, it reads data from the starting storage address of the status parameter storage area until historical status parameters are read. The specific implementation may include: reading the status parameters stored at each storage address sequentially from the starting storage address until the default data is read; if the default data is not read at the starting storage address, determining the previous storage address of the storage address where the default data is read; determining the status parameter read from the previous storage address as the historical status parameter.

[0027] In other words, after the smart device is powered on, data is read from the starting storage address of the status parameter storage area until a certain storage address is reached. When the default data is read, and this storage address is not the starting storage address, it means that the smart device has been used before. The status parameter storage area contains historical status parameters. According to the storage rules of status parameters (stored sequentially from the starting storage address to the last storage address, with the newer status parameters being closer to the last storage address), the historical status parameters are stored at the storage address preceding the address where the default data is located. Therefore, the status parameters read from the previous storage address are determined as historical status parameters.

[0028] The default data can be "F", "empty" or any preset data, and this embodiment does not limit it.

[0029] According to another embodiment of the present invention, if default data is read at the starting storage address, the initialization state parameter is determined to be a historical state parameter, and the smart device operates according to the initialization state parameter.

[0030] In other words, if the smart device reads the default data ("F" or "empty") from the starting storage address of the status parameter storage area after powering on, it is assumed that the smart device is powered on for the first time. The initialization status parameters can be set as historical status parameters, and the smart device will operate according to the initialization status parameters.

[0031] For example, Figure 2 This is a schematic diagram of a storage area provided according to an embodiment of the present invention. See also: Figure 2 The smart device can include a main program storage area, a free storage area, and a status parameter storage area. The main program storage area stores the main program, such as Code+Data. The free storage area is empty (Null). The status parameter storage area is divided into multiple storage blocks or slices, each with a capacity of N bytes, corresponding to a storage address. The starting storage address of the status parameter storage area is Add_Start, and the ending storage address is Add_End. Currently, the first storage address without stored data is Add_Null. After the smart device is powered on, it can start reading data from the starting storage address Add_Start of the status parameter storage area. The data read is sequentially called Status_Para_#1, Status_Para_#2, ..., Status_Para_#n, until the data read at storage address Add_Null is empty. Then it can be determined that the Status_Para_#n read from the storage address before Add_Null is a historical status parameter.

[0032] In this embodiment of the invention, data is read from the starting storage address until the historical state parameters are read, avoiding the need to divide the storage space (hardware partition or software partition) and add index tags. This not only saves storage space but also simplifies the implementation of the algorithm and improves the efficiency of data reading and writing.

[0033] Step 102: If a status parameter update instruction is received during the operation of the smart device according to the historical status parameters, the status parameters are updated.

[0034] In practical implementation, while the smart device is operating according to historical state parameters, the user may adjust the state parameters according to actual needs. The smart device will then receive a state parameter update command and update the state parameters accordingly, allowing it to operate under the updated state parameters. However, since the state parameters may be adjusted multiple times during operation, storing the state parameters in the state parameter storage area after each adjustment would increase the frequency of data read / write operations, reduce the utilization rate of the state parameter storage area, and affect the lifespan of the microprocessor. Therefore, although this solution performs state parameter updates or other related operations according to the state parameter update command, it does not immediately store the updated state parameters after each update; that is, it does not immediately perform data read / write operations in the state parameter storage area. This reduces the frequency of data read / write operations, improves the utilization rate of the state parameter storage area, and extends the lifespan of the microprocessor.

[0035] For example, suppose the smart device is an air conditioner. During the operation of the air conditioner, it receives a temperature adjustment command, which instructs the temperature to be adjusted to 25 degrees. The temperature can then be adjusted to 25 degrees and displayed on the display panel to inform the user that the temperature has been adjusted. Although these operations will be executed normally, the updated temperature of 25 degrees will not be stored in the status parameter storage area immediately.

[0036] In this embodiment of the invention, during normal operation of the smart device, the status parameters can be updated according to the status parameter update instruction, but the updated status parameters are not stored immediately. This reduces the frequency of data reading and writing, improves the utilization rate of the status parameter storage area and the lifespan of the microprocessor, and thus reduces the occurrence of abnormalities in the smart device.

[0037] Step 103: If the smart device is detected to be malfunctioning, obtain the current status parameters of the smart device.

[0038] During the operation of a smart device, if the system execution of the smart device becomes disordered, crashes, malfunctions, or even causes abnormal shutdown due to some reason, or if the smart device cannot be used normally due to a power outage, it can be considered that the smart device cannot operate normally. In this case, in order to quickly restore the smart device to the state before the power outage after the next power-on, it is necessary to store the current state parameters of the smart device. Therefore, the current state parameters of the smart device can be obtained.

[0039] For example, the current state parameter is the state parameter of the smart device at the current moment. If the state parameter is updated during operation, the current state parameter is the state parameter after the last state parameter update before the current moment. If the state parameter is not updated during operation, the current state parameter is the state parameter that has been used since the smart device was powered on and started running, that is, the historical state parameter.

[0040] Step 104: If the current state parameter is different from the historical state parameter and the remaining capacity of the state parameter storage area is less than the data capacity of the current state parameter, erase the state parameter stored in the target storage area in the state parameter storage area, and start storing the current state parameter from the starting storage address of the target storage area.

[0041] The target storage area is the free area in the erased state parameter storage area where no data is stored.

[0042] In this embodiment of the invention, if the status parameters are not modified during operation or are eventually modified to be the same as the historical status parameters, then the obtained current status parameters are the same as the historical status parameters. Storing them again would not only waste storage space but also increase the frequency of data read / write operations, affecting the lifespan of the status parameter storage area. Therefore, after obtaining the current status parameters, it is necessary to compare them with the historical status parameters. If they are the same, no data storage operation is performed; if they are different, the current status parameters are stored in the status parameter storage area, reducing the number of data read / write operations, i.e., the number of flash erase operations. Furthermore, if the remaining capacity of the status storage area is sufficient to store the current status parameters, the current status parameters can be stored directly. However, if the remaining capacity of the status storage area is insufficient to store the current status parameters, it is necessary to erase part of the storage area of ​​status parameters to clear usable space for the current status parameters.

[0043] In practice, if the current state parameter is different from the historical state parameter, it means that the current state parameter needs to be stored. In order to avoid the storage area being found to be insufficient when performing data storage operations, resulting in useless operations, the remaining capacity of the state parameter storage area and the data capacity of the current state parameter can be determined. The remaining capacity and the data capacity can be compared to determine whether the state parameter storage area is sufficient to store the current state parameter. This can avoid data storage failure and reduce useless operations and data loss.

[0044] As an example, the total capacity of the state parameter storage area and the capacity of the area corresponding to each storage address can be obtained. During the process of reading historical state parameters, it can be determined which storage addresses in the state parameter storage area have stored data, and then it can be determined which storage addresses have not stored data (i.e., the remaining storage area). Based on the capacity of the areas corresponding to these addresses (i.e. the remaining storage area), the remaining capacity of the state parameter storage area can be determined.

[0045] In practice, if the remaining capacity of the state parameter storage area is insufficient to store the current state parameter, some or all of the state parameters stored in the state parameter storage area are erased. This frees up a target storage area without stored data. The starting storage address of the target storage area is then determined, and the current state parameter is stored in the area corresponding to that starting storage address. Furthermore, when the remaining capacity is zero, the target storage area does not include any remaining storage areas in the state parameter storage area that did not store state parameters before erasure. When the remaining capacity is not zero, the target storage area may include any remaining storage areas in the state parameter storage area that did not store state parameters before erasure.

[0046] In some embodiments, the entire state parameter storage area can be used as the target storage area, all state parameters stored in the entire state parameter storage area can be erased, and the current state parameter can be stored in the area corresponding to the starting storage address of the state parameter storage area.

[0047] In other embodiments, a small region with a capacity equal to the difference between the data capacity and the remaining capacity can be divided in the state parameter storage area, and this small region can be merged with the remaining storage area to form the target storage area. Specifically, a small region with a capacity equal to the difference can be divided backward from the first storage address of the remaining storage area.

[0048] In some other embodiments, the space to be erased can be determined based on the minimum erase space capacity, the data capacity, and the remaining capacity. Then, a small region with a capacity equal to the space to be erased is divided forward from the first storage address of the remaining storage area, and this small region is merged with the remaining storage area to form the target storage area. Here, the minimum erase space capacity refers to the minimum storage space capacity that can be erased in a single data erase operation.

[0049] Specifically, the difference between the data capacity and the remaining capacity can be determined. If the minimum erase space capacity is less than the difference capacity, the difference capacity can be divided by the minimum erase space capacity, and the quotient can be rounded up to obtain a positive integer. The product of this positive integer and the minimum erase space capacity is determined as the space capacity to be erased. If the minimum erase space capacity is greater than or equal to the difference capacity, the minimum erase space capacity is determined as the space capacity to be erased.

[0050] In this embodiment of the invention, the state parameters in the state parameter storage area are only erased when the remaining capacity of the state parameter storage area is insufficient to store the current state parameter. This reduces the frequency of data erasure in the state parameter storage area and improves the lifespan of the state parameter storage area.

[0051] According to one embodiment of the present invention, the minimum erase space capacity and erase efficiency can be obtained, and the target storage area can be determined based on the data capacity, remaining capacity, minimum erase space capacity and erase efficiency.

[0052] Minimum erase space capacity refers to the minimum amount of storage space that can be erased in a single data erase operation, while erase efficiency refers to the time required to perform a single data erase operation.

[0053] In practice, the simplest way is to erase all state parameters in the entire state parameter storage area. However, if the amount of data is large, the erasure will be slow and may affect the efficiency of data storage. Therefore, the maximum number of times to perform the data erasure operation can be determined based on the minimum erasure space capacity and erasure efficiency. The erasure operation is performed within the maximum number of times, and it is ensured that the target storage area obtained after erasure is sufficient to store the current state parameters.

[0054] Furthermore, the maximum erase duration, the microprocessor's operating speed, and the maximum number of erases in the state parameter storage area can be obtained. These parameters can be combined to determine the target storage area, and it can be ensured that the capacity of the target storage area after erasure is greater than or equal to the data capacity of the current state parameters.

[0055] The maximum erase duration refers to the maximum time required for data erasure operations. Exceeding this duration may lead to data storage failure or affect data storage efficiency. The maximum erase duration can be set according to the performance of the microprocessor itself.

[0056] It should be noted that the target storage area can be determined in any way, based on the performance of the smart device, microprocessor, etc., the actual situation of the state parameter storage area, and the data capacity of the current state parameters. This embodiment of the invention does not limit the specific determination process; any method that ensures the target storage area has sufficient capacity to store the current state parameters is within the scope of protection of this invention. Furthermore, comprehensively considering various factors in determining the target storage area can improve the flexibility and accuracy of the determination.

[0057] For example, assuming the data capacity of the current state parameter is equal to the product of the minimum erase space capacity and the positive integer K1, and the remaining capacity is not zero, after performing K1 erase operations according to the minimum erase space capacity, the erased area is the area storing the current state parameter, and the erased area and the remaining storage area are merged as the target storage area. Let M_Null represent the capacity of the target storage area, M_Erase represent the minimum erase space capacity of the MCU, M_Para represent the capacity of the area storing the current state parameter, M_All represent the total capacity of the state parameter storage area, and Add_Start represent the starting storage address for storing the current state parameter. The relationship between these parameters can be expressed by the following formulas (1) and (2): M_Para=Max{M_Erase*K1}≤M_Null(1) Where K1 is a positive integer, the formula (1) indicates that the capacity of the area storing the current state parameters can be determined based on the data capacity of the current state parameters and the minimum erase space capacity, and the capacity of the area storing the current state parameters is less than the capacity of the target storage area in the state parameter storage area.

[0058] Add_Start≥(M_All-M_Erase*K1)(2) Formula (2) indicates that the starting storage address for storing the current state parameters is greater than or equal to the starting storage address of the target storage area.

[0059] The above embodiment describes the specific implementation of storing the current state parameter when the current state parameter is different from the historical state parameter and the capacity of the state parameter storage area is insufficient. The following describes the specific implementation of storing the current state parameter when the capacity of the state parameter storage area is sufficient.

[0060] According to one embodiment of the present invention, when the current state parameter is different from the historical state parameter and the remaining capacity of the state parameter storage area is not less than the data capacity of the current state parameter, the current state parameter is stored in the remaining storage area of ​​the state parameter storage area where no data is stored.

[0061] In other words, if the remaining capacity is greater than or equal to the data capacity, it means that the state parameter storage area is sufficient to store the current state parameter. Therefore, the current state parameter can be stored in the remaining storage area without erasing the state parameters already stored there. This allows for the storage of both current and historical state parameters, facilitating state queries.

[0062] In some embodiments, storing the current state parameter in the remaining storage area of ​​the state parameter storage area where no data is stored may include: determining the next storage address after the storage address of the historical state parameter has been read; and storing the current state parameter according to the next storage address.

[0063] In the specific implementation, the storage address for storing historical state parameters is the last storage address where state parameters are stored. Therefore, the next storage address is the first storage address where no state parameters are stored, which can be used as the starting storage address for the remaining storage area. The current state parameters can then be stored in the area corresponding to this starting storage address. In this way, state parameters are stored sequentially starting from the starting storage address, facilitating subsequent retrieval and management.

[0064] For example, see Figure 2 , Figure 2Add_Null is the starting storage address of the remaining storage area, and the current status parameters can be stored in the area corresponding to Add_Null.

[0065] In other embodiments, the current status parameters can be stored in the area corresponding to any storage address in the remaining storage area, and the correspondence between the storage address and the current status parameters can be recorded so that the smart device can read the current status parameters according to the correspondence after power-on.

[0066] In this embodiment of the invention, when the historical state parameters are different from the current state parameters and the state parameter storage area is sufficient to store the current state parameters, the current state parameters are stored according to the starting storage address of the remaining storage area. It is not necessary to erase the stored state parameters, which can retain more state parameters for subsequent querying or other processing.

[0067] According to one embodiment of the present invention, after storing the current state parameters in the state parameter storage area, the smart device will lose power due to power failure or malfunction. Then, after the smart device is powered on again, it can read data from the starting storage address until the current state parameters are read, and then operate according to the current state parameters.

[0068] In practice, before the smart device loses power, the current state parameters are stored in the state parameter storage area. After the smart device is powered on again, it can start reading the state parameters from the starting storage address of the state parameter storage area until the default data is read. The storage address above the storage address where the default data is read is determined, and the state parameters read from that storage address are used as the current state parameters stored at the time of the last power failure. The smart device then operates according to these current state parameters, enabling it to quickly restore to its previous state and improve the user experience.

[0069] For example, suppose the smart device is a refrigerator. A sudden power outage causes the refrigerator to stop operating. Before stopping, the current status parameters (such as temperature, light, mode, etc.) are stored in the status parameter storage area. After the refrigerator is powered on again, it can retrieve the temperature, light, mode, and other parameters from the status parameter storage area and quickly adjust the refrigerator's status according to these parameters, so that the refrigerator can quickly restore to the state before the power outage without the need for the user to make any further settings.

[0070] The data reading, writing, and erasing method provided in this invention reads data from the starting storage address after the smart device is powered on, without the need for hardware or software partitioning or setting index flags, reducing preliminary operations. Furthermore, while the smart device updates its status parameters normally during operation, storing these parameters for each update would lead to excessively frequent data reading and writing, affecting the lifespan of the microprocessor storing the data and reducing the utilization rate of the status parameter storage area. Therefore, instead of storing the status parameters with each update, the current status parameters are retrieved and prepared for storage when the smart device is detected to be malfunctioning. Moreover, since the smart device may be reconfigured to match the previously stored status parameters when powered off, storing the current status parameters only when they differ from historical parameters not only ensures timely memory of status parameters but also reduces the frequency of data reading, writing, and erasing in the status parameter storage area, improving the lifespan of the microprocessor and the utilization rate of the status parameter storage area, reducing the likelihood of smart device malfunctions, and enhancing the reliability of the smart device. Furthermore, when the remaining capacity of the state parameter storage area is insufficient to store the current state parameters, the state parameters in a portion of the storage area are erased instead of the entire state parameter storage area is erased. Reducing the erasure area can improve data erasure efficiency, thereby improving data storage efficiency.

[0071] Figure 3This is a flowchart of another data read / write and erase method provided by an embodiment of the present invention. After the smart device is powered on, it starts reading data, i.e., Data_Read, from the starting storage address Add_Start of the status parameter storage area. It is determined whether Data_Read is "F" (N bytes). If not, reading continues; if yes, the storage address Add_Null of the data "F" is recorded, and the historical status parameter stored at the previous storage address Add_Last of Add_Null is used as the current initialization status parameter. The smart device operates normally according to this historical status parameter. Alternatively, the storage address of the recorded data "F" can be set to occupy N bytes. Then, the address [Add_Null] minus [N bytes] (i.e., Add_Last) can be used as the storage address of the historical status parameter stored after the last exception, i.e., the storage address of the current initialization status parameter. The historical status parameter can then be read from this storage address. During operation, it is determined whether the smart device has an exception. If not, operation continues; if yes, it is determined whether the status parameter has been updated, i.e., whether the current status parameter is the same as the historical status parameter. If not, the process ends; if yes, it is determined whether the capacity of the status parameter storage area is insufficient. If yes, erase all status parameters stored at addresses Add_Start to Add_End, and start writing the current status parameters from Add_Start; otherwise, start writing the current status parameters from Add_Null.

[0072] The data reading, writing, and erasing method provided in this invention reads the status parameters from the starting storage address after the smart device is powered on, until the read data is empty or "F". This avoids dividing the storage space and adding index tags, saving storage space and simplifying the algorithm implementation. Furthermore, the status parameters are only stored when the smart device loses power or malfunctions, reducing the frequency of data reading and writing, reducing the number of FLASH erasures, reducing the MCU load rate, reducing the probability of system abnormalities caused by the main control program crashing, and improving the lifespan of the FLASH and the reliability of the system.

[0073] Figure 4 This is a schematic diagram of a data read / write and erase device according to an embodiment of the present invention. The device may include: The reading module 401 is configured to read data from the starting storage address of the status parameter storage area after the smart device is powered on, until the historical status parameters are read. The update module 402 is configured to update the status parameters if a status parameter update instruction is received during the operation of the smart device according to the historical status parameters. The acquisition module 403 is configured to acquire the current status parameters of the smart device when it is detected that the smart device is not operating normally; Storage module 404 is configured to erase the state parameters stored in the target storage area in the state parameter storage area when the current state parameter is different from the historical state parameter and the remaining capacity of the state parameter storage area is less than the data capacity of the current state parameter, and to store the current state parameter starting from the starting storage address of the target storage area.

[0074] According to one embodiment of the present invention, the reading module 401 is further configured to: Read the status parameters stored at each memory address sequentially, starting from the initial memory address, until the default data is read; If the default data is not read at the starting storage address, determine the storage address preceding the storage address where the default data was read; The status parameters read from the previous storage address are determined to be historical status parameters.

[0075] According to one embodiment of the present invention, the reading module 401 is further configured to: If the default data is read at the starting storage address, and the initialization state parameters are determined to be historical state parameters, the smart device will operate according to the initialization state parameters.

[0076] According to one embodiment of the present invention, the storage module 404 is further configured to: Obtain the minimum erase space capacity and erase efficiency; The target storage area is determined based on the data capacity, remaining capacity, minimum erase space capacity, and erase efficiency, wherein the capacity of the target storage area is greater than or equal to the data capacity.

[0077] According to one embodiment of the present invention, the storage module 404 is further configured to: If the current state parameter is different from the historical state parameter, and the remaining capacity of the state parameter storage area is not less than the data capacity of the current state parameter, the current state parameter will be stored in the remaining storage area of ​​the state parameter storage area where no data has been stored.

[0078] According to one embodiment of the present invention, the storage module 404 is further configured to: Determine the next storage address after the storage address where the historical status parameters were read; Store the current status parameters at the next storage address.

[0079] According to one embodiment of the present invention, the device further includes an erasing module configured to: Before using the state parameter storage area for the first time, erase all data in the state parameter storage area.

[0080] The data read / write and erase method provided in this invention allows the smart device to read data from the starting storage address after power-on, eliminating the need for hardware or software partitioning and index flag settings, thus reducing upfront operations. While the smart device updates its status parameters normally during operation, storing these parameters after each update would lead to excessively frequent data read / write operations, impacting the lifespan of the microprocessor storing the data and reducing the utilization rate of the status parameter storage area. Therefore, instead of storing status parameters with each update, the current status parameters are retrieved and prepared for storage when the smart device is detected to be malfunctioning. Furthermore, since the smart device may be reconfigured to match the previously stored status parameters after a power outage, storing the current status parameters only when they differ from historical parameters not only ensures timely memory of status parameters but also reduces the frequency of data read / write and erase operations in the status parameter storage area. This improves the lifespan of the microprocessor, the utilization rate of the status parameter storage area, reduces the likelihood of device malfunctions, and enhances the reliability of the smart device. Furthermore, when the remaining capacity of the state parameter storage area is insufficient to store the current state parameters, the state parameters in a portion of the storage area are erased instead of the entire state parameter storage area is erased. Reducing the erasure area can improve data erasure efficiency, thereby improving data storage efficiency.

[0081] The above is an illustrative scheme of a data read / write and erase device according to an embodiment of the present invention. It should be noted that the technical solution of this data read / write and erase device belongs to the same concept as the technical solution of the above-described data read / write and erase method. Details not described in detail in the technical solution of the data read / write and erase device can be found in the description of the technical solution of the above-described data read / write and erase method.

[0082] Figure 5 This is a schematic diagram of the structure of a smart device according to an embodiment of the present invention. The smart device 500 includes: a memory 501, a processor 502, and a computer program stored in the memory 501 and executable on the processor 502. When the processor 502 executes the computer program, it implements a data reading, writing, and erasing method as proposed in any of the above embodiments.

[0083] The present invention also provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements a data reading, writing, and erasing method as proposed in any of the above embodiments.

[0084] It should be noted that the logic and / or steps represented in the flowchart or otherwise described herein, for example, can be considered as a sequenced list of executable instructions for implementing logical functions, and can be embodied in any computer-readable medium for use by, or in conjunction with, an instruction execution system, apparatus, or device (such as a computer-based system, a processor-included system, or other system that can fetch and execute instructions from, an instruction execution system, apparatus, or device). For the purposes of this specification, "computer-readable medium" can be any means that can contain, store, communicate, propagate, or transmit programs for use by, or in conjunction with, an instruction execution system, apparatus, or device. More specific examples of computer-readable media (a non-exhaustive list) include: electrical connections (electronic devices) having one or more wires, portable computer disks (magnetic devices), random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), fiber optic devices, and portable optical disc read-only memory (CDROM). Additionally, computer-readable media can even be paper or other suitable media on which the program can be printed, as the program can be obtained electronically, for example, by optically scanning the paper or other medium, followed by editing, interpreting, or otherwise processing as necessary, and then stored in computer memory.

[0085] It should be understood that various parts of the present invention can be implemented in hardware, software, firmware, or a combination thereof. In the above embodiments, multiple steps or methods can be implemented in software or firmware stored in memory and executed by a suitable instruction execution system. For example, if implemented in hardware, as in another embodiment, it can be implemented using any one or a combination of the following techniques known in the art: discrete logic circuits having logic gates for implementing logical functions on data signals, application-specific integrated circuits (ASICs) having suitable combinational logic gates, programmable gate arrays (PGAs), field-programmable gate arrays (FPGAs), etc.

[0086] In the description of this specification, references to terms such as "one embodiment," "some embodiments," "example," "specific example," or "some examples," etc., indicate that a specific feature, structure, material, or characteristic described in connection with that embodiment or example is included in at least one embodiment or example of the invention. In this specification, the illustrative expressions of the above terms do not necessarily refer to the same embodiment or example. Furthermore, the specific features, structures, materials, or characteristics described may be combined in any suitable manner in one or more embodiments or examples.

[0087] Furthermore, the terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of technical features indicated. Thus, a feature defined as "first" or "second" may explicitly or implicitly include at least one of that feature. In the description of this invention, "a plurality of" means at least two, such as two, three, etc., unless otherwise explicitly specified.

[0088] In this invention, unless otherwise explicitly specified and limited, the terms "installation," "connection," "linking," and "fixing," etc., should be interpreted broadly. For example, they can refer to a fixed connection, a detachable connection, or an integral part; they can refer to a mechanical connection or an electrical connection; they can refer to a direct connection or an indirect connection through an intermediate medium; they can refer to the internal communication of two components or the interaction between two components, unless otherwise explicitly limited. Those skilled in the art can understand the specific meaning of the above terms in this invention according to the specific circumstances.

[0089] Although embodiments of the present invention have been shown and described above, it is understood that the above embodiments are exemplary and should not be construed as limiting the present invention. Those skilled in the art can make changes, modifications, substitutions and variations to the above embodiments within the scope of the present invention.

Claims

1. A data read / write and erase method, characterized by, The method includes: After the smart device is powered on, it reads data from the starting storage address of the status parameter storage area until it reads historical status parameters, which specifically include: Starting from the initial storage address, read the status parameters stored at each storage address sequentially until the default data is read; If the default data is not read at the starting storage address, determine the storage address preceding the storage address where the default data was read; The status parameter read from the previous storage address is determined to be the historical status parameter; If default data is read at the starting storage address, and the initialization state parameter is determined to be a historical state parameter, the smart device will operate according to the initialization state parameter. During the operation of the smart device according to the historical state parameters, if a state parameter update instruction is received, the state parameters are updated. If the smart device is detected to be malfunctioning, the current status parameters of the smart device are obtained; If the current state parameter is different from the historical state parameter and the remaining capacity of the state parameter storage area is less than the data capacity of the current state parameter, erase the state parameter stored in the target storage area in the state parameter storage area, and start storing the current state parameter from the starting storage address of the target storage area; Before erasing the state parameters stored in the target storage area from the state parameter storage area, the method further includes: Obtain the minimum erase space capacity and erase efficiency; The target storage area is determined based on the data capacity, the remaining capacity, the minimum erase space capacity, and the erase efficiency, wherein the capacity of the target storage area is greater than or equal to the data capacity.

2. The method of claim 1, wherein, The method further includes: If the current state parameter is different from the historical state parameter, and the remaining capacity of the state parameter storage area is not less than the data capacity of the current state parameter, the current state parameter is stored in the remaining storage area of ​​the state parameter storage area where no data is stored.

3. The method of claim 2, wherein, The step of storing the current state parameter to the remaining storage area in the state parameter storage area where no data is stored includes: Determine the next storage address after the storage address where the historical state parameter was read; The current state parameters are stored at the next storage address.

4. The method according to any one of claims 1 to 3, characterized in that, The method further includes: Before using the state parameter storage area for the first time, the entire state parameter storage area is erased.

5. A data read / write and erase apparatus, characterized by, To implement the data read / write and erase method as described in any one of claims 1-4, the apparatus comprises: The reading module is configured to read data from the starting storage address of the status parameter storage area after the smart device is powered on, until the historical status parameters are read. The update module is configured to update the status parameters if a status parameter update instruction is received during the operation of the smart device according to the historical status parameters. The acquisition module is configured to acquire the current status parameters of the smart device when it is detected that the smart device is not operating normally; The storage module is configured to erase the state parameters stored in the target storage area in the state parameter storage area when the current state parameters are different from the historical state parameters and the remaining capacity of the state parameter storage area is less than the data capacity of the current state parameters, and to store the current state parameters starting from the starting storage address of the target storage area.

6. A smart device, comprising: include: A memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor, when executing the computer program, implements the data read / write and erase method as described in any one of claims 1-4.

7. A computer-readable storage medium having stored thereon a computer program, characterized in that When the program is executed by the processor, it implements the data read / write and erase methods as described in any one of claims 1-4.