Refactoring link status polling
This commit is contained in:
parent
04f61db6f2
commit
14bfbbe2a1
|
@ -69,7 +69,7 @@ const APP: () = {
|
||||||
iir_state: [[iir::Vec5; IIR_CASCADE_LENGTH]; 2],
|
iir_state: [[iir::Vec5; IIR_CASCADE_LENGTH]; 2],
|
||||||
}
|
}
|
||||||
|
|
||||||
#[init(spawn=[telemetry, settings_update])]
|
#[init(spawn=[telemetry, settings_update, ethernet_link])]
|
||||||
fn init(c: init::Context) -> init::LateResources {
|
fn init(c: init::Context) -> init::LateResources {
|
||||||
// Configure the microcontroller
|
// Configure the microcontroller
|
||||||
let (mut stabilizer, _pounder) = hardware::setup(c.core, c.device);
|
let (mut stabilizer, _pounder) = hardware::setup(c.core, c.device);
|
||||||
|
@ -91,6 +91,9 @@ const APP: () = {
|
||||||
c.spawn.settings_update().unwrap();
|
c.spawn.settings_update().unwrap();
|
||||||
c.spawn.telemetry().unwrap();
|
c.spawn.telemetry().unwrap();
|
||||||
|
|
||||||
|
// Spawn the ethernet link period check task.
|
||||||
|
c.spawn.ethernet_link().unwrap();
|
||||||
|
|
||||||
// Enable ADC/DAC events
|
// Enable ADC/DAC events
|
||||||
stabilizer.adcs.0.start();
|
stabilizer.adcs.0.start();
|
||||||
stabilizer.adcs.1.start();
|
stabilizer.adcs.1.start();
|
||||||
|
@ -227,6 +230,12 @@ const APP: () = {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[task(priority = 1, resources=[network], schedule=[ethernet_link])]
|
||||||
|
fn ethernet_link(c: ethernet_link::Context) {
|
||||||
|
c.resources.network.processor.handle_link();
|
||||||
|
c.schedule.ethernet_link(c.scheduled + SystemTimer::ticks_from_secs(1)).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
#[task(binds = ETH, priority = 1)]
|
#[task(binds = ETH, priority = 1)]
|
||||||
fn eth(_: eth::Context) {
|
fn eth(_: eth::Context) {
|
||||||
unsafe { stm32h7xx_hal::ethernet::interrupt_handler() }
|
unsafe { stm32h7xx_hal::ethernet::interrupt_handler() }
|
||||||
|
|
|
@ -94,7 +94,7 @@ const APP: () = {
|
||||||
lockin: Lockin<4>,
|
lockin: Lockin<4>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[init(spawn=[settings_update, telemetry])]
|
#[init(spawn=[settings_update, telemetry, ethernet_link])]
|
||||||
fn init(c: init::Context) -> init::LateResources {
|
fn init(c: init::Context) -> init::LateResources {
|
||||||
// Configure the microcontroller
|
// Configure the microcontroller
|
||||||
let (mut stabilizer, _pounder) = setup(c.core, c.device);
|
let (mut stabilizer, _pounder) = setup(c.core, c.device);
|
||||||
|
@ -118,6 +118,9 @@ const APP: () = {
|
||||||
c.spawn.settings_update().unwrap();
|
c.spawn.settings_update().unwrap();
|
||||||
c.spawn.telemetry().unwrap();
|
c.spawn.telemetry().unwrap();
|
||||||
|
|
||||||
|
// Spawn the ethernet link servicing task.
|
||||||
|
c.spawn.ethernet_link().unwrap();
|
||||||
|
|
||||||
// Enable ADC/DAC events
|
// Enable ADC/DAC events
|
||||||
stabilizer.adcs.0.start();
|
stabilizer.adcs.0.start();
|
||||||
stabilizer.adcs.1.start();
|
stabilizer.adcs.1.start();
|
||||||
|
@ -298,6 +301,12 @@ const APP: () = {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[task(priority = 1, resources=[network], schedule=[ethernet_link])]
|
||||||
|
fn ethernet_link(c: ethernet_link::Context) {
|
||||||
|
c.resources.network.processor.handle_link();
|
||||||
|
c.schedule.ethernet_link(c.scheduled + SystemTimer::ticks_from_secs(1)).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
#[task(binds = ETH, priority = 1)]
|
#[task(binds = ETH, priority = 1)]
|
||||||
fn eth(_: eth::Context) {
|
fn eth(_: eth::Context) {
|
||||||
unsafe { stm32h7xx_hal::ethernet::interrupt_handler() }
|
unsafe { stm32h7xx_hal::ethernet::interrupt_handler() }
|
||||||
|
|
|
@ -47,7 +47,7 @@ pub enum NetworkState {
|
||||||
/// A structure of Stabilizer's default network users.
|
/// A structure of Stabilizer's default network users.
|
||||||
pub struct NetworkUsers<S: Default + Clone + Miniconf, T: Serialize> {
|
pub struct NetworkUsers<S: Default + Clone + Miniconf, T: Serialize> {
|
||||||
pub miniconf: MiniconfClient<S>,
|
pub miniconf: MiniconfClient<S>,
|
||||||
processor: NetworkProcessor,
|
pub processor: NetworkProcessor,
|
||||||
stream: DataStream,
|
stream: DataStream,
|
||||||
generator: Option<BlockGenerator>,
|
generator: Option<BlockGenerator>,
|
||||||
pub telemetry: TelemetryClient<T>,
|
pub telemetry: TelemetryClient<T>,
|
||||||
|
@ -143,12 +143,10 @@ where
|
||||||
UpdateState::Updated => NetworkState::Updated,
|
UpdateState::Updated => NetworkState::Updated,
|
||||||
};
|
};
|
||||||
|
|
||||||
let result = match self.miniconf.update() {
|
match self.miniconf.update() {
|
||||||
UpdateState::Updated => NetworkState::SettingsChanged,
|
UpdateState::Updated => NetworkState::SettingsChanged,
|
||||||
UpdateState::NoChange => poll_result,
|
UpdateState::NoChange => poll_result,
|
||||||
};
|
}
|
||||||
|
|
||||||
result
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -37,9 +37,25 @@ impl NetworkProcessor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn egress(&mut self) {
|
/// Handle ethernet link connection status.
|
||||||
let now = self.clock.current_ms();
|
///
|
||||||
self.stack.lock(|stack| stack.poll(now)).ok();
|
/// # Note
|
||||||
|
/// This may take non-trivial amounts of time to communicate with the PHY. As such, this should
|
||||||
|
/// only be called as often as necessary (e.g. once per second or so).
|
||||||
|
pub fn handle_link(&mut self) {
|
||||||
|
// If the PHY indicates there's no more ethernet link, reset the DHCP server in the network
|
||||||
|
// stack.
|
||||||
|
match self.phy.poll_link() {
|
||||||
|
true => self.network_was_reset = false,
|
||||||
|
|
||||||
|
// Only reset the network stack once per link reconnection. This prevents us from
|
||||||
|
// sending an excessive number of DHCP requests.
|
||||||
|
false if !self.network_was_reset => {
|
||||||
|
self.network_was_reset = true;
|
||||||
|
self.stack.lock(|stack| stack.handle_link_reset());
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Process and update the state of the network.
|
/// Process and update the state of the network.
|
||||||
|
@ -63,22 +79,6 @@ impl NetworkProcessor {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// If the PHY indicates there's no more ethernet link, reset the DHCP server in the network
|
|
||||||
// stack.
|
|
||||||
// TODO: Poll the link state in a task and handle resets. Polling this often is slow and
|
|
||||||
// uses necessary CPU time.
|
|
||||||
//match self.phy.poll_link() {
|
|
||||||
// true => self.network_was_reset = false,
|
|
||||||
|
|
||||||
// // Only reset the network stack once per link reconnection. This prevents us from
|
|
||||||
// // sending an excessive number of DHCP requests.
|
|
||||||
// false if !self.network_was_reset => {
|
|
||||||
// self.network_was_reset = true;
|
|
||||||
// self.stack.lock(|stack| stack.handle_link_reset());
|
|
||||||
// }
|
|
||||||
// _ => {}
|
|
||||||
//};
|
|
||||||
|
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue