aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/critical_section.rs25
-rw-r--r--src/lib.rs1
2 files changed, 26 insertions, 0 deletions
diff --git a/src/critical_section.rs b/src/critical_section.rs
new file mode 100644
index 0000000..d33e90f
--- /dev/null
+++ b/src/critical_section.rs
@@ -0,0 +1,25 @@
+#[cfg(all(cortex_m, feature = "critical-section-single-core"))]
+mod single_core_critical_section {
+ use critical_section::{set_impl, Impl, RawRestoreState};
+
+ use crate::interrupt;
+ use crate::register::primask;
+
+ struct SingleCoreCriticalSection;
+ set_impl!(SingleCoreCriticalSection);
+
+ unsafe impl Impl for SingleCoreCriticalSection {
+ unsafe fn acquire() -> RawRestoreState {
+ let was_active = primask::read().is_active();
+ interrupt::disable();
+ was_active
+ }
+
+ unsafe fn release(was_active: RawRestoreState) {
+ // Only re-enable interrupts if they were enabled before the critical section.
+ if was_active {
+ interrupt::enable()
+ }
+ }
+ }
+}
diff --git a/src/lib.rs b/src/lib.rs
index 4790f98..1796b78 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -90,6 +90,7 @@ mod macros;
pub mod asm;
#[cfg(armv8m)]
pub mod cmse;
+mod critical_section;
pub mod delay;
pub mod interrupt;
#[cfg(all(not(armv6m), not(armv8m_base)))]