-
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
Implement power management pm
for CPUs
#6802
Comments
The Kinetis CPUs are best implemented as a shared PM driver with possibly some small differences handled in preprocessor conditionals. |
jupp, agree. Updated the list |
How the periph driver are supposed to implement this? I think this is straightforward for spi, block/unblock are called in acquire/release. But how do we proceed for uart for instance. Are the block/unblock supposed to be called from Same kind of questions apply to xtimer, because with the current design, once xtimer is launched most implementation would unlikely never go to any power saving mode. |
pratically, it is quite simple - as long as peripherals are active, they need to block any power state that prevents them from working: timer: same thing: block lowpower modes when activated and unblock when powered off (stopped) on most platforms. This indeed blocks all low-power modes as long as the xtimer is used. This is a known issue or better known conceptual gap in our timer system design. @kaspar030 and me are working on a new proposal to solve this. |
That's what I understood, then. So in practical, as soon as shell or xtimer is used, we cannot reach any low power mode anymore with the current design. For the UART, some platform will need to setup the rx pin as an external interrupt before sleeping to be able to wake up from the UART. Do you see this kind of features as part of the UART driver or as an extra layer above ? I'm glad this topic is moving forward. |
I'd say this would be part of the uart driver, as it is up to the driver how it behaves in context with low power modes. But we need to be careful, as we don't want to run in situations, where we lose the first char send over the UART when we need to wakeup first... |
I prefer to see this not as a design flaw of xtimer, but rather a misconfiguration of the boards. UART: SPI/I2C: |
Yes and no. Sure you can configure the xtimer to use some low-power timer (typically clocked by a 32khz crystal). But this would mean that xtimer looses quite some accuracy compared to running it with some xx MHz timer. Though this might be sufficient for some scenarios, this might not be an option for others -> hence this is not a generic solution. What we need is IMHO a (or a set of) high level timer API(s), that can offer both... @kaspar030 and me are currently experimenting with some approaches, we will let the community know as soon as we have some results... |
A submodule-based approach is shown in #7597 . Once we agreed on that, I will showcase a pm implementation for the atmega1284p (just need to merge code here, it's already finished!) |
I proposed a different approach in #7648 which is not dependent on the current build system! |
A full implementation of pm_layered can be seen in my branch for the atmega1284p and periph on atmega_common |
Is someone still working on this? |
@benpicco yes, what's your question? |
@roberthartung Well I wanted to know what is still missing to make this usable - especially switching to sleep mode when no thread is scheduled and getting woken up by RTC/slow timer when the next task is scheduled. But as I understood now, I should wait for the new ztimer API which should make it possible to implement this? pm for devices that are not used/active would also be interesting. |
@benpicco I am using this actively today already. As listed above, I have a fully working branch for pm_layered in atmega1284p. PM for devices is quite hard. In general the developer should take care of this, by e.g. freeing i2c/spi/... which leads to |
I think this needs API additions. Something like "uart_rx_pause()/unpause()", which could be called by stdio_uart_read(), or something in that direction. Something that can be done the same or very similar for the other periphs. |
If the device supports wake on RX you would not even need that. You'd lose the first character either way, but for many applications that's fine. |
Yes. It would still be nice to be able to control this in some define way. Going to sleep as soon as the prompt of a shell arrives would make it unusable. Been there... I could imagine the shell staying awake for only a couple of seconds, then saying "sleeping now, press CTRL-D a couple of times to wake up, until '>' is shown ". So after the idle timer runs out, it needs to do something. |
The shell is special, it's a debug tool not the main use case. This way devices would not waste battery waiting for a shell interaction that never happens, while you can still comfortably debug it (just press enter once to wake up the device). |
Yup, but unblock what? I mean, how do we determine the pm mode that the shell should block/unblock, supporting multiple stdio_ backends over many platforms? shell is using getchar() for reading. We could of course hack "SHELL_PM_SLEEP_MODE", set that to "UART_STDIO_SLEEP_MODE", somehow populate that depending on the uart or stdio configuration, .... but it feels at least ... brittle. I'm just realizing that file descriptors don't have a way to sleep/unsleep them, either. ;( |
Ah, but as long as the MCU is doing something, it won't sleep anyways. Only when the shell is waiting in the prompt (in read()) the power mode might neet to be blocked. |
Huh, is this not a general problem? |
In my case I am just unblocking/blocking the UART used in the shell and that works just fine. |
that's with a hard_coded value for pm_block()/unblock()? |
pm_block/pm_unblock is implemented in the periph driver for uart. so you only have to know which UART is used. All I do is |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you want me to ignore this issue, please mark it with the "State: don't stale" label. Thank you for your contributions. |
This issue is created for tracking the
pm
implementation status and synchronize efforts.Steps needed for implementation:
pm
interfacepm_layered
where applicablepm_block
/pm_unblock
)Implementation status:
The text was updated successfully, but these errors were encountered: