Circuit dormancy method and dormancy circuit
By writing data to the data backup block of the flash memory unit and checking and comparing in the sleep mode of the microcontroller system, the problem of SRAM being continuously powered during sleep is solved, and the circuit is low power consumption and data completeness is achieved Improves user experience.
Patent Information
- Application Number
- CN202310552326.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-05-16
- Publication Date
- 2024-11-22
AI Technical Summary
In the sleep mode of the microcontroller system, the static random access memory (SRAM) needs to be continuously powered to save state data, resulting in an increase in power consumption and affecting the user experience.
A circuit sleep method is designed, using multiple data backup blocks in the flash memory unit to ensure data integrity by writing data to the current data backup block before entering the sleep mode and performing verification and comparison at wake-up. Complete power off during sleep, reducing power consumption.
It realizes complete power outage during sleep, reduces the power consumption of the circuit and improves the user's experience. At the same time, through the management of data backup blocks, data integrity problems caused by excessive erasing times are prevented.
Smart Images

Figure CN119002674A_ABST
Abstract
Description
Technical Field
[0001] This case is about a power saving mechanism of a circuit, and more particularly, a circuit sleep method and a sleep circuit. Background Art
[0002] In a microcontroller unit (MCU) system, when the system is in sleep mode, the system's central processing unit (CPU) and clock will stop operating, and the system's input and output ports will be suspended. When the system is awakened by a wakeup source in sleep mode, the CPU will restart and start executing from the state before the system entered sleep mode.
[0003] However, in order for the system to start executing from the state before entering the sleep mode after being awakened, the static random access memory (SRAM) in the system needs to store the data of the state before the system entered the sleep mode. As a result, in order to prevent the data stored in the SRAM from being lost during the sleep period, the system must continue to supply power to the SRAM in the sleep mode, resulting in increased power consumption of the system, which in turn affects the user experience. Summary of the invention
[0004] In one embodiment, a circuit hibernation method is provided, wherein the circuit includes a processing unit, a storage unit, and a flash memory unit. The flash memory unit includes a plurality of data backup blocks, one of which is a current data backup block. The hibernation method includes: when the processing unit receives a hibernation instruction, the processing unit writes all data stored in the storage unit into the current data backup block and performs a verification calculation on the data written into the current data backup block to obtain a first verification value and writes the first verification value into the current data backup block; after the processing unit writes the first verification value into the current data backup block, the circuit is powered off to put the circuit into a hibernation mode; when the processing unit receives a wake-up instruction when the circuit is in the hibernation mode, the processing unit restarts the circuit and determines whether the processing unit has written all data stored in the storage unit into the current data backup block before the circuit enters the hibernation mode. backup block; when the processing unit writes all the data stored in the storage unit into the current data backup block before the circuit enters the sleep mode, the processing unit performs a verification calculation on the data stored in the current data backup block to obtain a second verification value and compares the first verification value and the second verification value stored in the current data backup block; when the comparison result of the first verification value and the second verification value is consistent, the processing unit writes the data stored in the current data backup block back to the storage unit; and after the processing unit writes the data stored in the current data backup block back to the storage unit, the processing unit erases the data stored in the current data backup block and sets the next data backup block of the current data backup block as the current data backup block of the next sleep method.
[0005] In one embodiment, a method for hibernation of a circuit includes a processing unit, a storage unit, and a flash memory unit. The flash memory unit includes a plurality of data backup blocks, one of the plurality of data backup blocks is a current data backup block, and each data backup block records the number of erase and write operations. The hibernation method includes: when the processing unit receives a hibernation instruction, it determines whether the number of erase and write operations of the current data backup block exceeds a threshold value; when the number of erase and write operations of the current data backup block does not exceed the threshold value, the processing unit writes all data stored in the storage unit into the current data backup block and performs a verification calculation on the data written into the current data backup block to obtain a first verification value and writes the first verification value into the current data backup block; after the processing unit writes the first verification value into the current data backup block, it powers off the circuit to put the circuit into a hibernation mode; when the processing unit receives a wake-up instruction when the circuit is in the hibernation mode, the processing unit restarts the circuit and determines whether the processing unit has written all data stored in the storage unit into the current data backup block before the circuit enters the hibernation mode; When the processing unit has written all the data stored in the storage unit into the current data backup block before the circuit enters the sleep mode, the processing unit performs a verification calculation on the data stored in the current data backup block to obtain a second verification value and compares the first verification value and the second verification value stored in the current data backup block; when the comparison result of the first verification value and the second verification value is consistent, the processing unit writes the data stored in the current data backup block back to the storage unit; and after the processing unit writes the data stored in the current data backup block back to the storage unit, the processing unit adds 1 to the erase and write times of the current data backup block, erases the data stored in the current data backup block, and sets the next data backup block of the current data backup block as the current data backup block for the next round of the sleep method.
[0006] In one embodiment, a sleep circuit includes a storage unit, a flash memory unit and a processing unit. The flash memory unit is coupled to the storage unit, and the flash memory unit includes a plurality of data backup blocks. One of the plurality of data backup blocks is a current data backup block. The processing unit is coupled to the storage unit and the flash memory unit. The processing unit is used to write all data stored in the storage unit into the current data backup block when receiving a sleep instruction, and perform a checksum calculation on the data written into the current data backup block to obtain a first verification value and write the first verification value into the current data backup block. After the processing unit writes the first verification value into the current data backup block, the sleep circuit is powered off to make the sleep circuit enter a sleep mode. When the processing unit receives a wake-up instruction when the sleep circuit is in the sleep mode, the processing unit restarts the sleep circuit and determines whether the processing unit has written all data stored in the storage unit into the current data backup block before the sleep circuit enters the sleep mode. When the processing unit has written all data stored in the storage unit into the current data backup block before the sleep circuit enters the sleep mode, the processing unit performs a checksum calculation on the data stored in the current data backup block to obtain a second verification value and compares the first verification value and the second verification value stored in the current data backup block. When the comparison result of the first verification value and the second verification value is consistent, the processing unit writes the data stored in the current data backup block back to the storage unit. After the processing unit writes the data stored in the current data backup block back to the storage unit, the processing unit erases the data stored in the current data backup block and sets the next data backup block of the current data backup block as the current data backup block.
[0007] In one embodiment, a sleep circuit includes a storage unit, a flash memory unit and a processing unit. The flash memory unit is coupled to the storage unit, and the flash memory unit includes a plurality of data backup blocks. One of the plurality of data backup blocks is a current data backup block. The processing unit is coupled to the storage unit and the flash memory unit. The processing unit is used to write all data stored in the storage unit into the current data backup block when receiving a sleep instruction, and perform a checksum calculation on the data written into the current data backup block to obtain a first verification value and write the first verification value into the current data backup block. After the processing unit writes the first verification value into the current data backup block, the sleep circuit is powered off to make the sleep circuit enter a sleep mode. When the processing unit receives a wake-up instruction when the sleep circuit is in the sleep mode, the processing unit restarts the sleep circuit and determines whether the processing unit has written all data stored in the storage unit into the current data backup block before the sleep circuit enters the sleep mode. When the processing unit has written all data stored in the storage unit into the current data backup block before the sleep circuit enters the sleep mode, the processing unit performs a checksum calculation on the data stored in the current data backup block to obtain a second verification value and compares the first verification value and the second verification value stored in the current data backup block. When the comparison result of the first verification value and the second verification value is consistent, the processing unit writes the data stored in the current data backup block back to the storage unit. After the processing unit writes the data stored in the current data backup block back to the storage unit, the processing unit erases the data stored in the current data backup block and sets the next data backup block of the current data backup block as the current data backup block. Each data backup block also records the number of erasures. The processing unit is also used to determine whether the number of erasures of the current data backup block exceeds a threshold when receiving a sleep instruction. When the number of erasures of the current data backup block does not exceed the threshold, the processing unit writes all the data stored in the storage unit into the current data backup block and performs a verification calculation on the data written into the current data backup block to obtain the first verification value and write the first verification value into the current data backup block. And when the processing unit writes the data stored in the current data backup block back to the storage unit, the processing unit adds 1 to the number of erasures of the current data backup block and erases the data stored in the current data backup block and sets the next data backup block of the current data backup block as the current data backup block.
[0008] The detailed features and advantages of the present invention are described in detail in the implementation mode below, and the content is sufficient to enable any technical personnel in this field to understand the technical content of the present invention and implement it accordingly. According to the content disclosed in this specification, the scope of the patent application and the drawings, any technical personnel in this field can easily understand the relevant purposes and advantages of the present invention. BRIEF DESCRIPTION OF THE DRAWINGS
[0009] Figure 1 FIG. 4 is a block diagram of an embodiment of a sleep circuit.
[0010] Figure 2The present invention is a flow chart of an embodiment of a circuit sleep method.
[0011] Figure 3 FIG. 1 is a schematic diagram of a flash memory cell according to an embodiment of the present invention.
[0012] Figure 4 The present invention is a flow chart of another embodiment of a circuit sleep method. DETAILED DESCRIPTION
[0013] Figure 1 FIG. 1 is a block diagram of an embodiment of the sleep circuit 1. Figure 1 . The sleep circuit 1 includes a storage unit 11, a flash memory unit 12 and a processing unit 13. The storage unit 11 is used to store data of the state before the sleep circuit 1 enters the sleep mode. The flash memory unit 12 is coupled to the storage unit 11. The processing unit 13 is coupled to the storage unit 11 and the flash memory unit 12. In some embodiments, the storage unit 11 may be, but not limited to, a volatile storage medium. A volatile storage medium is, for example, a random access memory (RAM), and a random access memory is, for example, a static random access memory (SRAM) or a dynamic random access memory (DRAM). In some embodiments, the flash memory unit 12 may be, but not limited to, a non-volatile storage medium in which the stored data will not be lost due to power failure, and a non-volatile storage medium is, for example, a flash memory (Flash Memory), an embedded MultiMedia Card (embedded MultiMedia Card, eMMC), a solid state disk (SSD), etc. In some embodiments, the processing unit 13 may be, but not limited to, a central processing unit (CPU).
[0014] Figure 3 FIG. 1 is a schematic diagram of an embodiment of a flash memory unit 12. Figure 1 and Figure 3 The flash memory unit 12 includes a plurality of data backup blocks 120, one of which is a current data backup block.
[0015] Figure 2 FIG. 1 is a flow chart of an embodiment of a circuit sleep method. Figures 1 to 3. After the sleep circuit 1 is powered on for the first time (step S00), the processing unit 13 is used to write all the data Data stored in the storage unit 11 into the current data backup block when receiving the sleep command and perform a verification calculation on the data Data written into the current data backup block to obtain a first verification value V1 and write the first verification value V1 into the current data backup block (step S01). After the processing unit 13 writes the first verification value V1 into the current data backup block, the sleep circuit 1 is powered off to make the sleep circuit 1 enter the sleep mode (step S02). When the processing unit 13 receives a wake-up command when the sleep circuit 1 is in the sleep mode, the processing unit 13 restarts the sleep circuit 1 and determines whether the processing unit 13 has written all the data Data stored in the storage unit 11 into the current data backup block before the sleep circuit 1 enters the sleep mode (step S03). When the processing unit 13 has written all the data Data stored in the storage unit 11 into the current data backup block before the sleep circuit 1 enters the sleep mode, the processing unit 13 performs a checksum calculation on the data Data stored in the current data backup block to obtain a second verification value and compares the first verification value V1 and the second verification value stored in the current data backup block (step S04). When the comparison result of the first verification value V1 and the second verification value is consistent, the processing unit 13 writes the data Data stored in the current data backup block back to the storage unit 11 (step S05). After the processing unit 13 writes the data Data stored in the current data backup block back to the storage unit 11, the processing unit 13 erases the data Data stored in the current data backup block and sets the next data backup block of the current data backup block as the current data backup block (step S06). The sleep circuit 1 then starts to execute from the state before entering the sleep mode (step S07), and executes the next round of the sleep method when receiving the sleep instruction again.
[0016] The purpose of step S06 is to set the next data backup block of the current data backup block as the current data backup block for the sleep circuit 1 to perform the next round of the sleep method. Figure 3 . If the data backup block 121 is the current data backup block of this round of the sleep method, after the processing unit 13 writes the data Data stored in the data backup block 121 back to the storage unit 11, the processing unit 13 erases the data Data stored in the data backup block 121 and sets the next data backup block 122 of the data backup block 121 as the current data backup block. If the sleep circuit 1 receives a sleep instruction again and needs to execute the next round of the sleep method, the data backup block 122 is the current data backup block of the next round of the sleep method. In some embodiments, the processing unit 13 erases the data Data stored in the current data backup block by setting all the data stored in the current data backup block to 1.
[0017] In some embodiments, all data Data and the first verification value V1 in the storage unit 11 are stored in different storage areas in the data backup block 120. For example, see Figure 3 All data Data in the storage unit 11 are fixedly stored in a storage area 1201 in the data backup block 120, and the first verification value V1 is fixedly stored in a storage area 1202 in the data backup block 120. The storage area 1201 and the storage area 1202 are different storage areas.
[0018] In some embodiments, the processing unit 13 performs a verification calculation on the data Data written into the current data backup block to obtain a first verification value V1 and performs a verification calculation on the data Data stored in the current data backup block to obtain a second verification value. The verification calculation method may be but is not limited to SHA1 verification, SHA256 verification or MD5 verification.
[0019] Because the processing unit 13 has stored all the data Data stored in the storage unit 11 for storing the data of the state before the sleep circuit 1 enters the sleep mode to the current data backup block before the sleep circuit 1 enters the sleep mode. And because the data stored in the flash memory unit 12 will not be lost due to power failure, the data Data can still be completely written back to the storage unit 11 after the sleep mode ends so that the sleep circuit 1 can start to execute from the state before entering the sleep mode. Therefore, the storage unit 11 can also be completely powered off during the sleep period, thereby reducing the power consumption of the sleep circuit 1 during the sleep period and improving the user experience.
[0020] Figure 4 FIG. 1 is a flowchart of another embodiment of a circuit sleep method. Figure 1 , Figure 3 and Figure 4. In some embodiments, each data backup block 120 also records an erasure count EN. The processing unit 13 is also used to determine whether the erasure count EN of the current data backup block exceeds a threshold value when receiving a sleep command (step S11). When the erasure count EN of the current data backup block does not exceed the threshold value, the processing unit 13 writes all the data stored in the storage unit 11 into the current data backup block and performs a verification calculation on the data Data written into the current data backup block to obtain a first verification value V1 and write the first verification value V1 into the current data backup block (step S12). And when the processing unit 13 writes the data Data stored in the current data backup block back to the storage unit 11, the processing unit 13 adds 1 to the erasure count EN of the current data backup block and erases the data Data stored in the current data backup block and sets the next data backup block of the current data backup block as the current data backup block (step S17). In some embodiments, the threshold value is a value less than the maximum erasure count of the flash memory unit 12. In some embodiments, the maximum number of erase and write times of the flash memory unit 12 may be, but is not limited to, 100,000 and the threshold is selected from 90,000 to 100,000. Figure 4 Step S10 in the embodiment corresponds to Figure 2 In the embodiment of the present invention, step S00 is performed, and Figure 4 Steps S13, S14, S15, S16, S17, and S18 in the embodiment correspond to Figure 2 Steps S02, S03, S04, S05, S06, and S07 in the embodiment are not repeatedly described here.
[0021] In some embodiments, all data Data, the first verification value V1 and the erasure count EN in the storage unit 11 are stored in different storage areas in the data backup block 120. For example, see Figure 3 All data Data in the storage unit 11 are fixedly stored in the storage area 1201 in the data backup block 120, the first verification value V1 is fixedly stored in the storage area 1202 in the data backup block 120, and the erasure number EN is fixedly stored in the storage area 1203 in the data backup block 120. The storage area 1201, the storage area 1202 and the storage area 1203 are all different storage areas. In some embodiments, the erasure number EN is stored in the end area of the data backup block 120.
[0022] In order to prevent the current data backup block from reaching its life limit due to excessive erasure times EN, thereby affecting the integrity of the data Data stored in the current data backup block, in some embodiments, the processing unit 13 is also used to determine whether the erasure times of all data backup blocks 120 exceed the threshold value when the erasure times EN of the current data backup block exceeds the threshold value (step S19). If the erasure times of all data backup blocks 120 do not exceed the threshold value, the processing unit 13 sets the next data backup block of the current data backup block as the current data backup block (step S20) and determines whether the erasure times EN of the current data backup block at this time exceeds the threshold value (step S21). When the erasure times EN of the current data backup block at this time does not exceed the threshold value, the processing unit 13 writes all the data stored in the storage unit 11 into the current data backup block and performs verification calculation on the data Data written into the current data backup block to obtain a first verification value V1 and writes the first verification value V1 into the current data backup block (step S12). On the contrary, when the erasing number EN of the current data backup block exceeds the threshold value, the processing unit 13 executes step S19 again. Figure 3 . If the data backup block 121 is the current data backup block, when the erasure count EN of the data backup block 121 exceeds the threshold value, the processing unit 13 determines whether the erasure counts of all data backup blocks 120 exceed the threshold value. If the erasure counts of all data backup blocks 120 do not exceed the threshold value, the processing unit 13 sets the next data backup block 122 of the data backup block 121 as the current data backup block and determines whether the erasure count EN of the data backup block 122 exceeds the threshold value. When the erasure count EN of the data backup block 122 does not exceed the threshold value, the processing unit 13 writes all the data stored in the storage unit 11 into the data backup block 122 and performs a verification calculation on the data Data written into the data backup block 122 to obtain a first verification value V1 and write the first verification value V1 into the data backup block 122. When the erasure count EN of the data backup block 122 exceeds the threshold value, the processing unit 13 determines again whether the erasure counts of all data backup blocks 120 exceed the threshold value. If the erasure times of all data backup blocks 120 do not exceed the threshold, the processing unit 13 sets the next data backup block of the data backup block 122 as the current data backup block and determines whether the erasure times EN of the current data backup block exceeds the threshold. This can prevent the processing unit 13 from storing the data Data in the data backup block 120 that has reached its life limit due to excessive erasure times EN.
[0023] In some embodiments, the processing unit 13 is further configured to not write the data Data in the storage unit 11 into the current data backup block and to power off the sleep circuit 1 except the storage unit 11 so that the sleep circuit 1 except the storage unit 11 enters the sleep mode (step S22) when the erasing and writing times EN of all the data backup blocks 120 exceed the threshold value. In other words, the storage unit 11 at this time is still continuously powered when the sleep circuit 1 is in the sleep period. In some embodiments, the situation in which the processing unit 13 does not write all the data stored in the storage unit 11 into the current data backup block before the sleep circuit 1 enters the sleep mode is the situation in which the sleep circuit 1 executes step S22 (i.e., the erasing and writing times EN of all the data backup blocks 120 exceed the threshold value).
[0024] In some embodiments, when the comparison result of the first verification value V1 and the second verification value is inconsistent, the storage unit 11 has no data stored in the state before the sleep circuit 1 enters the sleep mode due to power failure, and the data stored in the current data backup block has not passed the verification calculation, so that the processing unit 13 cannot write the data stored in the current data backup block back to the storage unit 11, thereby causing the sleep circuit 1 to be unable to start from the state before entering the sleep mode. At this time, the processing unit 13 is also used to reset the sleep circuit 1 (step S23). In some embodiments, please refer to Figure 1 The sleep circuit 1 further includes a specific storage unit 15. Before resetting the sleep circuit 1, the processing unit 13 records the information of the current data backup block at this time (i.e., when the comparison result of the first verification value V1 and the second verification value is inconsistent) in the specific storage unit 15. The processing unit 13 checks whether the current data backup block is the data backup block of the recorded information according to the information recorded in the specific storage unit 15 each time it receives a sleep instruction after the reset. If so, the processing unit 13 sets the next data backup block as the current data backup block. In some embodiments, when the sleep circuit 1 receives the sleep instruction for the first time after the reset, the processing unit 13 sets the next data backup block of the data backup block of the recorded information as the current data backup block according to the information recorded in the specific storage unit 15. In some embodiments, when the sleep circuit 1 receives the sleep instruction for the first time after the reset or after the first power-on, the processing unit 13 sets the first data backup block of the flash memory unit 12 as the current data backup block. In some embodiments, the reason why the comparison result of the first verification value V1 and the second verification value is inconsistent is that the flash memory unit 12 itself has quality defects or the flash memory unit 12 has suffered unexpected physical damage. For example, it is hit by external force, the operating temperature is too high, or it is invaded by foreign objects.
[0025] In some embodiments, the sleep circuit 1 further comprises a register 14. The register 14 stores a backup flag. The processing unit 13 is further configured to set the backup flag to a full value when writing all the data Data stored in the storage unit 11 into the current data backup block.
[0026] In some embodiments, the step of the processing unit 13 determining whether all the data Data stored in the storage unit 11 are written into the current data backup block before the sleep circuit 1 enters the sleep mode includes reading the backup flag stored in the register 14 and determining whether the backup flag is a full value. For example, when the processing unit 13 writes all the data Data stored in the storage unit 11 into the current data backup block, the processing unit 13 sets the backup flag to 1. When the processing unit 13 wants to determine whether all the data Data stored in the storage unit 11 are written into the current data backup block before the sleep circuit 1 enters the sleep mode, the processing unit 13 determines whether the backup flag stored in the register 14 is 1. When the backup flag stored in the register 14 is 1, it means that the processing unit 13 has written all the data Data stored in the storage unit 11 into the current data backup block before the sleep circuit 1 enters the sleep mode. In some embodiments, the data size of the backup flag is one bit. Therefore, it can be seen that in some embodiments, the processing unit 13 only needs to read the backup flag whose data size is one bit stored in the register 14 to know whether all the data Data stored in the storage unit 11 are written into the current data backup block before the sleep circuit 1 enters the sleep mode. The processing unit 13 does not need to read the data stored in the flash memory unit 12 or perform data comparison on the data stored in the flash memory unit 12 to know whether all the data Data stored in the storage unit 11 are written into the current data backup block before the sleep circuit 1 enters the sleep mode.
[0027] In some embodiments, the sleep circuit 1 further includes a register 14. The data backup block 120 further stores a serial number. The register 14 further stores a backup block record value. The processing unit 13 is also used to set the backup block record value to the serial number of the current data backup block when writing all the data Data stored in the storage unit 11 to the current data backup block. For example, if the flash memory unit 12 has 8 data backup blocks 120, the serial numbers of the 8 data backup blocks 120 are 000, 001, 010, 011, 100, 101, 110 and 111 respectively. If the processing unit 13 writes all the data Data stored in the storage unit 11 to the current data backup block, the current data backup block is the data backup block 120 with the serial number 010, and the processing unit 13 sets the backup block record value to 010 at this time. In some embodiments, the data size of the backup block record value can be but is not limited to 3 bits.
[0028] In some embodiments, the processing unit 13 writes the data Data stored in the current data backup block back to the storage unit 11 according to the backup block record value stored in the register 14. For example, when the processing unit 13 determines that all the data Data stored in the storage unit 11 are written into the current data backup block before the sleep circuit 1 enters the sleep mode and the comparison result of the first verification value V1 and the second verification value is consistent, if the backup block record value stored in the register 14 is 010 at this time, the processing unit 13 writes the data Data stored in the data backup block 120 with the serial number 010 back to the storage unit 11 according to the backup block record value stored in the register 14.
[0029] In summary, in some embodiments, the processing unit 13 has stored all the data Data stored in the storage unit 11 for storing the data of the state before the sleep circuit 1 enters the sleep mode to the current data backup block before the sleep circuit 1 enters the sleep mode. And because the data stored in the flash memory unit 12 will not be lost due to power failure, the data Data can still be completely written back to the storage unit 11 after the sleep mode ends so that the sleep circuit 1 can start to execute from the state before entering the sleep mode. Therefore, the storage unit 11 can also be completely powered off during the sleep period, thereby reducing the power consumption of the sleep circuit 1 during the sleep period and improving the user experience. And the processing unit 13 can prevent the situation where the integrity of the data Data stored in the current data backup block is affected by the current data backup block reaching the life limit by comparing the number of erasures EN of each data backup block 120 with the threshold. The processing unit 13 can also know whether all the data Data stored in the storage unit 11 are written into the current data backup block before the sleep circuit 1 enters the sleep mode by only reading the backup flag whose data size is one bit stored in the register 14.
[0030] Although the technical content of this case has been disclosed as above in the form of a preferred embodiment, it is not intended to limit this case. Any slight changes and modifications made by any technical personnel in this field without departing from the spirit of this case should be included in the scope of this case. Therefore, the scope of protection of this case shall be determined by the scope of the attached patent application.
[0031]
Explanation of symbols
[0032] 1: Sleep circuit
[0033] 11: Storage Unit
[0034] 12: Flash memory unit
[0035] 13: Processing Unit
[0036] 14: Register
[0037] 15: Specific storage unit
[0038] S00~S07: Steps
[0039] S10~S19, S20~S23: Steps
[0040] 120~122: Data backup block
[0041] Data:
[0042] V1: First verification value
[0043] EN:Erase and write times
[0044] 1201~1203: Storage area.
Claims
1. A circuit sleep method, the circuit comprising a processing unit, a storage unit and a flash memory unit, the flash memory unit comprising a plurality of data backup blocks, one of the data backup blocks being a current data backup block, the sleep method comprising: When the processing unit receives a sleep instruction, the processing unit writes all data stored in the storage unit into the current data backup block and performs a verification calculation on the data written into the current data backup block to obtain a first verification value and writes the first verification value into the current data backup block; After the processing unit writes the first verification value into the current data backup block, the circuit is powered off to put the circuit into a sleep mode; When the processing unit receives a wake-up instruction when the circuit is in the sleep mode, the processing unit restarts the circuit and determines whether the processing unit has written all the data stored in the storage unit into the current data backup block before the circuit enters the sleep mode; When the processing unit writes all the data stored in the storage unit into the current data backup block before the circuit enters the sleep mode, the processing unit performs a verification calculation on the data stored in the current data backup block to obtain a second verification value and compares the first verification value and the second verification value stored in the current data backup block; When the comparison result of the first verification value and the second verification value is consistent, the processing unit writes the data stored in the current data backup block back to the storage unit; and After the processing unit writes the data stored in the current data backup block back to the storage unit, the processing unit erases the data stored in the current data backup block and sets the next data backup block of the current data backup block as the current data backup block of the next round of the sleep method.
2. The sleep method as claimed in claim 1, wherein each of the data backup blocks also records a number of erase and write times, and the sleep method further comprises: When the processing unit receives the sleep instruction, it determines whether the erasing and writing times of the current data backup block exceeds a threshold value; When the erasure count of the current data backup block does not exceed the threshold, the processing unit writes all the data stored in the storage unit into the current data backup block and performs a verification calculation on the data written into the current data backup block to obtain the first verification value and writes the first verification value into the current data backup block; and After the processing unit writes the data stored in the current data backup block back to the storage unit, the processing unit increases the erase count of the current data backup block by 1, erases the data stored in the current data backup block, and sets the next data backup block of the current data backup block as the current data backup block for the next round of the sleep method.
3. The sleep method according to claim 2, further comprising: When the erasure count of the current data backup block exceeds the threshold, the processing unit determines whether the erasure count of all the data backup blocks exceeds the threshold; when the erasure count of all the data backup blocks does not exceed the threshold, the next data backup block of the current data backup block is set as the current data backup block and a determination is made as to whether the erasure count of the current data backup block at this time exceeds the threshold.
4. The sleep method according to claim 3, further comprising: When the erasing times of all the data backup blocks exceed the threshold, the processing unit does not write all the data stored in the storage unit into the current data backup block and cuts off the power to the circuit except the storage unit to put the circuit except the storage unit into the sleep mode.
5. The sleep method according to claim 4, further comprising: When the comparison result of the first verification value and the second verification value is inconsistent, the processing unit resets the circuit.
6. The sleep method as claimed in claim 5, wherein the circuit further comprises a register storing a backup flag, and the sleep method further comprises: When the processing unit writes all the data stored in the storage unit into the current data backup block, the processing unit sets the backup flag to a full value.
7. The sleep method of claim 6, wherein the step of the processing unit determining whether all data stored in the storage unit is written into the current data backup block before the circuit enters the sleep mode comprises: The processing unit reads the backup flag stored in the register; and The processing unit determines whether the backup flag is a full value. The sleep method as claimed in claim 7 , wherein the threshold is selected from 90,000 to 100,000.
9. A sleep circuit, comprising: a storage unit; a flash memory unit coupled to the storage unit, the flash memory unit comprising a plurality of data backup blocks, one of the data backup blocks being a current data backup block; and A processing unit is coupled to the storage unit and the flash memory unit, and is used for writing all the data stored in the storage unit into the current data backup block when receiving a sleep instruction, and performing a check calculation on the data written into the current data backup block to obtain a first verification value and write the first verification value into the current data backup block. After the processing unit writes the first verification value into the current data backup block, the sleep circuit is powered off to make the sleep circuit enter a sleep mode. When the sleep circuit receives a wake-up instruction in the sleep mode, the processing unit restarts the sleep circuit and determines whether the processing unit has written all the data stored in the storage unit into the current data backup block before the sleep circuit enters the sleep mode. When the processing unit When the unit writes all the data stored in the storage unit into the current data backup block before the sleep circuit enters the sleep mode, the processing unit performs a verification calculation on the data stored in the current data backup block to obtain a second verification value and compares the first verification value and the second verification value stored in the current data backup block. When the comparison result of the first verification value and the second verification value is consistent, the processing unit writes the data stored in the current data backup block back to the storage unit. After the processing unit writes the data stored in the current data backup block back to the storage unit, the processing unit erases the data stored in the current data backup block and sets the next data backup block of the current data backup block as the current data backup block.
10. The sleep circuit as described in claim 9, each data backup block also records an erase count, and the processing unit is also used to determine whether the erase count of the current data backup block exceeds a threshold when receiving the sleep instruction. When the erase count of the current data backup block does not exceed the threshold, the processing unit writes all the data stored in the storage unit into the current data backup block and performs a verification calculation on the data written into the current data backup block to obtain the first verification value and write the first verification value into the current data backup block, and after the processing unit writes the data stored in the current data backup block back to the storage unit, the processing unit adds 1 to the erase count of the current data backup block and erases the data stored in the current data backup block and sets the next data backup block of the current data backup block as the current data backup block.
