-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sys/pm: Fix behavior of fallback pm_off() implementation #13978
Conversation
- pm_off() should prevent other threads from getting executed after it is called, as it should turn off the MCU completely according to its doc - Previously, the fallback implementation would still allow other threads to continue working - Simply disabling IRQs and never enabling them again should make sure the MCU behaves like it would be completely off - pm_off() should reduce the power consumption as much as possible - Previously, when IRQs came after the call to pm_set_lowest() in the fallback implementation of pm_off(), `while(1) {}` got executed at full power consumption - Just calling `pm_set(0);` in a loop while make sure that lowest power mode is restored if the MCU wakes up again. - The check if the lowest power mode is available is skipped, as no code gets executed afterwards anyway
After a second look into |
@maribu, can you improve the title of this PR? |
Btw: The implementation of |
Maybe @benpicco could test this using his mcb2388 board? However, in order to reproduce the issue (which in its full beauty can only occur if no off mode is implemented) the following patch needs to be (temporary) applied: diff --git a/cpu/lpc2387/periph/pm.c b/cpu/lpc2387/periph/pm.c
index 2afbb92509..5fe853fdb6 100644
--- a/cpu/lpc2387/periph/pm.c
+++ b/cpu/lpc2387/periph/pm.c
@@ -33,7 +33,7 @@ void pm_set(unsigned mode)
case 0:
/* Everything except battery backup is powered down */
DEBUG_PUTS("pm_set(): setting Deep Power Down mode.");
- PCON |= PM_DEEP_POWERDOWN;
+ PCON |= PM_IDLE;
break;
case 1:
/* PLL & Flash are powered down */ Note: The race condition fixed in this PR affects every user of |
Yup that works:
Whereas on
|
Contribution description
while(1) {}
got executed at full power consumptionpm_set(0);
in a loop while make sure that lowest power mode is restored if the MCU wakes up again.Testing procedure
The fallback implementation of
pm_off()
should now prevent any code from being executed after it is called.I'll add a test application to this PR later on.Update:tests/periph_pm
is fully sufficient for testing this.Issues/PRs references
Split out of #13973 (but improved afterwards)