Struct imxrt_hal::dma::Dma

source ·
pub struct Dma<const CHANNELS: usize> { /* private fields */ }
Expand description

A DMA driver.

This DMA driver manages the DMA controller and the multiplexer. It’s configured with pointers to both peripherals.

Dma allocates Channels. Channel provides the interface for scheduling transfers.

Implementations§

source§

impl<const CHANNELS: usize> Dma<CHANNELS>

source

pub unsafe fn channel(&'static self, index: usize) -> Channel

Creates the DMA channel described by index.

Safety

This will create a handle that may alias global, mutable state. You should only create one channel per index. If there are multiple channels for the same index, you’re responsible for ensuring synchronized access.

Panics

Panics if index is greater than or equal to the maximum number of channels.

source§

impl<const CHANNELS: usize> Dma<CHANNELS>

source

pub unsafe fn on_interrupt(&'static self, channel: usize)

Handle a DMA interrupt

Checks the interrupt status for the channel identified by channel. If the channel completed its transfer, on_interrupt wakes the channel’s waker.

Consider calling on_interrupt in a DMA channel’s interrupt handler:

use imxrt_dma::Dma;
static DMA: Dma<32> = // Handle to DMA driver.

// #[cortex_m_rt::interrupt]
fn DMA7_DMA23() {
    // Safety: only checking channels 7 and 23, which
    // are both valid on an i.MX RT 1060 chip.
    unsafe {
        DMA.on_interrupt(7);
        DMA.on_interrupt(23);
    }
}
Safety

This should only be used when the associated DMA channel is exclusively referenced by a DMA transfer future. Caller must ensure that on_interrupt is called in the correct interrupt handler.

Panics

Panics if channel is greater than or equal to the maximum number of channels.

source§

impl<const CHANNELS: usize> Dma<CHANNELS>

source

pub const unsafe fn new( controller: *const (), multiplexer: *const () ) -> Dma<CHANNELS>

Create the DMA driver.

Note that this can evaluate at compile time. Consider using this to expose a Dma through your higher-level API that you can use to allocate DMA channels.

CHANNELS specifies the total number of channels supported by the DMA controller. It’s referenced when allocating channels.

Safety

Caller must make sure that controller is a pointer to the start of the DMA controller register block. Caller must also make sure that multiplexer is a pointer to the start of the DMA multiplexer. Both pointers must be valid for your MCU.

An incorrect CHANNELS value prevents proper bounds checking when allocating channels. This may result in DMA channels that point to invalid memory.

Trait Implementations§

source§

impl<const CHANNELS: usize> Sync for Dma<CHANNELS>

Auto Trait Implementations§

§

impl<const CHANNELS: usize> !RefUnwindSafe for Dma<CHANNELS>

§

impl<const CHANNELS: usize> !Send for Dma<CHANNELS>

§

impl<const CHANNELS: usize> Unpin for Dma<CHANNELS>

§

impl<const CHANNELS: usize> !UnwindSafe for Dma<CHANNELS>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.