Computer system and method for energy management thereof

CN122963632APending Publication Date: 2026-10-23AMLOGIC (SHANGHAI) CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510484104.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-04-16
Publication Date
2026-10-23

AI Technical Summary

Technical Problem

[0003]一方面,用户对设备性能的要求不断提高,例如更快的处理速度、更高清的显示效果、更强大的功能等,这些都会导致系统能耗增加

Benefits of technology

[0031]在本发明实施例中,通过提前保存CPU工作寄存器的返回地址(RA)寄存器的信息,能够使得计算机系统实现CPU掉电,携带操作系统进入第一睡眠模式(即超深度睡眠),然后在唤醒阶段,通过至少恢复RA寄存器,并返回下一条指令地址至所述RA寄存器,可以恢复睡眠前状态,相比于不作任何处理就直接掉电导致信息丢失,采用上述方案,可以在实现超深度睡眠的基础上,准确地、无缝衔接地恢复睡眠前状态,实现软件对超深度睡眠过程及唤醒过程的无感。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122963632A_ABST
    Figure CN122963632A_ABST
Patent Text Reader

Abstract

The embodiment of the present application provides a computer system and an energy consumption management method thereof, the method comprising: saving first information before entering a first sleep mode, wherein the first information at least comprises information of a RA register of a CPU working register; entering the first sleep mode, wherein the first sleep mode at least comprises controlling CPU power-off; and in response to being woken up from the first sleep mode, at least restoring the RA register of the CPU working register and returning a next instruction address to the RA register to restore a pre-sleep state. The present application can accurately and seamlessly restore the pre-sleep state on the basis of realizing ultra-deep sleep, and realizes that software in the computer system is not aware of the ultra-deep sleep process and the wake-up process.
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 computer system and its energy management method. Background Technology

[0002] With the rapid development of the mobile internet, battery-powered computer systems, such as smartphones, tablets, laptops, wearable devices, and various embedded systems, are widely used in various fields such as daily life, industrial production, and healthcare due to their portability and flexibility.

[0003] On the one hand, users are constantly demanding higher device performance, such as faster processing speeds, higher-definition displays, and more powerful functions, all of which lead to increased system power consumption. On the other hand, users also want devices to have longer battery life, reduce charging frequency, and improve ease of use.

[0004] There is an urgent need for an energy management method to reduce the energy consumption of computer systems. Summary of the Invention

[0005] In view of this, embodiments of this application provide a computer system and its energy management method, which can accurately and seamlessly restore the pre-sleep state on the basis of achieving ultra-deep sleep, so that the software in the computer system is unaware of the ultra-deep sleep process and the wake-up process.

[0006] To achieve the above objectives, the embodiments of this application provide the following technical solutions.

[0007] In a first aspect, embodiments of this application provide a power management method for a computer system, comprising: before entering a first sleep mode, saving first information, the first information including at least information of the RA register of the CPU working register, the first sleep mode including at least controlling the CPU to power down; entering the first sleep mode; in response to being woken up from the first sleep mode, at least restoring the RA register of the CPU working register, and returning the address of the next instruction to the RA register to restore the state before sleep.

[0008] Optionally, the first information further includes: task stack information and system stack information; the step of responding to being woken up from the first sleep mode and at least restoring the RA register of the CPU working register includes: restoring the saved system stack information before restoring the RA register of the CPU working register; and after restoring the RA register of the CPU working register, switching the system stack to the task stack and restoring the saved task stack information.

[0009] Optionally, the operating system of the computer system is configured as event-driven; wherein the event-driven configuration is used to indicate that the system will automatically return to an idle task state when no event is generated.

[0010] Optionally, the method includes: the first sleep mode is entered after entering an idle task state, detecting whether a preset sleep condition is met, and in response to determining that the preset sleep condition is met, entering the sleep mode according to the interval between the trigger time of the current event and the next event; wherein the interval is within a first preset time range.

[0011] Optionally, the detection of whether the preset sleep conditions are met includes: determining that the preset sleep conditions are met when it is determined that there are no running events in the task stack and / or system stack; and determining that the preset sleep conditions are not met when it is determined that there are running events in the task stack and / or system stack.

[0012] Optionally, the method further includes: entering a second sleep mode, the second sleep mode being used to instruct a first hardware group other than the CPU to power down, the power of each hardware component in the first hardware group being greater than a first power threshold; wherein, the second sleep mode is entered after entering an idle task state, detecting whether a preset sleep condition is met, and in response to determining that the preset sleep condition is met, entering the second sleep mode within a second preset time range based on the interval between the trigger time of the current event and the next event, the upper limit of the second preset time range being less than the lower limit of the first preset time range.

[0013] Optionally, the method further includes: entering a third sleep mode, the third sleep mode being used to instruct at least a portion of the first hardware group and other hardware, excluding the CPU, to power down; wherein, the third sleep mode is entered after entering an idle task state, detecting whether a preset sleep condition is met, and in response to determining that the preset sleep condition is met, entering within a third preset time range based on the interval between the trigger time of the current event and the next event, wherein the upper limit of the third preset time range is less than or equal to the lower limit of the first preset time range, and the lower limit of the third preset time range is greater than or equal to the upper limit of the second preset time range.

[0014] Optionally, the task stack information includes a task stack pointer; and / or, the system stack information includes a system stack pointer.

[0015] Optionally, the method further includes: saving business timer information before entering the first sleep mode.

[0016] Optionally, saving the service timer information includes saving the sleep time of the service timer.

[0017] Optionally, in response to being woken up from the first sleep mode, the method further includes: restoring the service timer to the pre-sleep state.

[0018] Optionally, restoring the service timer to the pre-sleep state includes: adding the timing duration of the sleep timer to the saved sleep time of the service timer to obtain the pre-sleep state of the service timer; wherein the sleep timer is a timer running in the sleep mode.

[0019] Optionally, the method may further include disabling global interrupts before entering the first sleep mode.

[0020] Optionally, the method further includes: initializing all CPU interrupts.

[0021] Optionally, initializing all CPU interrupts includes: initializing the CPU clock signal; enabling CPU interrupts.

[0022] Optionally, the operating system of the computer system is FreeRTOS.

[0023] Secondly, embodiments of this application provide a computer system, including: a terminal, the terminal including a memory and a processor, the memory storing a computer program that can run on the processor, and the processor executing the steps of the above-described power management method for the computer system when running the computer program.

[0024] Optionally, the computer system further includes: an external bus wake-up source; and a power management unit, which, after being woken up by the external bus wake-up source, powers on the terminal.

[0025] Thirdly, embodiments of this application also provide a computer-readable storage medium having a computer program stored thereon, wherein when the computer program is run by a processor, the energy management method provided in the first aspect is executed.

[0026] Fourthly, embodiments of this application provide a computer program product, the computer program product including a computer program, which, when run on a computer, causes the computer to execute the energy management method of the first aspect.

[0027] Fifthly, embodiments of this application provide a chip (or communication device) storing a computer program, which, when executed by the chip, causes the energy management method provided in the first aspect to be executed.

[0028] In a sixth aspect, embodiments of this application provide a chip module on which a computer program is stored. When the computer program is executed by the chip module, the energy management method provided in the first aspect is executed.

[0029] In a seventh aspect, embodiments of this application provide a communication system, the communication system including means for performing the method provided in the first aspect.

[0030] Compared with the prior art, the technical solution of the embodiments of the present invention has the following beneficial effects:

[0031] In this embodiment of the invention, by pre-saving the information of the return address (RA) register of the CPU working register, the computer system can achieve CPU power-off, carry the operating system into the first sleep mode (i.e., ultra-deep sleep), and then in the wake-up phase, by restoring at least the RA register and returning the address of the next instruction to the RA register, the pre-sleep state can be restored. Compared with directly powering off without any processing, resulting in information loss, the above scheme can accurately and seamlessly restore the pre-sleep state on the basis of achieving ultra-deep sleep, so that the software is unaware of the ultra-deep sleep process and the wake-up process. Attached Figure Description

[0032] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of this application. For those skilled in the art, other drawings can be obtained based on the provided drawings without creative effort.

[0033] Figure 1 This is a flowchart illustrating an energy management method for a computer system according to an embodiment of the present invention;

[0034] Figure 2 This is a flowchart illustrating a method for saving first information according to an embodiment of the present invention;

[0035] Figure 3 This is a flowchart illustrating a method for entering a first sleep mode according to an embodiment of the present invention;

[0036] Figure 4 This is a flowchart illustrating a method for waking up from a first sleep mode according to an embodiment of the present invention;

[0037] Figure 5 This is a schematic diagram of the structure of a computer system according to an embodiment of the present invention. Detailed Implementation

[0038] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.

[0039] As mentioned earlier, for battery-powered computer systems, battery life is a key factor affecting user experience, thus necessitating a reduction in the energy consumption of battery-powered computer systems.

[0040] Research has revealed that in one energy management method, without powering down the Central Processing Unit (CPU), the CPU, carrying the operating system (OS), enters sleep mode. In this state, the CPU can be considered to be in a halted state, thus achieving the effect of waking up from a low-power state and continuing in the same location. In other words, the CPU can resume operation simply by reading the pointer from the halted state.

[0041] Further research revealed that although the CPU did not lose power in the above solution, there was still additional leakage current, depending on the amount of leakage current of the CPU. In some scenarios where the CPU leakage current is high, it is still difficult to meet the requirements.

[0042] Research has revealed another energy management method applicable to single-task systems. The CPU does not enter sleep mode with the operating system. Although the CPU itself loses power, because it is a single-task system, the CPU does not need to save anything. It can be powered on directly and run from scratch. Reinitializing the CPU will restore operation.

[0043] Further research revealed that, because the above solution is a single-task system, it lacks an operating system and is only suitable for smaller embedded systems. Specifically, without an operating system to assist in task management and scheduling, the system suffers from poor hierarchical structure and real-time performance in complex systems. It is highly likely that some processing will be delayed, requiring an increase in CPU frequency, thus increasing power consumption. Furthermore, it lacks flexibility in low-power design, easily wasting a significant amount of time and further increasing power consumption, ultimately failing to meet the requirements.

[0044] In this embodiment of the invention, by pre-saving the information of the return address (RA) register of the CPU working register, the computer system can achieve CPU power-off, carry the operating system into the first sleep mode (i.e., ultra-deep sleep), and then in the wake-up phase, by restoring at least the RA register and returning the address of the next instruction to the RA register, the pre-sleep state can be restored. Compared with directly powering off without any processing, resulting in information loss, the above scheme can accurately and seamlessly restore the pre-sleep state on the basis of achieving ultra-deep sleep, so that the software is unaware of the ultra-deep sleep process and the wake-up process.

[0045] To make the above-mentioned objectives, features and beneficial effects of the present invention more apparent and understandable, specific embodiments of the present invention will be described in detail below with reference to the accompanying drawings.

[0046] Reference Figure 1 , Figure 1 This is a flowchart illustrating an energy management method for a computer system according to an embodiment of the present invention. The method can be used in a computer system and may further include:

[0047] Step S11: Before entering the first sleep mode, save the first information, which includes at least the information of the RA register of the CPU working register, and the first sleep mode includes at least controlling the CPU to power down.

[0048] Step S12: Enter the first sleep mode;

[0049] Step S13: In response to being woken up from the first sleep mode, at least the RA register of the CPU working register is restored, and the address of the next instruction is returned to the RA register to restore the pre-sleep state.

[0050] In a specific implementation of step S11, the computer system may include a terminal and an external device for waking up the terminal.

[0051] In some embodiments, the operating system of the computer system may be configured as event-driven; wherein the event-driven configuration is used to indicate that the system will automatically return to the idle task state when no event is generated.

[0052] Specifically, it is only entered when the system is idle during the idle task state, so it does not occupy system resources.

[0053] Specifically, during the device's lifecycle from power-on to power-off, it spends the vast majority of its time in a dormant state. In this embodiment of the invention, the operating system is configured to be event-driven; if no event-driven event occurs, it automatically enters a low-power system to execute low-power strategies.

[0054] In this embodiment of the invention, by designing the operating system as event-driven, tasks are only triggered to run when an event occurs, without time slice rotation. When there are no events, the system always returns to the idle task state. Under the same battery power conditions, the battery can work for a longer time, extending battery life and enhancing the user experience.

[0055] In some embodiments, the operating system of the computer system is FreeRTOS.

[0056] Specifically, FreeRTOS is an open-source, free, and lightweight real-time operating system (RTOS) designed specifically for embedded systems. It features high portability, low cost, and enhanced system reliability.

[0057] By combining with FreeRTOS, embodiments of the present invention have the potential to be adapted to any battery-powered system, disabling interrupts as needed before sleep and enabling interrupts after waking up.

[0058] In some embodiments, the first information may further include: task stack information and system stack information.

[0059] The task stack is a private stack space used during task execution to store task context information and function calls. The system stack is a global stack space used by the operating system kernel, primarily for interrupt handling and kernel function calls.

[0060] In one specific embodiment, the task stack information includes: a task stack pointer; and / or, the system stack information includes: a system stack pointer.

[0061] It should be noted that task stack information can also contain other appropriate information besides pointers, and similarly, system stack information can also contain other appropriate information besides pointers.

[0062] Specifically, since the system is in an idle task when it enters deep sleep, it is necessary to save the task stack pointer to the retention memory, such as the Random Access Memory (RAM).

[0063] It should be noted that in one specific implementation, the CPU carries the OS into deep sleep and the CPU loses power to obtain lower power consumption. In user mode, without any processing, the CPU loses power directly in the task stack. When the CPU wakes up and powers on, it is easy to lose information.

[0064] Research revealed that during CPU power outages, the device automatically operates in machine mode, using the system stack for its code. In user mode, within the task stack environment, upon waking from machine mode and the system stack after a power outage, the software inevitably cannot return to idle tasks. Considering the numerous intermediate states of business execution, the system cannot restart the operating system, making it prone to malfunctions.

[0065] In one specific embodiment of the present invention, before entering deep sleep, the software first obtains the current task stack pointer (sp) in the idle task and saves it to the task control block (TCB), and then switches from user mode to machine mode.

[0066] Reference Figure 2 , Figure 2 This is a flowchart illustrating a method for saving first information according to an embodiment of the present invention. The method may include steps S21 to S26. The steps are described below.

[0067] In step S21, the task stack pointer is stored.

[0068] Specifically, since the system enters deep sleep under idle tasks, the task stack pointer is first saved to reserved storage space.

[0069] In step S22, the task stack is switched to the system stack.

[0070] In some specific implementations, switching from user mode to machine mode involves switching from the task stack to the system stack.

[0071] More specifically, since the task stack and system stack may switch at any time during system operation—for example, when software enters an interrupt, it works on the system stack, while when a task is running, it works on the task stack—it is necessary to store the pointer to the system stack.

[0072] In step S23, a stack space of a specified size is requested based on the current pointer.

[0073] Specifically, allocate a space in reserved storage space (such as reserved RAM) to store the CPU working registers.

[0074] In step S24, the updated pointer is stored in the specified storage address.

[0075] Specifically, the updated pointer is the system stack pointer, and the system stack pointer is stored in reserved storage space (such as reserved RAM).

[0076] In step S25, the value of the working register is stored in the specified stack space.

[0077] Furthermore, the value of the working register may include information from the CPU working register's return address (RA) register.

[0078] Specifically, the RA register can be stored and used as the return value of the PC pointer.

[0079] In practice, since the CPU loses power, it is necessary to save the CPU's working registers, including the important RA register, so that execution can continue when returning to the idle task sleep position.

[0080] In step S26, the status register is stored again.

[0081] Specifically, by storing the status register, functions such as disabling global interrupts can be implemented, thereby turning off the CPU's ability to respond to all maskable interrupts, which helps prepare for entering a low-power mode.

[0082] It should be noted that other contents in the CPU working registers besides the RA register can also be stored, as well as other appropriate registers.

[0083] Continue to refer to Figure 1 In step S12, the first sleep mode is entered.

[0084] In some embodiments, the first sleep mode is entered after entering an idle task state, detecting whether a preset sleep condition is met, and in response to determining that the preset sleep condition is met, entering the sleep mode according to the interval between the triggering time of the current event and the next event; wherein the interval is within a first preset time range.

[0085] In this embodiment of the invention, business processes can be divided into modules, and a voting mechanism can be provided, whereby completed representatives can sleep, while running representatives cannot sleep.

[0086] In one specific embodiment, the step of detecting whether the preset sleep conditions are met may include: determining that the preset sleep conditions are met when it is determined that there are no running events in the task stack and / or system stack; and determining that the preset sleep conditions are not met when it is determined that there are running events in the task stack and / or system stack.

[0087] In practice, in response to the voting result that sleep is not possible, the software can return to the idle task and execute Wait for interrupt (WFI) in all cases.

[0088] Furthermore, in response to the inability to sleep, the CPU frequency can be reduced to lower system power consumption. This allows for minimizing power consumption by reducing the CPU frequency when preset sleep conditions are not met and the CPU cannot be powered off.

[0089] In some embodiments, when it is determined that the preset sleep conditions are met, a voting mechanism can be set to calculate the sleep time based on the possible trigger time of the next service, and the system can decide to enter different low-power modes based on the length of the sleep time.

[0090] In one specific implementation, it can be determined first whether a shorter interval is met, and then whether a longer interval is met, and enter a lighter type of sleep within the shorter interval and a longer type of sleep within the longer interval.

[0091] In a second specific implementation, it can be determined first whether a shorter interval is met, and then whether a longer interval is met. The longer interval is used to enter a longer type of sleep, and the shorter interval is used to enter a lighter type of sleep.

[0092] In the third specific implementation, a preset time range corresponding to each sleep mode can be pre-set, and the corresponding sleep mode can be selected by determining which preset time range the interval time falls into.

[0093] It should be pointed out that, Figure 3 The illustration shows a specific embodiment that combines the second and third specific embodiments, but is not limited thereto.

[0094] Reference Figure 3 , Figure 3 This is a flowchart illustrating a method for entering a first sleep mode according to an embodiment of the present invention. The method may include steps S301 to S310, which are described below.

[0095] In step S301, the idle task state is entered.

[0096] Specifically, the computer system's operating system can be configured to be event-driven, automatically returning to an idle task state when no events occur.

[0097] In some embodiments, the first sleep mode to the third sleep mode are entered after entering the idle task state.

[0098] In step S302, global interrupts can be disabled.

[0099] Disabling global interrupts means turning off the CPU's ability to respond to all maskable interrupts by manipulating the CPU's status register.

[0100] In this embodiment of the invention, disabling global interrupts before entering the first sleep mode can be used to protect critical sections or prepare for entering a low-power mode.

[0101] In step S303, it is determined whether the preset sleep conditions are met. If the determination result is yes, step S305 can be executed; otherwise, step S304 can be executed.

[0102] The determination of preset sleep conditions can be referred to in the previous text and the relevant description of step S12, and will not be repeated here.

[0103] In some embodiments, an idle task mode and three sleep modes can be defined to manage different low-power modes.

[0104] The sleep patterns are divided into three modes: first sleep (deep sleep, also known as ultra-deep sleep), second sleep (light sleep, also known as light sleep), and third sleep (sleep, also known as deep sleep).

[0105] In one specific embodiment, the CPU can be powered down in the first sleep mode, and almost the entire chip is powered down; the second and third sleep modes have different degrees of power loss, but the CPU is not powered down, and only enters the sleep mode built into the CPU itself.

[0106] In step S304, the idle task mode is activated.

[0107] In some embodiments, the idle task mode may include: performing WFI, dividing clock (DIVCLK), clock gating (CLK gating), and enabling global interrupts (enable global int).

[0108] In step S305, it is determined whether the preset conditions for entering the second sleep mode are met. If the determination result is yes, step S306 can be executed; otherwise, step S307 can be executed.

[0109] In step S306, the second sleep mode, also known as light sleep or light sleep mode, is...

[0110] In some embodiments, the second sleep mode can be used to instruct a first hardware group other than the CPU to power down, wherein the power of each hardware component in the first hardware group is greater than a first power threshold.

[0111] The power of the hardware can be its rated operating power or a power determined based on the application scenario.

[0112] In a non-limiting specific embodiment, the value of the first power threshold can be selected from [0.1W, 10W].

[0113] The second sleep mode is entered after entering the idle task state, detecting whether the preset sleep conditions are met, and in response to determining that the preset sleep conditions are met, entering the second sleep mode within a second preset time range based on the interval between the current event and the trigger time of the next event. The upper limit of the second preset time range is less than the lower limit of the first preset time range.

[0114] In practice, the first preset time range of the first sleep mode when the CPU is powered off is the longest, and its lower limit is also relatively large.

[0115] In some embodiments, the second sleep mode may include: physical (PHY) / radio frequency (RF) power-off, clock threshold (CLK gating), and CPU WFI.

[0116] The power-down of the physical layer (PHY) can be used to indicate that the physical layer has entered a low-power mode or has been completely powered off.

[0117] In this embodiment of the invention, by setting an appropriate second preset time range and hardware with appropriate power, it is possible to control the hardware with higher power consumption to enter sleep mode, thereby meeting the low power consumption requirement to a certain extent.

[0118] In step S307, it is determined whether the preset conditions for entering the third sleep mode are met. If the determination result is yes, step S308 can be executed; otherwise, step S309 can be executed.

[0119] In step S308, the third sleep mode, also known as deep sleep or deep sleep mode, is...

[0120] In some embodiments, the third sleep mode is used to instruct at least a portion of the first hardware group and other hardware, excluding the CPU, to be powered down.

[0121] In this system, the power of each hardware component in the first hardware group is greater than the first power threshold, and the other hardware components are all hardware components other than the CPU and the first hardware group, which are partially or completely powered off in the third sleep mode.

[0122] For more information on the first power threshold, please refer to the preceding text and the description of step S306; it will not be repeated here.

[0123] The third sleep mode is entered after entering an idle task state, detecting whether a preset sleep condition is met, and in response to determining that the preset sleep condition is met, entering the sleep mode within a third preset time range based on the interval between the current event and the trigger time of the next event. The upper limit of the third preset time range is less than or equal to the lower limit of the first preset time range, and the lower limit of the third preset time range is greater than or equal to the upper limit of the second preset time range.

[0124] In practice, the first preset time range of the first sleep mode when the CPU is powered off is the longest, and its lower limit is also larger. Next is the third sleep mode, and then the second sleep mode. That is, the second preset time range of the second sleep mode is the shortest, and its upper limit is also smaller.

[0125] In some embodiments, the third sleep mode may include: MAC power-down / physical (PHY) / radio frequency (RF) power-down, clock threshold (CLK gating), and CPU WFI.

[0126] The power-down of the Media Access Control Address (MAC) can be used to indicate that the MAC layer has entered a low-power mode or has been completely powered off.

[0127] In this embodiment of the invention, by setting an appropriate third preset time range, most hardware except the CPU can be controlled to enter sleep mode, thereby meeting the low power consumption requirement to a greater extent.

[0128] In step S309, it is determined whether the preset conditions for entering the first sleep mode are met. If the determination result is yes, step S310 can be executed.

[0129] It should be noted that in the embodiments of the present invention, if the conditions for entering the preset first sleep mode are not met, the subsequent execution steps may not be specifically restricted.

[0130] In some embodiments, if the conditions for entering the preset first sleep mode are not met, the system may return to the idle task mode, or return to the third sleep mode, or return to the second sleep mode, or enter other appropriate working modes.

[0131] In step S310, the first sleep mode, also known as ultra-deep sleep or ultra-deep sleep mode, is...

[0132] In some embodiments, the first sleep mode is used to indicate that the CPU is powered down, the entire chip is almost completely powered down, that is, most of the hardware is powered down.

[0133] Continue to refer to Figure 1In step S13, in response to being woken up from the first sleep mode, at least the RA register of the CPU working register is restored, and the address of the next instruction is returned to the RA register to restore the pre-sleep state.

[0134] In practice, due to the need for extremely low standby power consumption, the CPU is powered off, and the system stack, task stack, working registers, etc. are all stored in the reserved storage space and restored sequentially after being woken up.

[0135] It should be noted that regardless of the low-power mode, the software implements the "sleep and wake up" function, meaning that the software resumes execution from the point where it entered sleep mode. However, in ultra-low-power mode, since the CPU has completely lost power, only a few wake-up sources are maintained. Therefore, the solution in this embodiment of the invention requires a special wake-up step based on the CPU power failure situation.

[0136] In some embodiments, the step of at least restoring the RA register of the CPU working register in response to being woken up from the first sleep mode may include: restoring saved system stack information before restoring the RA register of the CPU working register; and after restoring the RA register of the CPU working register, switching the system stack to the task stack and restoring saved task stack information.

[0137] Specifically, in order to achieve a seamless transition between sleep and wake-up, the task stack and system stack can be saved, as well as the PC return value.

[0138] More specifically, when the CPU is powered off, the software can still wake up from where it was sleeping. In order to make the software unaware of the wake-up process, the software must return to the idle task state after waking up and return to the position where it entered sleep to continue executing the code.

[0139] It should be noted that even if the PC pointer is stored, the software cannot actually obtain it directly. In this embodiment of the invention, when the CPU runs and calls a function, it stores the address of the current function in the RA register. When the function returns, it assigns RA to the PC, and then the PC is automatically incremented by N bytes before starting to execute the next instruction. In other words, the PC pointer is obtained instead of the RA register. Here, N is a positive integer.

[0140] In one specific embodiment, N=4, so RA can be stored, and upon waking up, RA can be directly incremented by 4.

[0141] In this embodiment of the invention, by pre-saving the information of the return address (RA) register of the CPU working register, the computer system can achieve CPU power-off, carry the operating system into the first sleep mode (i.e., ultra-deep sleep), and then in the wake-up phase, by restoring at least the RA register and returning the address of the next instruction to the RA register, the pre-sleep state can be restored. Compared with directly powering off without any processing, resulting in information loss, the above scheme can accurately and seamlessly restore the pre-sleep state on the basis of achieving ultra-deep sleep, so that the software is unaware of the ultra-deep sleep process and the wake-up process.

[0142] In some embodiments, the order of recovery after wake-up can be as follows: first, retrieve the stored system stack pointer, then restore the working registers, including RA. Then, switch from machine mode to user mode. Restoring RA and switching modes are crucial steps. In user mode, restore the previously stored task stack pointer, then increment RA by N and return to the initial sleep position to continue code execution.

[0143] For details, please refer to Figure 4 , Figure 4 This is a flowchart illustrating a method for waking up from a first sleep mode according to an embodiment of the present invention. The method may include steps S41 to S46, which are described below.

[0144] In step S41, the stored system stack is restored.

[0145] In step S42, the working registers are restored sequentially from the positions pointed to by the pointer.

[0146] Specifically, the stored system stack pointer can be obtained first, and then the working registers, including the RA register, can be restored.

[0147] In step S43, the status register is restored.

[0148] In step S44, the system stack pointer is updated to the position before sleeping.

[0149] In step S45, the system stack is switched to the task stack, and the current system stack pointer is saved to the specified register.

[0150] Specifically, you can switch from machine mode to user mode.

[0151] In step S46, the terminal is restored and the size of the address range to be skipped is added.

[0152] Specifically, in user mode, the previously stored task stack pointer is restored, and then the RA register can be manipulated, plus the size of the address segment to be skipped (RA to be restored plus N). After returning, the user can return to the initial sleep position and continue executing the code.

[0153] In some embodiments, the method further includes: saving service timer information before entering the first sleep mode.

[0154] Furthermore, the step of saving the service timer information may include: saving the sleep time of the service timer.

[0155] In this embodiment of the invention, saving the service timer information, especially the sleep time of the service timer, helps to return accurately.

[0156] In one specific embodiment, in response to being woken up from the first sleep mode, the method may further include: restoring the service timer to the pre-sleep state.

[0157] Furthermore, restoring the service timer to the pre-sleep state includes: adding the timing duration of the sleep timer to the saved sleep time of the service timer to obtain the pre-sleep state of the service timer; wherein the sleep timer is a timer running in the sleep mode.

[0158] In this embodiment of the invention, a timer is set to run in sleep mode.

[0159] Furthermore, the timer running in sleep mode can be a real-time clock timer (RTC timer).

[0160] RTC is a standalone hardware module that can provide accurate time and date information. It can also be used as an external timer for the CPU in conjunction with internal CPU timers (such as SysTick) to meet the system's time management needs.

[0161] In one specific embodiment, a 32K RTC timer can be used as the internal wake-up source.

[0162] In some embodiments, before entering the first sleep mode, the method may further include: disabling global interrupts. For example, see the preceding text and... Figure 3 The proposed solution is shown.

[0163] After being awakened from the first sleep mode, it may also include: initializing all CPU interrupts.

[0164] Furthermore, the step of initializing all CPU interrupts may include: initializing the CPU clock signal; enabling CPU interrupts.

[0165] In this embodiment of the invention, the CPU interrupt state can be restored by initializing the CPU clock signal and enabling CPU interrupts.

[0166] It should be noted that initializing all CPU interrupts after disabling global interrupts can also include other appropriate operations, such as configuring the interrupt controller and setting the interrupt vector table.

[0167] In this embodiment of the invention, the operation of initializing all CPU interrupts after disabling global interrupts ensures that the system can operate stably and efficiently after re-enabling global interrupts, while avoiding interrupt conflicts or data corruption. This further guarantees the implementation of low-power functions.

[0168] In some embodiments, in response to being woken up from the first sleep mode, the method further includes one or more of the following: restoring RF, restoring MAC, restoring PHY, and restoring other power-down components.

[0169] In some embodiments, after being awakened from the first sleep mode (or the second sleep mode or the third sleep mode), one can return to the idle task state.

[0170] In one specific embodiment, after returning to the idle task state, the method may further include: reinitializing the CPU's built-in time base (Tick), which is a timer used for OS scheduling; and re-enabling CPU interrupts to ensure that service interrupts can be opened normally.

[0171] Specifically, in an operating system, a tick can be a periodic time interrupt generated by a system timer, used to drive functions such as task scheduling, time management, and timeout handling in the operating system. The CPU's built-in tick usually refers to a periodic interrupt signal generated by a hardware timer (such as SysTick) inside the CPU.

[0172] In this embodiment of the invention, by setting the above two steps after returning to the idle task state, it can be ensured that the interrupt is enabled only after everything else has been restored.

[0173] It should be noted that, in this embodiment of the invention, an external wake-up source can be set to improve wake-up reliability.

[0174] Reference Figure 5 , Figure 5 This is a schematic diagram of the structure of a computer system according to an embodiment of the present invention.

[0175] The computer system may include a terminal, which may include a memory and a processor. The memory stores a computer program that can run on the processor. When the processor runs the computer program, it executes the steps of the above-described computer system energy management method.

[0176] In some embodiments, the terminal may include an RTC timer 51 and a retention memory (Retention MEM) 54.

[0177] Furthermore, the RTC timer 51 can be a timer with a lower precision than the service timer.

[0178] In one specific embodiment, it can be a 32K RTC timer.

[0179] Specifically, since the business timer is a high-precision timer and the sleep timer is a 32K low-precision timer, the high-precision timer and the 32K timer need to be synchronized and saved before entering sleep mode, and the 32K timer and the high-precision timer need to be synchronized and restored after waking up. This synchronization algorithm can be implemented in hardware or software.

[0180] Furthermore, the reserved storage space 54 can be reserved RAM.

[0181] For more information on RTC timers and reserved RAM, please refer to the previous text and... Figures 1 to 4 The explanation will not be repeated here.

[0182] In some embodiments, the computer system may further include: an external bus wake-up source 52; and a power management unit 53, which, after being woken up by the external bus wake-up source, powers on the terminal.

[0183] Specifically, an independent power management unit 53 can be set up. This power management unit 53 supports wake-up from the RTC timer 51 and external bus wake-up sources. After being woken up, the power management unit 53 sequentially powers on each power source of the chip.

[0184] In some embodiments, the system needs to maintain a minimum power supply unit for ultra-low power consumption. The lower the operating voltage of this power supply unit, the better, for example, it can operate at 0.7 to 0.9V.

[0185] The above embodiments can be implemented in whole or in part by software, hardware, firmware or any other combination thereof.

[0186] Computer systems can be placed in devices such as mobile phones, computers, tablets, in-vehicle terminals, and wearable devices, but are not limited to these.

[0187] In some embodiments, the device to which the computer system belongs may be a WIFI device or a Bluetooth device, such as a Bluetooth Low Energy device.

[0188] While the embodiments disclosed above are described in this application, this application is not limited thereto. Any person skilled in the art can make various modifications and alterations without departing from the spirit and scope of this application; therefore, the scope of protection of this application should be determined by the scope defined in the claims.

Claims

1. A method for energy consumption management of a computer system, characterized in that, include: Before entering the first sleep mode, first information is saved. The first information includes at least the information of the RA register of the CPU working register. The first sleep mode includes at least controlling the CPU to power down. Enter the first sleep mode; In response to being awakened from the first sleep mode, at least the RA register of the CPU working register is restored, and the address of the next instruction is returned to the RA register to restore the pre-sleep state.

2. The energy consumption management method according to claim 1, characterized in that, The first information also includes: task stack information and system stack information; The response to being woken up from the first sleep mode, at least restoring the RA register of the CPU working register, includes: Before restoring the RA register of the CPU working register, the saved system stack information is restored; after restoring the RA register of the CPU working register, the system stack is switched to the task stack, and the saved task stack information is restored.

3. The energy management method according to claim 1, characterized in that, The computer system's operating system is configured as event-driven; The event-driven approach is used to indicate that the system will automatically return to the idle task state when no events are generated.

4. The energy management method according to claim 1, characterized in that, The method includes: The first sleep mode is entered after entering the idle task state, checking whether the preset sleep conditions are met, and in response to determining that the preset sleep conditions are met, entering the sleep mode according to the interval between the current event and the trigger time of the next event. The interval time is within a first preset time range.

5. The energy management method according to claim 4, characterized in that, The detection of whether preset sleep conditions are met includes: If it is determined that there are no running events in the task stack and / or system stack, the preset sleep conditions are met; if it is determined that there are running events in the task stack and / or system stack, the preset sleep conditions are not met.

6. The energy management method according to claim 4, characterized in that, The method further includes: Enter the second sleep mode, which is used to indicate and control the power down of the first hardware group other than the CPU, and the power of each hardware component in the first hardware group is greater than a first power threshold. The second sleep mode is entered after entering the idle task state, detecting whether the preset sleep conditions are met, and in response to determining that the preset sleep conditions are met, entering the second preset time range according to the interval between the current event and the trigger time of the next event, where the upper limit of the second preset time range is less than the lower limit of the first preset time range.

7. The energy management method according to claim 6, characterized in that, The method further includes: Entering a third sleep mode, the third sleep mode being used to instruct at least a portion of the first hardware group and other hardware, excluding the CPU, to power down. The third sleep mode is entered after entering an idle task state, detecting whether a preset sleep condition is met, and in response to determining that the preset sleep condition is met, entering the sleep mode within a third preset time range based on the interval between the current event and the trigger time of the next event. The upper limit of the third preset time range is less than or equal to the lower limit of the first preset time range, and the lower limit of the third preset time range is greater than or equal to the upper limit of the second preset time range.

8. The energy management method according to claim 2, characterized in that, The task stack information includes: a task stack pointer; And / or, the system stack information includes: a system stack pointer.

9. The energy management method according to claim 1, characterized in that, The method further includes: Before entering the first sleep mode, save the business timer information.

10. The energy consumption management method according to claim 9, characterized in that, The information about saving the service timer includes: Save the sleep time of the aforementioned service timer.

11. The energy consumption management method according to claim 10, characterized in that, In response to being awakened from the first sleep mode, the method further includes: Restore the service timer to the state before sleep.

12. The energy management method according to claim 11, characterized in that, Restoring the service timer to the pre-sleep state includes: Add the sleep timer duration to the saved sleep timer to obtain the pre-sleep state of the business timer; The sleep timer is a timer that runs in the sleep mode.

13. The energy management method according to claim 1, characterized in that, Before entering the first sleep mode, it also includes: Disable global interrupts.

14. The energy management method according to claim 13, characterized in that, Also includes: Initialize all CPU interrupts.

15. The energy management method according to claim 14, characterized in that, The initialization of all CPU interrupts includes: Initialize the CPU clock signal; Enable CPU interrupts.

16. The energy consumption management method according to claim 1, characterized in that, The operating system of the computer system is FreeRTOS.

17. A computer system, characterized in that, include: A terminal, comprising a memory and a processor, wherein the memory stores a computer program executable on the processor, and the processor, when executing the computer program, performs the steps of the energy management method of the computer system according to any one of claims 1 to 16.

18. The computer system according to claim 17, characterized in that, Also includes: External bus wake-up source; The power management unit, after being woken up by the external bus wake-up source, powers on the terminal.