diff --git a/core/Cargo.toml b/core/Cargo.toml index 414917a..3943152 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -15,14 +15,14 @@ categories = [ license = "MIT OR Apache-2.0" [dependencies] -cortex-m = { version = "0.6.0", optional = true } +critical-section = { version = "1.1", optional = true } [dependencies.defmt] version = "0.3.0" optional = true [features] -thumbv6 = ["cortex-m"] +thumbv6 = ["critical-section"] defmt_0_3 = ["defmt"] [package.metadata.docs.rs] diff --git a/core/src/bbbuffer.rs b/core/src/bbbuffer.rs index 78610b5..f0f9455 100644 --- a/core/src/bbbuffer.rs +++ b/core/src/bbbuffer.rs @@ -1108,11 +1108,11 @@ mod atomic { AtomicBool, AtomicUsize, Ordering::{self, Acquire, Release}, }; - use cortex_m::interrupt::free; + use critical_section::with; #[inline(always)] pub fn fetch_add(atomic: &AtomicUsize, val: usize, _order: Ordering) -> usize { - free(|_| { + with(|_| { let prev = atomic.load(Acquire); atomic.store(prev.wrapping_add(val), Release); prev @@ -1121,7 +1121,7 @@ mod atomic { #[inline(always)] pub fn fetch_sub(atomic: &AtomicUsize, val: usize, _order: Ordering) -> usize { - free(|_| { + with(|_| { let prev = atomic.load(Acquire); atomic.store(prev.wrapping_sub(val), Release); prev @@ -1130,7 +1130,7 @@ mod atomic { #[inline(always)] pub fn swap(atomic: &AtomicBool, val: bool, _order: Ordering) -> bool { - free(|_| { + with(|_| { let prev = atomic.load(Acquire); atomic.store(val, Release); prev diff --git a/core/src/lib.rs b/core/src/lib.rs index 49ee1bd..61c5eae 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -92,8 +92,11 @@ //! //! This crate contains special support for Cortex-M0(+) targets with the `thumbv6` feature. By //! enabling the feature, unsupported atomic operations will be replaced with critical sections -//! implemented by disabling interrupts. The critical sections are very short, a few instructions at -//! most, so they should make no difference to most applications. +//! using the `critical_section` crate. The critical sections are very short, a few instructions at +//! most, so they should make no difference to most applications. When using this feature an +//! implementation must be provided for the `critical_section` crate. A single core version that +//! disables interrupts is available on the `cortex_m` crate by enabling the feature +//! `critical-section-single-core` on that crate. #![cfg_attr(not(feature = "std"), no_std)] #![deny(missing_docs)]