diff options
Diffstat (limited to 'macros/src/codegen/post_init.rs')
-rw-r--r-- | macros/src/codegen/post_init.rs | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/macros/src/codegen/post_init.rs b/macros/src/codegen/post_init.rs index 96c5df80..78548bcd 100644 --- a/macros/src/codegen/post_init.rs +++ b/macros/src/codegen/post_init.rs @@ -17,16 +17,24 @@ pub fn codegen(app: &App, analysis: &Analysis) -> Vec<TokenStream2> { // If it's live let cfgs = app.late_resources[name].cfgs.clone(); if analysis.locations.get(name).is_some() { - // Need to also include the cfgs stmts.push(quote!( - #(#cfgs)* - #mangled_name.as_mut_ptr().write(late.#name); + // We include the cfgs + #(#cfgs)* + // Late resource is a RacyCell<MaybeUninit<T>> + // - `get_mut_unchecked` to obtain `MaybeUninit<T>` + // - `as_mut_ptr` to obtain a raw pointer to `MaybeUninit<T>` + // - `write` the defined value for the late resource T + #mangled_name.get_mut_unchecked().as_mut_ptr().write(late.#name); )); } } } for (i, (monotonic, _)) in app.monotonics.iter().enumerate() { + // For future use + // let doc = format!(" RTIC internal: {}:{}", file!(), line!()); + // stmts.push(quote!(#[doc = #doc])); + let idx = Index { index: i as u32, span: Span::call_site(), @@ -36,7 +44,7 @@ pub fn codegen(app: &App, analysis: &Analysis) -> Vec<TokenStream2> { // Store the monotonic let name = util::monotonic_ident(&monotonic.to_string()); let name = util::mark_internal_ident(&name); - stmts.push(quote!(#name = Some(monotonics.#idx);)); + stmts.push(quote!(*#name.get_mut_unchecked() = Some(monotonics.#idx);)); } // Enable the interrupts -- this completes the `init`-ialization phase |