Skip to content

Commit

Permalink
Rework DMA descriptors (esp-rs#1054)
Browse files Browse the repository at this point in the history
  • Loading branch information
bugadani authored and playfulFence committed Jan 30, 2024
1 parent 469f980 commit d65a693
Show file tree
Hide file tree
Showing 9 changed files with 224 additions and 314 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

- DmaDescriptor struct to better model the hardware (#1054)
- DMA descriptor count no longer needs to be multiplied by 3 (#1054)

### Removed

### Breaking
Expand Down
55 changes: 6 additions & 49 deletions esp-hal-common/src/dma/gdma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,6 @@ use crate::{
system::{Peripheral, PeripheralClockControl},
};

#[cold]
fn on_tx_descriptor_not_divisible_by_3() {
panic!("The number of tx descriptors must be a multiple of 3");
}

#[cold]
fn on_rx_descriptor_not_divisible_by_3() {
panic!("The number of rx descriptors must be a multiple of 3");
}

macro_rules! impl_channel {
($num: literal) => {
paste::paste! {
Expand Down Expand Up @@ -562,57 +552,24 @@ macro_rules! impl_channel {
impl [<ChannelCreator $num>] {
/// Configure the channel for use
///
/// Descriptors should be sized as `((CHUNK_SIZE + 4091) / 4092) * 3`. I.e., to
/// transfer buffers of size `1..=4092`, you need 3 descriptors. The number of
/// descriptors must be a multiple of 3.
/// Descriptors should be sized as `(CHUNK_SIZE + 4091) / 4092`. I.e., to
/// transfer buffers of size `1..=4092`, you need 1 descriptor.
pub fn configure<'a>(
self,
burst_mode: bool,
tx_descriptors: &'a mut [u32],
rx_descriptors: &'a mut [u32],
tx_descriptors: &'a mut [DmaDescriptor],
rx_descriptors: &'a mut [DmaDescriptor],
priority: DmaPriority,
) -> Channel<'a, [<Channel $num>]> {
if tx_descriptors.len() % 3 != 0 {
on_tx_descriptor_not_divisible_by_3();
}

if rx_descriptors.len() % 3 != 0 {
on_rx_descriptor_not_divisible_by_3();
}

let mut tx_impl = [<Channel $num TxImpl>] {};
tx_impl.init(burst_mode, priority);

let tx_channel = ChannelTx {
descriptors: tx_descriptors,
burst_mode,
tx_impl: tx_impl,
write_offset: 0,
write_descr_ptr: core::ptr::null(),
available: 0,
last_seen_handled_descriptor_ptr: core::ptr::null(),
buffer_start: core::ptr::null(),
buffer_len: 0,
_phantom: PhantomData::default(),
};

let mut rx_impl = [<Channel $num RxImpl>] {};
rx_impl.init(burst_mode, priority);

let rx_channel = ChannelRx {
descriptors: rx_descriptors,
burst_mode,
rx_impl: rx_impl,
read_descr_ptr: core::ptr::null(),
available: 0,
last_seen_handled_descriptor_ptr: core::ptr::null(),
read_buffer_start: core::ptr::null(),
_phantom: PhantomData::default(),
};

Channel {
tx: tx_channel,
rx: rx_channel,
tx: ChannelTx::new(tx_descriptors, tx_impl, burst_mode),
rx: ChannelRx::new(rx_descriptors, rx_impl, burst_mode),
}
}
}
Expand Down
Loading

0 comments on commit d65a693

Please sign in to comment.