diff options
| author | EvalZero <[email protected]> | 2019-05-07 21:03:48 +0800 |
|---|---|---|
| committer | EvalZero <[email protected]> | 2019-05-07 21:03:48 +0800 |
| commit | d51e0783babc4ffa7286e8dadceb2b2be2129b33 (patch) | |
| tree | f00a127e373d4478458629d33b411ff5531230dd /components/drivers | |
| parent | 623ddc62b2df57b94674d1a46bfa3ff58593bbcb (diff) | |
[components][pm]fix some issues with low power components
Diffstat (limited to 'components/drivers')
| -rw-r--r-- | components/drivers/include/drivers/pm.h | 9 | ||||
| -rw-r--r-- | components/drivers/pm/pm.c | 41 |
2 files changed, 25 insertions, 25 deletions
diff --git a/components/drivers/include/drivers/pm.h b/components/drivers/include/drivers/pm.h index 5cffd8d465..e35b21cd48 100644 --- a/components/drivers/include/drivers/pm.h +++ b/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); diff --git a/components/drivers/pm/pm.c b/components/drivers/pm/pm.c index c273754914..98a993b526 100644 --- a/components/drivers/pm/pm.c +++ b/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) { |
