diff options
| author | W GTO <[email protected]> | 2026-09-22 16:34:22 +0800 |
|---|---|---|
| committer | Rbb666 <[email protected]> | 2026-11-24 15:13:29 +0800 |
| commit | a9a10d2dedd12368a1b26e375717422a81d55fd3 (patch) | |
| tree | f3be42ddebfb946d296cb0c79651b4e266c557fa | |
| parent | 209ea55c3210f69bf772cc80e22371d6057e63a1 (diff) | |
[drivers][pm] Resume devices with their suspend mode
Tickless threshold selection may downgrade sleep_mode after peripherals have been suspended. Preserve that suspend mode for device resume and paired notifications, while retaining the selected mode for CPU sleep and tickless timer handling.
Fixes #11046
| -rw-r--r-- | components/drivers/pm/pm.c | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/components/drivers/pm/pm.c b/components/drivers/pm/pm.c index f957f6a6a1..350ec83956 100644 --- a/components/drivers/pm/pm.c +++ b/components/drivers/pm/pm.c @@ -391,6 +391,7 @@ static void _pm_change_sleep_mode(struct rt_pm *pm) rt_tick_t timeout_tick = 0, delta_tick = 0; rt_base_t level = 0; uint8_t sleep_mode = PM_SLEEP_MODE_DEEP; + rt_uint8_t suspend_mode; level = rt_pm_enter_critical(pm->sleep_mode); @@ -414,21 +415,24 @@ static void _pm_change_sleep_mode(struct rt_pm *pm) } else { + /* Tickless selection may change the mode after devices are suspended. */ + suspend_mode = pm->sleep_mode; + /* Notify app will enter sleep mode */ if (_pm_notify.notify) { - _pm_notify.notify(RT_PM_ENTER_SLEEP, pm->sleep_mode, _pm_notify.data); + _pm_notify.notify(RT_PM_ENTER_SLEEP, suspend_mode, _pm_notify.data); } /* Suspend all peripheral device */ #ifdef PM_ENABLE_SUSPEND_SLEEP_MODE - rt_err_t ret = _pm_device_suspend(pm->sleep_mode); + rt_err_t ret = _pm_device_suspend(suspend_mode); if (ret != RT_EOK) { - _pm_device_resume(pm->sleep_mode); + _pm_device_resume(suspend_mode); if (_pm_notify.notify) { - _pm_notify.notify(RT_PM_EXIT_SLEEP, pm->sleep_mode, _pm_notify.data); + _pm_notify.notify(RT_PM_EXIT_SLEEP, suspend_mode, _pm_notify.data); } if (pm->sleep_mode > PM_SUSPEND_SLEEP_MODE) { @@ -439,7 +443,7 @@ static void _pm_change_sleep_mode(struct rt_pm *pm) return; } #else - _pm_device_suspend(pm->sleep_mode); + _pm_device_suspend(suspend_mode); #endif /* Tickless*/ if (pm->timer_mask & (0x01 << pm->sleep_mode)) @@ -473,10 +477,10 @@ static void _pm_change_sleep_mode(struct rt_pm *pm) } /* resume all device */ - _pm_device_resume(pm->sleep_mode); + _pm_device_resume(suspend_mode); if (_pm_notify.notify) - _pm_notify.notify(RT_PM_EXIT_SLEEP, pm->sleep_mode, _pm_notify.data); + _pm_notify.notify(RT_PM_EXIT_SLEEP, suspend_mode, _pm_notify.data); rt_pm_exit_critical(level, pm->sleep_mode); } |
