Skip to content

Commit ac2460a

Browse files
committed
Add "wait for any RX or TX" function
1 parent ee743bb commit ac2460a

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

src/dma/mod.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ pub use smoltcp_phy::*;
1212
#[cfg(feature = "async-await")]
1313
use futures::task::AtomicWaker;
1414

15-
#[cfg(feature = "ptp")]
15+
#[cfg(any(feature = "ptp", feature = "async-await"))]
1616
use core::task::Poll;
1717

1818
pub(crate) mod desc;
@@ -279,6 +279,24 @@ impl<'rx, 'tx> EthernetDMA<'rx, 'tx> {
279279
) -> TxPacket<'borrow, 'tx> {
280280
self.tx_ring.prepare_packet(length, packet_id).await
281281
}
282+
283+
/// Wait for an RX or TX interrupt to have
284+
/// occured.
285+
#[cfg(feature = "async-await")]
286+
pub async fn rx_or_tx(&mut self) {
287+
let mut polled_once = false;
288+
core::future::poll_fn(|ctx| {
289+
if polled_once {
290+
Poll::Ready(())
291+
} else {
292+
polled_once = true;
293+
EthernetDMA::rx_waker().register(ctx.waker());
294+
EthernetDMA::tx_waker().register(ctx.waker());
295+
Poll::Pending
296+
}
297+
})
298+
.await;
299+
}
282300
}
283301

284302
impl Drop for EthernetDMA<'_, '_> {

0 commit comments

Comments
 (0)