summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwangyq2018 <[email protected]>2019-04-02 15:24:50 +0800
committerwangyq2018 <[email protected]>2019-04-02 16:05:06 +0800
commite6a4ad7bf3ef712cb97fe3f62b4c24ddfee5df7e (patch)
tree8572caeb9b9ce0d7881a7b50ce32948752f36f99
parent2236024de0d471571f05a3e10f7ab085cf65da83 (diff)
[bsp/es32f0654] add pm driver
-rw-r--r--bsp/es32f0654/.config5
-rw-r--r--bsp/es32f0654/README.md1
-rw-r--r--bsp/es32f0654/drivers/Kconfig7
-rw-r--r--bsp/es32f0654/drivers/SConscript4
-rw-r--r--bsp/es32f0654/drivers/drv_pm.c110
-rw-r--r--bsp/es32f0654/drivers/drv_pm.h16
-rw-r--r--bsp/es32f0654/rtconfig.h3
7 files changed, 146 insertions, 0 deletions
diff --git a/bsp/es32f0654/.config b/bsp/es32f0654/.config
index 37802b7538..fefdebff2d 100644
--- a/bsp/es32f0654/.config
+++ b/bsp/es32f0654/.config
@@ -360,6 +360,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
#
# CONFIG_BSP_USING_SPI_FLASH is not set
diff --git a/bsp/es32f0654/README.md b/bsp/es32f0654/README.md
index 310c349c46..7199fca7b4 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 9ce357266b..d83a2242da 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 95cc4d9f08..781a92ab01 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 0000000000..256634b81d
--- /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 <rthw.h>
+#include <rtdevice.h>
+#include "board.h"
+#include "drv_pm.h"
+#include <ald_pmu.h>
+
+#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 0000000000..a4f6cc84ee
--- /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 aa5c09f2bf..b62c1ce6f5 100644
--- a/bsp/es32f0654/rtconfig.h
+++ b/bsp/es32f0654/rtconfig.h
@@ -178,6 +178,9 @@
/* RTC Drivers */
+/* PM Drivers */
+
+
/* Onboard Peripheral Drivers */