@@ -252,11 +252,9 @@ impl EthernetPTP {
252
252
pub async fn wait_until ( & mut self , timestamp : Timestamp ) {
253
253
self . configure_target_time_interrupt ( timestamp) ;
254
254
core:: future:: poll_fn ( |ctx| {
255
- // This is the happy path, the status bits have
256
- // usually been reset at this point.
257
- if EthernetPTP :: get_time ( ) . raw ( ) >= timestamp. raw ( ) {
255
+ if EthernetPTP :: read_and_clear_interrupt_flag ( ) {
258
256
Poll :: Ready ( ( ) )
259
- } else if EthernetPTP :: interrupt_handler ( ) {
257
+ } else if EthernetPTP :: get_time ( ) . raw ( ) >= timestamp . raw ( ) {
260
258
Poll :: Ready ( ( ) )
261
259
} else {
262
260
EthernetPTP :: waker ( ) . register ( ctx. waker ( ) ) ;
@@ -266,20 +264,33 @@ impl EthernetPTP {
266
264
. await ;
267
265
}
268
266
267
+ #[ inline( always) ]
268
+ fn read_and_clear_interrupt_flag ( ) -> bool {
269
+ let eth_ptp = unsafe { & * ETHERNET_PTP :: ptr ( ) } ;
270
+ eth_ptp. ptptssr . read ( ) . tsttr ( ) . bit_is_set ( )
271
+ }
272
+
269
273
/// Returns a boolean indicating whether or not the interrupt
270
274
/// was caused by a Timestamp trigger and clears the interrupt
271
275
/// flag.
272
276
pub fn interrupt_handler ( ) -> bool {
273
277
// SAFETY: we only perform one atomic read.
274
- let eth_ptp = unsafe { & * ETHERNET_PTP :: ptr ( ) } ;
278
+ let eth_mac = unsafe { & * crate :: peripherals :: ETHERNET_MAC :: ptr ( ) } ;
275
279
276
- let is_tsint = eth_ptp . ptptssr . read ( ) . tsttr ( ) . bit_is_set ( ) ;
280
+ let is_tsint = eth_mac . macsr . read ( ) . tsts ( ) . bit_is_set ( ) ;
277
281
if is_tsint {
278
282
EthernetMAC :: mask_timestamp_trigger_interrupt ( ) ;
279
283
}
280
284
281
285
#[ cfg( feature = "async-await" ) ]
282
- EthernetPTP :: waker ( ) . wake ( ) ;
286
+ if let Some ( waker) = EthernetPTP :: waker ( ) . take ( ) {
287
+ waker. wake ( ) ;
288
+ } else {
289
+ EthernetPTP :: read_and_clear_interrupt_flag ( ) ;
290
+ }
291
+
292
+ #[ cfg( not( feature = "async-await" ) ) ]
293
+ EthernetPTP :: read_and_clear_interrupt_flag ( ) ;
283
294
284
295
is_tsint
285
296
}
0 commit comments