Struct mnemos_d1_core::dmac::Dmac

source ·
pub struct Dmac {
    _p: (),
}
Expand description

A handle to the DMA controller (DMAC) peripheral.

A Dmac can be used used to claim DMA Channels from the DMAC’s shared pool of 16 channels, using the claim_channel and try_claim_channel methods. Once a Channel has been claimed, it may be used to perform DMA transfers using the Channel::transfer method. Dropping a Channel releases it back to the DMAC’s channel pool, allowing it to be claimed by other drivers.

The Dmac also provides a Dmac::transfer convenience method, which claims a channel to perform a single transfer and immediately releases it back to the pool once the transfer has completed.

This struct is constructed using Dmac::new, which initializes the DMA controller and returns a Dmac. Since this struct is essentially a token representing that the DMAC has been initialized, it may be freely copied into any driver that wishes to perform DMA operations.

Fields§

§_p: ()

Implementations§

source§

impl Dmac

source

pub const CHANNEL_COUNT: u8 = 16u8

The total number of DMA channels available on the DMAC.

source

pub fn new(dmac: DMAC, ccu: &mut Ccu) -> Self

Initializes the DMAC, enabling the queue IRQ for all channels.

source

pub async unsafe fn transfer( &self, src: ChannelMode, dst: ChannelMode, desc: NonNull<Descriptor>, )

Performs a DMA transfer described by the provided Descriptor on any available free DMA Channel.

This function will first use Dmac::claim_channel to claim an available DMA channel, waiting for one to become available if all channels are currently in use. Once a channel has been acquired, it sets the src and dst ChannelModes using Channel::set_channel_modes. Then, it performs the transfer using Channel::transfer.

If multiple transfers will be made in sequence, it may be more efficient to call Dmac::claim_channel once and perform multiple transfers on the same channel, to avoid releasing and re-claiming a channel in between transfers.

§Safety

The caller must ensure that the descriptor pointed to by desc, and the associated memory region used by the transfer, is valid for as long as the DMA transfer is active. When this function returns, the transfer has completed, and it is safe to drop the descriptor. If this future is cancelled, the transfer is cancelled and the descriptor and its associated buffer may be dropped safely. However, it is super ultra not okay to core::mem::forget this future. If you mem::forget a DMA transfer future inside your driver, you deserve whatever happens next.

§Cancel Safety

Dropping this future cancels the DMA transfer. If this future is dropped, the descriptor and its associated memory region may also be dropped safely.

Of course, the transfer may still have completed partially. If we were writing to a device, the device may be unhappy to have only gotten some of the data it wanted. If we were reading from a device, reads may have side effects and incomplete reads may leave the device in a weird state. Cancelling an incomplete transfer may result in, for example, writing out half of a string to the UART, or only part of a structured message over SPI, and so on. But, at least we don’t have abandoned DMA transfers running around in random parts of the heap you probably wanted to use for normal stuff like having strings, or whatever it is that people do on the computer.

source

pub async fn claim_channel(&self) -> Channel

Claims an idle DMA Channel from the DMAC’s channel pool, waiting for one to become available if none are currently idle.

For a version of this method which does not wait, see Dmac::try_claim_channel.

§Cancel Safety

This future can be cancelled freely with no potential negative consequences. Dropping this future cancels the attempt to claim a Channel from the DMAC pool. If a channel has been acquired, it will be released back to the pool, and may be acquired by other tasks.

source

pub fn try_claim_channel(&self) -> Option<Channel>

Claims an idle DMA channel, if one is available.

If no DMA channels are currently free, this function returns None. To instead wait for an active DMA channel to become free, use Dmac::claim_channel instead.

§Returns
  • Some(Channel) containing a free DMA channel ready to use for transfers, if one was available.
  • None if all DMA channels are currently in use.
source

pub fn handle_interrupt()

Handle a DMAC interrupt.

source

pub unsafe fn cancel_all()

Cancel all currently active DMA transfers.

This is generally used when shutting down the system, such as in panic and exception handlers.

§Safety

Cancelling DMA transfers abruptly might put peripherals in a weird state i guess?

Trait Implementations§

source§

impl Clone for Dmac

source§

fn clone(&self) -> Dmac

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Dmac

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Copy for Dmac

Auto Trait Implementations§

§

impl Freeze for Dmac

§

impl RefUnwindSafe for Dmac

§

impl Send for Dmac

§

impl Sync for Dmac

§

impl Unpin for Dmac

§

impl UnwindSafe for Dmac

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> Az for T

source§

fn az<Dst>(self) -> Dst
where T: Cast<Dst>,

Casts the value.
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<Src, Dst> CastFrom<Src> for Dst
where Src: Cast<Dst>,

source§

fn cast_from(src: Src) -> Dst

Casts the value.
source§

impl<T> CheckedAs for T

source§

fn checked_as<Dst>(self) -> Option<Dst>
where T: CheckedCast<Dst>,

Casts the value.
source§

impl<Src, Dst> CheckedCastFrom<Src> for Dst
where Src: CheckedCast<Dst>,

source§

fn checked_cast_from(src: Src) -> Option<Dst>

Casts the value.
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> CloneToUninit for T
where T: Copy,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> OverflowingAs for T

source§

fn overflowing_as<Dst>(self) -> (Dst, bool)
where T: OverflowingCast<Dst>,

Casts the value.
source§

impl<Src, Dst> OverflowingCastFrom<Src> for Dst
where Src: OverflowingCast<Dst>,

source§

fn overflowing_cast_from(src: Src) -> (Dst, bool)

Casts the value.
source§

impl<T> SaturatingAs for T

source§

fn saturating_as<Dst>(self) -> Dst
where T: SaturatingCast<Dst>,

Casts the value.
source§

impl<Src, Dst> SaturatingCastFrom<Src> for Dst
where Src: SaturatingCast<Dst>,

source§

fn saturating_cast_from(src: Src) -> Dst

Casts the value.
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
source§

impl<T> UnwrappedAs for T

source§

fn unwrapped_as<Dst>(self) -> Dst
where T: UnwrappedCast<Dst>,

Casts the value.
source§

impl<Src, Dst> UnwrappedCastFrom<Src> for Dst
where Src: UnwrappedCast<Dst>,

source§

fn unwrapped_cast_from(src: Src) -> Dst

Casts the value.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

impl<T> WrappingAs for T

source§

fn wrapping_as<Dst>(self) -> Dst
where T: WrappingCast<Dst>,

Casts the value.
source§

impl<Src, Dst> WrappingCastFrom<Src> for Dst
where Src: WrappingCast<Dst>,

source§

fn wrapping_cast_from(src: Src) -> Dst

Casts the value.