Skip to content

Commit 03fcf38

Browse files
committed
Use critical-section for critical sections
The implementation is plug-able, allowing an easier way to support multi-core systems. We don't use cortex-m anymore.
1 parent ca73bc8 commit 03fcf38

3 files changed

Lines changed: 7 additions & 5 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## [Unreleased]
44

5+
Use `critical-section` instead of `cortex-m` for the critical section implementation.
6+
57
## [0.1.1] 2023-01-12
68

79
Fix an incorrect lifetime caught by `implied_bounds_entailment`.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ categories = ["embedded", "no-std"]
1212
repository.workspace = true
1313

1414
[dependencies]
15-
cortex-m = "0.7.2"
15+
critical-section = "1.2"
1616
ral-registers = "0.1"
1717

1818
[workspace.package]

src/interrupt.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use core::{
1010
task::{Context, Poll, Waker},
1111
};
1212

13-
use cortex_m::interrupt::{self, Mutex};
13+
use critical_section::Mutex;
1414

1515
impl<const CHANNELS: usize> super::Dma<CHANNELS> {
1616
/// Handle a DMA interrupt
@@ -54,7 +54,7 @@ impl<const CHANNELS: usize> super::Dma<CHANNELS> {
5454
}
5555

5656
if channel.is_complete() | channel.is_error() {
57-
interrupt::free(|cs| {
57+
critical_section::with(|cs| {
5858
let waker = self.wakers[channel.channel()].borrow(cs);
5959
let mut waker = waker.borrow_mut();
6060
if let Some(waker) = waker.take() {
@@ -133,7 +133,7 @@ impl<'a> Transfer<'a> {
133133
impl Future for Transfer<'_> {
134134
type Output = Result<(), Error>;
135135
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
136-
interrupt::free(|cs| {
136+
critical_section::with(|cs| {
137137
let waker = self.channel.waker.borrow(cs);
138138
let mut waker = waker.borrow_mut();
139139
*waker = Some(cx.waker().clone());
@@ -166,7 +166,7 @@ impl Drop for Transfer<'_> {
166166
self.channel.disable();
167167
self.channel.clear_complete();
168168
self.channel.clear_error();
169-
interrupt::free(|cs| {
169+
critical_section::with(|cs| {
170170
let waker = self.channel.waker.borrow(cs);
171171
let mut waker = waker.borrow_mut();
172172
*waker = None;

0 commit comments

Comments
 (0)