diff options
author | 2022-08-11 22:43:27 +0000 | |
---|---|---|
committer | 2022-08-11 22:43:27 +0000 | |
commit | dc539a952a2411a28d63054b1af03eaaa8a58029 (patch) | |
tree | e26456eb8c4313661385ed86e142b7e337d2811a /src | |
parent | e0bfe3ae21903e9dbd80e903e726f7341662e12b (diff) | |
parent | 9e8c8e794d378ce51198fbb9ba27094b430e6d52 (diff) | |
download | cortex-m-dc539a952a2411a28d63054b1af03eaaa8a58029.tar.gz cortex-m-dc539a952a2411a28d63054b1af03eaaa8a58029.tar.zst cortex-m-dc539a952a2411a28d63054b1af03eaaa8a58029.zip |
Merge #448
448: Add implementation for critical-section 1.0, for cortex-m v0.7.x r=adamgreig a=Dirbaio
This is a subset of #447 without any breaking changes, just adding the `critical-section` implementation.
The goal is to release it in 0.7.6 so `critical-section` becomes usable without having to wait for cortex-m 0.8.
TODO before merging:
- [x] Wait for `critical-section 1.0` release https://github.com/rust-embedded/critical-section/pull/19
Co-authored-by: Dario Nieuwenhuis <dirbaio@dirbaio.net>
Diffstat (limited to 'src')
-rw-r--r-- | src/critical_section.rs | 25 | ||||
-rw-r--r-- | src/lib.rs | 1 |
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() + } + } + } +} @@ -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)))] |