diff --git a/examples/async-task.rs b/examples/async-task.rs index 4d25ec4401..7d0ee86e03 100644 --- a/examples/async-task.rs +++ b/examples/async-task.rs @@ -13,7 +13,6 @@ use panic_semihosting as _; #[rtic::app(device = lm3s6965, dispatchers = [SSI0, UART0], peripherals = true)] mod app { use cortex_m_semihosting::{debug, hprintln}; - use systick_monotonic::*; #[shared] struct Shared {} @@ -21,21 +20,13 @@ mod app { #[local] struct Local {} - #[monotonic(binds = SysTick, default = true)] - type MyMono = Systick<100>; - #[init] - fn init(cx: init::Context) -> (Shared, Local, init::Monotonics) { + fn init(cx: init::Context) -> (Shared, Local) { hprintln!("init").unwrap(); - normal_task::spawn().ok(); - async_task::spawn().ok(); + async_task::spawn().unwrap(); - ( - Shared {}, - Local {}, - init::Monotonics(Systick::new(cx.core.SYST, 12_000_000)), - ) + (Shared {}, Local {}) } #[idle] @@ -47,11 +38,6 @@ mod app { } } - #[task] - fn normal_task(_cx: normal_task::Context) { - hprintln!("hello from normal").ok(); - } - #[task] async fn async_task(_cx: async_task::Context) { hprintln!("hello from async").ok(); diff --git a/macros/src/codegen/async_dispatchers.rs b/macros/src/codegen/async_dispatchers.rs index c8116654e1..f428cef04f 100644 --- a/macros/src/codegen/async_dispatchers.rs +++ b/macros/src/codegen/async_dispatchers.rs @@ -45,23 +45,20 @@ pub fn codegen(app: &App, analysis: &Analysis) -> Vec { let executor_run_ident = util::executor_run_ident(name); let rq = util::rq_async_ident(name); - let (rq_ty, rq_expr) = { - ( - quote!(rtic::export::ASYNCRQ<(), 2>), // TODO: This needs updating to a counter instead of a queue - quote!(rtic::export::Queue::new()), - ) - }; items.push(quote!( #[doc(hidden)] #[allow(non_camel_case_types)] #[allow(non_upper_case_globals)] - static #rq: rtic::RacyCell<#rq_ty> = rtic::RacyCell::new(#rq_expr); + static #rq: core::sync::atomic::AtomicBool = core::sync::atomic::AtomicBool::new(false); )); stmts.push(quote!( if !(&*#exec_name.get()).is_running() { - if let Some(()) = rtic::export::interrupt::free(|_| (&mut *#rq.get_mut()).dequeue()) { + // TODO Fix this to be compare and swap + if #rq.load(core::sync::atomic::Ordering::Relaxed) { + #rq.store(false, core::sync::atomic::Ordering::Relaxed); + // The async executor needs a static priority #prio_name.get_mut().write(rtic::export::Priority::new(PRIORITY)); @@ -77,7 +74,7 @@ pub fn codegen(app: &App, analysis: &Analysis) -> Vec { if (&mut *#exec_name.get_mut()).poll(|| { #executor_run_ident.store(true, core::sync::atomic::Ordering::Release); rtic::pend(#device::#enum_::#interrupt); - }) && !rtic::export::interrupt::free(|_| (&*#rq.get_mut()).is_empty()) { + }) && #rq.load(core::sync::atomic::Ordering::Relaxed) { // If the ready queue is not empty and the executor finished, restart this // dispatch to check if the executor should be restarted. rtic::pend(#device::#enum_::#interrupt); diff --git a/macros/src/codegen/module.rs b/macros/src/codegen/module.rs index b4ad68aad8..7bbfdf37c2 100644 --- a/macros/src/codegen/module.rs +++ b/macros/src/codegen/module.rs @@ -183,13 +183,14 @@ pub fn codegen( #[doc(hidden)] pub fn #internal_spawn_ident() -> Result<(), ()> { unsafe { - let r = rtic::export::interrupt::free(|_| (&mut *#rq.get_mut()).enqueue(())); - - if r.is_ok() { + // TODO: Fix this to be compare and swap + if #rq.load(core::sync::atomic::Ordering::Acquire) { + Err(()) + } else { + #rq.store(true, core::sync::atomic::Ordering::Release); rtic::pend(#device::#enum_::#interrupt); + Ok(()) } - - r } })); diff --git a/macros/src/codegen/util.rs b/macros/src/codegen/util.rs index 61bde98fa5..aa720c0e5f 100644 --- a/macros/src/codegen/util.rs +++ b/macros/src/codegen/util.rs @@ -154,7 +154,7 @@ pub fn local_resources_ident(ctxt: Context, app: &App) -> Ident { /// Generates an identifier for a ready queue, async task version pub fn rq_async_ident(async_task_name: &Ident) -> Ident { - mark_internal_name(&format!("ASYNC_TACK_{}_RQ", async_task_name)) + mark_internal_name(&format!("ASYNC_TASK_{}_RQ", async_task_name)) } /// Suffixed identifier diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 0000000000..bbd57bcb24 --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,4 @@ +[toolchain] +channel = "nightly" +components = [ "rust-src", "rustfmt", "llvm-tools-preview" ] +targets = [ "thumbv7em-none-eabihf" ]