Reset all TCP sockets before MCU reset #53

Merged
sb10q merged 5 commits from tcp_reset into master 2021-01-26 17:45:14 +08:00
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;
Outdated
Review

This could be a boolean any_socket_active

This could be a boolean ``any_socket_active``
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,
Outdated
Review

let the loop run for one more cycle

let the loop run for one more cycle
// 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()