From 51913f2e2f45d4c3e266e9ab9b1345d301221956 Mon Sep 17 00:00:00 2001 From: linuswck Date: Tue, 27 Aug 2024 18:43:20 +0800 Subject: [PATCH] net: fix incorrect poll_iface() calls - poll_iface might be called by interrupt while poll_iface was being called in main loop - Disable interrupt when poll_iface is being processed - Only use IfacePollTimer to poll_iface --- src/net/net.rs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/net/net.rs b/src/net/net.rs index 81ad010..233c5b4 100644 --- a/src/net/net.rs +++ b/src/net/net.rs @@ -220,7 +220,9 @@ impl ServerHandle { } pub fn poll_iface(&mut self) { - self.iface.poll(now_fn(), &mut &mut self.dma, &mut self.socket_set); + cortex_m::interrupt::free(|_| { + self.iface.poll(now_fn(), &mut &mut self.dma, &mut self.socket_set); + }); } pub fn poll_at_iface(&mut self) -> Option { @@ -246,8 +248,7 @@ impl ServerHandle { if num_bytes > 0 { match socket.send_slice(&buffer[..num_bytes]) { Ok(_) => { - self.poll_iface(); - info!("Sent {} bytes.", num_bytes); + info!("Enqueued {} bytes.", num_bytes); } Err(err) => { info!("Bytes cannot be sent. Error: {:?}", err) @@ -515,11 +516,9 @@ pub fn for_each(mut callback: F) { #[interrupt] fn ETH() { let interrupt_reason = stm32_eth::eth_interrupt_handler(); - cortex_m::interrupt::free(|_| { - if interrupt_reason.rx { - eth_poll_iface(); - } - }); + if interrupt_reason.rx { + eth_poll_iface(); + } debug!("Ethernet Interrupt{:?}", interrupt_reason); }