@@ -20,6 +20,10 @@ mod consts {
20
20
pub const RXDESC_3_BUF1V : u32 = 1 << 24 ;
21
21
22
22
// 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 ;
23
27
/// Context Descriptor
24
28
pub const RXDESC_3_CTXT : u32 = 1 << 30 ;
25
29
/// First Descriptor
@@ -102,7 +106,7 @@ impl RxDescriptor {
102
106
}
103
107
104
108
/// Is owned by the DMA engine?
105
- fn is_owned ( & self ) -> bool {
109
+ pub ( super ) fn is_owned ( & self ) -> bool {
106
110
( self . inner_raw . read ( 3 ) & RXDESC_3_OWN ) == RXDESC_3_OWN
107
111
}
108
112
@@ -122,6 +126,10 @@ impl RxDescriptor {
122
126
self . inner_raw . read ( 3 ) & RXDESC_3_CTXT == RXDESC_3_CTXT
123
127
}
124
128
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
+
125
133
pub ( super ) fn frame_length ( & self ) -> usize {
126
134
if self . is_owned ( ) {
127
135
0
@@ -200,10 +208,6 @@ impl RxDescriptor {
200
208
201
209
self . packet_id = packet_id;
202
210
203
- // Cache the PTP timestamps if PTP is enabled.
204
- #[ cfg( feature = "ptp" ) ]
205
- self . attach_timestamp ( ) ;
206
-
207
211
Ok ( ( ) )
208
212
} else {
209
213
self . set_owned ( buffer) ;
@@ -216,11 +220,16 @@ impl RxDescriptor {
216
220
impl RxDescriptor {
217
221
/// Get PTP timestamps if available
218
222
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
+ }
220
229
}
221
230
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 ;
224
233
}
225
234
226
235
pub ( super ) fn timestamp ( & self ) -> Option < & Timestamp > {
0 commit comments