Skip to content
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

[2/3] DMA Move API: Move DMA descriptors to peripheral drivers #1719

Merged
merged 1 commit into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
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 esp-hal/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- esp-hal-embassy: make executor code optional (but default) again
- Improved interrupt latency on RISC-V based chips (#1679)
- `esp_wifi::initialize` no longer requires running maximum CPU clock, instead check it runs above 80MHz. (#1688)
- Move DMA descriptors from DMA Channel to each individual peripheral driver. (#1719)

### Removed
- uart: Removed `configure_pins` methods (#1592)
Expand Down
51 changes: 36 additions & 15 deletions esp-hal/src/aes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,8 @@ pub mod dma {
AesPeripheral,
Channel,
ChannelTypes,
DescriptorChain,
DmaDescriptor,
DmaPeripheral,
DmaTransferTxRx,
RxPrivate,
Expand Down Expand Up @@ -259,25 +261,42 @@ pub mod dma {
pub aes: super::Aes<'d>,

pub(crate) channel: Channel<'d, C, crate::Blocking>,
tx_chain: DescriptorChain,
rx_chain: DescriptorChain,
}

pub trait WithDmaAes<'d, C>
where
C: ChannelTypes,
C::P: AesPeripheral,
{
fn with_dma(self, channel: Channel<'d, C, crate::Blocking>) -> AesDma<'d, C>;
fn with_dma(
self,
channel: Channel<'d, C, crate::Blocking>,
tx_descriptors: &'static mut [DmaDescriptor],
rx_descriptors: &'static mut [DmaDescriptor],
) -> AesDma<'d, C>;
}

impl<'d, C> WithDmaAes<'d, C> for crate::aes::Aes<'d>
where
C: ChannelTypes,
C::P: AesPeripheral,
{
fn with_dma(self, mut channel: Channel<'d, C, crate::Blocking>) -> AesDma<'d, C> {
fn with_dma(
self,
mut channel: Channel<'d, C, crate::Blocking>,
tx_descriptors: &'static mut [DmaDescriptor],
rx_descriptors: &'static mut [DmaDescriptor],
) -> AesDma<'d, C> {
channel.tx.init_channel(); // no need to call this for both, TX and RX

AesDma { aes: self, channel }
AesDma {
aes: self,
channel,
tx_chain: DescriptorChain::new(tx_descriptors),
rx_chain: DescriptorChain::new(rx_descriptors),
}
}
}

Expand Down Expand Up @@ -321,6 +340,10 @@ pub mod dma {
fn tx(&mut self) -> &mut Self::TX {
&mut self.channel.tx
}

fn chain(&mut self) -> &mut DescriptorChain {
&mut self.tx_chain
}
}

impl<'d, C> DmaSupportRx for AesDma<'d, C>
Expand All @@ -333,6 +356,10 @@ pub mod dma {
fn rx(&mut self) -> &mut Self::RX {
&mut self.channel.rx
}

fn chain(&mut self) -> &mut DescriptorChain {
&mut self.rx_chain
}
}

impl<'d, C> AesDma<'d, C>
Expand Down Expand Up @@ -413,24 +440,18 @@ pub mod dma {
self.channel.rx.is_done();

unsafe {
self.tx_chain
.fill_for_tx(false, write_buffer_ptr, write_buffer_len)?;
self.channel
.tx
.prepare_transfer_without_start(
self.dma_peripheral(),
false,
write_buffer_ptr,
write_buffer_len,
)
.prepare_transfer_without_start(self.dma_peripheral(), &self.tx_chain)
.and_then(|_| self.channel.tx.start_transfer())?;

self.rx_chain
.fill_for_rx(false, read_buffer_ptr, read_buffer_len)?;
self.channel
.rx
.prepare_transfer_without_start(
false,
self.dma_peripheral(),
read_buffer_ptr,
read_buffer_len,
)
.prepare_transfer_without_start(self.dma_peripheral(), &self.rx_chain)
.and_then(|_| self.channel.rx.start_transfer())?;
}
self.enable_dma(true);
Expand Down
18 changes: 4 additions & 14 deletions esp-hal/src/dma/gdma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -494,8 +494,6 @@ macro_rules! impl_channel {
pub fn configure<'a>(
self,
burst_mode: bool,
tx_descriptors: &'a mut [DmaDescriptor],
rx_descriptors: &'a mut [DmaDescriptor],
priority: DmaPriority,
) -> crate::dma::Channel<'a, Channel<$num>, crate::Blocking> {
let mut tx_impl = ChannelTxImpl {};
Expand All @@ -504,12 +502,9 @@ macro_rules! impl_channel {
let mut rx_impl = ChannelRxImpl {};
rx_impl.init(burst_mode, priority);

let tx_chain = DescriptorChain::new(tx_descriptors);
let rx_chain = DescriptorChain::new(rx_descriptors);

crate::dma::Channel {
tx: ChannelTx::new(tx_chain, tx_impl, burst_mode),
rx: ChannelRx::new(rx_chain, rx_impl, burst_mode),
tx: ChannelTx::new(tx_impl, burst_mode),
rx: ChannelRx::new(rx_impl, burst_mode),
phantom: PhantomData,
}
}
Expand All @@ -522,8 +517,6 @@ macro_rules! impl_channel {
pub fn configure_for_async<'a>(
self,
burst_mode: bool,
tx_descriptors: &'a mut [DmaDescriptor],
rx_descriptors: &'a mut [DmaDescriptor],
priority: DmaPriority,
) -> crate::dma::Channel<'a, Channel<$num>, $crate::Async> {
let mut tx_impl = ChannelTxImpl {};
Expand All @@ -532,14 +525,11 @@ macro_rules! impl_channel {
let mut rx_impl = ChannelRxImpl {};
rx_impl.init(burst_mode, priority);

let tx_chain = DescriptorChain::new(tx_descriptors);
let rx_chain = DescriptorChain::new(rx_descriptors);

<Channel<$num> as ChannelTypes>::Binder::set_isr($async_handler);

crate::dma::Channel {
tx: ChannelTx::new(tx_chain, tx_impl, burst_mode),
rx: ChannelRx::new(rx_chain, rx_impl, burst_mode),
tx: ChannelTx::new(tx_impl, burst_mode),
rx: ChannelRx::new(rx_impl, burst_mode),
phantom: PhantomData,
}
}
Expand Down
Loading
Loading