@@ -65,27 +65,13 @@ mod app {
65
65
#[ monotonic( binds = SysTick , default = true ) ]
66
66
type Monotonic = Systick < 1000 > ;
67
67
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
-
79
68
#[ init]
80
69
fn init ( cx : init:: Context ) -> ( Shared , Local , init:: Monotonics ) {
81
70
defmt:: info!( "Pre-init" ) ;
82
71
let core = cx. core ;
83
72
let p = cx. device ;
84
73
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 ( ) ;
89
75
90
76
let ( clocks, gpio, ethernet) = crate :: common:: setup_peripherals ( p) ;
91
77
let mono = Systick :: new ( core. SYST , clocks. hclk ( ) . raw ( ) ) ;
@@ -192,7 +178,7 @@ mod app {
192
178
buf[ 12 ..14 ] . copy_from_slice ( & ETH_TYPE ) ;
193
179
buf[ 14 ..22 ] . copy_from_slice ( & now. raw ( ) . to_be_bytes ( ) ) ;
194
180
} )
195
- . ok ( ) ;
181
+ . unwrap ( ) ;
196
182
* tx_id = Some ( ( tx_id_val, now) ) ;
197
183
* tx_id_ctr += 1 ;
198
184
* tx_id_ctr |= 0x8000_0000 ;
@@ -210,7 +196,7 @@ mod app {
210
196
cx. shared . scheduled_time ,
211
197
)
212
198
. lock ( |dma, tx_id, ptp, _sched_time| {
213
- dma. interrupt_handler ( ) ;
199
+ let interrupt_summary = dma. interrupt_handler ( ) ;
214
200
215
201
#[ cfg( not( feature = "stm32f107" ) ) ]
216
202
{
@@ -302,15 +288,17 @@ mod app {
302
288
}
303
289
}
304
290
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!(
309
296
"Diff between TX timestamp and the time that was put into the packet: {}" ,
310
297
ts - sent_time
311
298
) ;
312
- } else {
313
- defmt:: warn!( "Failed to retrieve TX timestamp" ) ;
299
+ } else {
300
+ defmt:: warn!( "Failed to retrieve TX timestamp" ) ;
301
+ }
314
302
}
315
303
}
316
304
} ) ;
0 commit comments