Skip to content

Commit

Permalink
Merge pull request #600 from jannic/dma_word_size_check
Browse files Browse the repository at this point in the history
Ensure supported DMA word size at compile time
  • Loading branch information
jannic authored May 6, 2023
2 parents cd4cb7b + d6b2c5e commit 06b98e0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 103 deletions.
4 changes: 0 additions & 4 deletions on-target-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ harness = false
name = "dma_m2m_u32"
harness = false

[[test]]
name = "dma_m2m_u64"
harness = false

[[test]]
name = "dma_spi_loopback_u8"
harness = false
Expand Down
95 changes: 0 additions & 95 deletions on-target-tests/tests/dma_m2m_u64.rs

This file was deleted.

21 changes: 17 additions & 4 deletions rp2040-hal/src/dma/single_channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,21 @@ pub(crate) trait ChannelConfig {
fn start_both<CH: SingleChannel>(&mut self, other: &mut CH);
}

// RP2040's DMA engine only works with certain word sizes. Make sure that other
// word sizes will fail to compile.
struct IsValidWordSize<WORD> {
w: core::marker::PhantomData<WORD>,
}

impl<WORD> IsValidWordSize<WORD> {
const OK: usize = {
match mem::size_of::<WORD>() {
1 | 2 | 4 => 0, // ok
_ => panic!("Unsupported DMA word size"),
}
};
}

impl<CH: SingleChannel> ChannelConfig for CH {
fn config<WORD, FROM, TO>(
&mut self,
Expand All @@ -148,10 +163,8 @@ impl<CH: SingleChannel> ChannelConfig for CH {
TO: WriteTarget<TransmittedWord = WORD>,
{
// Configure the DMA channel.
assert!(
mem::size_of::<WORD>() != 8,
"DMA does not support transferring 64bit data"
);
let _ = IsValidWordSize::<WORD>::OK;

let (src, src_count) = from.rx_address_count();
let src_incr = from.rx_increment();
let (dest, dest_count) = to.tx_address_count();
Expand Down

0 comments on commit 06b98e0

Please sign in to comment.