This chapter introduces the GK7206 low power (power management, PM) sample, sample_pm. It demonstrates the chip power management features, including entering low power mode, the wake-up flow, and the related register settings.
The source lives in sample/pm/ in the SDK. It is a reference example demonstrating the low power features.
| Parameter | Value |
|---|---|
Command |
./sample_pm [test_count] |
test_count |
iteration count (optional, default 1) |
Memory use |
minimal |
Kernel module |
requires xm_pm.ko |
sample/pm/
├── Makefile # build script
└── sample_pm.c # main program
Before building this application, make sure the following are ready:
xm_pm.ko is loaded with the media stack# enter the sample directory
cd <SDK_PATH>/sample
# build the pm sample
make -C pm clean && make -C pm
Or build it from the top level:
make -C sample all
# transfer to the board over SCP
scp sample/pm/sample_pm root@<board-IP>:/tmp/
# or download it over TFTP
tftp -g -r sample_pm <board-IP>
# make it executable
chmod +x /tmp/sample_pm
# run it (1 iteration by default)
./sample_pm 1
# loop 5 times
./sample_pm 5
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 errors.
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 given number of iterations, printing program exit normally!.
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 it runs one iteration.
pm init failed
Cause: the PM module is not loaded or failed to initialize Fix: check that xm_pm.ko is loaded
pm enter sleep mode failed
Cause: cannot enter low power mode Fix: check the system state and whether another process is blocking it
This application uses a simple loop-test design:
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 the test
for (i = 0; i < test_count; i++) {
printf("pm test %d\n", i);
sample_pm_test();
}
printf("program exit normally!\n");
return 0;
}
sample_pm_test() 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: leave 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: release resources
xmedia_pm_exit();
printf("pm deinit success\n");
return XMEDIA_SUCCESS;
}
The GK7206 supports several low power modes:
| Mode | Description | Wake-up |
|---|---|---|
| Light sleep | Some clocks off, RAM retained | GPIO interrupt, timer |
| Deep sleep | More clocks off, lower voltage | GPIO interrupt, RTC |
| Shutdown | Most power off, only critical circuits kept | Power button, RTC |
This application demonstrates light sleep, which suits scenarios that need fast wake-up.
// initialize the PM module
xmedia_pm_init();
// clean up the PM module
xmedia_pm_exit();
// enter low power mode
xmedia_pm_enter_sleep_mode();
// leave low power mode
xmedia_pm_exit_sleep_mode();
Every API call should have its return value checked:
ret = xmedia_pm_enter_sleep_mode();
if (ret != XMEDIA_SUCCESS) {
printf("pm enter sleep mode failed\n");
// release resources
xmedia_pm_exit();
return ret;
}
| Problem | Likely cause | Fix |
|---|---|---|
pm init failed |
PM module not loaded | Check that xm_pm.ko is loaded |
pm enter sleep mode failed |
Cannot enter low power | Check the system state and whether another process is blocking it |
pm exit sleep mode failed |
Wake-up failed | Check the wake-up source configuration |
| Cannot wake up | No wake-up source configured | Configure GPIO or RTC as the wake-up source |