From def4fc8079dcb646ef3cab446a4b160e09e169bf Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Mon, 15 Jan 2018 23:26:07 +0100 Subject: v0.3.0 --- src/examples/_6_generics.rs | 78 ------------------------------ src/examples/_6_safe_static_mut_ref.rs | 36 ++++++++++++++ src/examples/_7_full_syntax.rs | 88 ---------------------------------- src/examples/_7_generics.rs | 78 ++++++++++++++++++++++++++++++ src/examples/_8_full_syntax.rs | 88 ++++++++++++++++++++++++++++++++++ src/examples/mod.rs | 5 +- 6 files changed, 205 insertions(+), 168 deletions(-) delete mode 100644 src/examples/_6_generics.rs create mode 100644 src/examples/_6_safe_static_mut_ref.rs delete mode 100644 src/examples/_7_full_syntax.rs create mode 100644 src/examples/_7_generics.rs create mode 100644 src/examples/_8_full_syntax.rs (limited to 'src/examples') diff --git a/src/examples/_6_generics.rs b/src/examples/_6_generics.rs deleted file mode 100644 index 22bb777..0000000 --- a/src/examples/_6_generics.rs +++ /dev/null @@ -1,78 +0,0 @@ -//! Working with resources in a generic fashion -//! -//! ``` -//! #![deny(unsafe_code)] -//! #![deny(warnings)] -//! #![feature(proc_macro)] -//! #![no_std] -//! -//! extern crate cortex_m_rtfm as rtfm; -//! extern crate stm32f103xx; -//! -//! use rtfm::{app, Resource, Threshold}; -//! use stm32f103xx::{SPI1, GPIOA}; -//! -//! app! { -//! device: stm32f103xx, -//! -//! resources: { -//! static GPIOA: GPIOA; -//! static SPI1: SPI1; -//! }, -//! -//! tasks: { -//! EXTI0: { -//! path: exti0, -//! priority: 1, -//! resources: [GPIOA, SPI1], -//! }, -//! -//! EXTI1: { -//! path: exti1, -//! priority: 2, -//! resources: [GPIOA, SPI1], -//! }, -//! }, -//! } -//! -//! fn init(p: init::Peripherals) -> init::LateResources { -//! init::LateResources { -//! GPIOA: p.device.GPIOA, -//! SPI1: p.device.SPI1, -//! } -//! } -//! -//! fn idle() -> ! { -//! loop { -//! rtfm::wfi(); -//! } -//! } -//! -//! // A generic function that uses some resources -//! fn work(t: &mut Threshold, gpioa: &G, spi1: &S) -//! where -//! G: Resource, -//! S: Resource, -//! { -//! gpioa.claim(t, |_gpioa, t| { -//! // drive NSS low -//! -//! spi1.claim(t, |_spi1, _| { -//! // transfer data -//! }); -//! -//! // drive NSS high -//! }); -//! } -//! -//! // This task needs critical sections to access the resources -//! fn exti0(t: &mut Threshold, r: EXTI0::Resources) { -//! work(t, &r.GPIOA, &r.SPI1); -//! } -//! -//! // This task has direct access to the resources -//! fn exti1(t: &mut Threshold, r: EXTI1::Resources) { -//! work(t, &r.GPIOA, &r.SPI1); -//! } -//! ``` -// Auto-generated. Do not modify. diff --git a/src/examples/_6_safe_static_mut_ref.rs b/src/examples/_6_safe_static_mut_ref.rs new file mode 100644 index 0000000..32eb3d9 --- /dev/null +++ b/src/examples/_6_safe_static_mut_ref.rs @@ -0,0 +1,36 @@ +//! 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; 16] = r.BUFFER; +//! } +//! +//! fn idle() -> ! { +//! loop { +//! rtfm::wfi(); +//! } +//! } +//! ``` +// Auto-generated. Do not modify. diff --git a/src/examples/_7_full_syntax.rs b/src/examples/_7_full_syntax.rs deleted file mode 100644 index f8db408..0000000 --- a/src/examples/_7_full_syntax.rs +++ /dev/null @@ -1,88 +0,0 @@ -//! A showcase of the `app!` macro syntax -//! -//! ``` -//! #![deny(unsafe_code)] -//! #![deny(warnings)] -//! #![feature(proc_macro)] -//! #![no_std] -//! -//! extern crate cortex_m_rtfm as rtfm; -//! extern crate stm32f103xx; -//! -//! use rtfm::{app, Threshold}; -//! -//! app! { -//! device: stm32f103xx, -//! -//! resources: { -//! static CO_OWNED: u32 = 0; -//! static ON: bool = false; -//! static OWNED: bool = false; -//! static SHARED: bool = false; -//! }, -//! -//! init: { -//! // This is the path to the `init` function -//! // -//! // `init` doesn't necessarily has to be in the root of the crate -//! path: main::init, -//! }, -//! -//! idle: { -//! // This is a path to the `idle` function -//! // -//! // `idle` doesn't necessarily has to be in the root of the crate -//! path: main::idle, -//! resources: [OWNED, SHARED], -//! }, -//! -//! tasks: { -//! SYS_TICK: { -//! path: sys_tick, -//! // If omitted priority is assumed to be 1 -//! // priority: 1, -//! resources: [CO_OWNED, ON, SHARED], -//! }, -//! -//! TIM2: { -//! // Tasks are enabled, between `init` and `idle`, by default but they -//! // can start disabled if `false` is specified here -//! enabled: false, -//! path: tim2, -//! priority: 1, -//! resources: [CO_OWNED], -//! }, -//! }, -//! } -//! -//! mod main { -//! use rtfm::{self, Resource, Threshold}; -//! -//! pub fn init(_p: ::init::Peripherals, _r: ::init::Resources) {} -//! -//! pub fn idle(t: &mut Threshold, mut r: ::idle::Resources) -> ! { -//! loop { -//! *r.OWNED != *r.OWNED; -//! -//! if *r.OWNED { -//! if r.SHARED.claim(t, |shared, _| *shared) { -//! rtfm::wfi(); -//! } -//! } else { -//! r.SHARED.claim_mut(t, |shared, _| *shared = !*shared); -//! } -//! } -//! } -//! } -//! -//! fn sys_tick(_t: &mut Threshold, mut r: SYS_TICK::Resources) { -//! *r.ON = !*r.ON; -//! -//! *r.CO_OWNED += 1; -//! } -//! -//! fn tim2(_t: &mut Threshold, mut r: TIM2::Resources) { -//! *r.CO_OWNED += 1; -//! } -//! ``` -// Auto-generated. Do not modify. diff --git a/src/examples/_7_generics.rs b/src/examples/_7_generics.rs new file mode 100644 index 0000000..22bb777 --- /dev/null +++ b/src/examples/_7_generics.rs @@ -0,0 +1,78 @@ +//! Working with resources in a generic fashion +//! +//! ``` +//! #![deny(unsafe_code)] +//! #![deny(warnings)] +//! #![feature(proc_macro)] +//! #![no_std] +//! +//! extern crate cortex_m_rtfm as rtfm; +//! extern crate stm32f103xx; +//! +//! use rtfm::{app, Resource, Threshold}; +//! use stm32f103xx::{SPI1, GPIOA}; +//! +//! app! { +//! device: stm32f103xx, +//! +//! resources: { +//! static GPIOA: GPIOA; +//! static SPI1: SPI1; +//! }, +//! +//! tasks: { +//! EXTI0: { +//! path: exti0, +//! priority: 1, +//! resources: [GPIOA, SPI1], +//! }, +//! +//! EXTI1: { +//! path: exti1, +//! priority: 2, +//! resources: [GPIOA, SPI1], +//! }, +//! }, +//! } +//! +//! fn init(p: init::Peripherals) -> init::LateResources { +//! init::LateResources { +//! GPIOA: p.device.GPIOA, +//! SPI1: p.device.SPI1, +//! } +//! } +//! +//! fn idle() -> ! { +//! loop { +//! rtfm::wfi(); +//! } +//! } +//! +//! // A generic function that uses some resources +//! fn work(t: &mut Threshold, gpioa: &G, spi1: &S) +//! where +//! G: Resource, +//! S: Resource, +//! { +//! gpioa.claim(t, |_gpioa, t| { +//! // drive NSS low +//! +//! spi1.claim(t, |_spi1, _| { +//! // transfer data +//! }); +//! +//! // drive NSS high +//! }); +//! } +//! +//! // This task needs critical sections to access the resources +//! fn exti0(t: &mut Threshold, r: EXTI0::Resources) { +//! work(t, &r.GPIOA, &r.SPI1); +//! } +//! +//! // This task has direct access to the resources +//! fn exti1(t: &mut Threshold, r: EXTI1::Resources) { +//! work(t, &r.GPIOA, &r.SPI1); +//! } +//! ``` +// Auto-generated. Do not modify. diff --git a/src/examples/_8_full_syntax.rs b/src/examples/_8_full_syntax.rs new file mode 100644 index 0000000..f8db408 --- /dev/null +++ b/src/examples/_8_full_syntax.rs @@ -0,0 +1,88 @@ +//! A showcase of the `app!` macro syntax +//! +//! ``` +//! #![deny(unsafe_code)] +//! #![deny(warnings)] +//! #![feature(proc_macro)] +//! #![no_std] +//! +//! extern crate cortex_m_rtfm as rtfm; +//! extern crate stm32f103xx; +//! +//! use rtfm::{app, Threshold}; +//! +//! app! { +//! device: stm32f103xx, +//! +//! resources: { +//! static CO_OWNED: u32 = 0; +//! static ON: bool = false; +//! static OWNED: bool = false; +//! static SHARED: bool = false; +//! }, +//! +//! init: { +//! // This is the path to the `init` function +//! // +//! // `init` doesn't necessarily has to be in the root of the crate +//! path: main::init, +//! }, +//! +//! idle: { +//! // This is a path to the `idle` function +//! // +//! // `idle` doesn't necessarily has to be in the root of the crate +//! path: main::idle, +//! resources: [OWNED, SHARED], +//! }, +//! +//! tasks: { +//! SYS_TICK: { +//! path: sys_tick, +//! // If omitted priority is assumed to be 1 +//! // priority: 1, +//! resources: [CO_OWNED, ON, SHARED], +//! }, +//! +//! TIM2: { +//! // Tasks are enabled, between `init` and `idle`, by default but they +//! // can start disabled if `false` is specified here +//! enabled: false, +//! path: tim2, +//! priority: 1, +//! resources: [CO_OWNED], +//! }, +//! }, +//! } +//! +//! mod main { +//! use rtfm::{self, Resource, Threshold}; +//! +//! pub fn init(_p: ::init::Peripherals, _r: ::init::Resources) {} +//! +//! pub fn idle(t: &mut Threshold, mut r: ::idle::Resources) -> ! { +//! loop { +//! *r.OWNED != *r.OWNED; +//! +//! if *r.OWNED { +//! if r.SHARED.claim(t, |shared, _| *shared) { +//! rtfm::wfi(); +//! } +//! } else { +//! r.SHARED.claim_mut(t, |shared, _| *shared = !*shared); +//! } +//! } +//! } +//! } +//! +//! fn sys_tick(_t: &mut Threshold, mut r: SYS_TICK::Resources) { +//! *r.ON = !*r.ON; +//! +//! *r.CO_OWNED += 1; +//! } +//! +//! fn tim2(_t: &mut Threshold, mut r: TIM2::Resources) { +//! *r.CO_OWNED += 1; +//! } +//! ``` +// Auto-generated. Do not modify. diff --git a/src/examples/mod.rs b/src/examples/mod.rs index 53e74ed..64d1e2e 100644 --- a/src/examples/mod.rs +++ b/src/examples/mod.rs @@ -6,5 +6,6 @@ pub mod _2_two_tasks; pub mod _3_preemption; pub mod _4_nested; pub mod _5_late_resources; -pub mod _6_generics; -pub mod _7_full_syntax; +pub mod _6_safe_static_mut_ref; +pub mod _7_generics; +pub mod _8_full_syntax; -- cgit v1.2.3