1. 概述

嵌入式系统低功耗管理的目的在于满足用户对性能需求的前提下,尽可能降低系统能耗以延长设备待机时间。高性能与有限的电池能量在嵌入式系统中矛盾最为突出,硬件低功耗设计与软件低功耗管理的联合应用成为解决矛盾的有效手段。
现在的各种 MCU 都或多或少的在低功耗方面提供了管理接口。比如对主控时钟频率的调整、工作电压的改变、总线频率的调整甚至关闭、外围设备工作时钟的关闭等。有了硬件上的支持,合理的软件设计就成为节能的关键。
目前TG6210A的 PMU模块在软件上为用户提供了两种低功耗的方案:PDS模式和HBN模式。
两种模式主要区别是功耗,gpio引脚唤醒和保持上的区别,请查阅下文具体描述。

2. API参考

2.1 pds模式低功耗(电流mA级别)

  • 函数原型:
    void pm_pds_mode_enter(enum pm_pds_sleep_level pds_level,

uint32_t sleep_time, hosal_wakeup_gpio_type_t *buf0,
hosal_keep_gpio_type_t *buf1);

  • 功能描述:pds入口函数
  • 函数参数:
    • pds_level:pds level,目前只支持PM_PDS_LEVEL_7参数
    • sleep_time:唤醒时间(单位s)
    • buf0:唤醒pds的gpio buffer,gpio唤醒支持9~15,40和41
    • buf1:pds模式下需要保持的gpio buffer,gpio保持支持0~8,16~38
      1. enum pm_pds_sleep_level {
      2. PM_PDS_LEVEL_1 = 1,
      3. PM_PDS_LEVEL_2 = 2,
      4. PM_PDS_LEVEL_3 = 3,
      5. PM_PDS_LEVEL_7 = 7,
      6. };
      ```c typedef struct { uint8_t int_trigger; /0: pull null, 1:pull down 2: pull up/ uint8_t gpio; } wakeup_io_cfg;

typedef struct { uint8_t buflen; uint8_t active; wakeup_io_cfg wk_gpio[1]; } hosal_wakeup_gpio_type_t;

typedef struct { uint8_t level; /0: 低电平 1:高电平/ uint8_t gpio; } keep_io_cfg;

typedef struct { uint8_t buflen; uint8_t active; keep_io_cfg keep_io[1]; } hosal_keep_gpio_type_t;

  1. - 返回值:
  2. - 无。
  3. <a name="OgguH"></a>
  4. ## 2.2 hbn模式低功耗(电流uA级别)
  5. - 函数原型:<br />`void pm_hbn_mode_enter(uint8_t level, uint64_t sleep_time,`
  6. `hosal_wakeup_gpio_type_t *buf);`
  7. - 功能描述:hbn入口函数。
  8. - 函数参数:
  9. - levelhbn level,目前只支持0
  10. - sleep_time:唤醒时间(单位 1/32768秒)
  11. - buf:唤醒hbngpio buffergpio唤醒支持9154041
  12. - 返回值:
  13. - 无。
  14. <a name="r8Yi5"></a>
  15. # 3. Demo示例
  16. ```c
  17. /* this case show whem entry hbn mode ,use gpio11 wakeup or 20s wakeup*/
  18. void demo_hosal_pm_hbn(void)
  19. {
  20. wakeup_io_cfg wk_cfg = {
  21. .int_trigger = 1, /*0: pull null, 1:pull down 2: pull up*/
  22. .gpio = 11,
  23. };
  24. hosal_wakeup_gpio_type_t *buf = NULL;
  25. buf = aos_malloc(sizeof(hosal_wakeup_gpio_type_t) + sizeof(wakeup_io_cfg) * 1);
  26. buf->buflen = 1;
  27. memcpy(buf->wk_gpio, &wk_cfg, sizeof(wk_cfg));
  28. pm_hbn_mode_enter(0, 20, buf);
  29. }
  • 该示例使用gpio11作为唤醒源(上升沿触发)或者20s后会自动唤醒。
/* this case show whem entry pds7 mode ,use gpio11/12 wakeup or 20s wakeup*/
void demo_hosal_pm_pds(void)
{
    wakeup_io_cfg wk_cfg[2] = {
        {
            .int_trigger = 1, /*0: pull null, 1:pull down 2: pull up*/ 
            .gpio = 11,
        }, 
        {
            .int_trigger = 1, /*0: pull null, 1:pull down 2: pull up*/ 
            .gpio = 12,
        }
    };

    keep_io_cfg kp_cfg[2] = {
        {
            .gpio = 0,
        },
        {
            .gpio = 1,
        }
    };

    hosal_wakeup_gpio_type_t * wk_io = NULL;
    hosal_keep_gpio_type_t * kp_io = NULL;

    bl_gpio_enable_output(0, 1, 0);
    bl_gpio_enable_output(1, 0, 1);
    bl_gpio_output_set(0, 1);
    bl_gpio_output_set(1, 0);
    aos_msleep(1000);
    wk_io = aos_malloc(sizeof(hosal_wakeup_gpio_type_t) + sizeof(wakeup_io_cfg) * 2);
    kp_io = aos_malloc(sizeof(hosal_keep_gpio_type_t) + sizeof(keep_io_cfg) * 2);

    wk_io->buflen = 2;
    kp_io->buflen = 2;

    memcpy(wk_io->wk_gpio, &wk_cfg, sizeof(wk_cfg));
    memcpy(kp_io->keep_io, &kp_cfg, sizeof(kp_cfg));

    //pm_pds_mode_enter(PM_PDS_LEVEL_7, 5 * 32768, wk_io, kp_io);

    pm_pds_mode_enter(PM_PDS_LEVEL_7, 5 * 32768, wk_io, kp_io);
}
  • 该示例使用gpio11和gpio12作为唤醒源(上升沿触发)或者5s后会自动唤醒。在pds过程中,gpio 0和1可以保持电平。