Skip to content

Commit 24eb142

Browse files
committed
Properly feature gate all async fns
Add prepare-transmission async fn as well
1 parent 1d57a63 commit 24eb142

File tree

3 files changed

+28
-19
lines changed

3 files changed

+28
-19
lines changed

src/dma/mod.rs

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -212,12 +212,6 @@ impl<'rx, 'tx> EthernetDMA<'rx, 'tx> {
212212
self.rx_ring.recv_next(packet_id.map(Into::into))
213213
}
214214

215-
/// Receive a packet.
216-
#[cfg(feature = "async-await")]
217-
pub async fn recv(&mut self, packet_id: Option<PacketId>) -> RxPacket {
218-
self.rx_ring.recv(packet_id).await
219-
}
220-
221215
/// Is Rx DMA currently running?
222216
///
223217
/// It stops if the ring is full. Call [`EthernetDMA::recv_next()`] to free an
@@ -265,6 +259,26 @@ impl<'rx, 'tx> EthernetDMA<'rx, 'tx> {
265259
pub fn tx_available(&mut self) -> bool {
266260
self.tx_ring.next_entry_available()
267261
}
262+
263+
/// Receive a packet.
264+
///
265+
/// See [`RxRing::recv`].
266+
#[cfg(feature = "async-await")]
267+
pub async fn recv(&mut self, packet_id: Option<PacketId>) -> RxPacket {
268+
self.rx_ring.recv(packet_id).await
269+
}
270+
271+
/// Prepare a packet for sending.
272+
///
273+
/// See [`TxRing::prepare_packet`].
274+
#[cfg(feature = "async-await")]
275+
pub async fn prepare_packet<'borrow>(
276+
&'borrow mut self,
277+
length: usize,
278+
packet_id: Option<PacketId>,
279+
) -> TxPacket<'borrow, 'tx> {
280+
self.tx_ring.prepare_packet(length, packet_id).await
281+
}
268282
}
269283

270284
#[cfg(feature = "ptp")]
@@ -315,6 +329,7 @@ impl EthernetDMA<'_, '_> {
315329
}
316330

317331
/// Get the TX timestamp for the given ID.
332+
#[cfg(feature = "async-await")]
318333
pub async fn tx_timestamp(
319334
&mut self,
320335
packet_id: &PacketId,

src/dma/rx/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ impl<'a> RxRing<'a> {
164164
/// will contain the ethernet data.
165165
#[cfg(feature = "async-await")]
166166
pub async fn recv(&mut self, packet_id: Option<PacketId>) -> RxPacket {
167-
let (entry_num, length) = core::future::poll_fn(|ctx| {
167+
let (entry, length) = core::future::poll_fn(|ctx| {
168168
let res = self.recv_next_impl(packet_id.clone());
169169

170170
match res {
@@ -178,7 +178,7 @@ impl<'a> RxRing<'a> {
178178
.await;
179179

180180
RxPacket {
181-
entry: &mut self.entries[entry_num],
181+
entry: &mut self.entries[entry],
182182
length,
183183
}
184184
}

src/dma/tx/mod.rs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -250,23 +250,17 @@ impl TxRing<'_> {
250250
}
251251

252252
/// Wait until the timestamp for the given ID is available.
253+
#[cfg(feature = "async-await")]
253254
pub async fn timestamp(
254255
&mut self,
255256
packet_id: &PacketId,
256257
) -> Result<Option<Timestamp>, PacketIdNotFound> {
257258
core::future::poll_fn(move |ctx| {
258-
let entry = if let Some(entry) = self.entry_for_id(packet_id) {
259-
entry
260-
} else {
261-
return Poll::Ready(Err(PacketIdNotFound));
262-
};
263-
264-
if self.entry_available(entry) {
265-
Poll::Ready(Ok(self.entry_timestamp(entry)))
266-
} else {
267-
ctx.waker().wake_by_ref();
268-
Poll::Pending
259+
let res = self.poll_timestamp(packet_id);
260+
if res.is_pending() {
261+
crate::dma::EthernetDMA::tx_waker().register(ctx.waker());
269262
}
263+
res
270264
})
271265
.await
272266
}

0 commit comments

Comments
 (0)