diff --git a/bsp/es32f0654/.config b/bsp/es32f0654/.config index 37802b75384c545f0c73cf721d4b78a11707f522..fefdebff2dd63d72831a55464328a88648063765 100644 --- a/bsp/es32f0654/.config +++ b/bsp/es32f0654/.config @@ -359,6 +359,11 @@ CONFIG_BSP_USING_UART2=y # # CONFIG_BSP_USING_RTC is not set +# +# PM Drivers +# +# CONFIG_BSP_USING_PM is not set + # # Onboard Peripheral Drivers # diff --git a/bsp/es32f0654/README.md b/bsp/es32f0654/README.md index 310c349c4653b239f3200ed842ab8aeb05cdc28c..7199fca7b4fd1e185d7c71bded34e2a8cdd523cd 100644 --- a/bsp/es32f0654/README.md +++ b/bsp/es32f0654/README.md @@ -43,6 +43,7 @@ ES-PDS-ES32F0654-V1.1 | PWM | 支持 | PWM0/1/2/3 | | TIMER | 支持 | TIMER0/1/2/3 | | RTC | 支持 | RTC | +| PM | 支持 | Power Management | ### 1.2 注意事项 diff --git a/bsp/es32f0654/drivers/Kconfig b/bsp/es32f0654/drivers/Kconfig index 9ce357266b9654e9c4e1634e08909703117fc08f..d83a2242dac7860c55bcde2108e42e64239ac3db 100644 --- a/bsp/es32f0654/drivers/Kconfig +++ b/bsp/es32f0654/drivers/Kconfig @@ -109,6 +109,13 @@ menu "Hardware Drivers Config" default n endmenu + menu "PM Drivers" + config BSP_USING_PM + bool "Using PM" + select RT_USING_PM + default n + endmenu + endmenu menu "Onboard Peripheral Drivers" diff --git a/bsp/es32f0654/drivers/SConscript b/bsp/es32f0654/drivers/SConscript index 95cc4d9f0899d2e78285ddb049f02ae6b997ef34..781a92ab0124d042b921c5c9a4d9748ff74008c8 100644 --- a/bsp/es32f0654/drivers/SConscript +++ b/bsp/es32f0654/drivers/SConscript @@ -39,6 +39,10 @@ if GetDepend('BSP_USING_HWTIMER0') or GetDepend('BSP_USING_HWTIMER1') or GetDepe if GetDepend(['BSP_USING_RTC']): src += ['drv_rtc.c'] +# add pm driver code +if GetDepend(['BSP_USING_PM']): + src += ['drv_pm.c'] + CPPPATH = [cwd] group = DefineGroup('Drivers', src, depend = [''], CPPPATH = CPPPATH) diff --git a/bsp/es32f0654/drivers/drv_pm.c b/bsp/es32f0654/drivers/drv_pm.c new file mode 100644 index 0000000000000000000000000000000000000000..256634b81d68645023719feec3ddd2d01cb13ab4 --- /dev/null +++ b/bsp/es32f0654/drivers/drv_pm.c @@ -0,0 +1,110 @@ +/* + * Copyright (C) 2018 Shanghai Eastsoft Microelectronics Co., Ltd. + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2019-04-01 wangyq the first version + */ + +#include +#include +#include "board.h" +#include "drv_pm.h" +#include + +#ifdef RT_USING_PM + +static void _drv_pm_enter(struct rt_pm *pm) +{ + rt_uint32_t mode; + + mode = pm->current_mode; + + switch (mode) + { + case PM_RUN_MODE_NORMAL: + break; + + case PM_SLEEP_MODE_SLEEP: + __WFI(); + break; + + case PM_SLEEP_MODE_TIMER: + pmu_stop2_enter(); + break; + + case PM_SLEEP_MODE_SHUTDOWN: + pmu_standby_enter(PMU_STANDBY_PORT_NONE); + break; + + default: + RT_ASSERT(0); + break; + } +} + +static void _drv_pm_exit(struct rt_pm *pm) +{ + rt_uint32_t mode; + + RT_ASSERT(pm != RT_NULL); + + mode = pm->current_mode; + + switch (mode) + { + case PM_RUN_MODE_NORMAL: + break; + + case PM_SLEEP_MODE_SLEEP: + break; + + case PM_SLEEP_MODE_TIMER: + break; + + case PM_SLEEP_MODE_SHUTDOWN: + break; + + default: + RT_ASSERT(0); + break; + } +} + +#if PM_RUN_MODE_COUNT > 1 +static void _drv_pm_frequency_change(struct rt_pm *pm, rt_uint32_t frequency) +{ + return; +} +#endif + +static int drv_hw_pm_init(void) +{ + static const struct rt_pm_ops _ops = + { + _drv_pm_enter, + _drv_pm_exit, + +#if PM_RUN_MODE_COUNT > 1 + _drv_pm_frequency_change, +#endif + RT_NULL, + RT_NULL, + RT_NULL + }; + + rt_uint8_t timer_mask; + + /* initialize timer mask */ + timer_mask = 1UL << PM_SLEEP_MODE_TIMER; + + /* initialize system pm module */ + rt_system_pm_init(&_ops, timer_mask, RT_NULL); + + return 0; +} +INIT_BOARD_EXPORT(drv_hw_pm_init); + +#endif diff --git a/bsp/es32f0654/drivers/drv_pm.h b/bsp/es32f0654/drivers/drv_pm.h new file mode 100644 index 0000000000000000000000000000000000000000..a4f6cc84eed89859f5beef2154384e9754f54782 --- /dev/null +++ b/bsp/es32f0654/drivers/drv_pm.h @@ -0,0 +1,16 @@ +/* + * Copyright (C) 2018 Shanghai Eastsoft Microelectronics Co., Ltd. + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2019-04-01 wangyq the first version + */ + +#ifndef DRV_PM_H__ +#define DRV_PM_H__ + +int rt_hw_pm_init(void); + +#endif diff --git a/bsp/es32f0654/rtconfig.h b/bsp/es32f0654/rtconfig.h index aa5c09f2bf1442cb00788f25bc2cd426dddbe0ee..b62c1ce6f5951eee76a94e1feec894c69611aba2 100644 --- a/bsp/es32f0654/rtconfig.h +++ b/bsp/es32f0654/rtconfig.h @@ -178,6 +178,9 @@ /* RTC Drivers */ +/* PM Drivers */ + + /* Onboard Peripheral Drivers */