diff --git a/Cargo.toml b/Cargo.toml index 977a517a63..112e624a8b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,6 +24,7 @@ compiletest_rs = "0.3.5" [dev-dependencies] panic-abort = "0.1.1" panic-itm = "0.1.0" +typenum = "1.10.0" [dev-dependencies.stm32f103xx] features = ["rt"] @@ -33,4 +34,4 @@ version = "0.9.0" cm7-r0p1 = ["cortex-m/cm7-r0p1"] [profile.release] -lto = true \ No newline at end of file +lto = true diff --git a/macros/src/trans.rs b/macros/src/trans.rs index 7fbe9e0798..612d9e5876 100644 --- a/macros/src/trans.rs +++ b/macros/src/trans.rs @@ -59,13 +59,13 @@ pub fn app(ctxt: &Context, app: &App) -> Tokens { }); resources.push(quote! { - pub struct #name { _0: () } + pub struct #name { _not_send_or_sync: PhantomData<*const ()> } #[allow(dead_code)] #[allow(unsafe_code)] impl #name { pub unsafe fn new() -> Self { - #name { _0: () } + #name { _not_send_or_sync: PhantomData } } } }); @@ -75,6 +75,9 @@ pub fn app(ctxt: &Context, app: &App) -> Tokens { mod __resource { extern crate #krate; + #[allow(unused_imports)] + use core::marker::PhantomData; + #(#resources)* } }); @@ -776,16 +779,26 @@ pub fn app(ctxt: &Context, app: &App) -> Tokens { .resources .iter() .map(|res| { - let ty = &app.resources[res].ty; + if ctxt.ceilings.resources()[res].is_owned() { + let ty = &app.resources[res].ty; - quote!(pub #res: &'static mut #ty) + quote!(pub #res: &'static mut #ty) + } else { + quote!(pub #res: __resource::#res) + } }) .collect::>(); let res_exprs = app.idle .resources .iter() - .map(|res| quote!(#res: __resource::#res::get())) + .map(|res| { + if ctxt.ceilings.resources()[res].is_owned() { + quote!(#res: __resource::#res::get()) + } else { + quote!(#res: __resource::#res::new()) + } + }) .collect::>(); root.push(quote! { @@ -797,6 +810,7 @@ pub fn app(ctxt: &Context, app: &App) -> Tokens { pub struct Context { pub resources: Resources, + pub threshold: #krate::Threshold<#krate::U0>, } #[allow(unsafe_code)] @@ -804,6 +818,7 @@ pub fn app(ctxt: &Context, app: &App) -> Tokens { pub unsafe fn new() -> Self { Context { resources: Resources::new(), + threshold: #krate::Threshold::new(), } } } @@ -829,6 +844,7 @@ pub fn app(ctxt: &Context, app: &App) -> Tokens { let init = &app.init.path; root.push(quote! { #[allow(unsafe_code)] + #[deny(const_err)] fn main() { #[allow(unused_imports)] use #hidden::#krate::Resource; diff --git a/src/lib.rs b/src/lib.rs index cb8e0b75b1..d6fd0b4c00 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -91,6 +91,25 @@ impl Core { } } +pub fn atomic(t: &mut Threshold

, f: F) -> R +where + F: FnOnce(&mut Threshold) -> R, + P: Unsigned, +{ + unsafe { + debug_assert!(P::to_u8() <= 255); + + if P::to_u8() < 255 { + interrupt::disable(); + let r = f(&mut Threshold::new()); + interrupt::enable(); + r + } else { + f(&mut Threshold::new()) + } + } +} + #[doc(hidden)] pub const unsafe fn uninitialized() -> T { #[allow(unions_with_drop_fields)] @@ -102,6 +121,7 @@ pub const unsafe fn uninitialized() -> T { U { none: () }.some } +#[doc(hidden)] pub unsafe fn set_pending(interrupt: I) where I: Nr, diff --git a/src/resource.rs b/src/resource.rs index f3f17d3aac..d03d684b29 100644 --- a/src/resource.rs +++ b/src/resource.rs @@ -3,7 +3,8 @@ use core::marker::PhantomData; #[cfg(not(armv6m))] use cortex_m::register::basepri; -use typenum::{Max, Maximum, Unsigned}; +use typenum::type_operators::IsGreaterOrEqual; +use typenum::{Max, Maximum, True, Unsigned}; pub struct Threshold where @@ -34,11 +35,17 @@ pub unsafe trait Resource { #[doc(hidden)] unsafe fn get() -> &'static mut Self::Data; - fn borrow<'cs>(&'cs self, _t: &'cs Threshold) -> &'cs Self::Data { + fn borrow<'cs, P>(&'cs self, _t: &'cs Threshold

) -> &'cs Self::Data + where + P: IsGreaterOrEqual + Unsigned, + { unsafe { Self::get() } } - fn borrow_mut<'cs>(&'cs mut self, _t: &'cs Threshold) -> &'cs mut Self::Data { + fn borrow_mut<'cs, P>(&'cs mut self, _t: &'cs Threshold

) -> &'cs mut Self::Data + where + P: IsGreaterOrEqual + Unsigned, + { unsafe { Self::get() } } diff --git a/tests/cfail/critical-section.rs b/tests/cfail/critical-section.rs index 65719788cb..a055de4af9 100644 --- a/tests/cfail/critical-section.rs +++ b/tests/cfail/critical-section.rs @@ -5,9 +5,10 @@ #![no_std] extern crate cortex_m_rtfm as rtfm; +extern crate panic_abort; extern crate stm32f103xx; -use rtfm::{app, Resource, Threshold}; +use rtfm::{app, Resource}; app! { device: stm32f103xx, @@ -21,23 +22,27 @@ app! { }, tasks: { - EXTI0: { - path: exti0, - priority: 1, + exti0: { + interrupt: EXTI0, resources: [ON], }, }, } -fn init(_p: init::Peripherals, _r: init::Resources) {} +fn init(_ctxt: init::Context) -> init::LateResources { + init::LateResources {} +} + +fn idle(mut ctxt: idle::Context) -> ! { + let t = &mut ctxt.threshold; + let on = ctxt.resources.ON; -fn idle(t: &mut Threshold, r: idle::Resources) -> ! { let state = rtfm::atomic(t, |t| { // ERROR borrow can't escape this *global* critical section - r.ON.borrow(t) //~ error cannot infer an appropriate lifetime + on.borrow(t) //~ error cannot infer an appropriate lifetime }); - let state = r.ON.claim(t, |state, _t| { + let state = on.claim(t, |state, _t| { // ERROR borrow can't escape this critical section state //~ error cannot infer an appropriate lifetime }); @@ -45,4 +50,4 @@ fn idle(t: &mut Threshold, r: idle::Resources) -> ! { loop {} } -fn exti0(_t: &mut Threshold, _r: EXTI0::Resources) {} +fn exti0(_ctxt: exti0::Context) {} diff --git a/tests/cfail/duplicated-task.rs b/tests/cfail/duplicated-task.rs index 82b7ac6306..b2f2c69149 100644 --- a/tests/cfail/duplicated-task.rs +++ b/tests/cfail/duplicated-task.rs @@ -8,21 +8,22 @@ extern crate stm32f103xx; use rtfm::app; -app! { - //~^ error proc macro panicked +app! { //~ error proc macro panicked device: stm32f103xx, tasks: { - SYS_TICK: { + a: { + interrupt: EXTI0, //~ error this interrupt is already bound to another task priority: 1, }, - SYS_TICK: { + b: { + interrupt: EXTI0, priority: 2, }, }, } -fn init(_p: init::Peripherals) {} +fn init(_ctxt: init::Context) -> init::LateResources {} -fn idle() -> ! {} +fn idle(_ctxt: idle::Context) -> ! {} diff --git a/tests/cfail/exception.rs b/tests/cfail/exception.rs index e2e749a27e..7e5a3ef36f 100644 --- a/tests/cfail/exception.rs +++ b/tests/cfail/exception.rs @@ -4,24 +4,27 @@ #![no_std] extern crate cortex_m_rtfm as rtfm; +extern crate panic_abort; extern crate stm32f103xx; use rtfm::app; app! { //~ error proc macro panicked - device: stm32f103xx, + device: stm32f103xx, //~ no variant named `SYS_TICK` found for type `stm32f103xx::Interrupt` tasks: { - // ERROR exceptions can't be enabled / disabled here - SYS_TICK: { - enabled: true, - priority: 1, + sys_tick: { + interrupt: SYS_TICK, // ERROR can't bind to exception }, }, } -fn init(_p: init::Peripherals) {} +fn init(_ctxt: init::Context) -> init::LateResources { + init::LateResources {} +} -fn idle() -> ! { +fn idle(_ctxt: idle::Context) -> ! { loop {} } + +fn sys_tick(_ctxt: sys_tick::Context) {} diff --git a/tests/cfail/idle.rs b/tests/cfail/idle.rs index 79fe99b0da..6dde1a6364 100644 --- a/tests/cfail/idle.rs +++ b/tests/cfail/idle.rs @@ -4,15 +4,18 @@ #![no_std] extern crate cortex_m_rtfm as rtfm; +extern crate panic_abort; extern crate stm32f103xx; use rtfm::app; -app! { //~ error mismatched types +app! { //~ mismatched types device: stm32f103xx, } -fn init(_p: init::Peripherals) {} +fn init(_ctxt: init::Context) -> init::LateResources { + init::LateResources {} +} // ERROR `idle` must be a diverging function -fn idle() {} +fn idle(_ctxt: idle::Context) {} diff --git a/tests/cfail/init-resource-share-idle.rs b/tests/cfail/init-resource-share-idle.rs index 4e2ed4aa84..476f519f84 100644 --- a/tests/cfail/init-resource-share-idle.rs +++ b/tests/cfail/init-resource-share-idle.rs @@ -3,6 +3,7 @@ #![no_std] extern crate cortex_m_rtfm as rtfm; +extern crate panic_abort; extern crate stm32f103xx; use rtfm::app; @@ -24,8 +25,10 @@ app! { //~ proc macro panicked }, } -fn init(_p: init::Peripherals, _r: init::Resources) {} +fn init(_ctxt: init::Context) -> init::LateResources { + init::LateResources {} +} -fn idle(_r: init::Resources) -> ! { +fn idle(_ctxt: idle::Context) -> ! { loop {} } diff --git a/tests/cfail/init-resource-share-task.rs b/tests/cfail/init-resource-share-task.rs index 391c543d2c..0a86478d7f 100644 --- a/tests/cfail/init-resource-share-task.rs +++ b/tests/cfail/init-resource-share-task.rs @@ -1,8 +1,10 @@ +#![deny(unsafe_code)] #![deny(warnings)] #![feature(proc_macro)] #![no_std] extern crate cortex_m_rtfm as rtfm; +extern crate panic_abort; extern crate stm32f103xx; use rtfm::app; @@ -19,18 +21,20 @@ app! { //~ proc macro panicked }, tasks: { - SYS_TICK: { - path: sys_tick, + exti0: { + interrupt: EXTI0, resources: [BUFFER], //~^ error: this resource is owned by `init` and can't be shared }, }, } -fn init(_p: init::Peripherals) {} +fn init(_ctxt: init::Context) -> init::LateResources { + init::LateResources {} +} -fn idle() -> ! { +fn idle(_ctxt: idle::Context) -> ! { loop {} } -fn sys_tick() {} +fn exti0(_ctxt: exti0::Context) {} diff --git a/tests/cfail/init.rs b/tests/cfail/init.rs index d2823e3f82..f59417a6f3 100644 --- a/tests/cfail/init.rs +++ b/tests/cfail/init.rs @@ -4,17 +4,19 @@ #![no_std] extern crate cortex_m_rtfm as rtfm; +extern crate panic_abort; extern crate stm32f103xx; use rtfm::app; -app! { //~ error mismatched types +app! { //~ error incorrect number of function parameters + //~^ note expected type `fn(init::Context) -> _ZN4init13LateResourcesE` device: stm32f103xx, } // ERROR `init` must have signature `fn (init::Peripherals)` fn init() {} -fn idle() -> ! { +fn idle(_ctxt: idle::Context) -> ! { loop {} } diff --git a/tests/cfail/interrupt.rs b/tests/cfail/interrupt.rs index 7c345a11e3..bb9014864a 100644 --- a/tests/cfail/interrupt.rs +++ b/tests/cfail/interrupt.rs @@ -4,24 +4,27 @@ #![no_std] extern crate cortex_m_rtfm as rtfm; +extern crate panic_abort; extern crate stm32f103xx; use rtfm::app; -app! { //~ error no variant named `EXTI33` found for type +app! { //~ error no variant named `EXTI33` found for type `stm32f103xx::Interrupt` device: stm32f103xx, tasks: { - EXTI33: { - path: exti33, + exti33: { + interrupt: EXTI33, }, }, } -fn init(_p: init::Peripherals) {} +fn init(_ctxt: init::Context) -> init::LateResources { + init::LateResources {} +} -fn idle() -> ! { +fn idle(_ctxt: idle::Context) -> ! { loop {} } -fn exti33() {} +fn exti33(_ctxt: exti33::Context) {} diff --git a/tests/cfail/late-resource-init.rs b/tests/cfail/late-resource-init.rs index a1059f3403..53a5caefc7 100644 --- a/tests/cfail/late-resource-init.rs +++ b/tests/cfail/late-resource-init.rs @@ -4,9 +4,10 @@ #![no_std] extern crate cortex_m_rtfm as rtfm; +extern crate panic_abort; extern crate stm32f103xx; -use rtfm::{app, Threshold}; +use rtfm::app; app! { device: stm32f103xx, @@ -17,34 +18,32 @@ app! { }, tasks: { - EXTI0: { - path: exti0, - priority: 1, + exti0: { + interrupt: EXTI0, + // priority: 1, resources: [A, LATE], }, - EXTI1: { - path: exti1, + exti1: { + interrupt: EXTI1, priority: 2, resources: [A, LATE], }, }, } -fn init(_p: init::Peripherals, r: init::Resources) -> init::LateResources { - // Try to use a resource that's not yet initialized: - r.LATE; - //~^ error: no field `LATE` +fn init(ctxt: init::Context) -> init::LateResources { + // Tried to use a resource that's not yet initialized: + let _late = ctxt.resources.LATE; + //~^ error: no field `LATE` on type `init::Resources` - init::LateResources { - LATE: 0, - } + init::LateResources { LATE: 0 } } -fn idle() -> ! { +fn idle(_ctxt: idle::Context) -> ! { loop {} } -fn exti0(_t: &mut Threshold, _r: EXTI0::Resources) {} +fn exti0(_ctxt: exti0::Context) {} -fn exti1(_t: &mut Threshold, _r: EXTI1::Resources) {} +fn exti1(_ctxt: exti1::Context) {} diff --git a/tests/cfail/lock.rs b/tests/cfail/lock.rs index eb03b7d541..367c3af986 100644 --- a/tests/cfail/lock.rs +++ b/tests/cfail/lock.rs @@ -5,9 +5,10 @@ #![no_std] extern crate cortex_m_rtfm as rtfm; +extern crate panic_abort; extern crate stm32f103xx; -use rtfm::{app, Resource, Threshold}; +use rtfm::{app, Resource}; app! { device: stm32f103xx, @@ -15,54 +16,62 @@ app! { resources: { static ON: bool = false; static MAX: u8 = 0; + static OWNED: bool = false; }, tasks: { - EXTI0: { - path: exti0, - priority: 1, + exti0: { + interrupt: EXTI0, + // priority: 1, resources: [MAX, ON], }, - EXTI1: { - path: exti1, + exti1: { + interrupt: EXTI1, priority: 2, - resources: [ON], + resources: [ON, OWNED], }, - EXTI2: { - path: exti2, + exti2: { + interrupt: EXTI2, priority: 16, resources: [MAX], }, }, } -fn init(_p: init::Peripherals, _r: init::Resources) {} +fn init(_ctxt: init::Context) -> init::LateResources { + init::LateResources {} +} -fn idle() -> ! { +fn idle(_ctxt: idle::Context) -> ! { loop {} } -fn exti0(mut t: &mut Threshold, mut r: EXTI0::Resources) { +#[allow(non_snake_case)] +fn exti0(mut ctxt: exti0::Context) { + let exti0::Resources { ON, mut MAX } = ctxt.resources; + let t = &mut ctxt.threshold; + // ERROR need to lock to access the resource because priority < ceiling - if *r.ON { - //~^ error type `EXTI0::ON` cannot be dereferenced + { + let _on = ON.borrow(t); + //~^ error type mismatch resolving } // OK need to lock to access the resource - if r.ON.claim(&mut t, |on, _| *on) {} + if ON.claim(t, |on, _| *on) {} // OK can claim a resource with maximum ceiling - r.MAX.claim_mut(&mut t, |max, _| *max += 1); + MAX.claim_mut(t, |max, _| *max += 1); } -fn exti1(mut t: &mut Threshold, r: EXTI1::Resources) { - // OK to directly access the resource because priority == ceiling - if *r.ON {} +#[allow(non_snake_case)] +fn exti1(ctxt: exti1::Context) { + let exti1::Resources { OWNED, .. } = ctxt.resources; - // though the resource can still be claimed -- the claim is a no-op - if r.ON.claim(&mut t, |on, _| *on) {} + // OK to directly access the resource because this task is the only owner + if *OWNED {} } -fn exti2(_t: &mut Threshold, _r: EXTI2::Resources) {} +fn exti2(_ctxt: exti2::Context) {} diff --git a/tests/cfail/peripheral-alias.rs b/tests/cfail/peripheral-alias.rs deleted file mode 100644 index 3528ec666b..0000000000 --- a/tests/cfail/peripheral-alias.rs +++ /dev/null @@ -1,28 +0,0 @@ -#![deny(unsafe_code)] -#![deny(warnings)] -#![feature(proc_macro)] -#![no_std] - -extern crate cortex_m_rtfm as rtfm; -extern crate stm32f103xx; - -use rtfm::app; - -app! { //~ error proc macro panicked - device: stm32f103xx, - - tasks: { - EXTI0: { - enabled: true, - priority: 1, - // ERROR peripheral appears twice in this list - resources: [GPIOA, GPIOA], - }, - }, -} - -fn init(_p: init::Peripherals) {} - -fn idle() -> ! { - loop {} -} diff --git a/tests/cfail/priority-too-high.rs b/tests/cfail/priority-too-high.rs index 15f6b7a86c..6453890b28 100644 --- a/tests/cfail/priority-too-high.rs +++ b/tests/cfail/priority-too-high.rs @@ -1,30 +1,30 @@ -#![deny(unsafe_code)] -#![deny(warnings)] #![feature(proc_macro)] #![no_std] extern crate cortex_m_rtfm as rtfm; +extern crate panic_abort; extern crate stm32f103xx; use rtfm::app; app! { //~ error attempt to subtract with overflow - //~^ error constant evaluation error device: stm32f103xx, tasks: { - SYS_TICK: { - path: sys_tick, + exti0: { + interrupt: EXTI0, // ERROR priority must be in the range [1, 16] priority: 17, }, }, } -fn init(_p: init::Peripherals) {} +fn init(_ctxt: init::Context) -> init::LateResources { + init::LateResources {} +} -fn idle() -> ! { +fn idle(_ctxt: idle::Context) -> ! { loop {} } -fn sys_tick() {} +fn exti0(_ctxt: exti0::Context) {} diff --git a/tests/cfail/priority-too-low.rs b/tests/cfail/priority-too-low.rs index e87951121f..8cf9b80247 100644 --- a/tests/cfail/priority-too-low.rs +++ b/tests/cfail/priority-too-low.rs @@ -4,27 +4,26 @@ #![no_std] extern crate cortex_m_rtfm as rtfm; +extern crate panic_abort; extern crate stm32f103xx; use rtfm::app; -app! { //~ error attempt to subtract with overflow - //~^ error constant evaluation error +app! { device: stm32f103xx, tasks: { - SYS_TICK: { - path: sys_tick, - // ERROR priority must be in the range [1, 16] - priority: 0, + exti0: { + interrupt: EXTI0, + priority: 0, //~ error this value is outside the valid range of `(1, 255)` }, }, } -fn init(_p: init::Peripherals) {} +fn init(_ctxt: init::Context) -> init::LateResources {} -fn idle() -> ! { +fn idle(_ctxt: idle::Context) -> ! { loop {} } -fn sys_tick() {} +fn exti0(_ctxt: exti0::Context) {} diff --git a/tests/cfail/resource-alias.rs b/tests/cfail/resource-alias.rs index e1c73bb581..b338070a95 100644 --- a/tests/cfail/resource-alias.rs +++ b/tests/cfail/resource-alias.rs @@ -4,6 +4,7 @@ #![no_std] extern crate cortex_m_rtfm as rtfm; +extern crate panic_abort; extern crate stm32f103xx; use rtfm::app; @@ -12,21 +13,23 @@ app! { //~ error proc macro panicked device: stm32f103xx, resources: { - // resource `MAX` listed twice - MAX: u8 = 0; - MAX: u16 = 0; + static MAX: u8 = 0; + static MAX: u16 = 0; //~ error this resource name appears more than once in this list }, tasks: { - EXTI0: { - enabled: true, - priority: 1, + exti0: { + interrupt: EXTI0, + resources: [ + MAX, + MAX, //~ error this resource name appears more than once in this list + ], }, }, } -fn init(_p: init::Peripherals) {} +fn init(_ctxt: init::Context) -> init::LateResources {} -fn idle() -> ! { +fn idle(_ctxt: idle::Context) -> ! { loop {} } diff --git a/tests/cfail/resource-not-send-sync.rs b/tests/cfail/resource-not-send-sync.rs index 60a20db1aa..9ed9b4e579 100644 --- a/tests/cfail/resource-not-send-sync.rs +++ b/tests/cfail/resource-not-send-sync.rs @@ -1,13 +1,13 @@ #![deny(unsafe_code)] #![deny(warnings)] -#![feature(const_fn)] #![feature(proc_macro)] #![no_std] extern crate cortex_m_rtfm as rtfm; +extern crate panic_abort; extern crate stm32f103xx; -use rtfm::{app, Threshold}; +use rtfm::app; app! { device: stm32f103xx, @@ -17,38 +17,47 @@ app! { }, tasks: { - EXTI0: { - path: exti0, - priority: 1, + exti0: { + interrupt: EXTI0, + // priority: 1, resources: [SHARED], }, - EXTI1: { - path: exti1, + exti1: { + interrupt: EXTI1, priority: 2, resources: [SHARED], }, }, } -fn init(_p: init::Peripherals, _r: init::Resources) {} +fn init(_ctxt: init::Context) -> init::LateResources { + init::LateResources {} +} -fn idle() -> ! { +fn idle(_ctxt: idle::Context) -> ! { loop {} } -fn is_send(_: &T) where T: Send {} -fn is_sync(_: &T) where T: Sync {} +fn is_send(_: &T) +where + T: Send, +{ +} +fn is_sync(_: &T) +where + T: Sync, +{ +} -fn exti0(_t: &mut Threshold, r: EXTI0::Resources) { +fn exti0(ctxt: exti0::Context) { // ERROR resource proxies can't be shared between tasks - is_sync(&r.SHARED); + is_sync(&ctxt.resources.SHARED); //~^ error `*const ()` cannot be shared between threads safely // ERROR resource proxies are not `Send`able across tasks - is_send(&r.SHARED); + is_send(&ctxt.resources.SHARED); //~^ error the trait bound `*const (): core::marker::Send` is not satisfied } -fn exti1(_t: &mut Threshold, _r: EXTI1::Resources) { -} +fn exti1(_ctxt: exti1::Context) {} diff --git a/tests/cfail/token-outlive.rs b/tests/cfail/token-outlive.rs index 819a3d1583..691e7d2ed3 100644 --- a/tests/cfail/token-outlive.rs +++ b/tests/cfail/token-outlive.rs @@ -1,13 +1,13 @@ #![deny(unsafe_code)] #![deny(warnings)] -#![feature(const_fn)] #![feature(proc_macro)] #![no_std] extern crate cortex_m_rtfm as rtfm; +extern crate panic_abort; extern crate stm32f103xx; -use rtfm::{app, Resource, Threshold}; +use rtfm::{app, Resource}; app! { device: stm32f103xx, @@ -17,30 +17,33 @@ app! { }, tasks: { - EXTI0: { - path: exti0, - priority: 1, + exti0: { + interrupt: EXTI0, + // priority: 1, resources: [STATE], }, - EXTI1: { - path: exti1, + exti1: { + interrupt: EXTI1, priority: 2, resources: [STATE], }, }, } -fn init(_p: init::Peripherals, _r: init::Resources) {} +fn init(_ctxt: init::Context) -> init::LateResources { + init::LateResources {} +} -fn idle() -> ! { +fn idle(_ctxt: idle::Context) -> ! { loop {} } -fn exti0(mut t: &mut Threshold, r: EXTI0::Resources) { +fn exti0(ctxt: exti0::Context) { // ERROR token should not outlive the critical section - let t = r.STATE.claim(&mut t, |_state, t| t); + let t = &mut ctxt.threshold; + let t = ctxt.resources.STATE.claim(t, |_state, t| t); //~^ error cannot infer an appropriate lifetime } -fn exti1(_t: &mut Threshold, _r: EXTI1::Resources) {} +fn exti1(_ctxt: exti1::Context) {} diff --git a/tests/cfail/token-transfer.rs b/tests/cfail/token-transfer.rs index f92e4b2b73..3890997f0f 100644 --- a/tests/cfail/token-transfer.rs +++ b/tests/cfail/token-transfer.rs @@ -5,15 +5,18 @@ #![no_std] extern crate cortex_m_rtfm as rtfm; +extern crate panic_abort; extern crate stm32f103xx; +extern crate typenum; use rtfm::{app, Threshold}; +use typenum::consts::U1; app! { //~ error bound `*const (): core::marker::Send` is not satisfied device: stm32f103xx, resources: { - static TOKEN: Option = None; + static TOKEN: Option> = None; }, idle: { @@ -21,17 +24,17 @@ app! { //~ error bound `*const (): core::marker::Send` is not satisfied }, tasks: { - EXTI0: { - path: exti0, + exti0: { + interrupt: EXTI0, resources: [TOKEN], }, } } -fn init(_p: init::Peripherals, _r: init::Resources) {} +fn init(_ctxt: init::Context) {} -fn idle(_t: &mut Threshold, _r: idle::Resources) -> ! { +fn idle(_ctxt: idle::Context) -> ! { loop {} } -fn exti0(_t: &mut Threshold, _r: EXTI0::Resources) {} +fn exti0(_ctxt: exti0::Context) {} diff --git a/tests/cfail/wrong-threshold.rs b/tests/cfail/wrong-threshold.rs index 149f357da3..c1b52f51a8 100644 --- a/tests/cfail/wrong-threshold.rs +++ b/tests/cfail/wrong-threshold.rs @@ -4,9 +4,10 @@ #![no_std] extern crate cortex_m_rtfm as rtfm; +extern crate panic_abort; extern crate stm32f103xx; -use rtfm::{app, Resource, Threshold}; +use rtfm::{app, Resource}; app! { device: stm32f103xx, @@ -17,32 +18,37 @@ app! { }, tasks: { - EXTI0: { - path: exti0, - priority: 1, + exti0: { + interrupt: EXTI0, + // priority: 1, resources: [A, B], }, - EXTI1: { - path: exti1, + exti1: { + interrupt: EXTI1, priority: 2, resources: [A, B], }, }, } -fn init(_p: init::Peripherals, _r: init::Resources) {} +fn init(_ctxt: init::Context) -> init::LateResources { + init::LateResources {} +} -fn idle() -> ! { +fn idle(_ctxt: idle::Context) -> ! { loop {} } -fn exti0(mut ot: &mut Threshold, r: EXTI0::Resources) { - r.A.claim(&mut ot, |_a, mut _it| { - //~^ error cannot borrow `ot` as mutable more than once at a time +fn exti0(mut ctxt: exti0::Context) { + let ot = &mut ctxt.threshold; + let exti0::Resources { A, B } = ctxt.resources; + + A.claim(ot, |_a, _it| { + //~^ error closure requires unique access to `ot` but `*ot` is already borrowed // ERROR must use inner token `it` instead of the outer one (`ot`) - r.B.claim(&mut ot, |_b, _| {}) + B.claim(ot, |_b, _| {}) }); } -fn exti1(_t: &mut Threshold, _r: EXTI1::Resources) {} +fn exti1(_ctxt: exti1::Context) {}