From 948e1fd0fbd96f574c31909843b2ed3debabf6fc Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Wed, 22 Nov 2017 09:27:14 +0100 Subject: v0.2.2 --- src/examples/_5_generics.rs | 67 ---------------------------- src/examples/_5_late_resources.rs | 91 +++++++++++++++++++++++++++++++++++++++ src/examples/_6_full_syntax.rs | 87 ------------------------------------- src/examples/_6_generics.rs | 67 ++++++++++++++++++++++++++++ src/examples/_7_full_syntax.rs | 87 +++++++++++++++++++++++++++++++++++++ src/examples/mod.rs | 5 ++- 6 files changed, 248 insertions(+), 156 deletions(-) delete mode 100644 src/examples/_5_generics.rs create mode 100644 src/examples/_5_late_resources.rs delete mode 100644 src/examples/_6_full_syntax.rs create mode 100644 src/examples/_6_generics.rs create mode 100644 src/examples/_7_full_syntax.rs (limited to 'src') diff --git a/src/examples/_5_generics.rs b/src/examples/_5_generics.rs deleted file mode 100644 index 82ecdf9..0000000 --- a/src/examples/_5_generics.rs +++ /dev/null @@ -1,67 +0,0 @@ -//! Working with resources in a generic fashion -//! -//! ``` -//! #![deny(unsafe_code)] -//! #![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, -//! -//! tasks: { -//! EXTI0: { -//! path: exti0, -//! priority: 1, -//! resources: [GPIOA, SPI1], -//! }, -//! -//! EXTI1: { -//! path: exti1, -//! priority: 2, -//! resources: [GPIOA, SPI1], -//! }, -//! }, -//! } -//! -//! fn init(_p: init::Peripherals) {} -//! -//! 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/_5_late_resources.rs b/src/examples/_5_late_resources.rs new file mode 100644 index 0000000..8a5b6e1 --- /dev/null +++ b/src/examples/_5_late_resources.rs @@ -0,0 +1,91 @@ +//! Demonstrates initialization of resources in `init`. +//! +//! ``` +//! +//! #![deny(unsafe_code)] +//! #![feature(proc_macro)] +//! #![no_std] +//! +//! extern crate cortex_m_rtfm as rtfm; +//! extern crate stm32f103xx; +//! +//! use rtfm::{app, Threshold}; +//! +//! app! { +//! device: stm32f103xx, +//! +//! resources: { +//! // Usually, resources are initialized with a constant initializer: +//! static ON: bool = false; +//! +//! // However, there are cases where this is not possible or not desired. +//! // For example, there may not be a sensible value to use, or the type may +//! // not be constructible in a constant (like `Vec`). +//! // +//! // While it is possible to use an `Option` in some cases, that requires +//! // you to properly initialize it and `.unwrap()` it at every use. It +//! // also consumes more memory. +//! // +//! // To solve this, it is possible to defer initialization of resources to +//! // `init` by omitting the initializer. Doing that will require `init` to +//! // return the values of all "late" resources. +//! static IP_ADDRESS: u32; +//! +//! // PORT is used by 2 tasks, making it a shared resource. This just tests +//! // another internal code path and is not important for the example. +//! static PORT: u16; +//! }, +//! +//! idle: { +//! // Test that late resources can be used in idle +//! resources: [IP_ADDRESS], +//! }, +//! +//! tasks: { +//! SYS_TICK: { +//! priority: 1, +//! path: sys_tick, +//! resources: [IP_ADDRESS, PORT, ON], +//! }, +//! +//! EXTI0: { +//! priority: 2, +//! path: exti0, +//! resources: [PORT], +//! } +//! } +//! } +//! +//! // The signature of `init` is now required to have a specific return type. +//! fn init(_p: init::Peripherals, _r: init::Resources) -> init::LateResourceValues { +//! // `init::Resources` does not contain `IP_ADDRESS`, since it is not yet +//! // initialized. +//! //_r.IP_ADDRESS; // doesn't compile +//! +//! // ...obtain value for IP_ADDRESS from EEPROM/DHCP... +//! let ip_address = 0x7f000001; +//! +//! init::LateResourceValues { +//! // This struct will contain fields for all resources with omitted +//! // initializers. +//! IP_ADDRESS: ip_address, +//! PORT: 0, +//! } +//! } +//! +//! fn sys_tick(_t: &mut Threshold, r: SYS_TICK::Resources) { +//! // Other tasks can access late resources like any other, since they are +//! // guaranteed to be initialized when tasks are run. +//! +//! r.IP_ADDRESS; +//! } +//! +//! fn exti0(_t: &mut Threshold, _r: EXTI0::Resources) {} +//! +//! fn idle(_t: &mut Threshold, _r: idle::Resources) -> ! { +//! loop { +//! rtfm::wfi(); +//! } +//! } +//! ``` +// Auto-generated. Do not modify. diff --git a/src/examples/_6_full_syntax.rs b/src/examples/_6_full_syntax.rs deleted file mode 100644 index 8052065..0000000 --- a/src/examples/_6_full_syntax.rs +++ /dev/null @@ -1,87 +0,0 @@ -//! A showcase of the `app!` macro syntax -//! -//! ``` -//! #![deny(unsafe_code)] -//! #![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, r: SYS_TICK::Resources) { -//! **r.ON = !**r.ON; -//! -//! **r.CO_OWNED += 1; -//! } -//! -//! fn tim2(_t: &mut Threshold, r: TIM2::Resources) { -//! **r.CO_OWNED += 1; -//! } -//! ``` -// Auto-generated. Do not modify. diff --git a/src/examples/_6_generics.rs b/src/examples/_6_generics.rs new file mode 100644 index 0000000..82ecdf9 --- /dev/null +++ b/src/examples/_6_generics.rs @@ -0,0 +1,67 @@ +//! Working with resources in a generic fashion +//! +//! ``` +//! #![deny(unsafe_code)] +//! #![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, +//! +//! tasks: { +//! EXTI0: { +//! path: exti0, +//! priority: 1, +//! resources: [GPIOA, SPI1], +//! }, +//! +//! EXTI1: { +//! path: exti1, +//! priority: 2, +//! resources: [GPIOA, SPI1], +//! }, +//! }, +//! } +//! +//! fn init(_p: init::Peripherals) {} +//! +//! 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/_7_full_syntax.rs b/src/examples/_7_full_syntax.rs new file mode 100644 index 0000000..8052065 --- /dev/null +++ b/src/examples/_7_full_syntax.rs @@ -0,0 +1,87 @@ +//! A showcase of the `app!` macro syntax +//! +//! ``` +//! #![deny(unsafe_code)] +//! #![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, r: SYS_TICK::Resources) { +//! **r.ON = !**r.ON; +//! +//! **r.CO_OWNED += 1; +//! } +//! +//! fn tim2(_t: &mut Threshold, 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 e0be5a6..53e74ed 100644 --- a/src/examples/mod.rs +++ b/src/examples/mod.rs @@ -5,5 +5,6 @@ pub mod _1_one_task; pub mod _2_two_tasks; pub mod _3_preemption; pub mod _4_nested; -pub mod _5_generics; -pub mod _6_full_syntax; +pub mod _5_late_resources; +pub mod _6_generics; +pub mod _7_full_syntax; -- cgit v1.2.3