Guide to Sleep and RTC Alarm Wakeup on the Forlinx OK113i-S Development Board

System sleep and wake technology is a crucial aspect of power management. Firstly, it allows the system to reduce power consumption to the lowest level when idle by putting external devices, internal IP of the chip, and clocks into a low-power state or completely shut off the power state, thereby greatly extending the product's runtime. Secondly, when users need the system to run, it can quickly recover power, clocks, internal IP of the chip, and the working state of external devices to ensure that the user's experience is not interrupted.

Forlinx T113 supports two types of sleep modes: freeze and mem. These two methods can be operated through the/sys/power/state file node, and the user can trigger the corresponding sleep state by writing freeze or mem to the file node. Before hibernation, the system configures the wakeup source. Once the system enters the sleep state, it can be awakened by these wake-up sources, such as keys, RTC, etc., when needed. This design allows users to choose when and how to wake up the system quickly according to their needs, achieving a balance between power consumption minimization and fast recovery. This mechanism enables the system to greatly reduce power consumption in the sleep state, while retaining the convenience of the user to use the system quickly after waking up.

Here's how to enter sleep mode and wake up the system using the RTC on the Forlinx Embedded OK113i-S development board.

Two Sleep Modes:

freeze: Freezes I/O devices, placing them into a low-power state, and puts the processor into an idle state. It offers the quickest wake-up time, but consumes more power than other methods. Measured current with only serial port connected and 5V power supply: Approximately 0.112A

mem: Suspend-to-RAM, where the computer stores current runtime state data in memory and shuts down the hard drive, external devices, etc., entering a wait state. At this time, the memory still needs power to maintain its data, but the whole machine consumes very little power. When recovering, the computer reads data from memory, returns to the state before suspension, and recovers quickly. Measured current with only serial port connected and 5V power supply: approximately 0.076A

1. cat /sys/power/state shows the supported modes.

OK113i-S development board supported modes

2. cat /sys/power/state shows the supported modes.

Guide to Sleep and RTC Alarm Wakeup on the Forlinx OK113i-S Development Board

3. cat /sys/power/state shows the supported modes.

Guide to Sleep and RTC Alarm Wakeup on the Forlinx OK113i-S Development Board

RTC Alarm Wakeup

Tips: Note that the internal RTC needs to be used here; external RTCs do not support wakeup functionality, and we will mention this later.

Enter the kernel configuration:

Guide to Sleep and RTC Alarm Wakeup on the Forlinx OK113i-S Development Board

Follow the instructions in the diagram to select the wake-up function.

Guide to Sleep and RTC Alarm Wakeup on the Forlinx OK113i-S Development Board

Guide to Sleep and RTC Alarm Wakeup on the Forlinx OK113i-S Development Board

Guide to Sleep and RTC Alarm Wakeup on the Forlinx OK113i-S Development Board

After completing the configuration, save it, then modify the device tree file to enable the internal RTC.

Guide to Sleep and RTC Alarm Wakeup on the Forlinx OK113i-S Development Board

Guide to Sleep and RTC Alarm Wakeup on the Forlinx OK113i-S Development Board

Compile after saving:

Guide to Sleep and RTC Alarm Wakeup on the Forlinx OK113i-S Development Board

After the compilation is successful, it is packaged into an image. After the programming is completed, we test it at the serial port terminal.

Enter the serial port terminal for test:

echo''+15''> /sys/class/rtc/rtc0/wakealarm

This sets a 15-second timer, which can be adjusted as needed. After executing this command, it will take effect. If the system goes into sleep after 15 seconds, it will not trigger a wake-up. (Note: This requires using the internal RTC; external RTC does not support wake-up functionality.)echo mem > /sys/power/state (The two commands need to be entered closely together; a long interval between them will make them ineffective.)

Guide to Sleep and RTC Alarm Wakeup on the Forlinx OK113i-S Development Board

(It should be noted here that when the internal RTC is not opened, the default external RTC node is rtc0. After modification, the external RTC device node will be changed to rtc1.)

Guide to Sleep and RTC Alarm Wakeup on the Forlinx OK113i-S Development Board

3. cat /sys/power/state shows the supported modes.

Guide to Sleep and RTC Alarm Wakeup on the Forlinx OK113i-S Development Board

RTC Alarm Wakeup

Tips: Note that the internal RTC needs to be used here; external RTCs do not support wakeup functionality, and it will be mentioned later.

Enter the kernel configuration:

Guide to Sleep and RTC Alarm Wakeup on the Forlinx OK113i-S Development Board

Follow the instructions in the diagram to select the wake-up function.

Guide to Sleep and RTC Alarm Wakeup on the Forlinx OK113i-S Development Board

Guide to Sleep and RTC Alarm Wakeup on the Forlinx OK113i-S Development Board

Guide to Sleep and RTC Alarm Wakeup on the Forlinx OK113i-S Development Board

After completing the configuration, save it, then modify the device tree file to enable the internal RTC.

Guide to Sleep and RTC Alarm Wakeup on the Forlinx OK113i-S Development Board

Guide to Sleep and RTC Alarm Wakeup on the Forlinx OK113i-S Development Board

Compile after saving:

Guide to Sleep and RTC Alarm Wakeup on the Forlinx OK113i-S Development Board

After the compilation is successful, it is packaged into an image. After the programming is completed, we test it at the serial port terminal.

Enter the serial port terminal for test:

echo''+15''> /sys/class/rtc/rtc0/wakealarm

This sets a 15-second timer, which can be adjusted as needed. After executing this command, it will take effect. If the system goes into sleep after 15 seconds, it will not trigger a wake-up. (Note: This requires using the internal RTC; external RTC does not support wake-up functionality.)

echo mem > /sys/power/state (The two commands need to be entered closely together; a long interval between them will make them ineffective.)

Guide to Sleep and RTC Alarm Wakeup on the Forlinx OK113i-S Development Board

It should be noted here that when the internal RTC is not opened, the default external RTC node is rtc0. After modification, the external RTC device node will be changed to rtc1.




Dear friends, we have created an exclusive embedded technical exchange group on Facebook, where our experts share the latest technological trends and practical skills. Join us and grow together!