-
Notifications
You must be signed in to change notification settings - Fork 161
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 rust-embedded/critical-section#19 Co-authored-by: Dario Nieuwenhuis <[email protected]>
- Loading branch information
Showing
7 changed files
with
44 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters