aboutsummaryrefslogtreecommitdiff
path: root/src/critical_section.rs
diff options
context:
space:
mode:
authorGravatar Dario Nieuwenhuis <dirbaio@dirbaio.net> 2022-08-11 01:49:33 +0200
committerGravatar Dario Nieuwenhuis <dirbaio@dirbaio.net> 2022-08-11 23:31:08 +0200
commit3a15a6b4b320fa328e8ab99c31f81536960dd280 (patch)
tree4c3ef55e91988845873479460e438afea445c919 /src/critical_section.rs
parent4e908625204a1e95dd3fd5bdcd8d66d6bc11c3bc (diff)
downloadcortex-m-3a15a6b4b320fa328e8ab99c31f81536960dd280.tar.gz
cortex-m-3a15a6b4b320fa328e8ab99c31f81536960dd280.tar.zst
cortex-m-3a15a6b4b320fa328e8ab99c31f81536960dd280.zip
Add implementation for critical-section 1.0
Co-Authored-By: Markus Reiter <me@reitermark.us>
Diffstat (limited to 'src/critical_section.rs')
-rw-r--r--src/critical_section.rs27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/critical_section.rs b/src/critical_section.rs
new file mode 100644
index 0000000..688058d
--- /dev/null
+++ b/src/critical_section.rs
@@ -0,0 +1,27 @@
+#[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()
+ }
+ }
+ }
+}
+
+pub use critical_section::with;