aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Jorge Aparicio <jorge@japaric.io> 2018-01-23 20:27:06 +0100
committerGravatar Jorge Aparicio <jorge@japaric.io> 2018-01-23 20:27:06 +0100
commitd30209fa372831d819607e6a324b7512f8d1cfaa (patch)
treeed29ab4b5932438f4244a0efab4869231967d7d3 /src
parentc921d43f58db6ac4050e53c6b372d530fce073b7 (diff)
downloadcortex-m-d30209fa372831d819607e6a324b7512f8d1cfaa.tar.gz
cortex-m-d30209fa372831d819607e6a324b7512f8d1cfaa.tar.zst
cortex-m-d30209fa372831d819607e6a324b7512f8d1cfaa.zip
initialize singletons at runtime
Diffstat (limited to 'src')
-rw-r--r--src/lib.rs2
-rw-r--r--src/macros.rs5
2 files changed, 5 insertions, 2 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 694d1b2..6af60d7 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -15,6 +15,7 @@
extern crate aligned;
extern crate bare_metal;
+extern crate untagged_option;
extern crate volatile_register;
#[macro_use]
@@ -31,3 +32,4 @@ pub mod peripheral;
pub mod register;
pub use peripheral::Peripherals;
+pub use untagged_option::UntaggedOption;
diff --git a/src/macros.rs b/src/macros.rs
index c9a32c2..c5799bf 100644
--- a/src/macros.rs
+++ b/src/macros.rs
@@ -54,13 +54,14 @@ macro_rules! singleton {
(: $ty:ty = $expr:expr) => {
$crate::interrupt::free(|_| unsafe {
static mut USED: bool = false;
- static mut VAR: $ty = $expr;
+ static mut VAR: $crate::UntaggedOption<$ty> = $crate::UntaggedOption { none: () };
if USED {
None
} else {
USED = true;
- let var: &'static mut _ = &mut VAR;
+ VAR.some = $expr;
+ let var: &'static mut _ = &mut VAR.some;
Some(var)
}
})