diff --git a/examples/full-syntax.rs b/examples/full-syntax.rs index 6965a63b68..918a2e679f 100644 --- a/examples/full-syntax.rs +++ b/examples/full-syntax.rs @@ -5,7 +5,6 @@ #![feature(proc_macro)] #![no_std] -#[macro_use(task)] extern crate cortex_m_rtfm as rtfm; extern crate stm32f103xx; @@ -16,6 +15,7 @@ app! { resources: { static CO_OWNED: u32 = 0; + static ON: bool = false; static OWNED: bool = false; static SHARED: bool = false; }, @@ -31,12 +31,14 @@ app! { tasks: { SYS_TICK: { + path: sys_tick, priority: 1, - resources: [CO_OWNED, SHARED], + resources: [CO_OWNED, ON, SHARED], }, TIM2: { enabled: true, + path: tim2, priority: 1, resources: [CO_OWNED], }, @@ -59,18 +61,12 @@ fn idle_(t: &mut Threshold, mut r: idle::Resources) -> ! { } } -task!(SYS_TICK, sys_tick, Local { - static STATE: bool = true; -}); - -fn sys_tick(_t: &mut Threshold, l: &mut Local, r: SYS_TICK::Resources) { - *l.STATE = !*l.STATE; +fn sys_tick(_t: &mut Threshold, r: SYS_TICK::Resources) { + **r.ON = !**r.ON; **r.CO_OWNED += 1; } -task!(TIM2, tim2); - fn tim2(_t: &mut Threshold, r: TIM2::Resources) { **r.CO_OWNED += 1; } diff --git a/examples/generics.rs b/examples/generics.rs index 335d159b6f..7c261d54f5 100644 --- a/examples/generics.rs +++ b/examples/generics.rs @@ -4,7 +4,6 @@ #![feature(proc_macro)] #![no_std] -#[macro_use(task)] extern crate cortex_m_rtfm as rtfm; extern crate stm32f103xx; @@ -17,12 +16,14 @@ app! { tasks: { EXTI0: { enabled: true, + path: exti0, priority: 1, resources: [GPIOA, SPI1], }, EXTI1: { enabled: true, + path: exti1, priority: 2, resources: [GPIOA, SPI1], }, @@ -54,15 +55,11 @@ where }); } -task!(EXTI0, exti0); - // this task needs critical sections to access the resources fn exti0(t: &mut Threshold, r: EXTI0::Resources) { work(t, &r.GPIOA, &r.SPI1); } -task!(EXTI1, exti1); - // this task has direct access to the resources fn exti1(t: &mut Threshold, r: EXTI1::Resources) { work(t, r.GPIOA, r.SPI1); diff --git a/examples/modules.rs b/examples/modules.rs index aabada4538..313ebc49aa 100644 --- a/examples/modules.rs +++ b/examples/modules.rs @@ -1,11 +1,9 @@ //! Using paths and modules - #![deny(unsafe_code)] #![feature(const_fn)] #![feature(proc_macro)] #![no_std] -#[macro_use(task)] extern crate cortex_m_rtfm as rtfm; extern crate stm32f103xx; @@ -16,6 +14,7 @@ app! { resources: { static CO_OWNED: u32 = 0; + static ON: bool = false; static OWNED: bool = false; static SHARED: bool = false; }, @@ -31,12 +30,14 @@ app! { tasks: { SYS_TICK: { + path: tasks::sys_tick, priority: 1, - resources: [CO_OWNED, SHARED], + resources: [CO_OWNED, ON, SHARED], }, TIM2: { enabled: true, + path: tasks::tim2, priority: 1, resources: [CO_OWNED], }, @@ -66,19 +67,13 @@ mod main { pub mod tasks { use rtfm::Threshold; - task!(SYS_TICK, sys_tick, Locals { - static STATE: bool = true; - }); - - fn sys_tick(_t: &mut Threshold, l: &mut Locals, r: ::SYS_TICK::Resources) { - *l.STATE = !*l.STATE; + pub fn sys_tick(_t: &mut Threshold, r: ::SYS_TICK::Resources) { + **r.ON = !**r.ON; **r.CO_OWNED += 1; } - task!(TIM2, tim2); - - fn tim2(_t: &mut Threshold, r: ::TIM2::Resources) { + pub fn tim2(_t: &mut Threshold, r: ::TIM2::Resources) { **r.CO_OWNED += 1; } } diff --git a/examples/nested.rs b/examples/nested.rs index fda2a7d431..2cb23f9501 100644 --- a/examples/nested.rs +++ b/examples/nested.rs @@ -8,7 +8,6 @@ #![feature(proc_macro)] #![no_std] -#[macro_use(task)] extern crate cortex_m_rtfm as rtfm; extern crate stm32f103xx; @@ -26,18 +25,21 @@ app! { tasks: { EXTI0: { enabled: true, + path: exti0, priority: 1, resources: [LOW, HIGH], }, EXTI1: { enabled: true, + path: exti1, priority: 2, resources: [LOW], }, EXTI2: { enabled: true, + path: exti2, priority: 3, resources: [HIGH], }, @@ -58,8 +60,6 @@ fn idle() -> ! { } } -task!(EXTI0, exti0); - fn exti0(t: &mut Threshold, r: EXTI0::Resources) { // because this task has a priority of 1 the preemption threshold is also 1 @@ -113,15 +113,11 @@ fn exti0(t: &mut Threshold, r: EXTI0::Resources) { // ~> exti1 } -task!(EXTI1, exti1); - fn exti1(_t: &mut Threshold, _r: EXTI1::Resources) { // B, H rtfm::bkpt(); } -task!(EXTI2, exti2); - fn exti2(_t: &mut Threshold, _r: EXTI2::Resources) { // D, G rtfm::bkpt(); diff --git a/examples/one-task.rs b/examples/one-task.rs index 8cfe089c08..e1d598ddfc 100644 --- a/examples/one-task.rs +++ b/examples/one-task.rs @@ -1,12 +1,10 @@ //! An application with one task - #![deny(unsafe_code)] #![feature(const_fn)] #![feature(proc_macro)] #![no_std] extern crate cortex_m; -#[macro_use(task)] extern crate cortex_m_rtfm as rtfm; extern crate stm32f103xx; @@ -16,6 +14,15 @@ use rtfm::{app, Threshold}; app! { device: stm32f103xx, + // Here resources are declared + // + // Resources are static variables that are safe to share across tasks + resources: { + // declaration of resources looks exactly like declaration of static + // variables + static ON: bool = false; + }, + // Here tasks are declared // // Each task corresponds to an interrupt or an exception. Every time the @@ -24,7 +31,11 @@ app! { tasks: { // Here we declare that we'll use the SYS_TICK exception as a task SYS_TICK: { + // Path to the task *handler* + path: sys_tick, + // This is the priority of the task. + // // 1 is the lowest priority a task can have. // The maximum priority is determined by the number of priority bits // the device has. This device has 4 priority bits so 16 is the @@ -34,12 +45,12 @@ app! { // These are the *resources* associated with this task // // The peripherals that the task needs can be listed here - resources: [GPIOC], + resources: [GPIOC, ON], }, } } -fn init(p: init::Peripherals) { +fn init(p: init::Peripherals, _r: init::Resources) { // power on GPIOC p.RCC.apb2enr.modify(|_, w| w.iopcen().enabled()); @@ -62,26 +73,15 @@ fn idle() -> ! { } } -// This binds the `sys_tick` handler to the `SYS_TICK` task -// -// This particular handler has local state associated to it. The value of the -// `STATE` variable will be preserved across invocations of this handler -task!(SYS_TICK, sys_tick, Locals { - static STATE: bool = false; -}); - // This is the task handler of the SYS_TICK exception // -// `t` is the preemption threshold token. We won't use it this time. -// `l` is the data local to this task. The type here must match the one declared -// in `task!`. // `r` is the resources this task has access to. `SYS_TICK::Resources` has one -// field per resource declared in `app!`. -fn sys_tick(_t: &mut Threshold, l: &mut Locals, r: SYS_TICK::Resources) { +// field per every resource declared in `app!`. +fn sys_tick(_t: &mut Threshold, r: SYS_TICK::Resources) { // toggle state - *l.STATE = !*l.STATE; + **r.ON = !**r.ON; - if *l.STATE { + if **r.ON { // set the pin PC13 high r.GPIOC.bsrr.write(|w| w.bs13().set()); } else { diff --git a/examples/preemption.rs b/examples/preemption.rs index 2ca6f951d0..e117695874 100644 --- a/examples/preemption.rs +++ b/examples/preemption.rs @@ -1,11 +1,9 @@ //! Two tasks running at different priorities with access to the same resource - #![deny(unsafe_code)] #![feature(const_fn)] #![feature(proc_macro)] #![no_std] -#[macro_use(task)] extern crate cortex_m_rtfm as rtfm; extern crate stm32f103xx; @@ -21,12 +19,14 @@ app! { tasks: { // the task `SYS_TICK` has higher priority than `TIM2` SYS_TICK: { + path: sys_tick, priority: 2, resources: [COUNTER], }, TIM2: { enabled: true, + path: tim2, priority: 1, resources: [COUNTER], }, @@ -43,8 +43,6 @@ fn idle() -> ! { } } -task!(SYS_TICK, sys_tick); - fn sys_tick(_t: &mut Threshold, r: SYS_TICK::Resources) { // .. @@ -55,8 +53,6 @@ fn sys_tick(_t: &mut Threshold, r: SYS_TICK::Resources) { // .. } -task!(TIM2, tim2); - fn tim2(t: &mut Threshold, mut r: TIM2::Resources) { // .. diff --git a/examples/two-tasks.rs b/examples/two-tasks.rs index eb74fa8f39..7343137db4 100644 --- a/examples/two-tasks.rs +++ b/examples/two-tasks.rs @@ -5,7 +5,6 @@ #![feature(proc_macro)] #![no_std] -#[macro_use(task)] extern crate cortex_m_rtfm as rtfm; extern crate stm32f103xx; @@ -23,6 +22,7 @@ app! { tasks: { SYS_TICK: { + path: sys_tick, priority: 1, // Both this task and TIM2 have access to the `COUNTER` resource resources: [COUNTER], @@ -34,6 +34,7 @@ app! { // indicates if the interrupt will be enabled or disabled once // `idle` starts enabled: true, + path: tim2, priority: 1, resources: [COUNTER], }, @@ -52,8 +53,6 @@ fn idle() -> ! { } } -task!(SYS_TICK, sys_tick); - // As both tasks are running at the same priority one can't preempt the other. // Thus both tasks have direct access to the resource fn sys_tick(_t: &mut Threshold, r: SYS_TICK::Resources) { @@ -64,8 +63,6 @@ fn sys_tick(_t: &mut Threshold, r: SYS_TICK::Resources) { // .. } -task!(TIM2, tim2); - fn tim2(_t: &mut Threshold, r: TIM2::Resources) { // .. diff --git a/tests/cfail/critical-section.rs b/tests/cfail/critical-section.rs index 3c8f0a97c0..7e73fd3346 100644 --- a/tests/cfail/critical-section.rs +++ b/tests/cfail/critical-section.rs @@ -3,7 +3,6 @@ #![feature(proc_macro)] #![no_std] -#[macro_use(task)] extern crate cortex_m_rtfm as rtfm; extern crate stm32f103xx; @@ -13,18 +12,19 @@ app! { device: stm32f103xx, resources: { - static STATE: bool = false; + static ON: bool = false; }, idle: { - resources: [STATE], + resources: [ON], }, tasks: { EXTI0: { enabled: true, + path: exti0, priority: 1, - resources: [STATE], + resources: [ON], }, }, } @@ -32,12 +32,12 @@ app! { fn init(_p: init::Peripherals, _r: init::Resources) {} fn idle(t: &mut Threshold, r: idle::Resources) -> ! { - let state = rtfm::atomic(|cs| { + let state = rtfm::atomic(t, |t| { // ERROR borrow can't escape this *global* critical section - r.STATE.borrow(cs) //~ error cannot infer an appropriate lifetime + r.ON.borrow(t) //~ error cannot infer an appropriate lifetime }); - let state = r.STATE.claim(t, |state, _t| { + let state = r.ON.claim(t, |state, _t| { // ERROR borrow can't escape this critical section state //~ error cannot infer an appropriate lifetime }); @@ -45,6 +45,4 @@ fn idle(t: &mut Threshold, r: idle::Resources) -> ! { loop {} } -task!(EXTI0, exti0); - fn exti0(_t: &mut Threshold, _r: EXTI0::Resources) {} diff --git a/tests/cfail/duplicated-handler-2.rs b/tests/cfail/duplicated-handler-2.rs deleted file mode 100644 index d02770c254..0000000000 --- a/tests/cfail/duplicated-handler-2.rs +++ /dev/null @@ -1,40 +0,0 @@ -#![deny(warnings)] -#![feature(proc_macro)] -#![no_std] - -#[macro_use(task)] -extern crate cortex_m_rtfm as rtfm; -extern crate stm32f103xx; - -use rtfm::{app, Threshold}; - -app! { - device: stm32f103xx, - - resources: { - static ON: bool = false; - }, - - tasks: { - EXTI0: { - enabled: true, - path: exti0, - priority: 1, - resources: [ON], - }, - }, -} - -fn init(_p: init::Peripherals, _r: init::Resources) {} - -fn idle() -> ! { - loop {} -} - -fn exti0(_r: EXTI0::Resources) {} - -// ERROR can't override the task handler specified in `app!` -task!(EXTI0, exti1); -//~^ error cannot find value `EXTI0` - -fn exti1(_t: &mut Threshold, _r: EXTI0::Resources) {} diff --git a/tests/cfail/duplicated-handler.rs b/tests/cfail/duplicated-handler.rs deleted file mode 100644 index d7741b5aff..0000000000 --- a/tests/cfail/duplicated-handler.rs +++ /dev/null @@ -1,36 +0,0 @@ -// error-pattern: the name `EXTI0` is defined multiple times - -#![deny(warnings)] -#![feature(proc_macro)] -#![no_std] - -#[macro_use(task)] -extern crate cortex_m_rtfm as rtfm; -extern crate stm32f103xx; - -use rtfm::{app, Threshold}; - -app! { - device: stm32f103xx, - - tasks: { - EXTI0: { - enabled: true, - priority: 1, - }, - }, -} - -fn init(_p: init::Peripherals) {} - -fn idle() -> ! { - loop {} -} - -task!(EXTI0, exti0); - -fn exti0(_t: &mut Threshold, _r: EXTI0::Resources) {} - -task!(EXTI0, exti1); - -fn exti1(_t: &mut Threshold, _r: EXTI0::Resources) {} diff --git a/tests/cfail/local-token.rs b/tests/cfail/local-token.rs deleted file mode 100644 index 90a9560c2b..0000000000 --- a/tests/cfail/local-token.rs +++ /dev/null @@ -1,45 +0,0 @@ -#![deny(warnings)] -#![feature(const_fn)] -#![feature(proc_macro)] -#![no_std] - -#[macro_use(task)] -extern crate cortex_m_rtfm as rtfm; -extern crate stm32f103xx; - -use rtfm::{app, Threshold}; - -app! { - device: stm32f103xx, - - tasks: { - EXTI0: { - enabled: true, - priority: 1, - }, - } -} - -fn init(_p: init::Peripherals) {} - -fn idle() -> ! { - loop {} -} - -task!(EXTI0, exti0, Old { - static TOKEN: Option = None; -}); - -fn exti0(nt: &mut Threshold, old: &mut Old, _r: EXTI0::Resources) { - if let Some(ot) = old.TOKEN.take() { - let _: (Threshold, Threshold) = (*nt, ot); - //~^ error cannot move out of borrowed content - - return - } - - // ERROR can't store a threshold token in a local variable, otherwise you - // would end up with two threshold tokens in a task (see `if let` above) - *old.TOKEN = Some(*nt); - //~^ error cannot move out of borrowed content -} diff --git a/tests/cfail/lock.rs b/tests/cfail/lock.rs index 77310ddc0e..8e6da468f8 100644 --- a/tests/cfail/lock.rs +++ b/tests/cfail/lock.rs @@ -3,7 +3,6 @@ #![feature(proc_macro)] #![no_std] -#[macro_use(task)] extern crate cortex_m_rtfm as rtfm; extern crate stm32f103xx; @@ -13,25 +12,28 @@ app! { device: stm32f103xx, resources: { - static STATE: bool = false; + static ON: bool = false; static MAX: u8 = 0; }, tasks: { EXTI0: { enabled: true, + path: exti0, priority: 1, - resources: [MAX, STATE], + resources: [MAX, ON], }, EXTI1: { enabled: true, + path: exti1, priority: 2, - resources: [STATE], + resources: [ON], }, EXTI2: { enabled: true, + path: exti2, priority: 16, resources: [MAX], }, @@ -44,29 +46,23 @@ fn idle() -> ! { loop {} } -task!(EXTI0, exti0); - fn exti0(mut t: &mut Threshold, mut r: EXTI0::Resources) { // OK need to lock to access the resource - if r.STATE.claim(&mut t, |state, _| **state) {} + if r.ON.claim(&mut t, |on, _| **on) {} // OK can claim a resource with maximum ceiling r.MAX.claim_mut(&mut t, |max, _| **max += 1); } -task!(EXTI1, exti1); - fn exti1(mut t: &mut Threshold, r: EXTI1::Resources) { // ERROR no need to lock. Has direct access because priority == ceiling - if (**r.STATE).claim(&mut t, |state, _| **state) { + if (**r.ON).claim(&mut t, |on, _| **on) { //~^ error no method named `claim` found for type } - if **r.STATE { + if **r.ON { // OK } } -task!(EXTI2, exti2); - fn exti2(_t: &mut Threshold, _r: EXTI2::Resources) {} diff --git a/tests/cfail/priority-too-high.rs b/tests/cfail/priority-too-high.rs index 01ddc032d5..c139471df9 100644 --- a/tests/cfail/priority-too-high.rs +++ b/tests/cfail/priority-too-high.rs @@ -2,17 +2,17 @@ #![feature(proc_macro)] #![no_std] -#[macro_use(task)] extern crate cortex_m_rtfm as rtfm; extern crate stm32f103xx; -use rtfm::{app, Threshold}; +use rtfm::app; app! { //~ error attempt to subtract with overflow device: stm32f103xx, tasks: { SYS_TICK: { + path: sys_tick, // ERROR priority must be in the range [1, 16] priority: 17, }, @@ -25,6 +25,4 @@ fn idle() -> ! { loop {} } -task!(SYS_TICK, sys_tick); - -fn sys_tick(_: &mut Threshold, _: SYS_TICK::Resources) {} +fn sys_tick() {} diff --git a/tests/cfail/priority-too-low.rs b/tests/cfail/priority-too-low.rs index d127c406ab..cefd34281a 100644 --- a/tests/cfail/priority-too-low.rs +++ b/tests/cfail/priority-too-low.rs @@ -2,17 +2,17 @@ #![feature(proc_macro)] #![no_std] -#[macro_use(task)] extern crate cortex_m_rtfm as rtfm; extern crate stm32f103xx; -use rtfm::{app, Threshold}; +use rtfm::app; app! { //~ error attempt to subtract with overflow device: stm32f103xx, tasks: { SYS_TICK: { + path: sys_tick, // ERROR priority must be in the range [1, 16] priority: 0, }, @@ -25,6 +25,4 @@ fn idle() -> ! { loop {} } -task!(SYS_TICK, sys_tick); - -fn sys_tick(_: &mut Threshold, _: SYS_TICK::Resources) {} +fn sys_tick() {} diff --git a/tests/cfail/token-outlive.rs b/tests/cfail/token-outlive.rs index 777729a5b6..dc9112e636 100644 --- a/tests/cfail/token-outlive.rs +++ b/tests/cfail/token-outlive.rs @@ -3,7 +3,6 @@ #![feature(proc_macro)] #![no_std] -#[macro_use(task)] extern crate cortex_m_rtfm as rtfm; extern crate stm32f103xx; @@ -19,12 +18,14 @@ app! { tasks: { EXTI0: { enabled: true, + path: exti0, priority: 1, resources: [STATE], }, EXTI1: { enabled: true, + path: exti1, priority: 2, resources: [STATE], }, @@ -37,14 +38,10 @@ fn idle() -> ! { loop {} } -task!(EXTI0, exti0); - fn exti0(mut t: &mut Threshold, r: EXTI0::Resources) { // ERROR token should not outlive the critical section let t = r.STATE.claim(&mut t, |_state, t| t); //~^ error cannot infer an appropriate lifetime } -task!(EXTI1, exti1); - fn exti1(_t: &mut Threshold, _r: EXTI1::Resources) {} diff --git a/tests/cfail/token-transfer.rs b/tests/cfail/token-transfer.rs index 7bf42339bb..b8bcc00048 100644 --- a/tests/cfail/token-transfer.rs +++ b/tests/cfail/token-transfer.rs @@ -3,7 +3,6 @@ #![feature(proc_macro)] #![no_std] -#[macro_use(task)] extern crate cortex_m_rtfm as rtfm; extern crate stm32f103xx; @@ -19,6 +18,7 @@ app! { //~ error bound `rtfm::Threshold: core::marker::Send` is not satisfied tasks: { EXTI0: { enabled: true, + path: exti0, priority: 1, resources: [TOKEN], }, @@ -31,6 +31,4 @@ fn idle() -> ! { loop {} } -task!(EXTI0, exti0); - fn exti0(_t: &mut Threshold, _r: EXTI0::Resources) {} diff --git a/tests/cfail/wrong-threshold.rs b/tests/cfail/wrong-threshold.rs index 05ebb2f7ed..57d6d30574 100644 --- a/tests/cfail/wrong-threshold.rs +++ b/tests/cfail/wrong-threshold.rs @@ -3,7 +3,6 @@ #![feature(proc_macro)] #![no_std] -#[macro_use(task)] extern crate cortex_m_rtfm as rtfm; extern crate stm32f103xx; @@ -20,12 +19,14 @@ app! { tasks: { EXTI0: { enabled: true, + path: exti0, priority: 1, resources: [A, B], }, EXTI1: { enabled: true, + path: exti1, priority: 2, resources: [A, B], }, @@ -38,8 +39,6 @@ fn idle() -> ! { loop {} } -task!(EXTI0, exti0); - 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 @@ -49,6 +48,4 @@ fn exti0(mut ot: &mut Threshold, r: EXTI0::Resources) { }); } -task!(EXTI1, exti1); - fn exti1(_t: &mut Threshold, r: EXTI1::Resources) {}