Skip to content

DMA: allow to stop incomplete transfers #439

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -28,6 +28,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Allow `Serial` reconfiguration by references to the `Tx` and `Rx` parts.
- Allow `Serial` release after splitting.
- `Spi::is_busy()`
- Allow to stop an incomplete DMA transfer.

## [v0.9.0] - 2022-03-02

27 changes: 24 additions & 3 deletions src/dma.rs
Original file line number Diff line number Diff line change
@@ -302,9 +302,16 @@ macro_rules! dma {
!self.payload.channel.in_progress()
}

pub fn wait(mut self) -> (BUFFER, RxDma<PAYLOAD, $CX>) {
/// Waits for the transfer to complete,
/// then stops it and returns the underlying buffer and RxDma.
pub fn wait(self) -> (BUFFER, RxDma<PAYLOAD, $CX>) {
while !self.is_done() {}

self.stop()
}

/// Stops the transfer and returns the underlying buffer and RxDma.
pub fn stop(mut self) -> (BUFFER, RxDma<PAYLOAD, $CX>) {
atomic::compiler_fence(Ordering::Acquire);

self.payload.stop();
@@ -340,9 +347,16 @@ macro_rules! dma {
!self.payload.channel.in_progress()
}

pub fn wait(mut self) -> (BUFFER, TxDma<PAYLOAD, $CX>) {
/// Waits for the transfer to complete,
/// then stops it and returns the underlying buffer and TxDma.
pub fn wait(self) -> (BUFFER, TxDma<PAYLOAD, $CX>) {
while !self.is_done() {}

self.stop()
}

/// Stops the transfer and returns the underlying buffer and TxDma.
pub fn stop(mut self) -> (BUFFER, TxDma<PAYLOAD, $CX>) {
atomic::compiler_fence(Ordering::Acquire);

self.payload.stop();
@@ -378,9 +392,16 @@ macro_rules! dma {
!self.payload.rxchannel.in_progress()
}

pub fn wait(mut self) -> (BUFFER, RxTxDma<PAYLOAD, $CX, TXC>) {
/// Waits for the transfer to complete,
/// then stops it and returns the underlying buffer and RxTxDma.
pub fn wait(self) -> (BUFFER, RxTxDma<PAYLOAD, $CX, TXC>) {
while !self.is_done() {}

self.stop()
}

/// Stops the transfer and returns the underlying buffer and RxTxDma.
pub fn stop(mut self) -> (BUFFER, RxTxDma<PAYLOAD, $CX, TXC>) {
atomic::compiler_fence(Ordering::Acquire);

self.payload.stop();