Low-Power Application
This chapter describes the GK7206 low-power (Power Management, PM) application example — sample_pm. The application demonstrates the chip's power management features, including entering low-power mode, the wake-up flow, and the related register configurations.
The application source code is located in the SDK directory sample/pm/. It is a reference example demonstrating the low-power features.
1 Application Overview
1.1 Features
- Low-power mode demonstration: demonstrates the complete flow of entering and exiting the chip's low-power mode
- Loop testing: supports repeating the test a specified number of times
- Status printing: prints status information when entering/exiting low-power mode
- No hardware dependency: no sensor or other peripherals required
1.2 Technical Specifications
| Parameter | Value |
|---|---|
Command format | ./sample_pm [test_count] |
test_count | Number of loop iterations (optional, default 1) |
Memory footprint | Minimal |
Kernel module | requires xm_pm.ko |
1.3 Directory Structure
sample/pm/
├── Makefile # Build script
└── sample_pm.c # Main program2 Build and Deployment
2.1 Prerequisites
Before building this application, make sure the following preparations have been completed:
- SDK environment is set up: follow SDK Compilation to set up the cross-compilation toolchain and SDK configuration
- Kernel module is loaded:
xm_pm.kois loaded together with the media stack
2.2 Build the Application
# Enter the sample directory
cd <SDK_PATH>/sample
# Build the pm sample
make -C pm clean && make -C pmOr build from the top level:
make -C sample all2.3 Deploy to the Board
# Transfer to the development board via SCP
scp sample/pm/sample_pm root@<board IP>:/tmp/
# Or download via TFTP
tftp -g -r sample_pm <board IP>2.4 Run the Application
# Add execute permission
chmod +x /tmp/sample_pm
# Run (once by default)
./sample_pm 1
# Loop 5 times
./sample_pm 52.5 Expected Output
Single test (./sample_pm 1)
sample_pm test start
test_count = 1
pm test 0
pm init success
pm enter sleep mode
pm exit sleep mode
pm deinit success
program exit normally!Success indicator: program exit normally!, with no error messages.
Loop test (./sample_pm 5)
sample_pm test start
test_count = 5
pm test 0
pm init success
pm enter sleep mode
pm exit sleep mode
pm deinit success
pm test 1
pm init success
pm enter sleep mode
pm exit sleep mode
pm deinit success
pm test 2
pm init success
pm enter sleep mode
pm exit sleep mode
pm deinit success
pm test 3
pm init success
pm enter sleep mode
pm exit sleep mode
pm deinit success
pm test 4
pm init success
pm enter sleep mode
pm exit sleep mode
pm deinit success
program exit normally!Success indicator: exits normally after the specified number of iterations, showing program exit normally!.
Running without arguments (./sample_pm)
sample_pm test start
test_count = 1
pm test 0
pm init success
pm enter sleep mode
pm exit sleep mode
pm deinit success
program exit normally!Default behavior: without arguments, the loop runs once by default.
Error cases
pm init failedCause: the PM module is not loaded or initialization failed Solution: check whether xm_pm.ko is loaded
pm enter sleep mode failedCause: failed to enter low-power mode Solution: check the system state and whether another process is blocking it
3 Internal Execution Logic in Detail
3.1 Application Architecture
This application uses a simple loop-test architecture:
int main(int argc, char *argv[])
{
int test_count = 1;
int i;
// Parse the command-line arguments
if (argc > 1) {
test_count = atoi(argv[1]);
}
printf("sample_pm test start\n");
printf("test_count = %d\n", test_count);
// Loop test
for (i = 0; i < test_count; i++) {
printf("pm test %d\n", i);
sample_pm_test();
}
printf("program exit normally!\n");
return 0;
}3.2 PM Test Flow
The sample_pm_test() function demonstrates the complete low-power flow:
xmedia_s32 sample_pm_test(void)
{
xmedia_s32 ret;
// Step 1: Initialize the PM module
ret = xmedia_pm_init();
if (ret != XMEDIA_SUCCESS) {
printf("pm init failed\n");
return ret;
}
printf("pm init success\n");
// Step 2: Enter low-power mode
ret = xmedia_pm_enter_sleep_mode();
if (ret != XMEDIA_SUCCESS) {
printf("pm enter sleep mode failed\n");
xmedia_pm_exit();
return ret;
}
printf("pm enter sleep mode\n");
// Step 3: Exit low-power mode
ret = xmedia_pm_exit_sleep_mode();
if (ret != XMEDIA_SUCCESS) {
printf("pm exit sleep mode failed\n");
xmedia_pm_exit();
return ret;
}
printf("pm exit sleep mode\n");
// Step 4: Clean up
xmedia_pm_exit();
printf("pm deinit success\n");
return XMEDIA_SUCCESS;
}3.3 Low-Power Modes
GK7206 supports several low-power modes:
| Mode | Description | Wake-up sources |
|---|---|---|
| Light sleep | Disables some clocks, RAM retained | GPIO interrupt, timer |
| Deep sleep | Disables more clocks, lowers voltage | GPIO interrupt, RTC |
| Power off | Shuts down most power supplies, only critical circuits remain | Power button, RTC |
This application demonstrates light sleep mode, which suits scenarios that require fast wake-up.
4 Key Programming Points
4.1 Initialization and Cleanup
// Initialize the PM module
xmedia_pm_init();
// Clean up the PM module
xmedia_pm_exit();4.2 Enter/Exit Low-Power Mode
// Enter low-power mode
xmedia_pm_enter_sleep_mode();
// Exit low-power mode
xmedia_pm_exit_sleep_mode();4.3 Error Handling
Check the return value of every API call:
ret = xmedia_pm_enter_sleep_mode();
if (ret != XMEDIA_SUCCESS) {
printf("pm enter sleep mode failed\n");
// Clean up
xmedia_pm_exit();
return ret;
}5 Troubleshooting
| Problem | Possible cause | Solution |
|---|---|---|
pm init failed | PM module not loaded | Check whether xm_pm.ko is loaded |
pm enter sleep mode failed | Cannot enter low-power mode | Check the system state and whether another process blocks it |
pm exit sleep mode failed | Wake-up failed | Check the wake-up source configuration |
| Cannot wake up | Wake-up source not configured | Configure GPIO or RTC as the wake-up source |
