Skip to content

Commit 7850052

Browse files
committed
Getting timestamp does not have to be mutable
1 parent 388577e commit 7850052

File tree

4 files changed

+9
-11
lines changed

4 files changed

+9
-11
lines changed

src/dma/mod.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -248,10 +248,7 @@ impl<'rx, 'tx> EthernetDMA<'rx, 'tx> {
248248
/// 2. Before calling [`interrupt_handler`](EthernetDMA::interrupt_handler) again, retrieve timestamps of sent and received frames using this function.
249249
///
250250
/// Retrieving RX timestamps can also be done using [`RxPacket::timestamp`].
251-
pub fn get_timestamp_for_id<'a, PKT>(
252-
&mut self,
253-
packet_id: PKT,
254-
) -> Result<Timestamp, TimestampError>
251+
pub fn get_timestamp_for_id<'a, PKT>(&self, packet_id: PKT) -> Result<Timestamp, TimestampError>
255252
where
256253
PKT: Into<PacketId>,
257254
{

src/dma/raw_descriptor.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,11 @@ impl<'data, T> DescriptorRing<'data, T> {
7878
(&mut self.descriptors[index], &mut self.buffers[index])
7979
}
8080

81-
pub fn descriptors(&mut self) -> impl Iterator<Item = &mut T> {
81+
pub fn descriptors(&self) -> impl Iterator<Item = &T> {
82+
self.descriptors.iter()
83+
}
84+
85+
pub fn descriptors_mut(&mut self) -> impl Iterator<Item = &mut T> {
8286
self.descriptors.iter_mut()
8387
}
8488

src/dma/rx/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ impl<'data> RxRing<'data, Running> {
148148

149149
#[cfg(feature = "ptp")]
150150
impl<'data, STATE> RxRing<'data, STATE> {
151-
pub fn get_timestamp_for_id(&mut self, id: PacketId) -> Result<Timestamp, TimestampError> {
151+
pub fn get_timestamp_for_id(&self, id: PacketId) -> Result<Timestamp, TimestampError> {
152152
for descriptor in self.ring.descriptors() {
153153
if let (Some(packet_id), Some(timestamp)) =
154154
(descriptor.packet_id(), descriptor.timestamp())

src/dma/tx/mod.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,15 +157,12 @@ impl<'data> TxRing<'data, Running> {
157157
#[cfg(feature = "ptp")]
158158
impl<'data> TxRing<'data, Running> {
159159
pub(crate) fn collect_timestamps(&mut self) {
160-
for descriptor in self.ring.descriptors() {
160+
for descriptor in self.ring.descriptors_mut() {
161161
descriptor.attach_timestamp();
162162
}
163163
}
164164

165-
pub(crate) fn get_timestamp_for_id(
166-
&mut self,
167-
id: PacketId,
168-
) -> Result<Timestamp, TimestampError> {
165+
pub(crate) fn get_timestamp_for_id(&self, id: PacketId) -> Result<Timestamp, TimestampError> {
169166
let descriptor = if let Some(descriptor) =
170167
self.ring.descriptors().find(|d| d.packet_id() == Some(&id))
171168
{

0 commit comments

Comments
 (0)