Browse Source

[bsp/es32f0654] add pm driver

wangyq2018 6 years ago
parent
commit
e6a4ad7bf3

+ 5 - 0
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
 #

+ 1 - 0
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  注意事项
 

+ 7 - 0
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"

+ 4 - 0
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)
 

+ 110 - 0
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

+ 16 - 0
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

+ 3 - 0
bsp/es32f0654/rtconfig.h

@@ -178,6 +178,9 @@
 /* RTC Drivers */
 
 
+/* PM Drivers */
+
+
 /* Onboard Peripheral Drivers */