-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Add custom idle-hook feature to thread mode executor #4951
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
base: main
Are you sure you want to change the base?
Add custom idle-hook feature to thread mode executor #4951
Conversation
|
Actually, I would need to use this with... |
|
That would be a cool and practical addition. |
Yes, we could also add the feature to But I think we could easily change this from fn my_custom_idle_hook() {
Executor::default_idle();
}to something like this fn my_custom_idle_hook(executor: &Executor) {
executor.default_idle();
}That would probably even be cleaner and more flexible. I will change it. |
a28b5e9 to
539e25d
Compare
|
Added |
Scope
This PR adds a backwards-compatible feature, that allows the registration of a custom idle-hook function for the thread mode executor.
By enabling the
idle-hookfeature forembassy-executoran additional executor method is provided to the application:This feature is also added to
embassy-executor-macrosfor convenient custom idle-hook registration:#[embassy_executor::main(idle_hook = "my_idle_hook")]The feature is supported on the following architectures:
arch-cortex-m,arch-cortex-ar,arch-riscv32,arch-avr,arch-std.The executor's default idle implementation is provided to the application
Executor::default_idle(&self), e.g. if the custom idle-hook wants/needs to use it.Goal
Previously, the idle behavior for each
Executorimplementation was pre-defined, e.g.WFE/WFI/SLEEPinstruction.If an application or chip requires a different/custom idle implementation or pre-idle/post-idle steps (as in embassy-stm32/src/low_power.rs), a custom
Executorhas to be implemented.The goal is to enable developers to use the existing executor implementations while being able to customize the idle behavior very easily (if necessary).
This reduces the overhead and duplication of implementing a custom
Executor.Examples
Example embassy-nrf
Example: embassy-nrf + nrf-softdevice
When using
nrf-softdevicethe arch-cortex-m executor's default idle implementation is not able to put the system into a low power mode.