New energy saving and consumption reduction technique of Wince: Efficient sleep wake-up

Source: Internet
Author: User
Tags sleep function

With the popularization of embedded products, power management development and design have become the key and important part of embedded system development. Because embedded devices are increasingly sensitive to energy consumption, power management technology is the key to the design of these products. At present, the Power Management Technology of embedded systems is switching from the traditional static control mode based on power management devices and peripherals control to the dynamic and static integrated control mode with the operating system as the core.

To address the challenges of power management, multiple power modes need to be designed during embedded system development so that multiple energy consumption modes can be selected at different working states. Sleep and wake-up functions are currently one of the hot topics in wincw system development. So what is the sleeping wake-up function? What effect does it achieve. First, we need to start with hardware. When the system enters the sleep mode, the entire system enters the low-power sleep mode. Only when any of the external interruptions is triggered or the real-time clock interruption is triggered, the system will be awakened.

1. What is the sleep wake-up function?

(1) What is the sleep wake-up function of wince?

In the wince system, multiple power statuses are supported: ① on, and you are actively using the device. ② Useridle status. The user stops interacting with the device, but the device may still be used. ③ Systemidle status, which enters this status after a period of useridle, but the driver and system are still active. ④ Suspend status. This status is entered when the driver and system process no longer interact with the system. ⑤ Coldreboot and reboot status, and the system power status after cold start. Among them, by power consumption from small to large can be divided into sleep, idle (idle), run (run) and other modes. During most of the time, all the devices work normally during run, while in sleep and idle mode, the system saves energy according to the specific mode.

Usually, embedded systems do not need to pay attention to the power loss of Wince devices most of the time, but pay attention to these losses in some cases. Therefore, the best way to save energy is to make the system sleep at the right time. For example, the wince system first checks the task load. If there is no task to be run, it generally enters the idle energy-saving status and waits for waking up. After a period of idle time, it then goes to sleep, suspended to Ram or hard disk. When the wince system is suspended, the CPU processor and power supply of most devices need to be disabled for power-saving systems, and then wake up by the timer or interrupt module when the system needs to be awakened. For example, when you press the on/off button, the timer that monitors user activity times out, or the application API can make the embedded system sleep. When the user presses on/off again or another wake-up interrupt occurs, the system kernel calls the oempoweroff () function and continues to run from the suspended oempoweroff () after the system wakes up. The oempoweroff function can be used to save CPU registers, set up and recover wake-up data. The system idle status is different from the previously mentioned useridle status. The former is a CPU load-driven, indicating that the system is idle; the latter is a user activity-driven, indicating that the user is idle.

(2) specific content of sleep wake-up function

Generally, there are six power supply States for wince: S0 to S5: S0. In fact, this is our normal working state. All devices are fully open. S1 is also called pos (power on suspend ), in this case, in addition to shutting down the CPU through the CPU clock controller, other components are still working normally. S2 then the CPU is in a stopped state and the bus clock is also disabled, but other devices are still running; s3: This is our familiar STR (suspend
To ram); S4 is also known as STD (suspend to disk). In this case, the system master power is off, but the hard disk is still charged and can be awakened. S5 is the most simple status, that is, all devices connected to the power supply are shut down ).

Wince power management sleep and wake-up functions: You can enable the peripherals to switch at a specified time, or the operating system can allocate electrical energy as needed, or the system can enter sleep state when no one is in use, but ensure that some communication devices are enabled. That is to say, the embedded system can manage idle devices, shut down the devices, and provide restoration methods. It mainly supports three power-saving methods: ① suspend means suspension, the display screen is automatically closed, but the host is powered on. At this time, you can press any key to restore the original state. ② Suspend
To ram is suspended to the memory. The system stores the current information in the memory. Only the memory and other key components are powered on, and the system is in a high power-saving state, after pressing any key, the system quickly restores the information from the memory to its original state. ③ Suspend to disk is suspended to the hard disk, that is, the system will automatically shut down, and the current data will be stored on the hard disk before shutdown. The computer will not need to start the system the next time you press the key to boot, read data directly from the hard disk to restore the original state.

In embedded systems, S3 is the most commonly used state, that is, suspend to Ram (suspended to memory. As the name suggests, STR stores all the operating status data before the system enters STR into the memory. In the STR state, the power supply continues to power the most necessary devices, such as memory, to ensure that data is not lost, while other devices are in the off state, and the power consumption of the system is extremely low. Once we press the power button, the system will be awakened, and the data will be immediately read from the memory and restored to the working status before Str. The memory read/write speed is extremely fast, so we feel that it takes only a few seconds to enter and exit the STR state. The S4 status means that STD (suspended to the hard disk) works exactly the same as STR, but the data is stored in the hard disk. Since the hard disk read/write speed is much slower than the memory speed, it is not as fast as STR, but the STD mode is a more power-saving advanced application, after saving the current system status to the hard disk, the hard disk stops rotating the system and enters the low power consumption status. When the system restarts, it will skip the self-check and directly restore the original system status from the hard disk, instead of the default status of the normal system, thus shortening the boot time.

II. Specific implementation process of the sleep function

Wince sleep can be understood as standby, which minimizes the power consumption of the system, but not shuts down. There are many ways to sleep the wince system, such as calling the setsystempowerstate function in an application or driver. Generally, for a driver that supports power management, the system will call the xxx_powerdown interface of the driver to turn off the power of the device, and then the system will call the oempoweroff () function for implementation. The oempoweroff () function is completed by the OEM, which may be located in the file of power. C or off. C. Oempoweroff () is implemented by the OEM, and its code and process may be different, but it is basically done as follows:

(1) perform platform-related actions before hibernation

These platform actions include setting up reasonable gpio for sleep mode, configuring a real-time clock, and calling bsppoweroff to turn off unnecessary device power when sleep. For example, clear the screen, set ad, and suspend USB. It also includes saving all register values of the chip to a static array (that is, in the stack), for example, saving the sleep return address or some data that is not expected to be lost in sleep mode. Finally, we call the cpulcdoff function to disable the LCD backlight.

(2) Call configstopgpio to set the status after Io sleep

This action is to save information such as the current gpio and LCD controller in the memory, set gpio to low power consumption, and disable devices such as kitl LCD. At the same time, call oalcpupoweroff () for suspension. Oalcpupoweroff () is an assembly function located in startup. S. Generally, it also includes saving the value of General registers to the stack, for example, saving the address and MMU register after wakeup, and saving the SP and LR registers to a certain position in the Memory RAM in various modes, this location is configured by config. bib specifies the reserved. Why is it not saved to the stack as before? This is because the system jumps to the reset to start execution after waking up, And the stack has not been initialized yet. This is also the reason for the complexity of the poweroff process.

(3) block all interruptions and clear the cache

After the sleep status of each Io is set, the system will block all the interrupts in the interrupt shield register, and then clean up the cache to prepare for hibernation.

(4) set wake-up interruption and call cpupoweroff

In general, the wake-up interrupt can be an external interrupt of 0, 1, 2, or RTC interrupt. After the wake-up interrupt is set, the system needs to call oalcpupoweroff again, set refresh to enable the SDRAM to enter the auto-Refresh mode, wait for the SDRAM auto-Refresh to take effect, and set the signal (sclk0, sclk1 and scke) is protected in power_of mode. clkcon is set to enter power_off mode, and the CPU enters the poweroff state. However, since shutdown will eventually be adjusted to the oempoweroff function, it is necessary to identify whether to sleep or shut down the function based on the actual situation. In addition, the most vulnerable part in this process is the call to oalcpupoweroff, because the CPU will lose power during sleep.

Iii. implementation process of the wake-up function

In sleep state, the energy consumption in the wincw system is greatly reduced. The next step is another arduous task: System wake-up. A wake-up system is basically a hardware process, which is closely related to the hardware. Generally, an external interrupt is used to wake up. This requires that the interrupt source cannot be powered off during sleep. In general, powerup and powerdown have been completed in the driver, and of course some drivers have different processing methods, such as using poweron and poweroff. However, no matter which reset method is used, the bootloader code is first executed. Therefore, the bootloader must be involved in the wake-up process. The detailed implementation process is as follows:

(1) Wake up the source system to generate an internal reset signal

When we carefully watch the switching from sleep to normal of the wince system, we need to go through a reset process. This process is called power on reset. That is to say, when the system is awakened by an external interruption, it is equivalent to a power reset process. The reason for Reset is similar to a hardware reset for the system and a value is saved in gstatus2. In addition, after power on reset, the system data in the ram stored in the sleep process will not be lost. The wake-up system we want to do is to restore these values to their original addresses.

(2) test whether to wake up in power_off mode.

After the wince system is awakened, what is the first program it runs? This is very important because wake-up = power reset, so after reset CPU, the first program to run will naturally be bootloader. Now let's take a look at how bootloader works. If it is a reset, it will jump directly to the 0 address, that is, resethandler to execute. In fact, both the hardreset and powerreset must be executed, mainly to initialize the CPU clock. This is because the power off mode is different from other sleep modes. After waking up in other sleep modes, the system continues to run from sleep.
After the off mode is awakened, it is executed from the reset.

Next, the system will judge the reason for reset by reading the value in the gstatus2 register. If the value is 0x2, it is the powerreset caused by wake-up, and then the wake-up recovery operation will continue. For example, first recover the CPU clock, enable self-refresh of RAM, then jump to an address in Ram to execute bootloader, and then load the data in nandflash, that is to say, the wince operating system is awakened. If the value in gstatus2 is 0x4, it indicates that a watchdog reset occurs, and the recovery process of the watchdog reset is executed. If neither of them is true, it is considered hard.
Reset, follow the normal steps to load the wince system.

(3) recover the SDRAM Controller information and power on the relevant equipment

The last step of system wake-up is that the system sets miscr, releases the SDRAM signal protection, and waits until the SDRAM is automatically refreshed and released. Read the gstatus values and use them to return to the program location before sleep. Finally, it restores information such as gpio and LCD controller stored in the memory, calls bsppoweron to open the power of the relevant device, and then returns.

Reposted Source

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.