diff options
author | 2021-03-13 22:56:42 +0100 | |
---|---|---|
committer | 2021-03-13 22:56:42 +0100 | |
commit | 7c731fdbafabaf64377f9917cef2cf79e3d8c85a (patch) | |
tree | f58e594e031a9030d6409c00c53788a5dd2fd7f9 | |
parent | d4d5713e5ac586e662d53468f8852ea09d1634c1 (diff) | |
download | rtic-7c731fdbafabaf64377f9917cef2cf79e3d8c85a.tar.gz rtic-7c731fdbafabaf64377f9917cef2cf79e3d8c85a.tar.zst rtic-7c731fdbafabaf64377f9917cef2cf79e3d8c85a.zip |
late example now works with RacyCell
-rw-r--r-- | examples/late.rs | 13 | ||||
-rw-r--r-- | macros/src/codegen/post_init.rs | 2 | ||||
-rw-r--r-- | macros/src/codegen/resources.rs | 22 |
3 files changed, 22 insertions, 15 deletions
diff --git a/examples/late.rs b/examples/late.rs index 1e9859f2..b53daac8 100644 --- a/examples/late.rs +++ b/examples/late.rs @@ -20,7 +20,7 @@ mod app { // Late resources #[resources] struct Resources { - // p: Producer<'static, u32, U4>, + p: Producer<'static, u32, U4>, c: Consumer<'static, u32, U4>, #[task_local] #[init(Queue(i::Queue::new()))] @@ -32,8 +32,7 @@ mod app { let (p, c) = cx.resources.q.split(); // Initialization of late resources - // (init::LateResources { p, c }, init::Monotonics()) - (init::LateResources { c }, init::Monotonics()) + (init::LateResources { p, c }, init::Monotonics()) } #[idle(resources = [c])] @@ -49,8 +48,8 @@ mod app { } } - // #[task(binds = UART0, resources = [p])] - // fn uart0(mut c: uart0::Context) { - // c.resources.p.lock(|p| p.enqueue(42).unwrap()); - // } + #[task(binds = UART0, resources = [p])] + fn uart0(mut c: uart0::Context) { + c.resources.p.lock(|p| p.enqueue(42).unwrap()); + } } diff --git a/macros/src/codegen/post_init.rs b/macros/src/codegen/post_init.rs index 733d6eec..c7a574ac 100644 --- a/macros/src/codegen/post_init.rs +++ b/macros/src/codegen/post_init.rs @@ -24,7 +24,7 @@ pub fn codegen(app: &App, analysis: &Analysis) -> Vec<TokenStream2> { // - `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); + #mangled_name.get_mut_unchecked().as_mut_ptr().write(late.#name); )); } } diff --git a/macros/src/codegen/resources.rs b/macros/src/codegen/resources.rs index ad01ccbf..37de9124 100644 --- a/macros/src/codegen/resources.rs +++ b/macros/src/codegen/resources.rs @@ -93,17 +93,23 @@ pub fn codegen( } )); - let ptr = if expr.is_none() { + let (ptr, doc) = if expr.is_none() { // late resource - quote!( - #(#cfgs)* - &mut #mangled_name.get_mut_unchecked().assume_init() + ( + quote!( + #(#cfgs)* + #mangled_name.get_mut_unchecked().as_mut_ptr() + ), + "late", ) } else { // early resource - quote!( - #(#cfgs)* - unsafe { #mangled_name.get_mut_unchecked() } + ( + quote!( + #(#cfgs)* + #mangled_name.get_mut_unchecked() + ), + "early", ) }; @@ -114,6 +120,8 @@ pub fn codegen( None => 0, }; + // let doc = format!(" RTIC internal ({} resource): {}:{}", doc, file!(), line!()); + mod_app.push(util::impl_mutex( extra, cfgs, |