summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--examples/src/bin/ble_bas_central.rs3
-rw-r--r--examples/src/bin/ble_bas_peripheral.rs3
-rw-r--r--examples/src/bin/ble_peripheral_gattspam.rs3
-rw-r--r--examples/src/bin/flash.rs3
-rw-r--r--examples/src/bin/interrupts.rs3
-rw-r--r--examples/src/example_common.rs140
-rw-r--r--nrf-softdevice/src/softdevice.rs38
7 files changed, 185 insertions, 8 deletions
diff --git a/examples/src/bin/ble_bas_central.rs b/examples/src/bin/ble_bas_central.rs
index 764b815..c1cbe7a 100644
--- a/examples/src/bin/ble_bas_central.rs
+++ b/examples/src/bin/ble_bas_central.rs
@@ -156,7 +156,8 @@ fn main() -> ! {
..Default::default()
};
- let sd = Softdevice::enable(&config);
+ let (sdp, p) = take_peripherals();
+ let sd = Softdevice::enable(sdp, &config);
let executor = EXECUTOR.put(Executor::new(cortex_m::asm::sev));
executor.spawn(softdevice_task(sd)).dewrap();
diff --git a/examples/src/bin/ble_bas_peripheral.rs b/examples/src/bin/ble_bas_peripheral.rs
index 53f4ff9..b2d294b 100644
--- a/examples/src/bin/ble_bas_peripheral.rs
+++ b/examples/src/bin/ble_bas_peripheral.rs
@@ -121,7 +121,8 @@ fn main() -> ! {
..Default::default()
};
- let sd = Softdevice::enable(&config);
+ let (sdp, p) = take_peripherals();
+ let sd = Softdevice::enable(sdp, &config);
let executor = EXECUTOR.put(Executor::new(cortex_m::asm::sev));
executor.spawn(softdevice_task(sd)).dewrap();
diff --git a/examples/src/bin/ble_peripheral_gattspam.rs b/examples/src/bin/ble_peripheral_gattspam.rs
index 6ad83fd..c97ec00 100644
--- a/examples/src/bin/ble_peripheral_gattspam.rs
+++ b/examples/src/bin/ble_peripheral_gattspam.rs
@@ -155,7 +155,8 @@ fn main() -> ! {
..Default::default()
};
- let sd = Softdevice::enable(&config);
+ let (sdp, p) = take_peripherals();
+ let sd = Softdevice::enable(sdp, &config);
let executor = EXECUTOR.put(Executor::new(cortex_m::asm::sev));
executor.spawn(softdevice_task(sd)).dewrap();
diff --git a/examples/src/bin/flash.rs b/examples/src/bin/flash.rs
index 8153f02..a7a7a87 100644
--- a/examples/src/bin/flash.rs
+++ b/examples/src/bin/flash.rs
@@ -41,7 +41,8 @@ async fn flash_task(sd: &'static Softdevice) {
fn main() -> ! {
info!("Hello World!");
- let sd = Softdevice::enable(&Default::default());
+ let (sdp, p) = take_peripherals();
+ let sd = Softdevice::enable(sdp, &Default::default());
let executor = EXECUTOR.put(Executor::new(cortex_m::asm::sev));
executor.spawn(softdevice_task(sd)).dewrap();
diff --git a/examples/src/bin/interrupts.rs b/examples/src/bin/interrupts.rs
index 8600d37..91454a1 100644
--- a/examples/src/bin/interrupts.rs
+++ b/examples/src/bin/interrupts.rs
@@ -87,7 +87,8 @@ fn SWI1_EGU1() {
fn main() -> ! {
info!("Hello World!");
- let sd = Softdevice::enable(&Default::default());
+ let (sdp, p) = take_peripherals();
+ let sd = Softdevice::enable(sdp, &Default::default());
let executor = EXECUTOR.put(Executor::new(cortex_m::asm::sev));
executor.spawn(softdevice_task(sd)).dewrap();
diff --git a/examples/src/example_common.rs b/examples/src/example_common.rs
index 65bfe6b..da753bc 100644
--- a/examples/src/example_common.rs
+++ b/examples/src/example_common.rs
@@ -2,6 +2,7 @@
use defmt_rtt as _; // global logger
use nrf52840_hal as _;
+use nrf_softdevice::pac;
use panic_probe as _;
pub use defmt::{info, intern};
@@ -17,6 +18,145 @@ fn timestamp() -> u64 {
n as u64
}
+// Take peripherals, split by softdevice and application
+pub fn take_peripherals() -> (nrf_softdevice::Peripherals, Peripherals) {
+ let p = pac::Peripherals::take().dewrap();
+
+ (
+ nrf_softdevice::Peripherals {
+ AAR: p.AAR,
+ ACL: p.ACL,
+ CCM: p.CCM,
+ CLOCK: p.CLOCK,
+ ECB: p.ECB,
+ EGU1: p.EGU1,
+ EGU2: p.EGU2,
+ EGU5: p.EGU5,
+ MWU: p.MWU,
+ NVMC: p.NVMC,
+ POWER: p.POWER,
+ RADIO: p.RADIO,
+ RNG: p.RNG,
+ RTC0: p.RTC0,
+ SWI1: p.SWI1,
+ SWI2: p.SWI2,
+ SWI5: p.SWI5,
+ TEMP: p.TEMP,
+ TIMER0: p.TIMER0,
+ },
+ Peripherals {
+ CC_HOST_RGF: p.CC_HOST_RGF,
+ COMP: p.COMP,
+ CRYPTOCELL: p.CRYPTOCELL,
+ EGU0: p.EGU0,
+ EGU3: p.EGU3,
+ EGU4: p.EGU4,
+ FICR: p.FICR,
+ GPIOTE: p.GPIOTE,
+ I2S: p.I2S,
+ LPCOMP: p.LPCOMP,
+ NFCT: p.NFCT,
+ P0: p.P0,
+ P1: p.P1,
+ PDM: p.PDM,
+ PPI: p.PPI,
+ PWM0: p.PWM0,
+ PWM1: p.PWM1,
+ PWM2: p.PWM2,
+ PWM3: p.PWM3,
+ QDEC: p.QDEC,
+ QSPI: p.QSPI,
+ RTC2: p.RTC2,
+ SAADC: p.SAADC,
+ SPI0: p.SPI0,
+ SPI1: p.SPI1,
+ SPI2: p.SPI2,
+ SPIM0: p.SPIM0,
+ SPIM1: p.SPIM1,
+ SPIM2: p.SPIM2,
+ SPIM3: p.SPIM3,
+ SPIS0: p.SPIS0,
+ SPIS1: p.SPIS1,
+ SPIS2: p.SPIS2,
+ SWI0: p.SWI0,
+ SWI3: p.SWI3,
+ SWI4: p.SWI4,
+ TIMER1: p.TIMER1,
+ TIMER2: p.TIMER2,
+ TIMER3: p.TIMER3,
+ TIMER4: p.TIMER4,
+ TWI0: p.TWI0,
+ TWI1: p.TWI1,
+ TWIM0: p.TWIM0,
+ TWIM1: p.TWIM1,
+ TWIS0: p.TWIS0,
+ TWIS1: p.TWIS1,
+ UART0: p.UART0,
+ UARTE0: p.UARTE0,
+ UARTE1: p.UARTE1,
+ UICR: p.UICR,
+ USBD: p.USBD,
+ WDT: p.WDT,
+ },
+ )
+}
+
+#[allow(non_snake_case)]
+pub struct Peripherals {
+ pub CC_HOST_RGF: pac::CC_HOST_RGF,
+ pub COMP: pac::COMP,
+ pub CRYPTOCELL: pac::CRYPTOCELL,
+ pub EGU0: pac::EGU0,
+ pub EGU3: pac::EGU3,
+ pub EGU4: pac::EGU4,
+ pub FICR: pac::FICR,
+ pub GPIOTE: pac::GPIOTE,
+ pub I2S: pac::I2S,
+ pub LPCOMP: pac::LPCOMP,
+ pub NFCT: pac::NFCT,
+ pub P0: pac::P0,
+ pub P1: pac::P1,
+ pub PDM: pac::PDM,
+ pub PPI: pac::PPI,
+ pub PWM0: pac::PWM0,
+ pub PWM1: pac::PWM1,
+ pub PWM2: pac::PWM2,
+ pub PWM3: pac::PWM3,
+ pub QDEC: pac::QDEC,
+ pub QSPI: pac::QSPI,
+ pub RTC2: pac::RTC2,
+ pub SAADC: pac::SAADC,
+ pub SPI0: pac::SPI0,
+ pub SPI1: pac::SPI1,
+ pub SPI2: pac::SPI2,
+ pub SPIM0: pac::SPIM0,
+ pub SPIM1: pac::SPIM1,
+ pub SPIM2: pac::SPIM2,
+ pub SPIM3: pac::SPIM3,
+ pub SPIS0: pac::SPIS0,
+ pub SPIS1: pac::SPIS1,
+ pub SPIS2: pac::SPIS2,
+ pub SWI0: pac::SWI0,
+ pub SWI3: pac::SWI3,
+ pub SWI4: pac::SWI4,
+ pub TIMER1: pac::TIMER1,
+ pub TIMER2: pac::TIMER2,
+ pub TIMER3: pac::TIMER3,
+ pub TIMER4: pac::TIMER4,
+ pub TWI0: pac::TWI0,
+ pub TWI1: pac::TWI1,
+ pub TWIM0: pac::TWIM0,
+ pub TWIM1: pac::TWIM1,
+ pub TWIS0: pac::TWIS0,
+ pub TWIS1: pac::TWIS1,
+ pub UART0: pac::UART0,
+ pub UARTE0: pac::UARTE0,
+ pub UARTE1: pac::UARTE1,
+ pub UICR: pac::UICR,
+ pub USBD: pac::USBD,
+ pub WDT: pac::WDT,
+}
+
macro_rules! depanic {
($( $i:expr ),*) => {
{
diff --git a/nrf-softdevice/src/softdevice.rs b/nrf-softdevice/src/softdevice.rs
index 1b3af43..72209d5 100644
--- a/nrf-softdevice/src/softdevice.rs
+++ b/nrf-softdevice/src/softdevice.rs
@@ -4,6 +4,7 @@ use core::sync::atomic::{AtomicBool, Ordering};
use crate::ble;
use crate::interrupt;
+use crate::pac;
use crate::raw;
use crate::util::*;
use crate::RawError;
@@ -12,6 +13,35 @@ unsafe extern "C" fn fault_handler(id: u32, pc: u32, info: u32) {
depanic!("fault_handler {:u32} {:u32} {:u32}", id, pc, info);
}
+#[allow(non_snake_case)]
+pub struct Peripherals {
+ pub AAR: pac::AAR,
+ #[cfg(not(any(feature = "nrf52810", feature = "nrf52811", feature = "nrf52832")))]
+ pub ACL: pac::ACL,
+ #[cfg(any(feature = "nrf52810", feature = "nrf52811", feature = "nrf52832"))]
+ pub BPROT: pac::BPROT,
+ pub CCM: pac::CCM,
+ pub CLOCK: pac::CLOCK,
+ pub ECB: pac::ECB,
+ pub EGU1: pac::EGU1,
+ #[cfg(not(any(feature = "nrf52810", feature = "nrf52811")))]
+ pub EGU2: pac::EGU2,
+ #[cfg(not(any(feature = "nrf52810", feature = "nrf52811")))]
+ pub EGU5: pac::EGU5,
+ #[cfg(any(feature = "nrf52832", feature = "nrf52833", feature = "nrf52840"))]
+ pub MWU: pac::MWU,
+ pub NVMC: pac::NVMC,
+ pub POWER: pac::POWER,
+ pub RADIO: pac::RADIO,
+ pub RNG: pac::RNG,
+ pub RTC0: pac::RTC0,
+ pub SWI1: pac::SWI1,
+ pub SWI2: pac::SWI2,
+ pub SWI5: pac::SWI5,
+ pub TEMP: pac::TEMP,
+ pub TIMER0: pac::TIMER0,
+}
+
/// Singleton instance of the enabled softdevice.
///
/// The `Softdevice` instance can be obtaind by enabling it with [`Softdevice::enable`]. Once
@@ -103,13 +133,15 @@ static mut SOFTDEVICE: Softdevice = Softdevice {
};
impl Softdevice {
- /// Enable the softdevice with the requested configuration.
+ /// 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 using `defmt` prior to panic.
+ /// - 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.
/// - Panics if called multiple times. Must be called at most once.
- pub fn enable(config: &Config) -> &'static Softdevice {
+ pub fn enable(_peripherals: Peripherals, config: &Config) -> &'static Softdevice {
if ENABLED.compare_and_swap(false, true, Ordering::AcqRel) {
depanic!("nrf_softdevice::enable() called multiple times.")
}