Skip to content

Commit 264ab8e

Browse files
committed
Rearrange async-await code a little
1 parent ecbec8c commit 264ab8e

File tree

1 file changed

+22
-24
lines changed

1 file changed

+22
-24
lines changed

src/dma/mod.rs

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -128,18 +128,6 @@ impl<'rx, 'tx> EthernetDMA<'rx, 'tx> {
128128
dma
129129
}
130130

131-
#[cfg(feature = "async-await")]
132-
pub(crate) fn rx_waker() -> &'static AtomicWaker {
133-
static WAKER: AtomicWaker = AtomicWaker::new();
134-
&WAKER
135-
}
136-
137-
#[cfg(feature = "async-await")]
138-
pub(crate) fn tx_waker() -> &'static AtomicWaker {
139-
static WAKER: AtomicWaker = AtomicWaker::new();
140-
&WAKER
141-
}
142-
143131
/// Split the [`EthernetDMA`] into concurrently operating send and
144132
/// receive parts.
145133
pub fn split(&mut self) -> (&mut RxRing<'rx>, &mut TxRing<'tx>) {
@@ -259,19 +247,39 @@ impl<'rx, 'tx> EthernetDMA<'rx, 'tx> {
259247
pub fn tx_available(&mut self) -> bool {
260248
self.tx_ring.next_entry_available()
261249
}
250+
}
251+
252+
impl Drop for EthernetDMA<'_, '_> {
253+
// On drop, stop all DMA actions.
254+
fn drop(&mut self) {
255+
self.tx_ring.stop(&self.eth_dma);
256+
257+
self.rx_ring.stop(&self.eth_dma);
258+
}
259+
}
260+
261+
#[cfg(feature = "async-await")]
262+
impl<'rx, 'tx> EthernetDMA<'rx, 'tx> {
263+
pub(crate) fn rx_waker() -> &'static AtomicWaker {
264+
static WAKER: AtomicWaker = AtomicWaker::new();
265+
&WAKER
266+
}
267+
268+
pub(crate) fn tx_waker() -> &'static AtomicWaker {
269+
static WAKER: AtomicWaker = AtomicWaker::new();
270+
&WAKER
271+
}
262272

263273
/// Receive a packet.
264274
///
265275
/// See [`RxRing::recv`].
266-
#[cfg(feature = "async-await")]
267276
pub async fn recv(&mut self, packet_id: Option<PacketId>) -> RxPacket {
268277
self.rx_ring.recv(packet_id).await
269278
}
270279

271280
/// Prepare a packet for sending.
272281
///
273282
/// See [`TxRing::prepare_packet`].
274-
#[cfg(feature = "async-await")]
275283
pub async fn prepare_packet<'borrow>(
276284
&'borrow mut self,
277285
length: usize,
@@ -282,7 +290,6 @@ impl<'rx, 'tx> EthernetDMA<'rx, 'tx> {
282290

283291
/// Wait for an RX or TX interrupt to have
284292
/// occured.
285-
#[cfg(feature = "async-await")]
286293
pub async fn rx_or_tx(&mut self) {
287294
let mut polled_once = false;
288295
core::future::poll_fn(|ctx| {
@@ -299,15 +306,6 @@ impl<'rx, 'tx> EthernetDMA<'rx, 'tx> {
299306
}
300307
}
301308

302-
impl Drop for EthernetDMA<'_, '_> {
303-
// On drop, stop all DMA actions.
304-
fn drop(&mut self) {
305-
self.tx_ring.stop(&self.eth_dma);
306-
307-
self.rx_ring.stop(&self.eth_dma);
308-
}
309-
}
310-
311309
#[cfg(feature = "ptp")]
312310
impl EthernetDMA<'_, '_> {
313311
/// Try to get the timestamp for the given packet ID.

0 commit comments

Comments
 (0)