More conversions to associated consts.
This commit is contained in:
parent
604a25ec5d
commit
6e0e83cfd9
@ -39,7 +39,7 @@ static STATE: State = State::new();
|
|||||||
#[allow(unused)]
|
#[allow(unused)]
|
||||||
pub(crate) async unsafe fn transfer_p2m(
|
pub(crate) async unsafe fn transfer_p2m(
|
||||||
regs: pac::bdma::Ch,
|
regs: pac::bdma::Ch,
|
||||||
state_number: usize,
|
state_number: u8,
|
||||||
src: *const u8,
|
src: *const u8,
|
||||||
dst: &mut [u8],
|
dst: &mut [u8],
|
||||||
#[cfg(dmamux)] dmamux_regs: pac::dmamux::Dmamux,
|
#[cfg(dmamux)] dmamux_regs: pac::dmamux::Dmamux,
|
||||||
@ -51,7 +51,7 @@ pub(crate) async unsafe fn transfer_p2m(
|
|||||||
|
|
||||||
// Reset status
|
// Reset status
|
||||||
// Generate a DMB here to flush the store buffer (M7) before enabling the DMA
|
// Generate a DMB here to flush the store buffer (M7) before enabling the DMA
|
||||||
STATE.ch_status[state_number].store(CH_STATUS_NONE, Ordering::Release);
|
STATE.ch_status[state_number as usize].store(CH_STATUS_NONE, Ordering::Release);
|
||||||
|
|
||||||
let on_drop = OnDrop::new(|| unsafe {
|
let on_drop = OnDrop::new(|| unsafe {
|
||||||
regs.cr().modify(|w| {
|
regs.cr().modify(|w| {
|
||||||
@ -78,8 +78,8 @@ pub(crate) async unsafe fn transfer_p2m(
|
|||||||
});
|
});
|
||||||
|
|
||||||
let res = poll_fn(|cx| {
|
let res = poll_fn(|cx| {
|
||||||
STATE.ch_wakers[state_number].register(cx.waker());
|
STATE.ch_wakers[state_number as usize].register(cx.waker());
|
||||||
match STATE.ch_status[state_number].load(Ordering::Acquire) {
|
match STATE.ch_status[state_number as usize].load(Ordering::Acquire) {
|
||||||
CH_STATUS_NONE => Poll::Pending,
|
CH_STATUS_NONE => Poll::Pending,
|
||||||
x => Poll::Ready(x),
|
x => Poll::Ready(x),
|
||||||
}
|
}
|
||||||
@ -93,7 +93,7 @@ pub(crate) async unsafe fn transfer_p2m(
|
|||||||
#[allow(unused)]
|
#[allow(unused)]
|
||||||
pub(crate) async unsafe fn transfer_m2p(
|
pub(crate) async unsafe fn transfer_m2p(
|
||||||
regs: pac::bdma::Ch,
|
regs: pac::bdma::Ch,
|
||||||
state_number: usize,
|
state_number: u8,
|
||||||
src: &[u8],
|
src: &[u8],
|
||||||
dst: *mut u8,
|
dst: *mut u8,
|
||||||
#[cfg(dmamux)] dmamux_regs: pac::dmamux::Dmamux,
|
#[cfg(dmamux)] dmamux_regs: pac::dmamux::Dmamux,
|
||||||
@ -105,7 +105,7 @@ pub(crate) async unsafe fn transfer_m2p(
|
|||||||
|
|
||||||
// Reset status
|
// Reset status
|
||||||
// Generate a DMB here to flush the store buffer (M7) before enabling the DMA
|
// Generate a DMB here to flush the store buffer (M7) before enabling the DMA
|
||||||
STATE.ch_status[state_number].store(CH_STATUS_NONE, Ordering::Release);
|
STATE.ch_status[state_number as usize].store(CH_STATUS_NONE, Ordering::Release);
|
||||||
|
|
||||||
let on_drop = OnDrop::new(|| unsafe {
|
let on_drop = OnDrop::new(|| unsafe {
|
||||||
regs.cr().modify(|w| {
|
regs.cr().modify(|w| {
|
||||||
@ -133,8 +133,8 @@ pub(crate) async unsafe fn transfer_m2p(
|
|||||||
});
|
});
|
||||||
|
|
||||||
let res = poll_fn(|cx| {
|
let res = poll_fn(|cx| {
|
||||||
STATE.ch_wakers[state_number].register(cx.waker());
|
STATE.ch_wakers[state_number as usize].register(cx.waker());
|
||||||
match STATE.ch_status[state_number].load(Ordering::Acquire) {
|
match STATE.ch_status[state_number as usize].load(Ordering::Acquire) {
|
||||||
CH_STATUS_NONE => Poll::Pending,
|
CH_STATUS_NONE => Poll::Pending,
|
||||||
x => Poll::Ready(x),
|
x => Poll::Ready(x),
|
||||||
}
|
}
|
||||||
@ -191,13 +191,11 @@ pub(crate) mod sealed {
|
|||||||
|
|
||||||
pub trait Channel {
|
pub trait Channel {
|
||||||
const CH_NUM: u8;
|
const CH_NUM: u8;
|
||||||
|
const STATE_NUM: u8;
|
||||||
fn dma_regs() -> pac::bdma::Dma;
|
const DMA_REGS: pac::bdma::Dma;
|
||||||
|
|
||||||
fn state_num(&self) -> usize;
|
|
||||||
|
|
||||||
fn regs(&self) -> pac::bdma::Ch {
|
fn regs(&self) -> pac::bdma::Ch {
|
||||||
Self::dma_regs().ch(Self::CH_NUM as usize)
|
Self::DMA_REGS.ch(Self::CH_NUM as usize)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -219,15 +217,17 @@ macro_rules! impl_dma_channel {
|
|||||||
impl Channel for crate::peripherals::$channel_peri {}
|
impl Channel for crate::peripherals::$channel_peri {}
|
||||||
impl sealed::Channel for crate::peripherals::$channel_peri {
|
impl sealed::Channel for crate::peripherals::$channel_peri {
|
||||||
const CH_NUM: u8 = $ch_num;
|
const CH_NUM: u8 = $ch_num;
|
||||||
|
const STATE_NUM: u8 = (dma_num!($dma_peri) * 8) + $ch_num;
|
||||||
|
const DMA_REGS: pac::bdma::Dma = crate::pac::$dma_peri;
|
||||||
|
|
||||||
#[inline]
|
//#[inline]
|
||||||
fn dma_regs() -> pac::bdma::Dma {
|
//fn dma_regs() -> pac::bdma::Dma {
|
||||||
crate::pac::$dma_peri
|
//crate::pac::$dma_peri
|
||||||
}
|
//}
|
||||||
|
|
||||||
fn state_num(&self) -> usize {
|
//fn state_num(&self) -> usize {
|
||||||
(dma_num!($dma_peri) * 8) + $ch_num
|
//(dma_num!($dma_peri) * 8) + $ch_num
|
||||||
}
|
//}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(dmamux))]
|
#[cfg(not(dmamux))]
|
||||||
@ -243,7 +243,7 @@ macro_rules! impl_dma_channel {
|
|||||||
{
|
{
|
||||||
use sealed::Channel as _Channel;
|
use sealed::Channel as _Channel;
|
||||||
|
|
||||||
let state_num = self.state_num();
|
let state_num = Self::STATE_NUM;
|
||||||
let regs = self.regs();
|
let regs = self.regs();
|
||||||
|
|
||||||
unsafe { transfer_m2p(regs, state_num, buf, dst) }
|
unsafe { transfer_m2p(regs, state_num, buf, dst) }
|
||||||
@ -264,7 +264,7 @@ macro_rules! impl_dma_channel {
|
|||||||
{
|
{
|
||||||
use sealed::Channel as _Channel;
|
use sealed::Channel as _Channel;
|
||||||
|
|
||||||
let state_num = self.state_num();
|
let state_num = Self::STATE_NUM;
|
||||||
let regs = self.regs();
|
let regs = self.regs();
|
||||||
|
|
||||||
use crate::dmamux::sealed::Channel as MuxChannel;
|
use crate::dmamux::sealed::Channel as MuxChannel;
|
||||||
@ -307,7 +307,7 @@ macro_rules! impl_dma_channel {
|
|||||||
{
|
{
|
||||||
use sealed::Channel as _Channel;
|
use sealed::Channel as _Channel;
|
||||||
|
|
||||||
let state_num = self.state_num();
|
let state_num = Self::STATE_NUM;
|
||||||
let regs = self.regs();
|
let regs = self.regs();
|
||||||
unsafe { transfer_p2m(regs, state_num, src, buf) }
|
unsafe { transfer_p2m(regs, state_num, src, buf) }
|
||||||
}
|
}
|
||||||
@ -331,7 +331,7 @@ macro_rules! impl_dma_channel {
|
|||||||
{
|
{
|
||||||
use sealed::Channel as _Channel;
|
use sealed::Channel as _Channel;
|
||||||
|
|
||||||
let state_num = self.state_num();
|
let state_num = Self::STATE_NUM;
|
||||||
let regs = self.regs();
|
let regs = self.regs();
|
||||||
|
|
||||||
use crate::dmamux::sealed::Channel as MuxChannel;
|
use crate::dmamux::sealed::Channel as MuxChannel;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user