全部文档
OneOS简介 硬件支持 快速开发指南 编译构造工具 API参考文档 高级语言 用户编程手册 应用笔记 FAQ

LPM设备


API列表

接口 说明
os_lpmgr_init() 功耗管理器初始化
os_lpmgr_request() 申请指定的功耗模式
os_lpmgr_release() 释放指定的功耗模式
os_lpmgr_run_enter() 切换运行模式
os_lpmgr_device_register() 注册功耗设备
os_lpmgr_device_unregister() 注销功耗设备
os_lpmgr_notify_set() 设置功耗模式切换的回调函数
os_lpmgr_default_set() 设置默认的功耗模式

os_lpmgr_init

该函数用于初始化功耗管理器,函数原型如下:

void os_lpmgr_init(const struct os_lpmgr_ops *ops, os_uint8_t timer_mask, void *user_data);
参数 说明
ops 功耗管理器操作函数集
timer_mask 定时器掩码
user_data 用户数据
返回 说明

功耗管理器操作函数集结构体 struct os_lpmgr_ops原型如下:

struct os_lpmgr_ops
{
    void (*sleep)(struct lpmgr *lpm, os_uint8_t mode);
    void (*run)(struct lpmgr *lpm, os_uint8_t mode);
    void (*timer_start)(struct lpmgr *lpm, os_uint32_t timeout);
    void (*timer_stop)(struct lpmgr *lpm);
    os_tick_t (*timer_get_tick)(struct lpmgr *lpm);
};

os_lpmgr_request

该函数用于申请指定的功耗模式,函数原型如下:

void os_lpmgr_request(os_uint8_t sleep_mode);
参数 说明
sleep_mode 待申请的低功耗模式
返回 说明

sleep_mode 参数支持下列取值:

enum
{
    /* sleep modes */
    SYS_SLEEP_MODE_NONE = 0,
    SYS_SLEEP_MODE_IDLE,
    SYS_SLEEP_MODE_LIGHT,
    SYS_SLEEP_MODE_DEEP,
    SYS_SLEEP_MODE_STANDBY,
    SYS_SLEEP_MODE_SHUTDOWN,
    SYS_SLEEP_MODE_MAX,
};

os_lpmgr_release

该函数用于释放指定的功耗模式,函数原型如下:

void os_lpmgr_release(os_uint8_t sleep_mode);
参数 说明
sleep_mode 待释放的低功耗模式
返回 说明

os_lpmgr_run_enter

该函数用于切换运行模式,函数原型如下:

int os_lpmgr_run_enter(os_uint8_t run_mode);
参数 说明
run_mode 待进入的运行模式
返回 说明
OS_EOK 运行模式切换成功
其他值 运行模式切换失败

run_mode 可取值:

enum
{
    /* run modes*/
    SYS_RUN_MODE_HIGH_SPEED = 0,
    SYS_RUN_MODE_NORMAL_SPEED,
    SYS_RUN_MODE_MEDIUM_SPEED,
    SYS_RUN_MODE_LOW_SPEED,
    SYS_RUN_MODE_MAX,
};

os_lpmgr_device_register

该函数用于注册功耗设备。函数原型如下:

void os_lpmgr_device_register(struct os_device *device, const struct os_lpmgr_device_ops *ops);
参数 说明
device 低功耗设备指针
ops 低功耗设备操作函数集
返回 说明

低功耗设备操作函数集结构体 struct os_lpmgr_device_ops原型如下:

struct os_lpmgr_device_ops
{
    int (*suspend)(const struct os_device *device, os_uint8_t mode);
    void (*resume)(const struct os_device *device, os_uint8_t mode);
    int (*frequency_change)(const struct os_device *device, os_uint8_t mode);
};

os_lpmgr_device_unregister

该函数用于注销功耗设备,函数原型如下:

void os_lpmgr_device_unregister(struct os_device *device);
参数 说明
device 低功耗设备指针
返回 说明

os_lpmgr_notify_set

该函数用于设置功耗模式切换的回调函数,当功耗模式切换时,功耗管理器通过回调通知应用层,函数原型如下:

void os_lpmgr_notify_set(void (*notify)(os_uint8_t event, os_uint8_t mode, void *data), void *data);
参数 说明
notify 功耗模式切换的回调函数
data 功耗模式切换的回调参数
返回 说明

os_lpmgr_default_set

该函数用于设置默认的功耗模式 ,函数原型如下:

void os_lpmgr_default_set(os_uint8_t sleep_mode);
参数 说明
sleep_mode 默认的功耗模式
返回 说明

使用示例

切换系统功耗模式

static void lpmgr_release_mode(int argc, char **argv)
{
    int mode = 0;
    if (argc >= 2)
    {
        mode = atoi(argv[1]);
    }

    os_lpmgr_release(mode);
}
SH_CMD_EXPORT(power_release, lpmgr_release_mode, "release power management mode");

static void lpmgr_request_mode(int argc, char **argv)
{
    int mode = 0;
    if (argc >= 2)
    {
        mode = atoi(argv[1]);
    }

    os_lpmgr_request(mode);
}
SH_CMD_EXPORT(power_request, lpmgr_request_mode, "request power management mode");

static void lpmgr_dump_status(void)
{
    os_uint32_t index;
    struct lpmgr *lpm;

    lpm = &gs_lpmgr;

    os_kprintf("| Power Management Mode | Counter | Timer |\n");
    os_kprintf("+-----------------------+---------+-------+\n");
    for (index = 0; index < SYS_SLEEP_MODE_MAX; index ++)
    {
        int has_timer = 0;
        if (lpm->timer_mask & (1 << index))
            has_timer = 1;

        os_kprintf("| %021s | %7d | %5d |\n", gs_lpmgr_sleep_str[index], lpm->modes[index], has_timer);
    }
    os_kprintf("+-----------------------+---------+-------+\n");

    os_kprintf("lpmgr current sleep mode: %s\n", gs_lpmgr_sleep_str[lpm->sleep_mode]);
    os_kprintf("lpmgr current run mode:   %s\n", gs_lpmgr_run_str[lpm->run_mode]);
}
SH_CMD_EXPORT(power_status, lpmgr_dump_status, "dump power management status");

运行结果如下:

sh />power_status
| Power Management Mode | Counter | Timer |
+-----------------------+---------+-------+
|             None Mode |       0 |     0 |
|             Idle Mode |       0 |     0 |
|       LightSleep Mode |       0 |     0 |
|        DeepSleep Mode |       0 |     1 |
|          Standby Mode |       0 |     0 |
|         Shutdown Mode |       0 |     0 |
+-----------------------+---------+-------+
lpmgr current sleep mode: Idle Mode
lpmgr current run mode:   Normal Speed
sh />
sh />power_request 1
sh />
sh />power_status
| Power Management Mode | Counter | Timer |
+-----------------------+---------+-------+
|             None Mode |       0 |     0 |
|             Idle Mode |       1 |     0 |
|       LightSleep Mode |       0 |     0 |
|        DeepSleep Mode |       0 |     1 |
|          Standby Mode |       0 |     0 |
|         Shutdown Mode |       0 |     0 |
+-----------------------+---------+-------+
lpmgr current sleep mode: Idle Mode
lpmgr current run mode:   Normal Speed
sh />

切换系统运行模式

static void lpmgr_run_mode_switch(int argc, char **argv)
{
    int mode = 0;
    if (argc >= 2)
    {
        mode = atoi(argv[1]);
    }

    os_lpmgr_run_enter(mode);
}
SH_CMD_EXPORT(power_run, lpmgr_run_mode_switch, "switch power management run mode");

static void lpmgr_dump_status(void)
{
    os_uint32_t index;
    struct lpmgr *lpm;

    lpm = &gs_lpmgr;

    os_kprintf("| Power Management Mode | Counter | Timer |\n");
    os_kprintf("+-----------------------+---------+-------+\n");
    for (index = 0; index < SYS_SLEEP_MODE_MAX; index ++)
    {
        int has_timer = 0;
        if (lpm->timer_mask & (1 << index))
            has_timer = 1;

        os_kprintf("| %021s | %7d | %5d |\n", gs_lpmgr_sleep_str[index], lpm->modes[index], has_timer);
    }
    os_kprintf("+-----------------------+---------+-------+\n");

    os_kprintf("lpmgr current sleep mode: %s\n", gs_lpmgr_sleep_str[lpm->sleep_mode]);
    os_kprintf("lpmgr current run mode:   %s\n", gs_lpmgr_run_str[lpm->run_mode]);
}
SH_CMD_EXPORT(power_status, lpmgr_dump_status, "dump power management status");

运行结果如下:

sh />power_status
| Power Management Mode | Counter | Timer |
+-----------------------+---------+-------+
|             None Mode |       0 |     0 |
|             Idle Mode |       0 |     0 |
|       LightSleep Mode |       0 |     0 |
|        DeepSleep Mode |       0 |     1 |
|          Standby Mode |       0 |     0 |
|         Shutdown Mode |       0 |     0 |
+-----------------------+---------+-------+
lpmgr current sleep mode: Idle Mode
lpmgr current run mode:   Normal Speed
sh />
sh />power_run 2
sh />switch to Medium Speed mode, frequency = 24 MHz
sh />
sh />power_status
| Power Management Mode | Counter | Timer |
+-----------------------+---------+-------+
|             None Mode |       0 |     0 |
|             Idle Mode |       0 |     0 |
|       LightSleep Mode |       0 |     0 |
|        DeepSleep Mode |       0 |     1 |
|          Standby Mode |       0 |     0 |
|         Shutdown Mode |       0 |     0 |
+-----------------------+---------+-------+
lpmgr current sleep mode: Idle Mode
lpmgr current run mode:   Medium Speed
sh />

results matching ""

    No results matching ""

    返回顶部