@@ -65,27 +65,13 @@ mod app {
6565 #[ monotonic( binds = SysTick , default = true ) ]
6666 type Monotonic = Systick < 1000 > ;
6767
68- /// On H7s, the ethernet DMA does not have access to the normal ram
69- /// so we must explicitly put them in SRAM.
70- #[ cfg_attr( feature = "stm32h7xx-hal" , link_section = ".sram1.eth" ) ]
71- static mut TX_DESCRIPTORS : [ TxDescriptor ; 4 ] = [ TxDescriptor :: new ( ) ; 4 ] ;
72- #[ cfg_attr( feature = "stm32h7xx-hal" , link_section = ".sram1.eth" ) ]
73- static mut TX_BUFFERS : [ [ u8 ; MTU + 2 ] ; 4 ] = [ [ 0u8 ; MTU + 2 ] ; 4 ] ;
74- #[ cfg_attr( feature = "stm32h7xx-hal" , link_section = ".sram1.eth2" ) ]
75- static mut RX_DESCRIPTORS : [ RxDescriptor ; 4 ] = [ RxDescriptor :: new ( ) ; 4 ] ;
76- #[ cfg_attr( feature = "stm32h7xx-hal" , link_section = ".sram1.eth2" ) ]
77- static mut RX_BUFFERS : [ [ u8 ; MTU + 2 ] ; 4 ] = [ [ 0u8 ; MTU + 2 ] ; 4 ] ;
78-
7968 #[ init]
8069 fn init ( cx : init:: Context ) -> ( Shared , Local , init:: Monotonics ) {
8170 defmt:: info!( "Pre-init" ) ;
8271 let core = cx. core ;
8372 let p = cx. device ;
8473
85- let rx_ring =
86- RxDescriptorRing :: new ( unsafe { & mut RX_DESCRIPTORS } , unsafe { & mut RX_BUFFERS } ) ;
87- let tx_ring =
88- TxDescriptorRing :: new ( unsafe { & mut TX_DESCRIPTORS } , unsafe { & mut TX_BUFFERS } ) ;
74+ let ( tx_ring, rx_ring) = crate :: common:: setup_rings ( ) ;
8975
9076 let ( clocks, gpio, ethernet) = crate :: common:: setup_peripherals ( p) ;
9177 let mono = Systick :: new ( core. SYST , clocks. hclk ( ) . raw ( ) ) ;
@@ -192,7 +178,7 @@ mod app {
192178 buf[ 12 ..14 ] . copy_from_slice ( & ETH_TYPE ) ;
193179 buf[ 14 ..22 ] . copy_from_slice ( & now. raw ( ) . to_be_bytes ( ) ) ;
194180 } )
195- . ok ( ) ;
181+ . unwrap ( ) ;
196182 * tx_id = Some ( ( tx_id_val, now) ) ;
197183 * tx_id_ctr += 1 ;
198184 * tx_id_ctr |= 0x8000_0000 ;
@@ -210,7 +196,7 @@ mod app {
210196 cx. shared . scheduled_time ,
211197 )
212198 . lock ( |dma, tx_id, ptp, _sched_time| {
213- dma. interrupt_handler ( ) ;
199+ let interrupt_summary = dma. interrupt_handler ( ) ;
214200
215201 #[ cfg( not( feature = "stm32f107" ) ) ]
216202 {
@@ -302,15 +288,17 @@ mod app {
302288 }
303289 }
304290
305- if let Some ( ( tx_id, sent_time) ) = tx_id. take ( ) {
306- if let Ok ( ts) = dma. get_timestamp_for_id ( PacketId ( tx_id) ) {
307- defmt:: info!( "TX timestamp: {}" , ts) ;
308- defmt:: debug!(
291+ if interrupt_summary. is_tx {
292+ if let Some ( ( tx_id, sent_time) ) = tx_id. take ( ) {
293+ if let Ok ( ts) = dma. get_timestamp_for_id ( PacketId ( tx_id) ) {
294+ defmt:: info!( "TX timestamp: {}" , ts) ;
295+ defmt:: debug!(
309296 "Diff between TX timestamp and the time that was put into the packet: {}" ,
310297 ts - sent_time
311298 ) ;
312- } else {
313- defmt:: warn!( "Failed to retrieve TX timestamp" ) ;
299+ } else {
300+ defmt:: warn!( "Failed to retrieve TX timestamp" ) ;
301+ }
314302 }
315303 }
316304 } ) ;
0 commit comments