diff options
author | 2017-11-22 09:27:14 +0100 | |
---|---|---|
committer | 2017-11-22 09:29:01 +0100 | |
commit | 948e1fd0fbd96f574c31909843b2ed3debabf6fc (patch) | |
tree | be8bb18bee86e726a52e19a4083fa0ae9386cdfb /src/examples/_6_generics.rs | |
parent | c184f91e3c3993dacbd8425019cde6a3607478bc (diff) | |
download | rtic-948e1fd0fbd96f574c31909843b2ed3debabf6fc.tar.gz rtic-948e1fd0fbd96f574c31909843b2ed3debabf6fc.tar.zst rtic-948e1fd0fbd96f574c31909843b2ed3debabf6fc.zip |
v0.2.2v0.2.2
Diffstat (limited to 'src/examples/_6_generics.rs')
-rw-r--r-- | src/examples/_6_generics.rs | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/src/examples/_6_generics.rs b/src/examples/_6_generics.rs new file mode 100644 index 00000000..82ecdf99 --- /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<G, S>(t: &mut Threshold, gpioa: &G, spi1: &S) +//! where +//! G: Resource<Data = GPIOA>, +//! S: Resource<Data = SPI1>, +//! { +//! 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. |