summaryrefslogtreecommitdiff
path: root/nrf-softdevice/src/softdevice.rs
diff options
context:
space:
mode:
Diffstat (limited to 'nrf-softdevice/src/softdevice.rs')
-rw-r--r--nrf-softdevice/src/softdevice.rs19
1 files changed, 11 insertions, 8 deletions
diff --git a/nrf-softdevice/src/softdevice.rs b/nrf-softdevice/src/softdevice.rs
index caad633..d744389 100644
--- a/nrf-softdevice/src/softdevice.rs
+++ b/nrf-softdevice/src/softdevice.rs
@@ -1,9 +1,8 @@
use core::marker::PhantomData;
+use core::mem::MaybeUninit;
use core::ptr;
use core::sync::atomic::{AtomicBool, Ordering};
-use embassy_util::Forever;
-
use crate::{pac, raw, RawError, SocEvent};
unsafe extern "C" fn fault_handler(id: u32, pc: u32, info: u32) {
@@ -85,13 +84,11 @@ fn cfg_set(id: u32, cfg: &raw::ble_cfg_t) {
}
static ENABLED: AtomicBool = AtomicBool::new(false);
-static SOFTDEVICE: Forever<Softdevice> = Forever::new();
+static mut SOFTDEVICE: MaybeUninit<Softdevice> = MaybeUninit::uninit();
impl Softdevice {
/// Enable the softdevice.
///
- /// This function takes ownership of the softdevice-reserved peripherals to ensure application code doesn't attempt to use them after enabling.
- ///
/// # Panics
/// - Panics if the requested configuration requires more memory than reserved for the softdevice. In that case, you can give more memory to the softdevice by editing the RAM start address in `memory.x`. The required start address is logged prior to panic.
/// - Panics if the requested configuration has too high memory requirements for the softdevice. The softdevice supports a maximum dynamic memory size of 64kb.
@@ -280,7 +277,7 @@ impl Softdevice {
.map(|x| x.rx_mps)
.unwrap_or(raw::BLE_L2CAP_MPS_MIN as u16);
- SOFTDEVICE.put(Softdevice {
+ let sd = Softdevice {
_private: PhantomData,
#[cfg(feature = "ble-gatt")]
@@ -288,7 +285,13 @@ impl Softdevice {
#[cfg(feature = "ble-l2cap")]
l2cap_rx_mps,
- })
+ };
+
+ unsafe {
+ let p = SOFTDEVICE.as_mut_ptr();
+ p.write(sd);
+ &mut *p
+ }
}
/// Return an instance to the softdevice without checking whether
@@ -296,7 +299,7 @@ impl Softdevice {
/// (a call to [`enable`] has returned without error) and no `&mut` references
/// to the softdevice are active
pub unsafe fn steal() -> &'static Softdevice {
- SOFTDEVICE.steal()
+ &*SOFTDEVICE.as_ptr()
}
/// Runs the softdevice event handling loop.