diff options
author | 2017-11-22 09:27:14 +0100 | |
---|---|---|
committer | 2017-11-22 09:29:01 +0100 | |
commit | 948e1fd0fbd96f574c31909843b2ed3debabf6fc (patch) | |
tree | be8bb18bee86e726a52e19a4083fa0ae9386cdfb /src | |
parent | c184f91e3c3993dacbd8425019cde6a3607478bc (diff) | |
download | rtic-948e1fd0fbd96f574c31909843b2ed3debabf6fc.tar.gz rtic-948e1fd0fbd96f574c31909843b2ed3debabf6fc.tar.zst rtic-948e1fd0fbd96f574c31909843b2ed3debabf6fc.zip |
v0.2.2v0.2.2
Diffstat (limited to 'src')
-rw-r--r-- | src/examples/_5_late_resources.rs | 91 | ||||
-rw-r--r-- | src/examples/_6_generics.rs (renamed from src/examples/_5_generics.rs) | 0 | ||||
-rw-r--r-- | src/examples/_7_full_syntax.rs (renamed from src/examples/_6_full_syntax.rs) | 0 | ||||
-rw-r--r-- | src/examples/mod.rs | 5 |
4 files changed, 94 insertions, 2 deletions
diff --git a/src/examples/_5_late_resources.rs b/src/examples/_5_late_resources.rs new file mode 100644 index 00000000..8a5b6e16 --- /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/_5_generics.rs b/src/examples/_6_generics.rs index 82ecdf99..82ecdf99 100644 --- a/src/examples/_5_generics.rs +++ b/src/examples/_6_generics.rs diff --git a/src/examples/_6_full_syntax.rs b/src/examples/_7_full_syntax.rs index 80520657..80520657 100644 --- a/src/examples/_6_full_syntax.rs +++ b/src/examples/_7_full_syntax.rs diff --git a/src/examples/mod.rs b/src/examples/mod.rs index e0be5a6f..53e74ed1 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; |