Skip to content

Commit

Permalink
DMA: Add some useful methods for checking for trasfer errors
Browse files Browse the repository at this point in the history
  • Loading branch information
usbalbin committed Jan 24, 2024
1 parent 9fbaab8 commit 1ea1f4b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/dma/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,13 @@ macro_rules! dma_stream {
dma.isr.read().$tcisr().bit_is_set()
}

#[inline(always)]
fn get_transfer_error_flag() -> bool {
//NOTE(unsafe) Atomic read with no side effects
let dma = unsafe { &*I::ptr() };
dma.isr.read().$teisr().bit_is_set()
}

#[inline(always)]
unsafe fn enable(&mut self) {
//NOTE(unsafe) We only access the registers that belongs to the StreamX
Expand Down
3 changes: 3 additions & 0 deletions src/dma/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ pub trait Stream: Sealed {
/// Get transfer complete flag.
fn get_transfer_complete_flag() -> bool;

/// Get transfer error flag.
fn get_transfer_error_flag() -> bool;

/// Enable the DMA stream.
///
/// # Safety
Expand Down
10 changes: 10 additions & 0 deletions src/dma/transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,11 @@ where
STREAM::get_transfer_complete_flag()
}

#[inline(always)]
pub fn get_transfer_error_flag(&self) -> bool {
STREAM::get_transfer_error_flag()
}

/// Clear half transfer interrupt (htif) for the DMA stream.
#[inline(always)]
pub fn clear_half_transfer_interrupt(&mut self) {
Expand Down Expand Up @@ -437,6 +442,11 @@ where
self.transfer.get_transfer_complete_flag()
}

#[inline(always)]
pub fn get_transfer_error_flag(&self) -> bool {
self.transfer.get_transfer_error_flag()
}

/// Clear half transfer interrupt (htif) for the DMA stream.
#[inline(always)]
pub fn clear_half_transfer_interrupt(&mut self) {
Expand Down

0 comments on commit 1ea1f4b

Please sign in to comment.