From 85208400e14928e191056712f23adb9c0d845c7c Mon Sep 17 00:00:00 2001 From: Ivan Mikhailov Date: Sun, 4 Sep 2022 10:51:44 +0200 Subject: [PATCH] DMA: allow to stop incomplete transfers --- CHANGELOG.md | 1 + src/dma.rs | 27 ++++++++++++++++++++++++--- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8f746e3e..11b9867b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Allow access to the `Tx` and `Rx` parts of the `Serial` without the need for splitting. - Allow `Serial` reconfiguration by references to the `Tx` and `Rx` parts. - Allow `Serial` release after splitting. +- Allow to stop an incomplete DMA transfer. ## [v0.9.0] - 2022-03-02 diff --git a/src/dma.rs b/src/dma.rs index b94ad9d3..3910d492 100644 --- a/src/dma.rs +++ b/src/dma.rs @@ -302,9 +302,16 @@ macro_rules! dma { !self.payload.channel.in_progress() } - pub fn wait(mut self) -> (BUFFER, RxDma) { + /// Waits for the transfer to complete, + /// then stops it and returns the underlying buffer and RxDma. + pub fn wait(self) -> (BUFFER, RxDma) { while !self.is_done() {} + self.stop() + } + + /// Stops the transfer and returns the underlying buffer and RxDma. + pub fn stop(mut self) -> (BUFFER, RxDma) { 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) { + /// Waits for the transfer to complete, + /// then stops it and returns the underlying buffer and TxDma. + pub fn wait(self) -> (BUFFER, TxDma) { while !self.is_done() {} + self.stop() + } + + /// Stops the transfer and returns the underlying buffer and TxDma. + pub fn stop(mut self) -> (BUFFER, TxDma) { 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) { + /// Waits for the transfer to complete, + /// then stops it and returns the underlying buffer and RxTxDma. + pub fn wait(self) -> (BUFFER, RxTxDma) { while !self.is_done() {} + self.stop() + } + + /// Stops the transfer and returns the underlying buffer and RxTxDma. + pub fn stop(mut self) -> (BUFFER, RxTxDma) { atomic::compiler_fence(Ordering::Acquire); self.payload.stop();