Pārlūkot izejas kodu

[components][pm]fix some issues with low power components

EvalZero 6 gadi atpakaļ
vecāks
revīzija
d51e0783ba

+ 1 - 0
bsp/es32f0334/drivers/drv_pm.c

@@ -6,6 +6,7 @@
  * Change Logs:
  * Date           Author        Notes
  * 2019-04-08     wangyq        the first version
+ * 2019-05-06     Zero-Free     adapt to the new power management interface
  */
 
 #include <rthw.h>

+ 1 - 0
bsp/es32f0654/drivers/drv_pm.c

@@ -6,6 +6,7 @@
  * Change Logs:
  * Date           Author        Notes
  * 2019-04-01     wangyq        the first version
+ * 2019-05-06     Zero-Free     adapt to the new power management interface
  */
 
 #include <rthw.h>

+ 1 - 1
bsp/stm32/libraries/HAL_Drivers/drv_lptim.c

@@ -5,7 +5,7 @@
  *
  * Change Logs:
  * Date           Author          Notes
- * 2017-08-01     tanek           the first version
+ * 2019-05-06     Zero-Free       first version
  */
 
 #include <board.h>

+ 1 - 1
bsp/stm32/libraries/HAL_Drivers/drv_lptim.h

@@ -5,7 +5,7 @@
  *
  * Change Logs:
  * Date           Author          Notes
- * 2012-08-21     heyuanjie87     the first version
+ * 2019-05-06     Zero-Free       first version
  */
 
 #ifndef  __DRV_PMTIMER_H__

+ 2 - 3
bsp/stm32/libraries/HAL_Drivers/drv_pm.c

@@ -5,8 +5,7 @@
  *
  * Change Logs:
  * Date           Author       Notes
- * 2018-07-31     tanek        first version
- * 2018-05-05     Zero-Free    adapt to the new power management interface
+ * 2019-05-06     Zero-Free    first version
  */
 
 #include <board.h>
@@ -79,7 +78,7 @@ static uint8_t run_speed[PM_RUN_MODE_MAX][2] =
     {2,  3},
 };
 
-static void run(struct rt_pm *pm, uint8_t mode, uint32_t frequency)
+static void run(struct rt_pm *pm, uint8_t mode)
 {
     static uint8_t last_mode;
     static char *run_str[] = PM_RUN_MODE_NAMES;

+ 4 - 5
components/drivers/include/drivers/pm.h

@@ -77,7 +77,7 @@ enum
  * device control flag to request or release power
  */
 #define RT_PM_DEVICE_CTRL_REQUEST   0x01
-#define RT_PM_DEVICE_CTRL_RELEASE   0x02
+#define RT_PM_DEVICE_CTRL_RELEASE   0x00
 
 struct rt_pm;
 
@@ -87,7 +87,7 @@ struct rt_pm;
 struct rt_pm_ops
 {
     void (*sleep)(struct rt_pm *pm, uint8_t mode);
-    void (*run)(struct rt_pm *pm, uint8_t mode, uint32_t frequency);
+    void (*run)(struct rt_pm *pm, uint8_t mode);
     void (*timer_start)(struct rt_pm *pm, rt_uint32_t timeout);
     void (*timer_stop)(struct rt_pm *pm);
     rt_tick_t (*timer_get_tick)(struct rt_pm *pm);
@@ -97,7 +97,7 @@ struct rt_device_pm_ops
 {
     int (*suspend)(const struct rt_device *device, uint8_t mode);
     void (*resume)(const struct rt_device *device, uint8_t mode);
-    int (*frequency_change)(const struct rt_device *device, uint8_t mode, uint32_t frequency);
+    int (*frequency_change)(const struct rt_device *device, uint8_t mode);
 };
 
 struct rt_device_pm
@@ -122,7 +122,6 @@ struct rt_pm
     rt_uint8_t device_pm_number;
     struct rt_device_pm *device_pm;
 
-    rt_uint32_t frequency;
     /* if the mode has timer, the corresponding bit is 1*/
     rt_uint8_t timer_mask;
     rt_uint8_t flags;
@@ -144,7 +143,7 @@ struct rt_pm_notify
 
 void rt_pm_request(uint8_t sleep_mode);
 void rt_pm_release(uint8_t sleep_mode);
-int rt_pm_run_mode_set(uint8_t run_mode, uint32_t frequency);
+int rt_pm_run_enter(uint8_t run_mode);
 
 void rt_pm_device_register(struct rt_device *device, const struct rt_device_pm_ops *ops);
 void rt_pm_device_unregister(struct rt_device *device);

+ 21 - 20
components/drivers/pm/pm.c

@@ -22,12 +22,12 @@ static struct rt_pm_notify _pm_notify;
 
 #define RT_PM_TICKLESS_THRESH (2)
 
-RT_WEAK uint32_t rt_pm_enter_critical(void)
+RT_WEAK uint32_t rt_pm_enter_critical(uint8_t sleep_mode)
 {
     return rt_hw_interrupt_disable();
 }
 
-RT_WEAK void rt_pm_exit_critical(uint32_t ctx)
+RT_WEAK void rt_pm_exit_critical(uint32_t ctx, uint8_t sleep_mode)
 {
     rt_hw_interrupt_enable(ctx);
 }
@@ -37,17 +37,19 @@ RT_WEAK void rt_pm_exit_critical(uint32_t ctx)
  */
 static int _pm_device_suspend(uint8_t mode)
 {
-    int index;
+    int index, ret = RT_EOK;
 
     for (index = 0; index < _pm.device_pm_number; index++)
     {
         if (_pm.device_pm[index].ops->suspend != RT_NULL)
         {
-            return _pm.device_pm[index].ops->suspend(_pm.device_pm[index].device, mode);
+            ret = _pm.device_pm[index].ops->suspend(_pm.device_pm[index].device, mode);
+            if(ret != RT_EOK)
+                break; 
         }
     }
 
-    return RT_EOK;
+    return ret;
 }
 
 /**
@@ -69,7 +71,7 @@ static void _pm_device_resume(uint8_t mode)
 /**
  * This function will update the frequency of all registered devices
  */
-static void _pm_device_frequency_change(uint8_t mode, uint32_t frequency)
+static void _pm_device_frequency_change(uint8_t mode)
 {
     rt_uint32_t index;
 
@@ -77,7 +79,7 @@ static void _pm_device_frequency_change(uint8_t mode, uint32_t frequency)
     for (index = 0; index < _pm.device_pm_number; index ++)
     {
         if (_pm.device_pm[index].ops->frequency_change != RT_NULL)
-            _pm.device_pm[index].ops->frequency_change(_pm.device_pm[index].device, mode, frequency);
+            _pm.device_pm[index].ops->frequency_change(_pm.device_pm[index].device, mode);
     }
 }
 
@@ -92,9 +94,9 @@ static void _pm_frequency_scaling(struct rt_pm *pm)
     {
         level = rt_hw_interrupt_disable();
         /* change system runing mode */
-        pm->ops->run(pm, pm->run_mode, pm->frequency);
+        pm->ops->run(pm, pm->run_mode);
         /* changer device frequency */
-        _pm_device_frequency_change(pm->run_mode, pm->frequency);
+        _pm_device_frequency_change(pm->run_mode);
         pm->flags &= ~RT_PM_FREQUENCY_PENDING;
         rt_hw_interrupt_enable(level);
     }
@@ -138,7 +140,7 @@ static void _pm_change_sleep_mode(struct rt_pm *pm, uint8_t mode)
     }
     else
     {
-        level = rt_pm_enter_critical();
+        level = rt_pm_enter_critical(mode);
 
         /* Notify app will enter sleep mode */
         if (_pm_notify.notify)
@@ -151,7 +153,7 @@ static void _pm_change_sleep_mode(struct rt_pm *pm, uint8_t mode)
             _pm_device_resume(mode);
             if (_pm_notify.notify)
                 _pm_notify.notify(RT_PM_EXIT_SLEEP, mode, _pm_notify.data);
-            rt_pm_exit_critical(level);
+            rt_pm_exit_critical(level, mode);
 
             return;
         }
@@ -202,7 +204,7 @@ static void _pm_change_sleep_mode(struct rt_pm *pm, uint8_t mode)
         if (_pm_notify.notify)
             _pm_notify.notify(RT_PM_EXIT_SLEEP, mode, _pm_notify.data);
 
-        rt_pm_exit_critical(level);
+        rt_pm_exit_critical(level, mode);
     }
 }
 
@@ -381,11 +383,11 @@ static rt_size_t _rt_pm_device_write(rt_device_t dev,
     {
         /* get request */
         request = *(unsigned char *)buffer;
-        if (request == '1')
+        if (request ==  0x01)
         {
             rt_pm_request(pos);
         }
-        else if (request == '0')
+        else if (request == 0x00)
         {
             rt_pm_release(pos);
         }
@@ -416,7 +418,7 @@ static rt_err_t _rt_pm_device_control(rt_device_t dev,
     return RT_EOK;
 }
 
-int rt_pm_run_mode_set(uint8_t mode, uint32_t frequency)
+int rt_pm_run_enter(uint8_t mode)
 {
     rt_base_t level;
     struct rt_pm *pm;
@@ -429,15 +431,14 @@ int rt_pm_run_mode_set(uint8_t mode, uint32_t frequency)
     if (mode < pm->run_mode)
     {
         /* change system runing mode */
-        pm->ops->run(pm, mode, frequency);
+        pm->ops->run(pm, mode);
         /* changer device frequency */
-        _pm_device_frequency_change(mode, frequency);
+        _pm_device_frequency_change(mode);
     }
     else
     {
         pm->flags |= RT_PM_FREQUENCY_PENDING;
     }
-    pm->frequency = frequency;
     pm->run_mode = mode;
     rt_hw_interrupt_enable(level);
 
@@ -525,9 +526,9 @@ static void rt_pm_run_mode_switch(int argc, char **argv)
         mode = atoi(argv[1]);
     }
 
-    rt_pm_run_mode_set(mode, 0);
+    rt_pm_run_enter(mode);
 }
-MSH_CMD_EXPORT_ALIAS(rt_pm_run_mode_switch, pm_run_set, switch power management run mode);
+MSH_CMD_EXPORT_ALIAS(rt_pm_run_mode_switch, pm_run, switch power management run mode);
 
 static void rt_pm_dump_status(void)
 {

+ 1 - 0
examples/pm/timer_app.c

@@ -6,6 +6,7 @@
  * Change Logs:
  * Date           Author       Notes
  * 2018-08-07     Tanek        first implementation
+ * 2019-05-06     Zero-Free    adapt to the new power management interface
  */
 
 #include <board.h>