A data processing method and related apparatus

By calculating the checksum of the program segment in the IoT device and marking the working area and backup area, the problem of long checksum processing time under frequent power outages is solved, and the real-time response performance of the terminal and power saving are achieved.

CN114253758BActive Publication Date: 2026-01-27HUAWEI TECH CO LTD
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202010997523.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-09-21
Publication Date
2026-01-27
Estimated Expiration
2040-09-21

AI Technical Summary

Technical Problem

In existing technologies, IoT devices take a long time to calculate the checksum of volatile memory under frequent power outages, resulting in a high warning voltage threshold setting and affecting the real-time response performance of the device.

Method used

After the program segment is executed in the terminal, the checksum of the address range used by the program segment is calculated, and the total checksum is determined based on the checksum of the program segment and the checksums of other address ranges. This reduces the energy consumption and time of checksum calculation. By marking the interchange between the working range and the backup range, the correctness of the data backup is ensured.

Benefits of technology

It effectively reduces the energy consumption and time of checksum calculation, extends the effective operating time of the terminal, ensures real-time response performance, and avoids the overhead of frequent data verification.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114253758B_ABST
    Figure CN114253758B_ABST
Patent Text Reader

Abstract

The application discloses a data processing method applied to an intermittently working terminal, and comprises the following steps: executing a first program segment; calculating a first check code corresponding to a first address interval, wherein the first address interval is an address interval used when the first program segment is executed; acquiring a second check code corresponding to a second address interval, wherein the second address interval is an address interval except the first address interval in a third address interval, and the third address interval is an address interval used when a program to which the first program segment belongs is executed; determining a third check code according to the first check code and the second check code, and storing the third check code in a non-volatile memory, so as to check data in a volatile memory after power supply is restored. According to the scheme, the calculation of the check code does not need to be performed on the whole address interval of the saved data, the energy consumption and time for calculating the check code can be reduced, the terminal can continuously operate, and the real-time response performance of the terminal is ensured.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of computer technology, and in particular to a data processing method and related apparatus. Background Technology

[0002] With the development of IoT technology, more and more IoT devices are being driven by energy harvesting and operate on an intermittent basis. During operation, IoT devices need to frequently back up their operating state on non-volatile memory (NVM) so that they can resume operation based on the backed-up state after a power outage and subsequent restoration of power.

[0003] Currently, to avoid frequent backups of the operating state, related technologies use volatile memory to store data, so that the operating state is not backed up by the NVM during brief power outages. Specifically, by setting a warning voltage threshold, when the voltage of the IoT device falls below the warning voltage threshold, all data in the volatile memory is verified, and the resulting checksum is stored in the NVM. The IoT device then stops operating. After power is restored, the data in the volatile memory is verified based on the checksum in the NVM to determine if any errors have occurred.

[0004] However, since calculating the checksum of all data in the volatile memory takes a long time, in order to ensure that the checksum can be successfully calculated and stored in the NVM, the warning voltage threshold is usually set to a high voltage value. This can easily cause IoT devices to stop operating when there is still a lot of power left, affecting the real-time response performance of IoT devices. Summary of the Invention

[0005] This application provides a data processing method and related apparatus. During the operation of a terminal, after the terminal executes a program segment, it calculates the checksum of the address range used by the program segment. Based on the checksum and the checksums of other address ranges in the address range used by the entire program, it determines the total checksum of the address range used by the program. This eliminates the need to calculate the checksum for the entire address range where the data is stored, thereby reducing the energy consumption and time required to calculate the checksum, enabling the terminal to run continuously and ensuring the real-time response performance of the terminal.

[0006] This application provides a data processing method for a terminal that operates intermittently, i.e., a terminal that operates intermittently under frequent power outages. The method may include: the terminal executing a first program segment, which may be one of multiple program segments in an application. During the execution of the first program segment, the terminal needs to use and modify data in a first address range. After executing the first program segment, the terminal calculates a first checksum corresponding to the first address range, for example, by calculating the first checksum based on a Cyclic Redundancy Check (CRC) operation. The terminal obtains a second checksum corresponding to a second address range, which is an address range other than the first address range in a third address range. This third address range is the address range used when executing the program to which the first program segment belongs. The second checksum may be calculated when the terminal executes other program segments. Since the third address range is composed of the first and second address ranges, the terminal can determine the third checksum corresponding to the third address range based on the first and second checksums. The terminal stores the third check code in non-volatile memory. This third check code is used to verify the correctness of the data in volatile memory after the terminal restores power. The third address range is located in volatile memory.

[0007] In this solution, after executing a program segment, the terminal calculates the checksum of the address range used by that program segment. Based on this checksum and the checksums of other address ranges within the entire address range used by the program, the total checksum of the address range used by the program can be determined. The terminal no longer needs to calculate the checksum for the entire address range where the data is stored, thus reducing the energy consumption and time required for checksum calculation. This allows the terminal to operate continuously and ensures its real-time response performance.

[0008] In some possible implementations, the volatile memory may further include a fourth address range. The data stored in this fourth address range is the same as the data stored in the third address range before the execution of the first program segment; that is, the fourth address range is used to back up the data in the third address range. The third address range is marked as the working range, and the fourth address range is marked as the backup range. The working range is the range used during program execution, and the backup range is used to back up the data in the working range.

[0009] In other words, before executing the first program segment, the terminal can copy data from the third address range to the third address range to ensure that the data in the third address range (which serves as the working range) is identical to the data in the fourth address range (which serves as the backup range), thus achieving data backup in the working range. Therefore, if a power outage occurs during the execution of the first program segment, the terminal can copy the data from the backup range to the working range after power is restored to restore the data in the working range.

[0010] In some possible implementations, the terminal obtains the second check code corresponding to the second address range, including: the terminal calculates the fourth check code of the address range in the fourth address range that corresponds to the first address range; the terminal determines the second check code based on the check code corresponding to the fourth address range and the fourth check code.

[0011] In simple terms, after the first program segment completes execution, because the data in the first address interval of the third address interval has changed, the address intervals in the fourth address interval that are different from the data in the third address interval are the address intervals corresponding to the first address interval. The other address intervals in the fourth address interval are actually the same as the data in the second address interval of the third address interval. Thus, the terminal can calculate the checksum of the address interval in the fourth address interval that corresponds to the first address interval, and based on the zero-padding property of the checksum operation and the checksum of the fourth address interval, determine the checksums of the other address intervals in the fourth address interval, i.e., the second checksum corresponding to the second address interval.

[0012] In this scheme, by calculating the second check code corresponding to the second address interval in the working interval based on the data in the backup interval, the time and energy consumed by CRC operation can be effectively reduced when the first address interval is small. This improves the efficiency of the terminal in calculating the check code after executing the program segment, thereby saving the terminal's power and extending the effective operating time of the terminal.

[0013] In some possible implementations, after the first program segment has been executed, the method further includes: the terminal marking the fourth address range as the working range and the third address range as the backup range; and the terminal copying the data from the third address range to the fourth address range.

[0014] In this solution, after the program segment is executed, the working range and backup range are quickly swapped by changing the address range markers. This can effectively prevent data errors caused by power outages during data copying.

[0015] In some possible implementations, the method further includes: the terminal storing a first checksum and a second checksum in volatile memory; the first and second checksums are used to compare with a third checksum after power is restored to verify the correctness of the data in the volatile memory. That is, after power is restored, a new checksum can be calculated directly based on the first and second checksums in the volatile memory, and this new checksum can be compared with the third checksum stored in the NVM to verify whether any errors occurred in the data in the volatile memory during the power outage.

[0016] In this solution, the correctness of the data in the volatile memory is verified by storing the first and second check codes in the volatile memory. This eliminates the need to recalculate the check codes in the volatile memory, saving the terminal time in verifying the correctness of the data and extending the effective operating time of the terminal.

[0017] In some possible implementations, the method further includes: after power is restored, the terminal obtains the duration of the power outage; if the power outage duration is less than a first duration, the data in the volatile memory is determined to be correct; if the power outage duration is greater than the first duration but less than a second duration, the correctness of the data in the volatile memory needs to be verified; if the power outage duration is greater than the second duration, the data in the volatile memory is determined to be incorrect. Here, the first duration indicates that the power outage time is short enough that the data in the volatile memory is guaranteed not to be erroneous; therefore, when the power outage duration is less than the first duration, the terminal can skip the data verification step. Similarly, the second duration indicates that the power outage time is long enough that the data in the volatile memory has definitely become erroneous.

[0018] In this solution, by setting a first duration and a second duration, the terminal can decide whether to perform data verification based on the actual power outage duration, avoiding data verification every time power is restored, saving the terminal's data verification time, and extending the terminal's effective operating time.

[0019] In some possible implementations, before the terminal executes the first program segment, the method further includes: executing one or more second program segments based on the terminal's voltage being higher than a threshold voltage. The second program segment can refer to any other program segment within the program to which the first program segment belongs, and this program may include one or more second program segments. The terminal marks the address range used when executing the one or more second program segments. Based on the current voltage being lower than the threshold voltage, the terminal calculates the checksum corresponding to the marked address range.

[0020] In other words, when the terminal is at a high battery level, it only marks the modified address range after executing the program segment; when the terminal is at a low battery level, it then performs checksum calculation on all marked address ranges to minimize the number of checksum calculations.

[0021] In some possible implementations, before the terminal executes the first program segment, the method further includes: the terminal determining a first address range corresponding to the first program segment; the terminal obtaining a checksum corresponding to the first address range, the checksum being stored in volatile memory; the terminal determining that the data in the first address range is correct based on the checksum; and based on the correctness of the data in the first address range, the terminal determining that the first program segment can be executed.

[0022] In this scheme, based on the characteristic that the data in the volatile memory changes randomly, and assuming that the check code is correct, the correctness of the data to be used by the program segment can be determined based on the check code, which can further ensure the correctness of the data and guarantee the normal operation of the terminal.

[0023] In some possible implementations, the method also includes: the terminal periodically storing data from volatile memory to non-volatile memory, thereby periodically backing up test points in non-volatile memory. This way, if the terminal determines that the data verification in volatile memory is incorrect after power is restored, it can restore to the most recent test point stored in NVM, avoiding the terminal frequently re-executing the program.

[0024] A second aspect of this application provides a terminal, comprising: a processing unit and an acquisition unit; the processing unit is configured to execute a first program segment; the processing unit is further configured to calculate a first checksum corresponding to a first address range, the first address range being the address range used when executing the first program segment; the acquisition unit is configured to acquire a second checksum corresponding to a second address range, the second address range being an address range other than the first address range in a third address range, the third address range being the address range used when executing the program to which the first program segment belongs; the processing unit is further configured to determine a third checksum based on the first checksum and the second checksum, the third checksum being the checksum corresponding to the third address range; the processing unit is further configured to store the third checksum in a non-volatile memory, the third checksum being used to verify the correctness of data in the volatile memory after the terminal is powered back on, the third address range being located in the volatile memory.

[0025] In some possible implementations, the volatile memory also includes a fourth address range, the data of which is the same as the data stored in the third address range before the execution of the first program segment; wherein the third address range is marked as the working range and the fourth address range is marked as the backup range, the working range is the range used during program execution, and the backup range is used to back up the data in the working range.

[0026] In some possible implementations, the processing unit is specifically used to: calculate the fourth check code of the address interval corresponding to the first address interval in the fourth address interval; and determine the second check code based on the check code corresponding to the fourth address interval and the fourth check code.

[0027] In some possible implementations, the processing unit is also used to: mark the fourth address range as the working range and the third address range as the backup range; and copy the data in the third address range to the fourth address range.

[0028] In some possible implementations, the processing unit is further configured to: store the first check code and the second check code in a volatile memory, and use the first check code and the second check code to compare with the third check code after the terminal restores power, so as to verify the correctness of the data in the volatile memory.

[0029] In some possible implementations, the processing unit is further configured to: after the terminal restores power, obtain the duration of the power outage; if the power outage duration is less than a first duration, determine that the data in the volatile memory is correct; if the power outage duration is greater than the first duration and less than a second duration, determine that the correctness of the data in the volatile memory needs to be verified; if the power outage duration is greater than the second duration, determine that the data in the volatile memory is incorrect; wherein the first duration is less than the second duration.

[0030] In some possible implementations, the processing unit is also configured to: execute one or more second program segments based on the terminal voltage being higher than a threshold voltage; mark the address range used when executing one or more second program segments; and calculate the checksum corresponding to the marked address range based on the terminal voltage being lower than a threshold voltage.

[0031] In some possible implementations, the processing unit is further configured to: determine the first address range corresponding to the first program segment; obtain the check code corresponding to the first address range, the check code corresponding to the first address range being stored in volatile memory; determine that the data in the first address range is correct based on the check code corresponding to the first address range; and determine to execute the first program segment based on the correctness of the data in the first address range.

[0032] In some possible implementations, the processing unit is also used to periodically store data in volatile memory to non-volatile memory.

[0033] A third aspect of this application provides a terminal comprising: a processor, a non-volatile memory, and a volatile memory; wherein the non-volatile memory or the volatile memory stores computer-readable instructions; the processor reads the computer-readable instructions to enable the terminal to implement the method as described in any implementation of the first aspect.

[0034] A fourth aspect of this application provides a computer-readable storage medium storing a computer program that, when run on a computer, causes the computer to perform the method as described in any implementation of the first aspect.

[0035] The fifth aspect of this application provides a computer program product that, when run on a computer, causes the computer to perform the method described in any implementation of the first aspect.

[0036] A sixth aspect of this application provides a chip including one or more processors. Part or all of the processors are used to read and execute a computer program stored in a memory to perform the methods in any possible implementation of any of the above aspects. Optionally, the chip includes a memory, which is connected to the processor via a circuit or wire. Further optionally, the chip also includes a communication interface, to which the processor is connected. The communication interface is used to receive data and / or information to be processed, the processor obtains the data and / or information from the communication interface, processes the data and / or information, and outputs the processing result through the communication interface. The communication interface can be an input / output interface. The methods provided in this application can be implemented by a single chip or by multiple chips working together. Attached Figure Description

[0037] Figure 1 A schematic diagram illustrating the backup operation status of an IoT device provided in an embodiment of this application;

[0038] Figure 2 A flowchart illustrating a data processing method provided in an embodiment of this application;

[0039] Figure 3 A schematic diagram illustrating the distribution of address ranges provided in an embodiment of this application;

[0040] Figure 4 A schematic diagram illustrating another address range distribution provided in an embodiment of this application;

[0041] Figure 5 A comparative schematic diagram of the operation of a terminal provided in an embodiment of this application;

[0042] Figure 6a This application provides a schematic diagram of the structure of a circuit for determining the duration of a power outage.

[0043] Figure 6b A schematic diagram of voltage change curves for a time-holding circuit provided in an embodiment of this application;

[0044] Figure 7 A flowchart illustrating an executable program segment provided in an embodiment of this application;

[0045] Figure 8 A schematic diagram illustrating the calculation of a checksum provided in an embodiment of this application;

[0046] Figure 9 A schematic diagram of a terminal operation process provided in an embodiment of this application;

[0047] Figure 10a A schematic diagram illustrating the relationship between a program segment and an address range provided in an embodiment of this application;

[0048] Figure 10b A flowchart illustrating the execution of a program segment by a terminal under low power conditions, provided as an embodiment of this application;

[0049] Figure 11 This application provides a schematic diagram of a terminal operating after power restoration.

[0050] Figure 12 This is a schematic diagram of the structure of a terminal 1200 provided in an embodiment of this application;

[0051] Figure 13 This is a schematic diagram of the structure of a terminal 100 provided in an embodiment of this application. Detailed Implementation

[0052] The embodiments of this application are described below with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of this application, and not all of them. As those skilled in the art will recognize, with the development of technology and the emergence of new scenarios, the technical solutions provided by the embodiments of this application are also applicable to similar technical problems.

[0053] The terms "first," "second," etc., used in the specification, claims, and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments described herein can be implemented in a sequence other than that illustrated or described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion; for example, a process, method, system, product, or device that includes a series of steps or modules is not necessarily limited to those explicitly listed, but may include other steps or modules not explicitly listed or inherent to such processes, methods, products, or devices. The naming or numbering of steps appearing in this application does not imply that the steps in the method flow must be performed in the chronological / logical order indicated by the naming or numbering. The execution order of named or numbered process steps can be changed according to the desired technical purpose, as long as the same or similar technical effect is achieved.

[0054] With the development of IoT technology and the widespread adoption of IoT devices, the number of deployed IoT devices is constantly increasing. Faced with this massive population of IoT devices, traditional battery power is no longer suitable. Specifically, traditional battery power is not environmentally friendly; equipping each IoT device with a battery generates a significant amount of electronic waste. Furthermore, battery-powered IoT devices are difficult to maintain, and charging or replacing batteries is challenging in harsh deployment environments.

[0055] Therefore, given the limitations of battery power, a new power supply method has emerged. By configuring energy harvesting devices on IoT devices, these devices can harvest energy from their operating environment to generate power, such as light, radio frequency, pressure, or heat, and convert this energy into electrical energy. Using energy harvesting to power IoT devices offers high deployment flexibility, reduces limitations on usage scenarios, and provides strong robustness.

[0056] When using energy harvesting to power IoT devices, the unpredictable and unstable nature of external energy sources can lead to frequent power outages, making it difficult for the programs within the IoT devices to complete a full execution within a single power cycle. To enable programs to continue executing during frequent power outages, intermittent computing has been proposed and applied to IoT devices.

[0057] To ensure that IoT devices can continue to execute programs even with frequent power outages, IoT devices need to frequently back up their running state on the NVM during operation. This involves backing up register values ​​and variables used during program execution to the NVM so that the device can resume operation based on the backed-up running state after a power outage and subsequent power restoration.

[0058] For example, see Figure 1 , Figure 1 This is a schematic diagram illustrating the backup operation state of an IoT device, provided as an embodiment of this application. Figure 1 As shown, the program execution flow is to execute program segments 1 to 4 sequentially. Before each program segment begins execution, the current running state is backed up to the NVM. If a power outage occurs during the execution of any program segment, after the IoT device is powered back up, the running state backed up at the nearest detection point is retrieved from the NVM, thereby resuming program execution and ensuring the continuous operation of the IoT device under frequent power outages.

[0059] Because NVM has slow write speeds and a limited write lifespan, frequently backing up the running state to NVM will rapidly reduce its lifespan, ultimately rendering IoT devices unusable. Therefore, to avoid frequent backups of the running state, related technologies use volatile memory to store data, so that NVM backups are not performed during brief power outages.

[0060] Volatile memories, such as SRAM, offer faster read / write speeds, lower power consumption, and longer lifespan compared to NVM, and also possess data retention properties. When the processor's supply voltage drops below a certain threshold (typically 1.8V), the processor will stop working, but the SRAM will still retain the stored data without errors; as the supply voltage continues to decrease, when the SRAM's supply voltage falls below an even lower threshold (typically 0.4V), the data in the SRAM will gradually become corrupted.

[0061] Since IoT devices typically experience relatively short power outages, the data retention properties of SRAM can be leveraged to avoid backing up the state to NVM during brief power outages, thereby reducing system state backup overhead. However, because the duration for which SRAM retains data without errors is uncertain, it is necessary to check for data corruption in the SRAM after power is restored.

[0062] In related technologies, by setting a warning voltage threshold, when the voltage of an IoT device falls below the warning voltage threshold, all data in the SRAM is verified, and the resulting checksum is stored in the NVM. The IoT device then stops operating. After power is restored, all data in the SRAM is verified again, and the resulting checksum is compared with the checksum stored in the NVM. If the two checksums match, it is assumed that no errors occurred in the data in the SRAM during the power outage, and program execution resumes from the interrupt point. If the two checksums do not match, it is assumed that an error occurred in the data in the SRAM during the power outage, and program execution needs to restart.

[0063] However, since calculating the checksum of all the data in SRAM takes a long time, in order to ensure that the checksum can be successfully calculated and stored in non-volatile memory, the warning voltage threshold is usually set to a high voltage value in related technologies. This can easily cause IoT devices to stop operating when there is still a lot of power left, affecting the real-time response performance of IoT devices.

[0064] In view of this, the present application provides a data processing method. During the operation of the terminal, after the terminal executes a program segment, it calculates the checksum of the address range used by the program segment, and based on the checksum and the checksums of other address ranges in the address range used by the entire program, it determines the total checksum of the data in the volatile memory. This eliminates the need to calculate the checksum for the entire address range where the data is stored, thereby reducing the energy consumption and time of calculating the checksum, enabling the terminal to run continuously and ensuring the real-time response performance of the terminal.

[0065] For ease of understanding, the following will provide a detailed description of some technical terms involved in the embodiments of this application.

[0066] Verification: Perform verification operations on the target data, such as Cyclic Redundancy Check (CRC) operations, to obtain the checksum of the data.

[0067] Verification: The process of performing a verification operation on the target data, comparing the new verification code with the verification code obtained from the previous verification operation on the target data, to determine whether the target data has changed.

[0068] XOR operation A logical operation. If the values ​​a and b are different, the XOR operation between a and b will result in 1. If the values ​​a and b are the same, the XOR operation between a and b will result in 0. In binary arithmetic,

[0069] CRC: A channel coding technique that generates a fixed-length checksum based on data such as network packets or computer files. It is primarily used to detect errors that may occur during data transmission or storage. CRC possesses mathematical properties such as linear additivity and zero-padding.

[0070] The linear additivity of CRC can be expressed as shown in Equation 1:

[0071]

[0072] Here, A and B are two independent data. The linear additivity of CRC means that the CRC result after performing an XOR operation on A and B is equal to the result after performing CRC operations on A and B separately and then performing an XOR operation on them.

[0073] The zero-padding property of CRC can be represented by Equation 2:

[0074]

[0075] Here, A0...0 represents adding n zeros after data A, that is, shifting data A left by n bits. The zero-padding property of CRC means that the CRC result of a data left-shifted by n bits can be directly obtained by multiplying it by a certain coefficient, without having to recalculate the CRC of the entire data.

[0076] The terminal involved in the following embodiments of this application refers to a device that has an application program installed and can work intermittently, such as an Internet of Things (IoT) device. This terminal may be equipped with an energy harvesting device capable of harvesting energy from the operating environment to power the terminal, such as harvesting light energy, radio frequency energy, pressure, or heat energy and converting this energy into electrical energy to power the terminal's intermittent operation. For example, the terminal may refer to an access device in the Internet of Things with sensor detection or intelligent functions, which can be applied in outdoor, warehouse, or indoor environments, such as monitoring devices supporting temperature detection (fire prevention equipment), light detection equipment, humidity detection equipment, etc., and smart home devices such as smart switches, smart cameras, smart water meters, and smart appliances.

[0077] Please refer to Figure 2 , Figure 2 This is a flowchart illustrating a data processing method provided in an embodiment of this application. Figure 2 As shown in the figure, this application provides a data processing method, which is applied to a terminal that works intermittently, and the method may include the following steps.

[0078] Step 201: The terminal executes the first program segment.

[0079] In this embodiment, one or more applications may be installed on the terminal, and each application may include multiple program segments. For each application, there is its corresponding application code, and the terminal executes the application code to run the application.

[0080] An application's code can be divided into multiple non-overlapping sub-code segments, also known as program segments or atomic execution blocks (AEBs). Methods for dividing application code into multiple program segments include, but are not limited to, the following: obtaining multiple detection points in the application code based on static analysis techniques, and dividing the application code according to these detection points, where the code segment between two adjacent detection points constitutes a program segment; or, when the application code is written based on a task model, one application code can correspond to multiple tasks, and each program segment in the application code is a sub-code segment corresponding to each task.

[0081] Multiple program segments, separated from a single application code, have a fixed execution order. During operation, the terminal can execute these program segments sequentially according to their execution order. The first program segment mentioned above can be the program segment currently being executed by the terminal.

[0082] Step 202: The terminal calculates the first check code corresponding to the first address range, which is the address range used when executing the first program segment.

[0083] It should be understood that during the execution of a program segment by the terminal, it needs to access and modify data in memory in order to execute the program segment. For a program segment, the data that the terminal needs to access is usually located in a fixed address range in memory. By accessing this address range, the terminal can obtain and modify the data in that address range. This address range can be called the address range used by the terminal when executing the program segment.

[0084] Typically, for the same program segment, the address range used by the terminal when executing that program segment is fixed. The terminal can determine the address range used for each program segment during execution. For example, if the program developer pre-specifies the address range corresponding to the program segment, or if the address range corresponding to each program segment is captured by analysis tools in related technologies, the terminal can determine the address range used when executing each program segment based on the mapping relationship between program segments and address ranges.

[0085] In this embodiment, the terminal can determine the first address range used when executing the first program segment, and calculate the first checksum corresponding to the first address range after the terminal finishes executing the first program segment. For example, the terminal can calculate the checksum corresponding to the data in the first address range using CRC operations to obtain the first checksum. The terminal can also calculate the first checksum using other checksum calculation methods, as long as the checksum calculation method possesses the aforementioned linear additivity and zero-padding properties. This embodiment does not specifically limit the method by which the terminal calculates the checksum. For ease of description, the following embodiment will be described using the method of obtaining the checksum based on CRC operations as an example.

[0086] Step 203: The terminal obtains the second check code corresponding to the second address range. The second address range is the address range other than the first address range in the third address range. The third address range is the address range used when executing the program to which the first program segment belongs.

[0087] It should be understood that since each program segment in the terminal has a fixed corresponding address range, the multiple address ranges corresponding to all program segments in the same program can constitute the address range corresponding to that program.

[0088] For example, program A includes program segments A1, A2, and A3, which correspond to address ranges 1, 2, and 3, respectively. Therefore, address range 4, formed by address ranges 1, 2, and 3, is the address range corresponding to program A. Address ranges 1, 2, and 3 can be three independent address ranges; for example, address range 1 might be 1-10, address range 2 11-15, address range 3 16-20, and address range 4 1-20. Address ranges 1, 2, and 3 can also overlap; for example, address range 1 might be 1-10, address range 2 5-15, address range 3 10-20, and address range 4 also 1-20.

[0089] In other words, in this embodiment, the terminal can determine the address range (i.e., the third address range) used when executing the program to which the first program segment belongs, and determine the address range other than the first address range (i.e., the second address range) within the third address range based on the third address range and the first address range. Since the second address range is the address range used by the terminal when executing other program segments in the program, the terminal will also calculate the checksum of the address range used by the other program segments after the other program segments have been executed. Therefore, the terminal can obtain the second checksum corresponding to the second address range.

[0090] Step 204: The terminal determines the third verification code based on the first verification code and the second verification code. The third verification code is the verification code corresponding to the third address range.

[0091] After obtaining the first and second check codes, the terminal can determine the third check code corresponding to the third address range based on the zero-padding property of the check operation.

[0092] For example, see Figure 3 , Figure 3 This is a schematic diagram illustrating the distribution of an address range as provided in an embodiment of this application. For example... Figure 3 As shown, assuming the data in the first address range is represented as 1010 and the data in the second address range is represented as 2020, then the first checksum corresponding to the first address range can be represented as CS1 = CRC(1010), the second checksum corresponding to the second address range can be represented as CS2 = CRC(2020), and the third checksum corresponding to the third address range can be represented as CS3 = CRC(1010, 2020). Based on the zero-padding property of CRC, the third checksum CS3 can be calculated according to the following formula 3:

[0093]

[0094]

[0095] In Formula 3, the constant is a given constant value. Formula 3 shows that the total checksum for the two address ranges can be calculated based on the checksums corresponding to each range.

[0096] It should be understood that Formula 3 above uses the example of a second checksum corresponding to the second address interval to describe the process of calculating the third checksum based on the first and second checksums. In practice, the second address interval can also be divided into multiple address intervals, and each of the multiple address intervals constituting the second address interval has a corresponding checksum. Therefore, the second checksum can also refer to multiple checksums corresponding to multiple address intervals within the second address interval.

[0097] For example, see Figure 4 , Figure 4 This is a schematic diagram illustrating another address range distribution provided in an embodiment of this application. For example... Figure 4As shown, the first address range includes address range 1, and the first check code can refer to the check code corresponding to address range 1, that is, the first check code is CRC(1010); the second address range includes address range 2 and address range 3, and the second check code can refer to the check code corresponding to address range 2 and address range 3. The second check code can include CRC(1010) and CRC(1010).

[0098] Similarly, when the second check code refers to multiple check codes corresponding to the second address range, the third check code can also be calculated from the first and second check codes based on the zero-padding property of CRC. The specific calculation process will not be described in detail in this embodiment.

[0099] Step 205: Store the third check code in NVM. The third check code is used to verify the correctness of the data in the volatile memory after the terminal power is restored. The third address range is located in the volatile memory.

[0100] After calculating the third checksum, the terminal can store it in the NVM to ensure its correctness after a power outage. Since the data in the NVM remains error-free after a power outage, the terminal can verify the data in the third address range based on the third checksum stored in the NVM after a power outage and subsequent restoration of power. In other words, after power is restored, the terminal can recalculate the checksum in the third address range located in volatile memory and compare it with the third checksum stored in the NVM. If the two checksums match, it can be assumed that the data in the volatile memory was error-free during the power outage, and the terminal can continue executing the program based on the data in the volatile memory. If the two checksums do not match, it can be assumed that the data in the volatile memory was error-free during the power outage, and the terminal can no longer execute the program based on the data in the volatile memory.

[0101] In this embodiment, after executing a program segment, the terminal calculates the checksum of the address range used by that program segment. Based on this checksum and the checksums of other address ranges within the entire address range used by the program, the terminal can determine the total checksum of the address range used by the program. The terminal no longer needs to calculate the checksum for the entire address range where the data is stored, thereby reducing the energy consumption and time required for checksum calculation. This allows the terminal to operate continuously and ensures its real-time response performance.

[0102] Please refer to Figure 5 , Figure 5 This is a schematic diagram illustrating the operation comparison of a terminal provided in an embodiment of this application. For example... Figure 5As shown, in related technologies, the terminal stops executing the program after its voltage reaches a warning voltage, while the processor actually shuts down after a certain period of time. During the time between the terminal stopping program execution and the processor shutting down, the terminal is in standby mode, and the program cannot continue to advance, resulting in poor real-time responsiveness of the terminal.

[0103] In the solution provided in this embodiment, after the terminal's voltage reaches the warning voltage, it can continue to execute program segments and verify the address range used by the program segments to ensure the correctness of the data after power is restored. In this way, the terminal continues to execute the program until the processor actually loses power and stops running. That is to say, in this solution, the terminal can extend its program execution time as much as possible, ensuring the terminal's real-time response performance.

[0104] In one possible embodiment, the terminal can periodically store data from the volatile memory to the NVM. For example, the terminal can copy the data from the volatile memory to the NVM every 5 or 10 minutes, thereby periodically backing up the test points in the NVM. In this way, if the terminal determines that the data verification in the volatile memory is incorrect after power is restored, it can restore to the most recent test point stored in the NVM, avoiding the terminal frequently re-executing the program.

[0105] In one possible embodiment, the terminal may store the first and second check codes in volatile memory and the third check code in NVM. In this way, after a power outage and subsequent power restoration, the terminal can directly calculate a new check code based on the first and second check codes in the volatile memory and compare this new check code with the third check code stored in the NVM. If the new check code matches the third check code, it can be determined that the first and second check codes in the volatile memory were error-free, meaning the data in the volatile memory was not corrupted during the power outage. If the new check code does not match the third check code, it can be determined that either the first or second check code in the volatile memory was corrupted, meaning the data in the volatile memory was corrupted during the power outage.

[0106] By storing the first and second check codes in volatile memory, the correctness of the data in the volatile memory can be verified. This eliminates the need to recalculate the check codes in the volatile memory, saving the terminal time in verifying data correctness and extending the terminal's effective operating time.

[0107] In one possible embodiment, when the terminal verifies the correctness of the data in the volatile memory after a power outage using the checksum stored in the volatile memory and the checksum stored in the NVM, the terminal can also verify the program segment based on the checksum in the volatile memory before executing each program segment to further ensure the correctness of the data.

[0108] For example, before executing the first program segment, the terminal can determine the first address range corresponding to the first program segment and obtain the checksum corresponding to the first address range, which is stored in volatile memory. If the terminal determines that the data in the first address range is correct based on the checksum, it determines that the first program segment can be executed. If the data in the first address range is incorrect, the terminal can restart the system or restore to the most recent detection point stored on the NVM.

[0109] It should be understood that since the data in volatile memory changes randomly, if the checksum is correct, determining whether the data in the address range corresponding to the program segment is correct based on the checksum before executing the program segment can further ensure the correctness of the data and guarantee the normal operation of the terminal.

[0110] Because volatile memory retains data, in the case of a short power outage, it can be determined that the volatile memory has not malfunctioned even without verifying the data in it. However, in the case of a longer power outage, it can be determined that the volatile memory has malfunctioned even without verifying the data in it.

[0111] Based on this, in one possible embodiment, after power is restored, the terminal can obtain its own power outage duration. If the terminal's power outage duration is less than a first duration, it is determined that the data in the volatile memory is correct; if the terminal's power outage duration is greater than the first duration but less than a second duration, it is determined that the correctness of the data in the volatile memory needs to be verified; if the terminal's power outage duration is greater than the second duration, it is determined that the data in the volatile memory is incorrect; wherein, the first duration is less than the second duration.

[0112] It should be understood that although the data retention characteristics of volatile memory may fluctuate due to factors such as its operating environment and material, terminal designers have still determined two durations to ensure accuracy: the first duration and the second duration mentioned above. The first duration indicates that the power outage time is short enough that the data in the volatile memory is guaranteed not to be corrupted. Therefore, if the power outage duration is less than the first duration, the terminal can skip the data verification step. Similarly, the second duration indicates that the power outage time is long enough that the data in the volatile memory has definitely become corrupted. Therefore, if the power outage duration is longer than the second duration, the terminal can restart the system or restore to the most recent detection point stored on the NVM.

[0113] By setting a first duration and a second duration, the terminal can decide whether to perform data verification based on the actual power outage duration, avoiding data verification every time power is restored, saving the terminal's data verification time, and extending the terminal's effective operating time.

[0114] As a possible example, see [link to relevant documentation]. Figure 6a , Figure 6a This is a schematic diagram of a circuit for determining the duration of a power outage, provided as an embodiment of this application. Figure 6a As shown, the circuit includes an intermittent power supply circuit (shown in the left dashed box) and a time-holding circuit (shown in the right dashed box). The time-holding circuit consists of switch S1, switch S2, capacitor C2, and resistor. The operating mode of the time-holding circuit is as follows:

[0115] 1. When the terminal processor is powered off, switches S1 and S2 are disconnected, so that capacitor C2 supplies power to the resistor.

[0116] 2. Once capacitor C1 has charged to the processor's startup threshold, the voltage across capacitor C2 is detected to estimate the power outage duration T. off With the first duration T LB Second duration T UB The size relationship between them.

[0117] 3. Close switches S1 and S2 to charge capacitor C2 for the next measurement of power outage duration.

[0118] Specifically, the voltage change curve across capacitor C2 after power is off can be found in [reference needed]. Figure 6b , Figure 6b This is a schematic diagram of the voltage change curve of a time-holding circuit provided in an embodiment of this application.

[0119] In one possible embodiment, the volatile memory in the terminal may further include a fourth address range, and the data stored in this fourth address range is the same as the data stored in the third address range before the execution of the first program segment. The third address range is labeled as the working buffer, which is the area used during program execution; that is, the program accesses and modifies corresponding data within the working buffer during execution. The fourth address range is labeled as the backup buffer, which is used to back up the data in the working buffer.

[0120] In other words, before executing the first program segment, the terminal can copy data from the third address range to the third address range to ensure that the data in the third address range (which serves as the working range) is identical to the data in the fourth address range (which serves as the backup range), thus achieving data backup in the working range. Therefore, if a power outage occurs during the execution of the first program segment, the terminal can copy the data from the backup range to the working range after power is restored to restore the data in the working range.

[0121] For example, see Figure 7 , Figure 7 This is a flowchart illustrating an executable program segment provided in an embodiment of this application. Figure 7 As shown, the process of the terminal executing program segments before and after a power outage includes the following steps.

[0122] In step 701, the terminal executes program segment 1.

[0123] This program segment 1 includes an increment operation on the variable x. Therefore, the terminal increments the variable x in the workspace, changing its value from 0 to 1. Furthermore, during the execution of program segment 1—that is, after the terminal performs the increment operation on variable x—a power outage occurs, and power is restored to the terminal after a brief interruption.

[0124] In step 702, after the terminal restores power, the terminal copies the data in the backup interval to the working interval.

[0125] Because the terminal performed an increment operation on variable x in the working range before the power outage, the value of variable x in the working range is 1 after power is restored, while the value of variable x in the backup range remains 0. The terminal can copy data from the backup range to the working range, thus ensuring that the value of variable x in the working range remains 0.

[0126] In step 703, the terminal re-executes program segment 1.

[0127] After the terminal restores the data in the working area, the terminal continues to run, that is, it re-executes program segment 1 and performs an addition operation on the variable x in the working area, thereby changing the value of variable x from 0 to 1.

[0128] Depend on Figure 7 As can be seen from the above steps, if no backup interval is set in the terminal, then after the terminal restores power, the value of variable x in the working interval will be 1. Therefore, when the terminal re-executes program segment 1, the initial value of variable x will not be 0; the terminal will modify the value of variable x from 1 to 2, resulting in data errors and affecting the normal operation of the terminal.

[0129] In this embodiment, by setting a backup interval, the data in the working interval is backed up before the terminal executes the program segment. This ensures that the data in the working interval can be restored after the terminal loses power and power is restored, thereby avoiding data errors in the terminal and ensuring data accuracy.

[0130] It should be understood that in order to ensure that the backup interval can effectively serve its data backup function, the terminal needs to copy the data after each program segment is executed to ensure that the data in the backup interval and the working interval are identical.

[0131] In one possible embodiment, the process of the terminal performing data copying may include: after the first program segment is executed, the terminal marks the fourth address range as the working range and the third address range as the backup range; then, the terminal copies the data from the third address range to the fourth address range.

[0132] In other words, after executing the first program segment, the terminal swaps pointers, marking the third address range (previously the working range) as the backup range and the fourth address range (previously the backup range) as the working range, thus exchanging the working and backup ranges. Then, the terminal copies the data from the fourth address range to the third address range to ensure data consistency. For example, before executing the first program segment, the terminal marks the third address range as the working range using pointer "0" and the fourth address range as the backup range using pointer "1"; after executing the first program segment, the terminal swaps the pointers to mark the third address range as the backup range using pointer "1" and the fourth address range as the working range using pointer "0".

[0133] In this embodiment, after the program segment is executed, the working area and the backup area are quickly swapped by exchanging pointers, which can effectively avoid data errors caused by power outages during data copying.

[0134] For example, if data in the third address range is directly copied to the fourth address range after the first program segment is executed, then if the terminal loses power during the data copying process, after power is restored, the terminal still needs to copy data from the backup range (i.e., the fourth address range) to the working range (i.e., the third address range). However, since the backup range already contained some data from the working range before the power outage, the data in the backup range is actually corrupted and contains errors. Therefore, restoring the data from the backup range to the working range will also result in corrupted data in the working range, thus affecting the normal operation of the terminal.

[0135] In this embodiment, even if a power outage occurs during the copying of data from the third address range to the fourth address range using the pointer swapping scheme, the data in the backup address range will not be corrupted during the copying process because the third address range has been marked as a backup range. After power is restored, the data in the backup address range will still be correct, thus ensuring the normal operation of the terminal.

[0136] In one possible embodiment, if the terminal is configured with a working area and a backup area, the terminal can also obtain the second check code corresponding to the second address area based on the data in the backup area.

[0137] Specifically, the process by which the terminal obtains the second check code corresponding to the second address range may include: the terminal calculating the fourth check code of the address range in the fourth address range that corresponds to the first address range; and determining the second check code based on the check code corresponding to the fourth address range and the fourth check code.

[0138] It is understandable that, since the fourth address range is a backup range corresponding to the third address range, the address range of the fourth address range is the same as and fixed in the third address range. For example, the address range of the third address range can be 1-100, while the address range of the fourth address range can be 101-200. Therefore, before executing the first program segment, for any address range in the third address range, there is a corresponding address range in the fourth address range, so that the data in these two address ranges is the same. For example, the address range of 50-60 in the third address range corresponds to the address range of 150-160 in the fourth address range, and the data in the address range of 50-60 is the same as that in the address range of 150-160.

[0139] In other words, after the first program segment completes execution, because the data in the first address interval of the third address interval has changed, the address interval in the fourth address interval that is different from the data in the third address interval is the address interval corresponding to the first address interval. The other address intervals in the fourth address interval are actually the same as the data in the second address interval of the third address interval. Therefore, the terminal can calculate the checksum of the address interval in the fourth address interval that corresponds to the first address interval, and based on the aforementioned zero-padding property and the checksum of the fourth address interval, determine the checksums of the other address intervals in the fourth address interval, i.e., the second checksum corresponding to the second address interval.

[0140] For example, see Figure 8 , Figure 8 This is a schematic diagram illustrating a method for calculating a checksum, provided as an embodiment of this application. Figure 8 As shown, before the execution of the program segment, the data in the backup interval is the same as that in the working interval. Address intervals S0 and S1 in the backup interval correspond to address intervals S0' and S1' in the working interval, respectively. Furthermore, the checksums corresponding to address intervals S0 and S1 are calculated after the execution of other program segments. After executing program segment 1, program segment 1 accesses and modifies address interval S2' in the working interval, thus dividing the working interval into three address intervals: S01', S2', and S11'. Correspondingly, the backup interval can also be divided into three corresponding address intervals: S01, S02+S12, and S11.

[0141] Depend on Figure 8 It can be seen that the checksum corresponding to the working interval after executing program segment 1 can actually be calculated based on the checksums corresponding to address intervals S01', S2', and S11' respectively. Specifically, the sub-checksum of address interval S2' can be directly calculated by performing checksum calculations on the data in address interval S2'. The checksums corresponding to address intervals S01' and S11' can be obtained by calculating the checksums corresponding to address intervals S01 and S11 in the backup interval. By directly calculating the checksum of address interval S02 in the backup interval, and based on the known checksum of address interval S0, the checksum of address interval S01 can be calculated, i.e., CS(S01') = CS(S01) = CS(S0) - CS(S02). Similarly, by directly calculating the checksum of address interval S12 in the backup interval, and based on the known checksum of address interval S1, the checksum of address interval S11 can be calculated, i.e., CS(S11') = CS(S11) = CS(S1) - CS(S12).

[0142] By calculating the second checksum corresponding to the second address interval in the working interval based on the data in the backup interval, the time and energy consumed by CRC operation can be effectively reduced when the first address interval is small. This improves the efficiency of the terminal in calculating the checksum after executing the program segment, thereby saving the terminal's power and extending the effective operating time of the terminal.

[0143] Understandably, when the operating environment has a sufficient energy source, the terminal's battery level can be maintained at a high level, ensuring that the terminal will not experience power outages for an extended period. In this case, the terminal does not need to calculate the checksum after each program segment execution, thus conserving energy.

[0144] For example, before the terminal executes the first program segment, the terminal executes one or more second program segments based on the terminal's voltage being higher than a threshold voltage. The second program segment can refer to any other program segment within the program to which the first program segment belongs, and this program may include one or more second program segments. The terminal marks the address range used when executing the one or more second program segments. Based on the current voltage being lower than the threshold voltage, the terminal calculates the checksum corresponding to the marked address range. This threshold voltage indicates that the terminal is at a low power level, meaning the terminal may face power loss at any time. The value of the threshold voltage can be determined based on the terminal's actual energy harvesting capability; this embodiment does not impose a specific limitation.

[0145] The terminal may mark the address range used when executing a program segment after each program segment is executed; or the terminal may mark the address range used when executing multiple program segments after multiple program segments are executed.

[0146] Furthermore, after executing each program segment, the terminal can check its current voltage to determine if it is below a threshold voltage. When the terminal determines that the current voltage is below the threshold, it uniformly calculates the checksum for the marked address range, minimizing the number of checksum calculations.

[0147] To facilitate understanding, the data processing method provided in the embodiments of this application will be described in detail below with specific examples. Please refer to... Figure 9 , Figure 9 This is a schematic diagram of a terminal operation process provided in an embodiment of this application.

[0148] like Figure 9 As shown, the operation process of the terminal after power-on includes the following steps.

[0149] Step S1: After each power restoration, the terminal first determines the duration of the previous power outage. If the power outage time was too long, i.e., T... off >TUB The terminal restarts or restores to the most recent detection point stored on the NVM. Among them, T off T represents the duration of the power outage of the terminal. UB This refers to the second duration mentioned above, which is the upper limit of the time during which data on volatile memory is bound to be corrupted.

[0150] Step S2: If the power outage time is short enough, i.e., T off <T LB If the flag bit of the data in the volatile memory is set to 0, i.e., flag = 0, the flag bit is set to 0. The flag is used to mark the correctness of the data in the volatile memory. When the flag is 0, it means that the data is correct and the data verification operation can be skipped.

[0151] Step S3: If the power outage duration is within T... UB and T LB Between, i.e., T LB <T off <T UB If the flag of the data in the volatile memory is set to 1, that is, flag=1, it means that the data may not be correct and needs to be verified.

[0152] Step S4, at T LB <T off <T UB In this case, before executing the program segment, the terminal needs to verify whether the checksum corresponding to the data in the volatile memory is correct. That is, the terminal verifies the correctness of the checksum corresponding to the data in the volatile memory by comparing whether the checksum stored in the volatile memory is the same as the checksum stored in the NVM. If the verification fails (i.e., the checksums are different), it means that the data in the volatile memory is incorrect, and the terminal restarts or restores to the most recent checkpoint stored in the NVM.

[0153] Step S5: The terminal determines whether the current voltage V is greater than the threshold voltage V. T .

[0154] Step S6: When the voltage V is higher than the threshold voltage V T When the terminal is in a high power level, it can operate in a high power level mode, meaning that the checksum does not need to be calculated after each program segment is executed.

[0155] The terminal determines the flag of the data required by the program segment to be executed. If flag = 1, the terminal needs to verify the data to be used by the program segment, and if the verification fails, the terminal will restart or restore to the most recent checkpoint stored on the NVM. If flag = 0, the terminal does not need to verify the data to be used by the program segment.

[0156] Step S7: If the data to be used by the program segment passes verification or does not need to be verified, the terminal copies the data in the backup area to the working area.

[0157] Step S8: The terminal executes this program segment.

[0158] Step S9: After the program segment is executed, the terminal marks the modified address range (i.e., marks the address range where the data used by the program segment is located), and then schedules the next ready program segment, repeating steps S6 to S9.

[0159] Step S10: When the voltage V is lower than the threshold voltage V T When this occurs, it indicates that the terminal is currently in a low power level and needs to execute a low power level operating mode, which means that a checksum is calculated after each program segment is executed. The terminal calculates the checksum for the marked address range, as well as the total checksum for the address range used by the entire program, and stores the total checksum in the NVM.

[0160] Step S11: Optionally, the terminal can copy all the data on the volatile memory to the NVM as a detection point.

[0161] Step S12: The terminal exchanges the pointers of the backup interval and the working interval, that is, it marks the original backup interval in the volatile memory as the working interval and the original working interval as the backup interval, and copies the data in the backup interval after the pointer exchange to the working interval.

[0162] Step S13: The terminal determines the flag of the data required by the program segment to be executed. If flag = 1, the terminal needs to verify the data to be used by the program segment, and if the verification of this data fails, the terminal will restart or restore to the most recent detection point stored on the NVM. If flag = 0, the terminal does not need to verify the data to be used by the program segment.

[0163] Step S14: The terminal verifies the data to be used by the next program segment in the working area, that is, verifies the data to be used by the program segment by verifying the check code stored in the volatile memory.

[0164] Step S15: The terminal determines whether the data to be used by the program segment has been verified. If the verification fails, the terminal restarts or restores to the most recent detection point stored on the NVM.

[0165] Step S16: If the verification passes, the terminal executes the program segment.

[0166] Step S17: After the program segment is executed, the terminal exchanges pointers between the backup interval and the working interval.

[0167] Step S18: The terminal calculates the checksum corresponding to the address range used by the program segment in the backup interval, and calculates the total checksum corresponding to the address range used by the program based on the checksum, and stores the total checksum in NVM.

[0168] Step S19: The terminal copies the data from the backup area to the working area, then schedules the next ready program segment, and repeats steps S13 to S19 until power is cut off.

[0169] The above describes the operation process of the terminal after power-on in detail. The following will describe in detail the changes of data in the volatile memory area during the operation of the terminal, with reference to the accompanying drawings.

[0170] Please refer to Figure 10a , Figure 10a This is a schematic diagram illustrating the relationship between a program segment and an address range, provided as an embodiment of this application.

[0171] like Figure 10a As shown, the application code includes program segment 1, program segment 2 and program segment 3, which will use address ranges DB1, DB2 and DB3 respectively.

[0172] Please refer to Figure 10b , Figure 10b This is a flowchart illustrating how a terminal executes a program segment under low battery conditions, as provided in an embodiment of this application. Figure 10b As shown, the process of the terminal executing a program segment under low power levels includes the following steps.

[0173] At time t0, the terminal successfully executed program segment 1. DB1 in the working interval was updated to DB1'. Furthermore, the terminal detected that the current voltage value was lower than the threshold voltage, and the terminal entered a low-power level operating mode.

[0174] At time t1, the terminal calculates the checksum of the modified address range, specifically the checksum of DB1', obtaining CS1. Additionally, during the execution of the previous program segment, the terminal also calculates the checksums of other address ranges within the working range, namely CS0, CS_delta, and CSn. Thus, the terminal can calculate the total checksum CS_total for the working range based on the multiple sub-checksums corresponding to the working range and store CS_total in the NVM. Furthermore, the terminal copies the data from the working range to the backup range.

[0175] At time t2, the terminal prepares to schedule and execute program segment 2, which will use the address range DB2 in the working space. Since the correctness of the data in DB2 has not been verified during this power-on cycle, the terminal can verify the correctness of data ranges DB2, DB3, and DB4 using the checksum CS_delta. If the verification result shows that no data errors have occurred, the terminal can execute program segment 2.

[0176] At time t3, the terminal scheduler executes program segment 2, and all modifications to DB2 during the execution of program segment 2 occur within the working interval.

[0177] At time t4, the terminal successfully executes program segment 2, updating DB2 in the working interval to DB2'. The terminal then quickly updates DB2' to the backup interval by swapping pointers.

[0178] At time t5, the terminal calculates the checksum of the modified address range, specifically the checksum of DB2', resulting in CS2. For the checksums of DB3 to DB4, the terminal can calculate them using the checksums CS_delta of DB2 to DB4 and the checksum CS(DB2), i.e., CS_delta - CS(DB2). Thus, the terminal can calculate the total checksum CS_total based on the multiple sub-checksums CS0, CS1, CS2, CS_delta - CS(DB2), and CSn corresponding to the working range, and store CS_total in the NVM.

[0179] At time t6, the terminal copies DB2' from the backup interval to the working interval and verifies the data correctness of DB3. Since DB2 was already verified by CS_delta at time t2, the terminal can determine which program segment 3 to schedule.

[0180] At time t7, the terminal scheduler executes program segment 3. During the execution of program segment 3, all modifications to DB3 occur within the working interval.

[0181] At time t8, a power outage occurred during the execution of program segment 3 in the terminal. The data in the working space may be corrupted, therefore the data in the working space is no longer available.

[0182] Please refer to Figure 11 , Figure 11 This is a schematic diagram illustrating the operation of a terminal after power restoration, as provided in an embodiment of this application. Figure 11 As shown, the terminal performs the following steps after power is restored.

[0183] Step 1101: The terminal verifies the correctness of the checksum in the volatile memory using the total checksum CS_total on the NVM. Specifically, the terminal recalculates a new total checksum based on the checksums in the volatile memory (CS0, CS1, CS2, CS_delta, and CSN), and compares the new total checksum with the total checksum stored on the NVM. If they match, the checksum in the volatile memory is correct; if they do not match, the data in the volatile memory is incorrect.

[0184] Step 1102: If the checksum verification on the volatile memory is correct, the terminal verifies whether the data (i.e., DB3) to be used by program segment 3 is correct based on the checksum CS_delta.

[0185] Step 1103: If the data to be used in program segment 3 is verified to be correct, the terminal copies the data from the backup area to the working area.

[0186] Step 1104, Terminal scheduling execution program segment 3.

[0187] exist Figures 1 to 11 Based on the corresponding embodiments, in order to better implement the above-described solutions of the embodiments of this application, related equipment for implementing the above solutions is also provided below. For details, please refer to... Figure 12 , Figure 12 This application provides a schematic diagram of the structure of a terminal 1200, which includes a processing unit 1201 and an acquisition unit 1202. The processing unit 1201 is configured to execute a first program segment. The processing unit 1201 is also configured to calculate a first checksum corresponding to a first address range, where the first address range is the address range used when executing the first program segment. The acquisition unit 1202 is configured to acquire a second checksum corresponding to a second address range, where the second address range is the address range other than the first address range in a third address range, and the third address range is the address range used when executing the program to which the first program segment belongs. The processing unit 1201 is also configured to determine a third checksum based on the first and second checksums, where the third checksum is the checksum corresponding to the third address range. The processing unit 1201 is also configured to store the third checksum in a non-volatile memory, where the third checksum is used to verify the correctness of the data in the volatile memory after the terminal regains power, and the third address range is located in the volatile memory.

[0188] In some possible implementations, the volatile memory also includes a fourth address range, the data of which is the same as the data stored in the third address range before the execution of the first program segment; wherein the third address range is marked as the working range and the fourth address range is marked as the backup range, the working range is the range used during program execution, and the backup range is used to back up the data in the working range.

[0189] In some possible implementations, the processing unit 1201 is specifically used to: calculate the fourth check code of the address interval corresponding to the first address interval in the fourth address interval; and determine the second check code based on the check code corresponding to the fourth address interval and the fourth check code.

[0190] In some possible implementations, the processing unit 1201 is also used to: mark the fourth address range as the working range and mark the third address range as the backup range; and copy the data in the third address range to the fourth address range.

[0191] In some possible implementations, the processing unit 1201 is further configured to: store the first check code and the second check code in a volatile memory, wherein the first check code and the second check code are used to compare with the third check code after the terminal is powered on, so as to verify the correctness of the data in the volatile memory.

[0192] In some possible implementations, the processing unit 1201 is further configured to: after the terminal restores power, obtain the power outage duration of the terminal; if the power outage duration is less than a first duration, determine that the data in the volatile memory is correct; if the power outage duration is greater than the first duration and less than a second duration, determine that the correctness of the data in the volatile memory needs to be verified; if the power outage duration is greater than the second duration, determine that the data in the volatile memory is incorrect; wherein the first duration is less than the second duration.

[0193] In some possible implementations, the processing unit 1201 is further configured to: execute one or more second program segments based on the terminal voltage being higher than a threshold voltage; mark the address range used when executing one or more second program segments; and calculate the check code corresponding to the marked address range based on the terminal voltage being lower than a threshold voltage.

[0194] In some possible implementations, the processing unit 1201 is further configured to: determine the first address range corresponding to the first program segment; obtain the check code corresponding to the first address range, the check code corresponding to the first address range being stored in volatile memory; determine that the data in the first address range is correct based on the check code corresponding to the first address range; and determine to execute the first program segment based on the correctness of the data in the first address range.

[0195] In some possible implementations, the processing unit 1201 is also used to periodically store data in the volatile memory to the non-volatile memory.

[0196] Please refer to Figure 13 , Figure 13 This is a schematic diagram of the structure of a terminal 100 provided in an embodiment of this application.

[0197] like Figure 13 As shown, terminal 100 may include a processor 110, an external memory interface 120, an internal memory 121, a universal serial bus (USB) interface 130, an energy harvesting module 140, a power management module 141, a battery 142, antenna 1, antenna 2, a mobile communication module 150, a wireless communication module 160, and a sensor module 170, etc. The sensor module 170 may include a pressure sensor, a gyroscope sensor, a barometric pressure sensor, a magnetic sensor, an accelerometer, a distance sensor, a proximity sensor, a fingerprint sensor, a temperature sensor, a touch sensor, an ambient light sensor, a bone conduction sensor, etc.

[0198] It is understood that the structures illustrated in the embodiments of this application do not constitute a specific limitation on the terminal 100. In other embodiments of this application, the terminal 100 may include more or fewer components than illustrated, or combine some components, or split some components, or have different component arrangements. The illustrated components may be implemented in hardware, software, or a combination of software and hardware.

[0199] A pressure sensor detects pressure signals and converts them into electrical signals. A gyroscope sensor is used to determine the motion attitude of terminal 100. A barometric pressure sensor measures air pressure.

[0200] The accelerometer can detect the magnitude of acceleration of terminal 100 in various directions (including three-axis or six-axis). When terminal 100 is stationary, the magnitude and direction of gravity can be detected.

[0201] Distance sensor, used to measure distance.

[0202] An ambient light sensor is used to detect the brightness of ambient light.

[0203] A fingerprint sensor is used to collect fingerprints.

[0204] Temperature sensors are used to detect temperature.

[0205] Processor 110 may include one or more processing units, such as: application processor (AP), modem processor, graphics processing unit (GPU), image signal processor (ISP), controller, memory, video codec, digital signal processor (DSP), baseband processor, and / or neural network processing unit (NPU), etc. Different processing units may be independent devices or integrated into one or more processors.

[0206] The controller can serve as the central nervous system and command center of the terminal 100. The controller can generate operation control signals based on the instruction opcode and timing signals to control the fetching and execution of instructions.

[0207] The processor 110 may also include a memory for storing instructions and data. In some embodiments, the memory in the processor 110 is a cache memory. This memory can store instructions or data that the processor 110 has just used or that are used repeatedly. If the processor 110 needs to use the instruction or data again, it can retrieve it directly from the memory. This avoids repeated accesses, reduces the waiting time of the processor 110, and thus improves the efficiency of the system.

[0208] In some embodiments, the processor 110 may include one or more interfaces. Interfaces may include an inter-integrated circuit (I1C) interface, an inter-integrated circuit sound (I1S) interface, a pulse code modulation (PCM) interface, a universal asynchronous receiver / transmitter (UART) interface, a mobile industry processor interface (MIPI), a general-purpose input / output (GPIO) interface, a subscriber identity module (SIM) interface, and / or a universal serial bus (USB) interface, etc.

[0209] It is understood that the interface connection relationships between the modules illustrated in the embodiments of this application are merely illustrative and do not constitute a structural limitation on the terminal 100. In other embodiments of this application, the terminal 100 may also adopt different interface connection methods or a combination of multiple interface connection methods as described in the above embodiments.

[0210] The energy harvesting module 140 is used to obtain energy input from the operating environment, such as light energy, radio frequency, pressure or heat energy, and convert this energy into electrical energy and store it in the battery 142.

[0211] The power management module 141 is used to connect the battery 142, the energy harvesting module 140, and the processor 110. The power management module 141 receives input from the battery 142 and / or the energy harvesting module 140 to power the processor 110, internal memory 121, external memory, and wireless communication module 160, etc.

[0212] The wireless communication function of terminal 100 can be implemented through antenna 1, antenna 2, mobile communication module 150, wireless communication module 160, modem processor and baseband processor, etc.

[0213] Antennas 1 and 2 are used to transmit and receive electromagnetic wave signals. Each antenna in terminal 100 can be used to cover one or more communication frequency bands. Different antennas can also be multiplexed to improve antenna utilization. For example, antenna 1 can be multiplexed as a diversity antenna for a wireless local area network. In some other embodiments, the antennas can be used in conjunction with tuning switches.

[0214] The mobile communication module 150 can provide solutions for wireless communication applications including 1G / 3G / 4G / 5G on the terminal 100. The mobile communication module 150 may include at least one filter, switch, power amplifier, low-noise amplifier (LNA), etc. The mobile communication module 150 can receive electromagnetic waves via antenna 1, and perform filtering, amplification, and other processing on the received electromagnetic waves before transmitting them to a modem processor for demodulation. The mobile communication module 150 can also amplify the signal modulated by the modem processor and convert it into electromagnetic waves for radiation via antenna 2. In some embodiments, at least some functional modules of the mobile communication module 150 may be housed in the processor 110. In some embodiments, at least some functional modules of the mobile communication module 150 and at least some modules of the processor 110 may be housed in the same device.

[0215] The wireless communication module 160 can provide solutions for wireless communication applications on the terminal 100, including wireless local area networks (WLAN) (such as wireless fidelity (Wi-Fi) networks), Bluetooth (BT), global navigation satellite system (GNSS), frequency modulation (FM), near field communication (NFC), and infrared (IR) technologies. The wireless communication module 160 can be one or more devices integrating at least one communication processing module. The wireless communication module 160 receives electromagnetic waves via antenna 1, performs frequency modulation and filtering of the electromagnetic wave signals, and sends the processed signal to processor 110. The wireless communication module 160 can also receive signals to be transmitted from processor 110, perform frequency modulation and amplification, and convert them into electromagnetic waves for radiation via antenna 2.

[0216] In some embodiments, antenna 1 of terminal 100 is coupled to mobile communication module 150, and antenna 2 is coupled to wireless communication module 160, enabling terminal 100 to communicate with networks and other devices via wireless communication technology. The wireless communication technology may include Global System for Mobile Communications (GSM), General Packet Radio Service (GPRS), Code Division Multiple Access (CDMA), Wideband Code Division Multiple Access (WCDMA), Time Division Code Division Multiple Access (TD-SCDMA), Long Term Evolution (LTE), BT, GNSS, WLAN, NFC, FM, and / or IR technologies, etc. The GNSS may include the Global Positioning System (GPS), the Global Navigation Satellite System (GLONASS), the BeiDou Navigation Satellite System (BDS), the Quasi-Zenith Satellite System (QZSS), and / or satellite-based augmentation systems (SBAS).

[0217] The external storage interface 120 can be used to connect an external storage card, such as a Micro SD card, to expand the storage capacity of the terminal 100. The external storage card communicates with the processor 110 through the external storage interface 120 to perform data storage functions. For example, music, video, and other files can be saved on the external storage card.

[0218] Internal memory 121 can be used to store computer executable program code, which includes instructions. Processor 110 executes various functional applications and data processing of terminal 100 by running the instructions stored in internal memory 121. Internal memory 121 may include volatile memory 121A and non-volatile memory 121B. Volatile memory 121A is used to store data used during program execution, and non-volatile memory 121B is used to store checksums corresponding to the data in volatile memory 121A and to back up the data in volatile memory 121A.

[0219] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working processes of the systems, devices, and units described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here.

[0220] In the several embodiments provided in this application, it should be understood that the disclosed systems, apparatuses, and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be an indirect coupling or communication connection between apparatuses or units through some interfaces, and may be electrical, mechanical, or other forms.

[0221] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.

[0222] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.

[0223] If the integrated unit is implemented as 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 this application, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory, random access memory, magnetic disks, or optical disks.

Claims

1. A data processing method, characterized in that, The method is applied to terminals that operate intermittently, and includes: Execute the first program segment; Calculate the first checksum corresponding to the first address range, where the first address range is the address range used when executing the first program segment, and the first address range is used to store the data accessed when executing the first program segment; Obtain the second check code corresponding to the second address range, where the second address range is the address range other than the first address range in the third address range, and the third address range is the address range used when executing the program to which the first program segment belongs. The second check code is calculated after executing the program segment corresponding to the second address range. Based on the first check code and the second check code, a third check code is determined, wherein the third check code is the check code corresponding to the third address range; The third check code is stored in a non-volatile memory. The third check code is used to verify the correctness of the data in the volatile memory after the terminal restores power. The third address range is located in the volatile memory.

2. The data processing method according to claim 1, characterized in that, The volatile memory also includes a fourth address range, the data stored in the fourth address range being the same as the data stored in the third address range before the execution of the first program segment; The third address range is marked as the working range, and the fourth address range is marked as the backup range. The working range is the range used when the program is executed, and the backup range is used to back up the data in the working range.

3. The data processing method according to claim 2, characterized in that, The step of obtaining the second checksum corresponding to the second address range includes: Calculate the fourth checksum of the address interval in the fourth address interval that corresponds to the first address interval; The second check code is determined based on the check code corresponding to the fourth address range and the fourth check code.

4. The data processing method according to claim 2 or 3, characterized in that, After the first program segment has been executed, the method further includes: The fourth address range is marked as the working range, and the third address range is marked as the backup range; Copy the data from the third address range to the fourth address range.

5. The data processing method according to any one of claims 1 to 3, characterized in that, The method further includes: The first and second check codes are stored in the volatile memory. The first and second check codes are used to compare with the third check code after the terminal is powered back on, so as to verify the correctness of the data in the volatile memory.

6. The data processing method according to any one of claims 1 to 3, characterized in that, The method further includes: After the terminal is powered back on, the duration of the power outage is obtained. If the power outage duration is less than the first duration, then the data in the volatile memory is determined to be correct; If the power outage duration is greater than the first duration but less than the second duration, then it is determined that the correctness of the data in the volatile memory needs to be verified. If the power outage duration is longer than the second duration, then the data in the volatile memory is determined to be incorrect. Wherein, the first duration is shorter than the second duration.

7. The data processing method according to any one of claims 1 to 3, characterized in that, Before executing the first program segment, the method further includes: If the voltage of the terminal is higher than the threshold voltage, execute one or more second program segments; Mark the address range used when executing the one or more second program segments; Calculate the checksum corresponding to the marked address range based on the fact that the voltage of the terminal is lower than the threshold voltage.

8. The data processing method according to any one of claims 1 to 3, characterized in that, Before executing the first program segment, the method further includes: Determine the first address range corresponding to the first program segment; Obtain the check code corresponding to the first address range, and store the check code corresponding to the first address range in the volatile memory; The data in the first address range is determined to be correct based on the check code corresponding to the first address range. Based on the correctness of the data in the first address range, the first program segment is to be executed.

9. The data processing method according to any one of claims 1 to 3, characterized in that, The method further includes: The data in the volatile memory is periodically stored to the non-volatile memory.

10. A terminal, characterized in that, The terminal includes: a processor, non-volatile memory, and volatile memory; the processor is used for: Execute the first program segment; Calculate the first checksum corresponding to the first address range, where the first address range is the address range used when executing the first program segment, and the first address range is used to store the data accessed when executing the first program segment; Obtain the second check code corresponding to the second address range, where the second address range is the address range other than the first address range in the third address range, and the third address range is the address range used when executing the program to which the first program segment belongs. The second check code is calculated after executing the program segment corresponding to the second address range. Based on the first check code and the second check code, a third check code is determined, wherein the third check code is the check code corresponding to the third address range; The third check code is stored in the non-volatile memory. The third check code is used to verify the correctness of the data in the volatile memory after the terminal restores power. The third address range is located in the volatile memory.

11. The terminal according to claim 10, characterized in that, The volatile memory also includes a fourth address range, the data stored in the fourth address range being the same as the data stored in the third address range before the execution of the first program segment; The third address range is marked as the working range, and the fourth address range is marked as the backup range. The working range is the range used when the program is executed, and the backup range is used to back up the data in the working range.

12. The terminal according to claim 11, characterized in that, The processor is specifically used for: Calculate the fourth checksum of the address interval in the fourth address interval that corresponds to the first address interval; The second check code is determined based on the check code corresponding to the fourth address range and the fourth check code.

13. The terminal according to claim 11 or 12, characterized in that, The processor is also used for: The fourth address range is marked as the working range, and the third address range is marked as the backup range; Copy the data from the third address range to the fourth address range.

14. The terminal according to any one of claims 10 to 12, characterized in that, The processor is also used for: The first and second check codes are stored in the volatile memory. The first and second check codes are used to compare with the third check code after the terminal is powered back on, so as to verify the correctness of the data in the volatile memory.

15. The terminal according to any one of claims 10 to 12, characterized in that, The processor is also used for: After the terminal is powered back on, the duration of the power outage is obtained. If the power outage duration is less than the first duration, then the data in the volatile memory is determined to be correct; If the power outage duration is greater than the first duration but less than the second duration, then it is determined that the correctness of the data in the volatile memory needs to be verified. If the power outage duration is longer than the second duration, then the data in the volatile memory is determined to be incorrect. Wherein, the first duration is shorter than the second duration.

16. The terminal according to any one of claims 10 to 12, characterized in that, The processor is also used for: If the voltage of the terminal is higher than the threshold voltage, execute one or more second program segments; Mark the address range used when executing the one or more second program segments; Calculate the checksum corresponding to the marked address range based on the fact that the voltage of the terminal is lower than the threshold voltage.

17. The terminal according to any one of claims 10 to 12, characterized in that, The processor is also used for: Determine the first address range corresponding to the first program segment; Obtain the check code corresponding to the first address range, and store the check code corresponding to the first address range in the volatile memory; The data in the first address range is determined to be correct based on the check code corresponding to the first address range. Based on the correctness of the data in the first address range, the first program segment is to be executed.

18. The terminal according to any one of claims 10 to 12, characterized in that, The processor is also used for: The data in the volatile memory is periodically stored to the non-volatile memory.

19. A computer-readable storage medium, characterized in that, Includes computer-readable instructions that, when executed on a computer, cause the computer to perform the method as described in any one of claims 1 to 9.

20. A computer program product, characterized in that, Includes computer-readable instructions, which, when executed on a computer, cause the computer to perform the method as described in any one of claims 1 to 9.

Citation Information

Patent Citations

  • CRC code generating method and circuit applicable to ultra-high-speed communication system

    CN103763064A

  • Computer program run phase code memory checking method

    CN108038021A

  • Interrupt recovery method for machine tool processing file and machine tool suitable for the method

    CN109426579A