From c7b9507a57f2ba28c18b15dd2719a1c56f74a302 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Thu, 20 Jul 2017 22:53:44 -0500 Subject: `Resource` trait, docs, examples and rtfm-syntax related changes --- src/examples/_5_generics.rs | 73 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 src/examples/_5_generics.rs (limited to 'src/examples/_5_generics.rs') diff --git a/src/examples/_5_generics.rs b/src/examples/_5_generics.rs new file mode 100644 index 0000000..a8f42cd --- /dev/null +++ b/src/examples/_5_generics.rs @@ -0,0 +1,73 @@ +//! Working with resources in a generic fashion +//! +//! ``` +//! +//! #![deny(unsafe_code)] +//! #![feature(proc_macro)] +//! #![no_std] +//! +//! #[macro_use(task)] +//! extern crate cortex_m_rtfm as rtfm; +//! extern crate stm32f103xx; +//! +//! use rtfm::{app, Resource, Threshold}; +//! use stm32f103xx::{SPI1, GPIOA}; +//! +//! app! { +//! device: stm32f103xx, +//! +//! tasks: { +//! EXTI0: { +//! enabled: true, +//! priority: 1, +//! resources: [GPIOA, SPI1], +//! }, +//! +//! EXTI1: { +//! enabled: true, +//! priority: 2, +//! resources: [GPIOA, SPI1], +//! }, +//! }, +//! } +//! +//! fn init(_p: init::Peripherals) {} +//! +//! fn idle() -> ! { +//! loop { +//! rtfm::wfi(); +//! } +//! } +//! +//! // a generic function to use resources in any task (regardless of its priority) +//! 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 +//! }); +//! } +//! +//! 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); +//! } +//! ``` +// Auto-generated. Do not modify. -- cgit v1.2.3