nrf_mpsl/lib.rs
1//! An interface for the Nordic multiprotocol service layer (MPSL).
2//!
3//! # Example
4//!
5//! ```rust,no_run
6//! #![no_std]
7//! #![no_main]
8//! #![feature(type_alias_impl_trait)]
9//!
10//! use embassy_executor::Spawner;
11//! use embassy_nrf::bind_interrupts;
12//! use nrf_mpsl::{MultiprotocolServiceLayer, Peripherals, raw};
13//! use static_cell::StaticCell;
14//!
15//! // This is where we register the interrupt handlers for the MPSL
16//! bind_interrupts!(struct Irqs {
17//! SWI0_EGU0 => nrf_mpsl::LowPrioInterruptHandler;
18//! POWER_CLOCK => nrf_mpsl::ClockInterruptHandler;
19//! RADIO => nrf_mpsl::HighPrioInterruptHandler;
20//! TIMER0 => nrf_mpsl::HighPrioInterruptHandler;
21//! RTC0 => nrf_mpsl::HighPrioInterruptHandler;
22//! });
23//!
24//! #[embassy_executor::main]
25//! async fn main(spawner: Spawner) -> ! {
26//! let p = embassy_nrf::init(Default::default());
27//!
28//! // Create the clock configuration
29//! let lfclk_cfg = raw::mpsl_clock_lfclk_cfg_t {
30//! source: raw::MPSL_CLOCK_LF_SRC_RC as u8,
31//! rc_ctiv: 16,
32//! rc_temp_ctiv: 2,
33//! accuracy_ppm: raw::MPSL_CLOCK_LF_ACCURACY_500_PPM as u16,
34//! };
35//!
36//! // On nrf52 chips, the peripherals needed by MPSL are:
37//! // RTC0, TIMER0, TEMP, PPI_CH19, PPI_CH30, PPI_CH31
38//! // The list of peripherals is different for other chips.
39//! let mpsl_p = Peripherals::new(
40//! p.RTC0,
41//! p.TIMER0,
42//! p.TEMP,
43//! p.PPI_CH19,
44//! p.PPI_CH30,
45//! p.PPI_CH31,
46//! );
47//!
48//! // Initialize the MPSL
49//! static MPSL: StaticCell<MultiprotocolServiceLayer> = StaticCell::new();
50//! let mpsl = MPSL.init(MultiprotocolServiceLayer::new(mpsl_p, Irqs, lfclk_cfg).unwrap());
51//!
52//! // Spawn the MPSL task
53//! spawner.must_spawn(mpsl_task(mpsl));
54//!
55//! // Your application logic can go here.
56//! loop {
57//! // Do something
58//! }
59//! }
60//!
61//! #[embassy_executor::task]
62//! async fn mpsl_task(mpsl: &'static MultiprotocolServiceLayer) -> ! {
63//! mpsl.run().await
64//! }
65//!
66//! #[panic_handler]
67//! fn panic(_info: &core::panic::PanicInfo) -> ! {
68//! loop {}
69//! }
70//! ```
71#![no_std]
72#![deny(missing_docs)]
73
74/// Unsafe low-level bindings for the Nordic multiprotocol service layer.
75pub use nrf_mpsl_sys as raw;
76
77// This mod MUST go first, so that the others see its macros.
78pub(crate) mod fmt;
79
80/// Error handling.
81mod error;
82/// Flash operations using the timeslot API.
83#[cfg(feature = "nrf52")]
84mod flash;
85/// High-frequency clock management.
86mod hfclk;
87/// Multiprotocol service layer.
88mod mpsl;
89/// Temperature sensor access.
90mod temp;
91
92#[cfg(feature = "critical-section-impl")]
93mod critical_section_impl;
94
95pub use error::*;
96#[cfg(feature = "nrf52")]
97pub use flash::*;
98pub use hfclk::*;
99pub use mpsl::*;
100pub use temp::*;