Reset all TCP sockets before MCU reset (#53)

Co-Authored-By: topquark12 <aw@m-labs.hk>
Co-Committed-By: topquark12 <aw@m-labs.hk>
This commit is contained in:
topquark12 2021-01-26 17:45:14 +08:00 committed by sb10q
parent 6b9d61737e
commit 7cb0ed70be
1 changed files with 264 additions and 249 deletions

View File

@ -186,6 +186,7 @@ fn main() -> ! {
net::run(clocks, dp.ETHERNET_MAC, dp.ETHERNET_DMA, eth_pins, hwaddr, ipv4_config.clone(), |iface| {
Server::<Session>::run(iface, |server| {
leds.r1.off();
let mut should_reset = false;
loop {
let mut new_ipv4_config = None;
@ -202,6 +203,7 @@ fn main() -> ! {
warn!("poll: {:?}", e);
});
if ! should_reset {
// TCP protocol handling
server.for_each(|mut socket, session| {
if ! socket.is_active() {
@ -421,8 +423,7 @@ fn main() -> ! {
for i in 0..CHANNELS {
channels.power_down(i);
}
SCB::sys_reset();
should_reset = true;
}
Command::Dfu => {
for i in 0..CHANNELS {
@ -431,8 +432,7 @@ fn main() -> ! {
unsafe {
dfu::set_dfu_trigger();
}
SCB::sys_reset();
should_reset = true;
}
}
Ok(SessionInput::Error(e)) => {
@ -457,6 +457,21 @@ fn main() -> ! {
}
}
});
} else {
// Should reset, close all TCP sockets.
let mut any_socket_alive = false;
server.for_each(|mut socket, _| {
if socket.is_active() {
socket.abort();
any_socket_alive = true;
}
});
// Must let loop run for one more cycle to poll server for RST to be sent,
// this makes sure system does not reset right after socket.abort() is called.
if !any_socket_alive {
SCB::sys_reset();
}
}
// Apply new IPv4 address/gateway
new_ipv4_config.take()