summaryrefslogtreecommitdiff
path: root/nrf-softdevice
diff options
context:
space:
mode:
authoralexmoon <alex.r.moon@gmail.com>2022-08-17 16:09:09 -0600
committerGitHub <noreply@github.com>2022-08-17 16:09:09 -0600
commite1e4e2a2c2e9a8243368214fac02532e79c127a8 (patch)
tree6103e9dc1ca5d2a15c92fb016dc161d88a831e59 /nrf-softdevice
parenta0467c55b09c4b48f4f5a428f6ba56734804b638 (diff)
parentbeed7433fb8dd80e6a395034aa90613c5d6d74fd (diff)
downloadnrf-softdevice-e1e4e2a2c2e9a8243368214fac02532e79c127a8.zip
Merge pull request #129 from embassy-rs/cs
Update to critical-section 1.0
Diffstat (limited to 'nrf-softdevice')
-rw-r--r--nrf-softdevice/Cargo.toml5
-rw-r--r--nrf-softdevice/src/critical_section_impl.rs23
2 files changed, 20 insertions, 8 deletions
diff --git a/nrf-softdevice/Cargo.toml b/nrf-softdevice/Cargo.toml
index 1c8f9ce..40f582c 100644
--- a/nrf-softdevice/Cargo.toml
+++ b/nrf-softdevice/Cargo.toml
@@ -28,7 +28,7 @@ ble-gatt = []
ble-gatt-server = ["ble-gatt"]
ble-gatt-client = ["ble-gatt"]
-critical-section-impl = ["critical-section/custom-impl"]
+critical-section-impl = ["critical-section-1/restore-state-bool", "critical-section-02/custom-impl"]
# Workaround l2cap credit bug. If set, infinite credits are issued
# to the peer in batches. The `credits` config when establishing the channel is ignored.
@@ -38,7 +38,8 @@ ble-l2cap-credit-wrokaround = []
[dependencies]
defmt = { version = "0.3", optional = true }
log = { version = "0.4.11", optional = true }
-critical-section = { version = "0.2.1" }
+critical-section-02 = { package = "critical-section", version = "0.2", optional = true }
+critical-section-1 = { package = "critical-section", version = "1.0", optional = true }
num_enum = { version = "0.5.1", default-features = false }
embassy-util = { version = "0.1.0" }
diff --git a/nrf-softdevice/src/critical_section_impl.rs b/nrf-softdevice/src/critical_section_impl.rs
index 59f9445..cb955fd 100644
--- a/nrf-softdevice/src/critical_section_impl.rs
+++ b/nrf-softdevice/src/critical_section_impl.rs
@@ -53,10 +53,11 @@ unsafe fn raw_critical_section<R>(f: impl FnOnce() -> R) -> R {
}
struct CriticalSection;
-critical_section::custom_impl!(CriticalSection);
+critical_section_1::set_impl!(CriticalSection);
+critical_section_02::custom_impl!(CriticalSection);
-unsafe impl critical_section::Impl for CriticalSection {
- unsafe fn acquire() -> u8 {
+unsafe impl critical_section_1::Impl for CriticalSection {
+ unsafe fn acquire() -> bool {
let nvic = &*NVIC::PTR;
let nested_cs = CS_FLAG.load(Ordering::SeqCst);
@@ -74,14 +75,14 @@ unsafe impl critical_section::Impl for CriticalSection {
compiler_fence(Ordering::SeqCst);
- return nested_cs as u8;
+ nested_cs
}
- unsafe fn release(token: u8) {
+ unsafe fn release(nested_cs: bool) {
compiler_fence(Ordering::SeqCst);
let nvic = &*NVIC::PTR;
- if token == 0 {
+ if !nested_cs {
raw_critical_section(|| {
CS_FLAG.store(false, Ordering::Relaxed);
// restore only non-reserved irqs.
@@ -90,3 +91,13 @@ unsafe impl critical_section::Impl for CriticalSection {
}
}
}
+
+unsafe impl critical_section_02::Impl for CriticalSection {
+ unsafe fn acquire() -> u8 {
+ <Self as critical_section_1::Impl>::acquire() as _
+ }
+
+ unsafe fn release(token: u8) {
+ <Self as critical_section_1::Impl>::release(token != 0)
+ }
+}