From 219e17268018f397ff3c8a41519c8345aeab7f2f Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Sat, 9 Dec 2017 13:38:41 +0100 Subject: drop the Static wrapper --- examples/full-syntax.rs | 10 +++++----- examples/one-task.rs | 4 ++-- examples/preemption.rs | 4 ++-- examples/two-tasks.rs | 4 ++-- 4 files changed, 11 insertions(+), 11 deletions(-) (limited to 'examples') diff --git a/examples/full-syntax.rs b/examples/full-syntax.rs index a8f79a7..b84077f 100644 --- a/examples/full-syntax.rs +++ b/examples/full-syntax.rs @@ -63,22 +63,22 @@ mod main { *r.OWNED != *r.OWNED; if *r.OWNED { - if r.SHARED.claim(t, |shared, _| **shared) { + if r.SHARED.claim(t, |shared, _| *shared) { rtfm::wfi(); } } else { - r.SHARED.claim_mut(t, |shared, _| **shared = !**shared); + r.SHARED.claim_mut(t, |shared, _| *shared = !*shared); } } } } fn sys_tick(_t: &mut Threshold, r: SYS_TICK::Resources) { - **r.ON = !**r.ON; + *r.ON = !*r.ON; - **r.CO_OWNED += 1; + *r.CO_OWNED += 1; } fn tim2(_t: &mut Threshold, r: TIM2::Resources) { - **r.CO_OWNED += 1; + *r.CO_OWNED += 1; } diff --git a/examples/one-task.rs b/examples/one-task.rs index 2e77676..90eb459 100644 --- a/examples/one-task.rs +++ b/examples/one-task.rs @@ -79,9 +79,9 @@ fn idle() -> ! { #[allow(unsafe_code)] fn sys_tick(_t: &mut Threshold, r: SYS_TICK::Resources) { // toggle state - **r.ON = !**r.ON; + *r.ON = !*r.ON; - if **r.ON { + if *r.ON { // set the pin PC13 high // NOTE(unsafe) atomic write to a stateless register unsafe { diff --git a/examples/preemption.rs b/examples/preemption.rs index 98dde8d..07e9362 100644 --- a/examples/preemption.rs +++ b/examples/preemption.rs @@ -47,7 +47,7 @@ fn sys_tick(_t: &mut Threshold, r: SYS_TICK::Resources) { // This task can't be preempted by `tim2` so it has direct access to the // resource data - **r.COUNTER += 1; + *r.COUNTER += 1; // .. } @@ -61,7 +61,7 @@ fn tim2(t: &mut Threshold, mut r: TIM2::Resources) { // lead to undefined behavior. r.COUNTER.claim_mut(t, |counter, _t| { // `claim_mut` creates a critical section - **counter += 1; + *counter += 1; }); // .. diff --git a/examples/two-tasks.rs b/examples/two-tasks.rs index df6e784..e9d31e7 100644 --- a/examples/two-tasks.rs +++ b/examples/two-tasks.rs @@ -45,7 +45,7 @@ fn idle() -> ! { fn sys_tick(_t: &mut Threshold, r: SYS_TICK::Resources) { // .. - **r.COUNTER += 1; + *r.COUNTER += 1; // .. } @@ -53,7 +53,7 @@ fn sys_tick(_t: &mut Threshold, r: SYS_TICK::Resources) { fn tim2(_t: &mut Threshold, r: TIM2::Resources) { // .. - **r.COUNTER += 1; + *r.COUNTER += 1; // .. } -- cgit v1.2.3 From a6dd004113fcbc03ffacacc519d742ee84886c1d Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Sat, 9 Dec 2017 14:43:29 +0100 Subject: implement the Resource trait for owned resources this unbreaks the "generics" example --- examples/custom-type.rs | 50 ++++++++++++++++++++++++++++++++++++++++++++++ examples/full-syntax.rs | 4 ++-- examples/generics.rs | 2 +- examples/late-resources.rs | 1 - examples/one-task.rs | 2 +- examples/preemption.rs | 2 +- examples/two-tasks.rs | 4 ++-- 7 files changed, 57 insertions(+), 8 deletions(-) create mode 100644 examples/custom-type.rs (limited to 'examples') diff --git a/examples/custom-type.rs b/examples/custom-type.rs new file mode 100644 index 0000000..79d6cc4 --- /dev/null +++ b/examples/custom-type.rs @@ -0,0 +1,50 @@ +#![deny(unsafe_code)] +#![deny(warnings)] +#![feature(proc_macro)] +#![no_std] + +extern crate cortex_m_rtfm as rtfm; +extern crate stm32f103xx; + +use rtfm::{app, Threshold}; + +pub struct Foo; + +app! { + device: stm32f103xx, + + resources: { + static CO_OWNED: Foo = Foo; + static ON: Foo = Foo; + static OWNED: Foo = Foo; + static SHARED: Foo = Foo; + }, + + idle: { + resources: [OWNED, SHARED], + }, + + tasks: { + SYS_TICK: { + path: sys_tick, + resources: [CO_OWNED, ON, SHARED], + }, + + TIM2: { + enabled: false, + path: tim2, + priority: 1, + resources: [CO_OWNED], + }, + }, +} + +fn init(_p: ::init::Peripherals, _r: ::init::Resources) {} + +fn idle(_t: &mut Threshold, _r: ::idle::Resources) -> ! { + loop {} +} + +fn sys_tick(_t: &mut Threshold, _r: SYS_TICK::Resources) {} + +fn tim2(_t: &mut Threshold, _r: TIM2::Resources) {} diff --git a/examples/full-syntax.rs b/examples/full-syntax.rs index b84077f..5b27412 100644 --- a/examples/full-syntax.rs +++ b/examples/full-syntax.rs @@ -73,12 +73,12 @@ mod main { } } -fn sys_tick(_t: &mut Threshold, r: SYS_TICK::Resources) { +fn sys_tick(_t: &mut Threshold, mut r: SYS_TICK::Resources) { *r.ON = !*r.ON; *r.CO_OWNED += 1; } -fn tim2(_t: &mut Threshold, r: TIM2::Resources) { +fn tim2(_t: &mut Threshold, mut r: TIM2::Resources) { *r.CO_OWNED += 1; } diff --git a/examples/generics.rs b/examples/generics.rs index 7cf9257..ca7726d 100644 --- a/examples/generics.rs +++ b/examples/generics.rs @@ -70,5 +70,5 @@ fn exti0(t: &mut Threshold, r: EXTI0::Resources) { // This task has direct access to the resources fn exti1(t: &mut Threshold, r: EXTI1::Resources) { - work(t, r.GPIOA, r.SPI1); + work(t, &r.GPIOA, &r.SPI1); } diff --git a/examples/late-resources.rs b/examples/late-resources.rs index d42431c..07c321f 100644 --- a/examples/late-resources.rs +++ b/examples/late-resources.rs @@ -1,5 +1,4 @@ //! Demonstrates initialization of resources in `init`. - #![deny(unsafe_code)] #![deny(warnings)] #![feature(proc_macro)] diff --git a/examples/one-task.rs b/examples/one-task.rs index 90eb459..07def59 100644 --- a/examples/one-task.rs +++ b/examples/one-task.rs @@ -77,7 +77,7 @@ fn idle() -> ! { // `r` is the set of resources this task has access to. `SYS_TICK::Resources` // has one field per resource declared in `app!`. #[allow(unsafe_code)] -fn sys_tick(_t: &mut Threshold, r: SYS_TICK::Resources) { +fn sys_tick(_t: &mut Threshold, mut r: SYS_TICK::Resources) { // toggle state *r.ON = !*r.ON; diff --git a/examples/preemption.rs b/examples/preemption.rs index 07e9362..8e50188 100644 --- a/examples/preemption.rs +++ b/examples/preemption.rs @@ -42,7 +42,7 @@ fn idle() -> ! { } } -fn sys_tick(_t: &mut Threshold, r: SYS_TICK::Resources) { +fn sys_tick(_t: &mut Threshold, mut r: SYS_TICK::Resources) { // .. // This task can't be preempted by `tim2` so it has direct access to the diff --git a/examples/two-tasks.rs b/examples/two-tasks.rs index e9d31e7..4f567f0 100644 --- a/examples/two-tasks.rs +++ b/examples/two-tasks.rs @@ -42,7 +42,7 @@ fn idle() -> ! { // 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) { +fn sys_tick(_t: &mut Threshold, mut r: SYS_TICK::Resources) { // .. *r.COUNTER += 1; @@ -50,7 +50,7 @@ fn sys_tick(_t: &mut Threshold, r: SYS_TICK::Resources) { // .. } -fn tim2(_t: &mut Threshold, r: TIM2::Resources) { +fn tim2(_t: &mut Threshold, mut r: TIM2::Resources) { // .. *r.COUNTER += 1; -- cgit v1.2.3 From d30bdcb096774c1f56d9823fb2fbb78bf5cd3584 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Sat, 9 Dec 2017 17:14:51 +0100 Subject: safe `&'static mut` references via init.resources --- examples/safe-static-mut-ref.rs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 examples/safe-static-mut-ref.rs (limited to 'examples') diff --git a/examples/safe-static-mut-ref.rs b/examples/safe-static-mut-ref.rs new file mode 100644 index 0000000..bb87212 --- /dev/null +++ b/examples/safe-static-mut-ref.rs @@ -0,0 +1,32 @@ +//! Safe creation of `&'static mut` references +#![deny(unsafe_code)] +#![deny(warnings)] +#![feature(proc_macro)] +#![no_std] + +extern crate cortex_m_rtfm as rtfm; +extern crate stm32f103xx; + +use rtfm::app; + +app! { + device: stm32f103xx, + + resources: { + static BUFFER: [u8; 16] = [0; 16]; + }, + + init: { + resources: [BUFFER], + }, +} + +fn init(_p: init::Peripherals, r: init::Resources) { + let _buf: &'static mut [u8] = r.BUFFER; +} + +fn idle() -> ! { + loop { + rtfm::wfi(); + } +} -- cgit v1.2.3