Skip to content

Commit

Permalink
Use pending_ prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
Dominic Fischer committed Sep 20, 2024
1 parent 651d17a commit 08742e7
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 42 deletions.
4 changes: 2 additions & 2 deletions esp-hal/src/dma/gdma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ impl<const N: u8> RegisterAccess for Channel<N> {
result
}

fn out_interrupts() -> EnumSet<DmaTxInterrupt> {
fn pending_out_interrupts() -> EnumSet<DmaTxInterrupt> {
let mut result = EnumSet::new();

let int_raw = Self::out_int().raw().read();
Expand Down Expand Up @@ -364,7 +364,7 @@ impl<const N: u8> RegisterAccess for Channel<N> {
result
}

fn in_interrupts() -> EnumSet<DmaRxInterrupt> {
fn pending_in_interrupts() -> EnumSet<DmaRxInterrupt> {
let mut result = EnumSet::new();

let int_raw = Self::in_int().raw().read();
Expand Down
86 changes: 50 additions & 36 deletions esp-hal/src/dma/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1030,7 +1030,10 @@ impl TxCircularState {
where
T: TxPrivate,
{
if channel.out_interrupts().contains(DmaTxInterrupt::Eof) {
if channel
.pending_out_interrupts()
.contains(DmaTxInterrupt::Eof)
{
channel.clear_out(DmaTxInterrupt::Eof);

let descr_address = channel.last_out_dscr_address() as *mut DmaDescriptor;
Expand Down Expand Up @@ -1282,22 +1285,23 @@ pub trait RxPrivate: crate::private::Sealed {

fn clear_in(&self, interrupts: impl Into<EnumSet<DmaRxInterrupt>>);

fn in_interrupts(&self) -> EnumSet<DmaRxInterrupt>;
fn pending_in_interrupts(&self) -> EnumSet<DmaRxInterrupt>;

fn is_done(&self) -> bool;

fn has_error(&self) -> bool {
self.in_interrupts()
self.pending_in_interrupts()
.contains(DmaRxInterrupt::DescriptorError)
}

fn has_dscr_empty_error(&self) -> bool {
self.in_interrupts()
self.pending_in_interrupts()
.contains(DmaRxInterrupt::DescriptorEmpty)
}

fn has_eof_error(&self) -> bool {
self.in_interrupts().contains(DmaRxInterrupt::ErrorEof)
self.pending_in_interrupts()
.contains(DmaRxInterrupt::ErrorEof)
}

fn clear_interrupts(&self);
Expand Down Expand Up @@ -1337,7 +1341,7 @@ where
fn start_transfer(&mut self) -> Result<(), DmaError> {
R::start_in();

if R::in_interrupts().contains(DmaRxInterrupt::DescriptorError) {
if R::pending_in_interrupts().contains(DmaRxInterrupt::DescriptorError) {
Err(DmaError::DescriptorError)
} else {
Ok(())
Expand Down Expand Up @@ -1467,12 +1471,13 @@ where
CH::Channel::clear_in(interrupts);
}

fn in_interrupts(&self) -> EnumSet<DmaRxInterrupt> {
CH::Channel::in_interrupts()
fn pending_in_interrupts(&self) -> EnumSet<DmaRxInterrupt> {
CH::Channel::pending_in_interrupts()
}

fn is_done(&self) -> bool {
self.in_interrupts().contains(DmaRxInterrupt::SuccessfulEof)
self.pending_in_interrupts()
.contains(DmaRxInterrupt::SuccessfulEof)
}

fn init_channel(&mut self) {
Expand Down Expand Up @@ -1515,19 +1520,20 @@ pub trait TxPrivate: crate::private::Sealed {

fn clear_out(&self, interrupts: impl Into<EnumSet<DmaTxInterrupt>>);

fn out_interrupts(&self) -> EnumSet<DmaTxInterrupt>;
fn pending_out_interrupts(&self) -> EnumSet<DmaTxInterrupt>;

fn start_transfer(&mut self) -> Result<(), DmaError>;

#[cfg(esp32s3)]
fn set_ext_mem_block_size(&self, size: DmaExtMemBKSize);

fn is_done(&self) -> bool {
self.out_interrupts().contains(DmaTxInterrupt::TotalEof)
self.pending_out_interrupts()
.contains(DmaTxInterrupt::TotalEof)
}

fn has_error(&self) -> bool {
self.out_interrupts()
self.pending_out_interrupts()
.contains(DmaTxInterrupt::DescriptorError)
}

Expand Down Expand Up @@ -1566,7 +1572,7 @@ where
fn start_transfer(&mut self) -> Result<(), DmaError> {
R::start_out();

if R::out_interrupts().contains(DmaTxInterrupt::DescriptorError) {
if R::pending_out_interrupts().contains(DmaTxInterrupt::DescriptorError) {
Err(DmaError::DescriptorError)
} else {
Ok(())
Expand All @@ -1585,8 +1591,8 @@ where
fn clear_out(&self, interrupts: impl Into<EnumSet<DmaTxInterrupt>>) {
R::clear_out(interrupts)
}
fn out_interrupts(&self) -> EnumSet<DmaTxInterrupt> {
R::out_interrupts()
fn pending_out_interrupts(&self) -> EnumSet<DmaTxInterrupt> {
R::pending_out_interrupts()
}

fn waker() -> &'static embassy_sync::waitqueue::AtomicWaker;
Expand Down Expand Up @@ -1693,8 +1699,8 @@ where
CH::Channel::clear_out(interrupts);
}

fn out_interrupts(&self) -> EnumSet<DmaTxInterrupt> {
CH::Channel::out_interrupts()
fn pending_out_interrupts(&self) -> EnumSet<DmaTxInterrupt> {
CH::Channel::pending_out_interrupts()
}

fn waker() -> &'static embassy_sync::waitqueue::AtomicWaker {
Expand Down Expand Up @@ -1729,13 +1735,13 @@ pub trait RegisterAccess: crate::private::Sealed {
fn unlisten_out(interrupts: impl Into<EnumSet<DmaTxInterrupt>>);
fn is_listening_out() -> EnumSet<DmaTxInterrupt>;
fn clear_out(interrupts: impl Into<EnumSet<DmaTxInterrupt>>);
fn out_interrupts() -> EnumSet<DmaTxInterrupt>;
fn pending_out_interrupts() -> EnumSet<DmaTxInterrupt>;

fn listen_in(interrupts: impl Into<EnumSet<DmaRxInterrupt>>);
fn unlisten_in(interrupts: impl Into<EnumSet<DmaRxInterrupt>>);
fn is_listening_in() -> EnumSet<DmaRxInterrupt>;
fn clear_in(interrupts: impl Into<EnumSet<DmaRxInterrupt>>);
fn in_interrupts() -> EnumSet<DmaRxInterrupt>;
fn pending_in_interrupts() -> EnumSet<DmaRxInterrupt>;

fn last_out_dscr_address() -> usize;

Expand Down Expand Up @@ -2551,7 +2557,7 @@ where
if self
.instance
.tx()
.out_interrupts()
.pending_out_interrupts()
.contains(DmaTxInterrupt::DescriptorError)
{
Err(DmaError::DescriptorError)
Expand Down Expand Up @@ -2604,7 +2610,7 @@ where
if self
.instance
.rx()
.in_interrupts()
.pending_in_interrupts()
.contains(DmaRxInterrupt::DescriptorError)
{
Err(DmaError::DescriptorError)
Expand Down Expand Up @@ -2658,12 +2664,12 @@ where
if self
.instance
.tx()
.out_interrupts()
.pending_out_interrupts()
.contains(DmaTxInterrupt::DescriptorError)
|| self
.instance
.rx()
.in_interrupts()
.pending_in_interrupts()
.contains(DmaRxInterrupt::DescriptorError)
{
Err(DmaError::DescriptorError)
Expand Down Expand Up @@ -2741,7 +2747,7 @@ where
if self
.instance
.tx()
.out_interrupts()
.pending_out_interrupts()
.contains(DmaTxInterrupt::DescriptorError)
{
Err(DmaError::DescriptorError)
Expand Down Expand Up @@ -2855,7 +2861,7 @@ pub(crate) mod asynch {
Poll::Ready(Ok(()))
} else if self
.tx
.out_interrupts()
.pending_out_interrupts()
.contains(DmaTxInterrupt::DescriptorError)
{
self.tx.clear_interrupts();
Expand Down Expand Up @@ -2909,7 +2915,7 @@ pub(crate) mod asynch {
if self.rx.is_done() {
self.rx.clear_interrupts();
Poll::Ready(Ok(()))
} else if !self.rx.in_interrupts().is_disjoint(
} else if !self.rx.pending_in_interrupts().is_disjoint(
DmaRxInterrupt::DescriptorError
| DmaRxInterrupt::DescriptorEmpty
| DmaRxInterrupt::ErrorEof,
Expand Down Expand Up @@ -2972,12 +2978,16 @@ pub(crate) mod asynch {
cx: &mut core::task::Context<'_>,
) -> Poll<Self::Output> {
TX::waker().register(cx.waker());
if self.tx.out_interrupts().contains(DmaTxInterrupt::Done) {
if self
.tx
.pending_out_interrupts()
.contains(DmaTxInterrupt::Done)
{
self.tx.clear_out(DmaTxInterrupt::Done);
Poll::Ready(Ok(()))
} else if self
.tx
.out_interrupts()
.pending_out_interrupts()
.contains(DmaTxInterrupt::DescriptorError)
{
self.tx.clear_interrupts();
Expand Down Expand Up @@ -3032,10 +3042,14 @@ pub(crate) mod asynch {
cx: &mut core::task::Context<'_>,
) -> Poll<Self::Output> {
RX::waker().register(cx.waker());
if self.rx.in_interrupts().contains(DmaRxInterrupt::Done) {
if self
.rx
.pending_in_interrupts()
.contains(DmaRxInterrupt::Done)
{
self.rx.clear_in(DmaRxInterrupt::Done);
Poll::Ready(Ok(()))
} else if !self.rx.in_interrupts().is_disjoint(
} else if !self.rx.pending_in_interrupts().is_disjoint(
DmaRxInterrupt::DescriptorError
| DmaRxInterrupt::DescriptorEmpty
| DmaRxInterrupt::ErrorEof,
Expand Down Expand Up @@ -3070,7 +3084,7 @@ pub(crate) mod asynch {
}

fn handle_interrupt<Channel: RegisterAccess, Rx: RxChannel<Channel>, Tx: TxChannel<Channel>>() {
if Channel::in_interrupts().is_disjoint(
if Channel::pending_in_interrupts().is_disjoint(
DmaRxInterrupt::DescriptorError
| DmaRxInterrupt::DescriptorEmpty
| DmaRxInterrupt::ErrorEof,
Expand All @@ -3085,31 +3099,31 @@ pub(crate) mod asynch {
Rx::waker().wake()
}

if Channel::out_interrupts().contains(DmaTxInterrupt::DescriptorError) {
if Channel::pending_out_interrupts().contains(DmaTxInterrupt::DescriptorError) {
Channel::unlisten_out(
DmaTxInterrupt::DescriptorError | DmaTxInterrupt::TotalEof | DmaTxInterrupt::Done,
);
Tx::waker().wake()
}

if Channel::in_interrupts().contains(DmaRxInterrupt::SuccessfulEof) {
if Channel::pending_in_interrupts().contains(DmaRxInterrupt::SuccessfulEof) {
Channel::unlisten_in(DmaRxInterrupt::SuccessfulEof);
Rx::waker().wake()
}

if Channel::in_interrupts().contains(DmaRxInterrupt::Done) {
if Channel::pending_in_interrupts().contains(DmaRxInterrupt::Done) {
Channel::unlisten_in(DmaRxInterrupt::Done);
Rx::waker().wake()
}

if Channel::out_interrupts().contains(DmaTxInterrupt::TotalEof)
if Channel::pending_out_interrupts().contains(DmaTxInterrupt::TotalEof)
&& Channel::is_listening_out().contains(DmaTxInterrupt::TotalEof)
{
Channel::unlisten_out(DmaTxInterrupt::TotalEof);
Tx::waker().wake()
}

if Channel::out_interrupts().contains(DmaTxInterrupt::Done) {
if Channel::pending_out_interrupts().contains(DmaTxInterrupt::Done) {
Channel::unlisten_out(DmaTxInterrupt::Done);
Tx::waker().wake()
}
Expand Down
8 changes: 4 additions & 4 deletions esp-hal/src/dma/pdma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ macro_rules! ImplSpiChannel {
result
}

fn out_interrupts() -> EnumSet<DmaTxInterrupt> {
fn pending_out_interrupts() -> EnumSet<DmaTxInterrupt> {
let mut result = EnumSet::new();

let spi = unsafe { &*crate::peripherals::[<SPI $num>]::PTR };
Expand Down Expand Up @@ -279,7 +279,7 @@ macro_rules! ImplSpiChannel {
result
}

fn in_interrupts() -> EnumSet<DmaRxInterrupt> {
fn pending_in_interrupts() -> EnumSet<DmaRxInterrupt> {
let mut result = EnumSet::new();

let spi = unsafe { &*crate::peripherals::[<SPI $num>]::PTR };
Expand Down Expand Up @@ -571,7 +571,7 @@ macro_rules! ImplI2sChannel {
result
}

fn out_interrupts() -> EnumSet<DmaTxInterrupt> {
fn pending_out_interrupts() -> EnumSet<DmaTxInterrupt> {
let mut result = EnumSet::new();

let reg_block = unsafe { &*crate::peripherals::[<$peripheral>]::PTR };
Expand Down Expand Up @@ -663,7 +663,7 @@ macro_rules! ImplI2sChannel {
result
}

fn in_interrupts() -> EnumSet<DmaRxInterrupt> {
fn pending_in_interrupts() -> EnumSet<DmaRxInterrupt> {
let mut result = EnumSet::new();

let reg_block = unsafe { &*crate::peripherals::[<$peripheral>]::PTR };
Expand Down

0 comments on commit 08742e7

Please sign in to comment.