From e6a4ad7bf3ef712cb97fe3f62b4c24ddfee5df7e Mon Sep 17 00:00:00 2001 From: wangyq2018 Date: Tue, 2 Apr 2019 15:24:50 +0800 Subject: [PATCH] [bsp/es32f0654] add pm driver --- bsp/es32f0654/.config | 5 ++ bsp/es32f0654/README.md | 1 + bsp/es32f0654/drivers/Kconfig | 7 ++ bsp/es32f0654/drivers/SConscript | 4 ++ bsp/es32f0654/drivers/drv_pm.c | 110 +++++++++++++++++++++++++++++++ bsp/es32f0654/drivers/drv_pm.h | 16 +++++ bsp/es32f0654/rtconfig.h | 3 + 7 files changed, 146 insertions(+) create mode 100644 bsp/es32f0654/drivers/drv_pm.c create mode 100644 bsp/es32f0654/drivers/drv_pm.h diff --git a/bsp/es32f0654/.config b/bsp/es32f0654/.config index 37802b753..fefdebff2 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 310c349c4..7199fca7b 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 9ce357266..d83a2242d 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 95cc4d9f0..781a92ab0 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 000000000..256634b81 --- /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 000000000..a4f6cc84e --- /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 aa5c09f2b..b62c1ce6f 100644 --- a/bsp/es32f0654/rtconfig.h +++ b/bsp/es32f0654/rtconfig.h @@ -178,6 +178,9 @@ /* RTC Drivers */ +/* PM Drivers */ + + /* Onboard Peripheral Drivers */ -- GitLab