diff options
author | 2021-04-20 13:58:22 +0000 | |
---|---|---|
committer | 2021-04-20 13:58:22 +0000 | |
commit | f586c3c5a8a14e37d69d229fd6e69459a6074cc4 (patch) | |
tree | 194d5268b165f21c925fb4523a67233c33c2bba5 | |
parent | b8b13573aebfa6719e25f0e2c8b1c28cdb66301a (diff) | |
parent | bc10fe266d7a3fbae0235cee23d62f75877bf6c4 (diff) | |
download | rtic-f586c3c5a8a14e37d69d229fd6e69459a6074cc4.tar.gz rtic-f586c3c5a8a14e37d69d229fd6e69459a6074cc4.tar.zst rtic-f586c3c5a8a14e37d69d229fd6e69459a6074cc4.zip |
Merge #476
476: reclaim stack space used in late init r=korken89 a=conorpp
Fixes #474.
Tested that there is no longer any stack overhead leftover from moving init resources.
(made mistake force pushing with last PR when trying to fix lint)
The expansion for an example with 2 buffers as resources changes from:
```rust
let (late, mut monotonics) = crate::APP::init(init::Context::new(core.into()));
__rtic_internal_mybuffer.as_mut_ptr().write(late.mybuffer);
__rtic_internal_mybuffer2.as_mut_ptr().write(late.mybuffer2);
rtic::export::interrupt::enable();
crate::APP::idle(idle::Context::new(&rtic::export::Priority::new(0)))
```
to:
```rust
#[inline(never)]
fn __rtic_init_resources<F>(f: F)
where
F: FnOnce(),
{
f();
}
__rtic_init_resources(|| {
let (late, mut monotonics) = crate::APP::init(init::Context::new(core.into()));
__rtic_internal_mybuffer.as_mut_ptr().write(late.mybuffer);
__rtic_internal_mybuffer2.as_mut_ptr().write(late.mybuffer2);
rtic::export::interrupt::enable();
});
crate::APP::idle(idle::Context::new(&rtic::export::Priority::new(0)))
```
Co-authored-by: Conor Patrick <conorpp94@gmail.com>
-rw-r--r-- | macros/src/codegen.rs | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/macros/src/codegen.rs b/macros/src/codegen.rs index cf728a7d..21db1438 100644 --- a/macros/src/codegen.rs +++ b/macros/src/codegen.rs @@ -66,9 +66,17 @@ pub fn app(app: &App, analysis: &Analysis, extra: &Extra) -> TokenStream2 { #(#pre_init_stmts)* - #call_init + #[inline(never)] + fn __rtic_init_resources<F>(f: F) where F: FnOnce() { + f(); + } + + // Wrap late_init_stmts in a function to ensure that stack space is reclaimed. + __rtic_init_resources(||{ + #call_init - #(#post_init_stmts)* + #(#post_init_stmts)* + }); #call_idle } |