diff options
author | 2017-12-09 10:55:45 +0100 | |
---|---|---|
committer | 2017-12-09 10:55:45 +0100 | |
commit | 9bab4175eb4120612e07470d060d6aca3b5edfd5 (patch) | |
tree | 338d4a0114d241c465618801dbca006b0ff0f335 | |
parent | c6ed9ef43f6606f654c2392413ca8ed380a35056 (diff) | |
download | cortex-m-9bab4175eb4120612e07470d060d6aca3b5edfd5.tar.gz cortex-m-9bab4175eb4120612e07470d060d6aca3b5edfd5.tar.zst cortex-m-9bab4175eb4120612e07470d060d6aca3b5edfd5.zip |
s/all/take/g s/_all/steal/g
-rw-r--r-- | src/peripheral/mod.rs | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/src/peripheral/mod.rs b/src/peripheral/mod.rs index c9c7a28..7482398 100644 --- a/src/peripheral/mod.rs +++ b/src/peripheral/mod.rs @@ -62,23 +62,25 @@ pub struct Peripherals { pub TPIU: TPIU, } +// NOTE `no_mangle` is used here to prevent linking different minor versions of this crate as that +// would let you `take` the core peripherals more than once (one per minor version) #[no_mangle] static mut CORE_PERIPHERALS: bool = false; impl Peripherals { /// Returns all the core peripherals *once* - pub fn all() -> Option<Self> { + pub fn take() -> Option<Self> { interrupt::free(|_| { if unsafe { CORE_PERIPHERALS } { None } else { - Some(unsafe { Peripherals::_all() }) + Some(unsafe { Peripherals::steal() }) } }) } #[doc(hidden)] - pub unsafe fn _all() -> Self { + pub unsafe fn steal() -> Self { debug_assert!(!CORE_PERIPHERALS); CORE_PERIPHERALS = true; |