@@ -20,6 +20,10 @@ mod consts {
2020 pub const RXDESC_3_BUF1V : u32 = 1 << 24 ;
2121
2222 // Write-back bits
23+ /// Timestamp Dropped
24+ pub const RXDESC_1_TD : u32 = 1 << 16 ;
25+ /// Timestamp Avaialble
26+ pub const RXDESC_1_TSA : u32 = 1 << 14 ;
2327 /// Context Descriptor
2428 pub const RXDESC_3_CTXT : u32 = 1 << 30 ;
2529 /// First Descriptor
@@ -102,7 +106,7 @@ impl RxDescriptor {
102106 }
103107
104108 /// Is owned by the DMA engine?
105- fn is_owned ( & self ) -> bool {
109+ pub ( super ) fn is_owned ( & self ) -> bool {
106110 ( self . inner_raw . read ( 3 ) & RXDESC_3_OWN ) == RXDESC_3_OWN
107111 }
108112
@@ -122,6 +126,10 @@ impl RxDescriptor {
122126 self . inner_raw . read ( 3 ) & RXDESC_3_CTXT == RXDESC_3_CTXT
123127 }
124128
129+ pub ( super ) fn has_timestamp ( & self ) -> bool {
130+ ( self . inner_raw . read ( 1 ) & RXDESC_1_TSA ) == RXDESC_1_TSA && self . is_last ( )
131+ }
132+
125133 pub ( super ) fn frame_length ( & self ) -> usize {
126134 if self . is_owned ( ) {
127135 0
@@ -200,10 +208,6 @@ impl RxDescriptor {
200208
201209 self . packet_id = packet_id;
202210
203- // Cache the PTP timestamps if PTP is enabled.
204- #[ cfg( feature = "ptp" ) ]
205- self . attach_timestamp ( ) ;
206-
207211 Ok ( ( ) )
208212 } else {
209213 self . set_owned ( buffer) ;
@@ -216,11 +220,16 @@ impl RxDescriptor {
216220impl RxDescriptor {
217221 /// Get PTP timestamps if available
218222 pub ( super ) fn read_timestamp ( & self ) -> Option < Timestamp > {
219- todo ! ( ) ;
223+ if self . is_context ( ) && !self . is_owned ( ) {
224+ let ( high, low) = ( self . inner_raw . read ( 1 ) , self . inner_raw . read ( 0 ) ) ;
225+ Some ( Timestamp :: from_parts ( high, low) )
226+ } else {
227+ None
228+ }
220229 }
221230
222- fn attach_timestamp ( & mut self ) {
223- self . cached_timestamp = self . read_timestamp ( ) ;
231+ pub ( super ) fn attach_timestamp ( & mut self , timestamp : Option < Timestamp > ) {
232+ self . cached_timestamp = timestamp ;
224233 }
225234
226235 pub ( super ) fn timestamp ( & self ) -> Option < & Timestamp > {
0 commit comments