Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update critical-section crate.
  • Loading branch information
reitermarkus committed May 8, 2022
commit 4b01e89ea93b14103e0cf929f6dee1cfc9169c11
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ links = "cortex-m" # prevent multiple versions of this crate to be linked toget

[dependencies]
bitfield = "0.13.2"
critical-section = { version = "0.2", optional = true }
critical-section = { version = "0.3", optional = true }
embedded-hal = "0.2.4"
volatile-register = "0.2.0"

Expand All @@ -32,7 +32,7 @@ cm7 = []
cm7-r0p1 = ["cm7"]
linker-plugin-lto = []
std = []
single-core-critical-section = ["critical-section", "critical-section/custom-impl"]
single-core-critical-section = ["critical-section", "critical-section/token-bool"]

[workspace]
members = [
Expand All @@ -59,4 +59,4 @@ targets = [

[patch.crates-io]
# See https://github.com/embassy-rs/critical-section/pull/13.
critical-section = { git = "https://github.com/reitermarkus/critical-section", branch = "cortex-m" }
critical-section = { git = "https://github.com/embassy-rs/critical-section" }
2 changes: 1 addition & 1 deletion cortex-m-semihosting/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ no-semihosting = []

[dependencies]
cortex-m = { path = "..", version = ">= 0.5.8, < 0.8" }
critical-section = "0.2"
critical-section = "0.3"
21 changes: 10 additions & 11 deletions src/critical_section.rs
Original file line number Diff line number Diff line change
@@ -1,28 +1,27 @@
#[cfg(all(cortex_m, feature = "single-core-critical-section"))]
mod single_core_critical_section {
use critical_section::{set_impl, Impl, RawToken};

use crate::interrupt;
use crate::register::primask::{self, Primask};

struct CriticalSection;
critical_section::custom_impl!(CriticalSection);

const TOKEN_IGNORE: u8 = 0;
const TOKEN_REENABLE: u8 = 1;
struct SingleCoreCriticalSection;
set_impl!(SingleCoreCriticalSection);

unsafe impl critical_section::Impl for CriticalSection {
unsafe fn acquire() -> u8 {
unsafe impl Impl for SingleCoreCriticalSection {
unsafe fn acquire() -> RawToken {
match primask::read() {
Primask::Active => {
interrupt::disable();
TOKEN_REENABLE
true
}
Primask::Inactive => TOKEN_IGNORE,
Primask::Inactive => false,
}
}

unsafe fn release(token: u8) {
unsafe fn release(primask_was_active: RawToken) {
// Only re-enable interrupts if they were enabled before the critical section.
if token == TOKEN_REENABLE {
if primask_was_active {
interrupt::enable()
}
}
Expand Down
2 changes: 1 addition & 1 deletion testsuite/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ semihosting = ["cortex-m-semihosting", "minitest/semihosting"]
cortex-m-rt.path = "../cortex-m-rt"
cortex-m.path = ".."
minitest.path = "minitest"
critical-section = "0.2"
critical-section = "0.3"

[dependencies.rtt-target]
version = "0.3.1"
Expand Down