aboutsummaryrefslogtreecommitdiff
path: root/examples/init.rs
diff options
context:
space:
mode:
authorGravatar bors[bot] <26634292+bors[bot]@users.noreply.github.com> 2021-07-09 11:00:11 +0000
committerGravatar GitHub <noreply@github.com> 2021-07-09 11:00:11 +0000
commite1a4d001f8e724596cd9de3e90698ce7de473b3f (patch)
treef7aac5eae4cc2e19cc06bfd6fa8dab843dcfb276 /examples/init.rs
parent13dc3992e616d817e38c167c4b47db816855f18b (diff)
parentf3d9fd9b638a25b497e1ca02e7ce5de86c9fc1c9 (diff)
downloadrtic-e1a4d001f8e724596cd9de3e90698ce7de473b3f.tar.gz
rtic-e1a4d001f8e724596cd9de3e90698ce7de473b3f.tar.zst
rtic-e1a4d001f8e724596cd9de3e90698ce7de473b3f.zip
Merge #494
494: Resoures take 2 r=korken89 a=korken89 Co-authored-by: Emil Fresk <emil.fresk@gmail.com>
Diffstat (limited to 'examples/init.rs')
-rw-r--r--examples/init.rs16
1 files changed, 10 insertions, 6 deletions
diff --git a/examples/init.rs b/examples/init.rs
index 9de79581..97e3c513 100644
--- a/examples/init.rs
+++ b/examples/init.rs
@@ -11,18 +11,22 @@ use panic_semihosting as _;
mod app {
use cortex_m_semihosting::{debug, hprintln};
- #[init]
- fn init(cx: init::Context) -> (init::LateResources, init::Monotonics) {
- static mut X: u32 = 0;
+ #[shared]
+ struct Shared {}
+ #[local]
+ struct Local {}
+
+ #[init(local = [x: u32 = 0])]
+ fn init(cx: init::Context) -> (Shared, Local, init::Monotonics) {
// Cortex-M peripherals
let _core: cortex_m::Peripherals = cx.core;
// Device specific peripherals
let _device: lm3s6965::Peripherals = cx.device;
- // Safe access to local `static mut` variable
- let _x: &'static mut u32 = X;
+ // Locals in `init` have 'static lifetime
+ let _x: &'static mut u32 = cx.local.x;
// Access to the critical section token,
// to indicate that this is a critical seciton
@@ -32,6 +36,6 @@ mod app {
debug::exit(debug::EXIT_SUCCESS);
- (init::LateResources {}, init::Monotonics())
+ (Shared {}, Local {}, init::Monotonics())
}
}