From a717630c535ba5417058a494c14795d50fe77c03 Mon Sep 17 00:00:00 2001 From: Ryan Summers Date: Wed, 17 Mar 2021 20:16:13 +0100 Subject: [PATCH 1/7] Adding prototype PHY reset detection --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/bin/dual-iir.rs | 78 +++++++++--------------------- src/bin/lockin-external.rs | 78 +++++++++--------------------- src/hardware/configuration.rs | 6 +-- src/hardware/mod.rs | 2 + src/lib.rs | 1 + src/net/mod.rs | 89 +++++++++++++++++++++++++++++++++++ 8 files changed, 141 insertions(+), 117 deletions(-) create mode 100644 src/net/mod.rs diff --git a/Cargo.lock b/Cargo.lock index b435a6b..8b66fe7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -707,7 +707,7 @@ dependencies = [ [[package]] name = "smoltcp-nal" version = "0.1.0" -source = "git+https://github.com/quartiq/smoltcp-nal.git?branch=main#56519012d7c6a382eaa0d7ecb26f2701771d9ce8" +source = "git+https://github.com/quartiq/smoltcp-nal.git?branch=feature/reset-support#a6db6579100987502563578fb386109ad08758a7" dependencies = [ "embedded-nal", "heapless 0.6.1", diff --git a/Cargo.toml b/Cargo.toml index 6b14532..f1d88b3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -56,7 +56,7 @@ git = "https://github.com/quartiq/minimq.git" [patch.crates-io.smoltcp-nal] git = "https://github.com/quartiq/smoltcp-nal.git" -branch = "main" +branch = "feature/reset-support" [patch.crates-io.serde-json-core] git = "https://github.com/rust-embedded-community/serde-json-core.git" diff --git a/src/bin/dual-iir.rs b/src/bin/dual-iir.rs index 4a27d48..6c391c7 100644 --- a/src/bin/dual-iir.rs +++ b/src/bin/dual-iir.rs @@ -4,17 +4,18 @@ use stm32h7xx_hal as hal; -use stabilizer::hardware; +use stabilizer::{hardware, net}; -use miniconf::{minimq, Miniconf, MqttInterface}; +use miniconf::Miniconf; use serde::Deserialize; use dsp::iir; use hardware::{ - Adc0Input, Adc1Input, AfeGain, CycleCounter, Dac0Output, Dac1Output, - NetworkStack, AFE0, AFE1, + Adc0Input, Adc1Input, AfeGain, Dac0Output, Dac1Output, AFE0, AFE1, }; +use net::{Action, MqttSettings}; + const SCALE: f32 = i16::MAX as _; // The number of cascaded IIR biquads per channel. Select 1 or 2! @@ -41,9 +42,7 @@ const APP: () = { afes: (AFE0, AFE1), adcs: (Adc0Input, Adc1Input), dacs: (Dac0Output, Dac1Output), - mqtt_interface: - MqttInterface, - clock: CycleCounter, + mqtt_settings: MqttSettings, // Format: iir_state[ch][cascade-no][coeff] #[init([[[0.; 5]; IIR_CASCADE_LENGTH]; 2])] @@ -57,23 +56,13 @@ const APP: () = { // Configure the microcontroller let (mut stabilizer, _pounder) = hardware::setup(c.core, c.device); - let mqtt_interface = { - let mqtt_client = { - minimq::MqttClient::new( - hardware::design_parameters::MQTT_BROKER.into(), - "", - stabilizer.net.stack, - ) - .unwrap() - }; - - MqttInterface::new( - mqtt_client, - "dt/sinara/stabilizer", - Settings::default(), - ) - .unwrap() - }; + let mqtt_settings = MqttSettings::new( + stabilizer.net.stack, + "", + "dt/sinara/stabilizer", + stabilizer.net.phy, + stabilizer.cycle_counter, + ); // Enable ADC/DAC events stabilizer.adcs.0.start(); @@ -85,11 +74,10 @@ const APP: () = { stabilizer.adc_dac_timer.start(); init::LateResources { - mqtt_interface, afes: stabilizer.afes, adcs: stabilizer.adcs, dacs: stabilizer.dacs, - clock: stabilizer.cycle_counter, + mqtt_settings, } } @@ -138,44 +126,22 @@ const APP: () = { } } - #[idle(resources=[mqtt_interface, clock], spawn=[settings_update])] + #[idle(resources=[mqtt_settings], spawn=[settings_update])] fn idle(mut c: idle::Context) -> ! { - let clock = c.resources.clock; - loop { - let sleep = c.resources.mqtt_interface.lock(|interface| { - match interface.network_stack().poll(clock.current_ms()) { - Ok(updated) => !updated, - Err(err) => { - log::info!("Network error: {:?}", err); - false - } + match c.resources.mqtt_settings.lock(|settings| settings.update()) { + Some(Action::Sleep) => cortex_m::asm::wfi(), + Some(Action::UpdateSettings) => { + c.spawn.settings_update().unwrap() } - }); - - match c - .resources - .mqtt_interface - .lock(|interface| interface.update()) - { - Ok(update) => { - if update { - c.spawn.settings_update().unwrap(); - } else if sleep { - cortex_m::asm::wfi(); - } - } - Err(miniconf::MqttError::Network( - smoltcp_nal::NetworkError::NoIpAddress, - )) => {} - Err(error) => log::info!("Unexpected error: {:?}", error), + _ => {} } } } - #[task(priority = 1, resources=[mqtt_interface, afes, iir_ch])] + #[task(priority = 1, resources=[mqtt_settings, afes, iir_ch])] fn settings_update(mut c: settings_update::Context) { - let settings = &c.resources.mqtt_interface.settings; + let settings = &c.resources.mqtt_settings.mqtt_interface.settings; // Update the IIR channels. c.resources.iir_ch.lock(|iir| *iir = settings.iir_ch); diff --git a/src/bin/lockin-external.rs b/src/bin/lockin-external.rs index 7d2db0e..bb84e91 100644 --- a/src/bin/lockin-external.rs +++ b/src/bin/lockin-external.rs @@ -4,16 +4,18 @@ use generic_array::typenum::U4; -use miniconf::{minimq, Miniconf, MqttInterface}; use serde::Deserialize; use dsp::{Accu, Complex, ComplexExt, Lockin, RPLL}; use stabilizer::hardware::{ - design_parameters, setup, Adc0Input, Adc1Input, AfeGain, CycleCounter, - Dac0Output, Dac1Output, InputStamper, NetworkStack, AFE0, AFE1, + design_parameters, setup, Adc0Input, Adc1Input, AfeGain, Dac0Output, + Dac1Output, InputStamper, AFE0, AFE1, }; +use miniconf::Miniconf; +use stabilizer::net::{Action, MqttSettings}; + #[derive(Copy, Clone, Debug, Deserialize, Miniconf)] enum Conf { PowerPhase, @@ -56,11 +58,7 @@ const APP: () = { afes: (AFE0, AFE1), adcs: (Adc0Input, Adc1Input), dacs: (Dac0Output, Dac1Output), - clock: CycleCounter, - - mqtt_interface: - MqttInterface, - + mqtt_settings: MqttSettings, settings: Settings, timestamper: InputStamper, @@ -73,21 +71,13 @@ const APP: () = { // Configure the microcontroller let (mut stabilizer, _pounder) = setup(c.core, c.device); - let mqtt_interface = { - let mqtt_client = minimq::MqttClient::new( - design_parameters::MQTT_BROKER.into(), - "", - stabilizer.net.stack, - ) - .unwrap(); - - MqttInterface::new( - mqtt_client, - "dt/sinara/lockin", - Settings::default(), - ) - .unwrap() - }; + let mqtt_settings = MqttSettings::new( + stabilizer.net.stack, + "", + "dt/sinara/lockin", + stabilizer.net.phy, + stabilizer.cycle_counter, + ); let settings = Settings::default(); @@ -118,10 +108,8 @@ const APP: () = { afes: stabilizer.afes, adcs: stabilizer.adcs, dacs: stabilizer.dacs, + mqtt_settings, timestamper: stabilizer.timestamper, - clock: stabilizer.cycle_counter, - - mqtt_interface, settings, @@ -202,44 +190,22 @@ const APP: () = { } } - #[idle(resources=[mqtt_interface, clock], spawn=[settings_update])] + #[idle(resources=[mqtt_settings], spawn=[settings_update])] fn idle(mut c: idle::Context) -> ! { - let clock = c.resources.clock; - loop { - let sleep = c.resources.mqtt_interface.lock(|interface| { - match interface.network_stack().poll(clock.current_ms()) { - Ok(updated) => !updated, - Err(err) => { - log::info!("Network error: {:?}", err); - false - } + match c.resources.mqtt_settings.lock(|settings| settings.update()) { + Some(Action::Sleep) => cortex_m::asm::wfi(), + Some(Action::UpdateSettings) => { + c.spawn.settings_update().unwrap() } - }); - - match c - .resources - .mqtt_interface - .lock(|interface| interface.update()) - { - Ok(update) => { - if update { - c.spawn.settings_update().unwrap(); - } else if sleep { - cortex_m::asm::wfi(); - } - } - Err(miniconf::MqttError::Network( - smoltcp_nal::NetworkError::NoIpAddress, - )) => {} - Err(error) => log::info!("Unexpected error: {:?}", error), + _ => {} } } } - #[task(priority = 1, resources=[mqtt_interface, settings, afes])] + #[task(priority = 1, resources=[mqtt_settings, settings, afes])] fn settings_update(mut c: settings_update::Context) { - let settings = &c.resources.mqtt_interface.settings; + let settings = &c.resources.mqtt_settings.mqtt_interface.settings; c.resources.afes.0.set_gain(settings.afe[0]); c.resources.afes.1.set_gain(settings.afe[1]); diff --git a/src/hardware/configuration.rs b/src/hardware/configuration.rs index dfab1e0..74307dd 100644 --- a/src/hardware/configuration.rs +++ b/src/hardware/configuration.rs @@ -13,8 +13,8 @@ use embedded_hal::digital::v2::{InputPin, OutputPin}; use super::{ adc, afe, cycle_counter::CycleCounter, dac, design_parameters, - digital_input_stamper, eeprom, pounder, timers, DdsOutput, NetworkStack, - AFE0, AFE1, + digital_input_stamper, eeprom, pounder, timers, DdsOutput, EthernetPhy, + NetworkStack, AFE0, AFE1, }; pub struct NetStorage { @@ -56,7 +56,7 @@ impl NetStorage { /// The available networking devices on Stabilizer. pub struct NetworkDevices { pub stack: NetworkStack, - pub phy: ethernet::phy::LAN8742A, + pub phy: EthernetPhy, } /// The available hardware interfaces on Stabilizer. diff --git a/src/hardware/mod.rs b/src/hardware/mod.rs index cc7a34a..60e7768 100644 --- a/src/hardware/mod.rs +++ b/src/hardware/mod.rs @@ -40,6 +40,8 @@ pub type NetworkStack = smoltcp_nal::NetworkStack< hal::ethernet::EthernetDMA<'static>, >; +pub type EthernetPhy = hal::ethernet::phy::LAN8742A; + pub use configuration::{setup, PounderDevices, StabilizerDevices}; #[inline(never)] diff --git a/src/lib.rs b/src/lib.rs index 0c9bf2a..975b08f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -5,3 +5,4 @@ extern crate log; pub mod hardware; +pub mod net; diff --git a/src/net/mod.rs b/src/net/mod.rs new file mode 100644 index 0000000..a996555 --- /dev/null +++ b/src/net/mod.rs @@ -0,0 +1,89 @@ +use crate::hardware::{ + design_parameters::MQTT_BROKER, CycleCounter, EthernetPhy, NetworkStack, +}; + +use miniconf::{minimq, MqttInterface}; + +pub enum Action { + Sleep, + UpdateSettings, +} + +pub struct MqttSettings +where + S: miniconf::Miniconf + Default, +{ + pub mqtt_interface: MqttInterface, + clock: CycleCounter, + phy: EthernetPhy, + network_was_reset: bool, +} + +impl MqttSettings +where + S: miniconf::Miniconf + Default, +{ + pub fn new( + stack: NetworkStack, + client_id: &str, + prefix: &str, + phy: EthernetPhy, + clock: CycleCounter, + ) -> Self { + let mqtt_interface = { + let mqtt_client = { + minimq::MqttClient::new(MQTT_BROKER.into(), client_id, stack) + .unwrap() + }; + + MqttInterface::new(mqtt_client, prefix, S::default()).unwrap() + }; + + Self { + mqtt_interface, + clock, + phy, + network_was_reset: false, + } + } + + pub fn update(&mut self) -> Option { + let now = self.clock.current_ms(); + + let sleep = match self.mqtt_interface.network_stack().poll(now) { + Ok(updated) => !updated, + Err(err) => { + log::info!("Network error: {:?}", err); + false + } + }; + + // If the PHY indicates there's no more ethernet link, reset the network stack and close all + // sockets. + if self.phy.poll_link() == false { + // Only reset the network stack once per link reconnection. This prevents us from + // sending an excessive number of DHCP requests. + if !self.network_was_reset { + self.network_was_reset = true; + self.mqtt_interface.network_stack().reset(); + } + } else { + self.network_was_reset = false; + } + + match self.mqtt_interface.update() { + Ok(true) => Some(Action::UpdateSettings), + Ok(false) if sleep => Some(Action::Sleep), + Ok(_) => None, + + Err(miniconf::MqttError::Network( + smoltcp_nal::NetworkError::NoIpAddress, + )) => None, + + Err(error) => { + log::info!("Unexpected error: {:?}", error); + None + } + } + } +} From 9459152f6f71122a3a97565d85252c32af81a469 Mon Sep 17 00:00:00 2001 From: Ryan Summers Date: Wed, 24 Mar 2021 13:40:17 +0100 Subject: [PATCH 2/7] Updating dependencies --- Cargo.lock | 8 ++++---- Cargo.toml | 3 +-- src/net/mod.rs | 2 +- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8b66fe7..d203a3c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -390,9 +390,9 @@ dependencies = [ [[package]] name = "managed" -version = "0.7.2" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c75de51135344a4f8ed3cfe2720dc27736f7711989703a0b43aadf3753c55577" +checksum = "0ca88d725a0a943b096803bd34e73a4437208b6077654cc4ecb2947a5f91618d" [[package]] name = "matrixmultiply" @@ -697,7 +697,7 @@ dependencies = [ [[package]] name = "smoltcp" version = "0.7.0" -source = "git+https://github.com/ryan-summers/smoltcp.git?branch=feature/dhcp-lease-updates#e3954ebb8149341c52a4992e037d4b5109387910" +source = "git+https://github.com/smoltcp-rs/smoltcp.git#1bff999a6f3f7adf623d837ea96cc807e1b3a470" dependencies = [ "bitflags", "byteorder", @@ -707,7 +707,7 @@ dependencies = [ [[package]] name = "smoltcp-nal" version = "0.1.0" -source = "git+https://github.com/quartiq/smoltcp-nal.git?branch=feature/reset-support#a6db6579100987502563578fb386109ad08758a7" +source = "git+https://github.com/quartiq/smoltcp-nal.git?branch=feature/reset-support#c43e751afe3c14aac153fa4425231270dbfd918b" dependencies = [ "embedded-nal", "heapless 0.6.1", diff --git a/Cargo.toml b/Cargo.toml index f1d88b3..fe610d5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -63,8 +63,7 @@ git = "https://github.com/rust-embedded-community/serde-json-core.git" branch = "master" [patch.crates-io.smoltcp] -git = "https://github.com/ryan-summers/smoltcp.git" -branch = "feature/dhcp-lease-updates" +git = "https://github.com/smoltcp-rs/smoltcp.git" [dependencies.mcp23017] git = "https://github.com/mrd0ll4r/mcp23017.git" diff --git a/src/net/mod.rs b/src/net/mod.rs index a996555..1939703 100644 --- a/src/net/mod.rs +++ b/src/net/mod.rs @@ -65,7 +65,7 @@ where // sending an excessive number of DHCP requests. if !self.network_was_reset { self.network_was_reset = true; - self.mqtt_interface.network_stack().reset(); + self.mqtt_interface.network_stack().handle_link_reset(); } } else { self.network_was_reset = false; From 5e448f284bde0b7c43a85b278266bb6d7298123e Mon Sep 17 00:00:00 2001 From: Ryan Summers Date: Wed, 24 Mar 2021 13:48:34 +0100 Subject: [PATCH 3/7] Updating net module --- src/bin/dual-iir.rs | 2 +- src/bin/lockin-external.rs | 2 +- src/net/mod.rs | 35 +++++++++++++++++++++++++++-------- 3 files changed, 29 insertions(+), 10 deletions(-) diff --git a/src/bin/dual-iir.rs b/src/bin/dual-iir.rs index 6c391c7..0e2215b 100644 --- a/src/bin/dual-iir.rs +++ b/src/bin/dual-iir.rs @@ -141,7 +141,7 @@ const APP: () = { #[task(priority = 1, resources=[mqtt_settings, afes, iir_ch])] fn settings_update(mut c: settings_update::Context) { - let settings = &c.resources.mqtt_settings.mqtt_interface.settings; + let settings = &c.resources.mqtt_settings.mqtt.settings; // Update the IIR channels. c.resources.iir_ch.lock(|iir| *iir = settings.iir_ch); diff --git a/src/bin/lockin-external.rs b/src/bin/lockin-external.rs index bb84e91..b62ea42 100644 --- a/src/bin/lockin-external.rs +++ b/src/bin/lockin-external.rs @@ -205,7 +205,7 @@ const APP: () = { #[task(priority = 1, resources=[mqtt_settings, settings, afes])] fn settings_update(mut c: settings_update::Context) { - let settings = &c.resources.mqtt_settings.mqtt_interface.settings; + let settings = &c.resources.mqtt_settings.mqtt.settings; c.resources.afes.0.set_gain(settings.afe[0]); c.resources.afes.1.set_gain(settings.afe[1]); diff --git a/src/net/mod.rs b/src/net/mod.rs index 1939703..f38f3d9 100644 --- a/src/net/mod.rs +++ b/src/net/mod.rs @@ -4,16 +4,21 @@ use crate::hardware::{ use miniconf::{minimq, MqttInterface}; +/// Potential actions for firmware to take. pub enum Action { + /// Indicates that firmware can sleep for the next event. Sleep, + + /// Indicates that settings have updated and firmware needs to propogate changes. UpdateSettings, } +/// MQTT settings interface. pub struct MqttSettings where S: miniconf::Miniconf + Default, { - pub mqtt_interface: MqttInterface, + pub mqtt: MqttInterface, clock: CycleCounter, phy: EthernetPhy, network_was_reset: bool, @@ -23,6 +28,14 @@ impl MqttSettings where S: miniconf::Miniconf + Default, { + /// Construct a new MQTT settings interface. + /// + /// # Args + /// * `stack` - The network stack to use for communication. + /// * `client_id` - The ID of the MQTT client. May be an empty string for auto-assigning. + /// * `prefix` - The MQTT device prefix to use for this device. + /// * `phy` - The PHY driver for querying the link state. + /// * `clock` - The clock to utilize for querying the current system time. pub fn new( stack: NetworkStack, client_id: &str, @@ -30,7 +43,7 @@ where phy: EthernetPhy, clock: CycleCounter, ) -> Self { - let mqtt_interface = { + let mqtt = { let mqtt_client = { minimq::MqttClient::new(MQTT_BROKER.into(), client_id, stack) .unwrap() @@ -40,17 +53,22 @@ where }; Self { - mqtt_interface, + mqtt, clock, phy, network_was_reset: false, } } + /// Update the MQTT interface and service the network + /// + /// # Returns + /// An option containing an action that should be completed as a result of network servicing. pub fn update(&mut self) -> Option { let now = self.clock.current_ms(); - let sleep = match self.mqtt_interface.network_stack().poll(now) { + // First, service the network stack to process and inbound and outbound traffic. + let sleep = match self.mqtt.network_stack().poll(now) { Ok(updated) => !updated, Err(err) => { log::info!("Network error: {:?}", err); @@ -58,20 +76,21 @@ where } }; - // If the PHY indicates there's no more ethernet link, reset the network stack and close all - // sockets. + // If the PHY indicates there's no more ethernet link, reset the DHCP server in the network + // stack. if self.phy.poll_link() == false { // Only reset the network stack once per link reconnection. This prevents us from // sending an excessive number of DHCP requests. if !self.network_was_reset { self.network_was_reset = true; - self.mqtt_interface.network_stack().handle_link_reset(); + self.mqtt.network_stack().handle_link_reset(); } } else { self.network_was_reset = false; } - match self.mqtt_interface.update() { + // Finally, service the MQTT interface and handle any necessary messages. + match self.mqtt.update() { Ok(true) => Some(Action::UpdateSettings), Ok(false) if sleep => Some(Action::Sleep), Ok(_) => None, From d0c1bef55f41e201bb2d6c5f41086603ae75dd40 Mon Sep 17 00:00:00 2001 From: Ryan Summers Date: Thu, 8 Apr 2021 13:37:24 +0200 Subject: [PATCH 4/7] Updating dependencies --- Cargo.lock | 7 +------ Cargo.toml | 5 +---- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3aa8999..83f9171 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -710,7 +710,7 @@ dependencies = [ [[package]] name = "smoltcp-nal" version = "0.1.0" -source = "git+https://github.com/quartiq/smoltcp-nal.git?branch=feature/reset-support#c43e751afe3c14aac153fa4425231270dbfd918b" +source = "git+https://github.com/quartiq/smoltcp-nal.git?rev=db2d6c6#db2d6c6ac538a128e63da2f166a0907f4c99989a" dependencies = [ "embedded-nal", "heapless 0.6.1", @@ -835,8 +835,3 @@ name = "wasi" version = "0.10.2+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" - -[[patch.unused]] -name = "smoltcp" -version = "0.7.0" -source = "git+https://github.com/smoltcp-rs/smoltcp.git#09f941851ded868b759e7db067abd67f2fe136a6" diff --git a/Cargo.toml b/Cargo.toml index 144444f..63ea340 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -60,15 +60,12 @@ rev = "314fa5587d" [dependencies.smoltcp-nal] git = "https://github.com/quartiq/smoltcp-nal.git" -branch = "feature/reset-support" +rev = "db2d6c6" [patch.crates-io.minimq] git = "https://github.com/quartiq/minimq.git" rev = "933687c2e4b" -[patch.crates-io.smoltcp] -git = "https://github.com/smoltcp-rs/smoltcp.git" - [patch.crates-io.serde-json-core] git = "https://github.com/rust-embedded-community/serde-json-core.git" rev = "ee06ac91bc" From 164fd5969d1b1cc86497853872fb1d8e56700669 Mon Sep 17 00:00:00 2001 From: Ryan Summers Date: Thu, 8 Apr 2021 13:56:57 +0200 Subject: [PATCH 5/7] Updating smoltcp-nal --- Cargo.lock | 2 +- Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 83f9171..6224d53 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -710,7 +710,7 @@ dependencies = [ [[package]] name = "smoltcp-nal" version = "0.1.0" -source = "git+https://github.com/quartiq/smoltcp-nal.git?rev=db2d6c6#db2d6c6ac538a128e63da2f166a0907f4c99989a" +source = "git+https://github.com/quartiq/smoltcp-nal.git?rev=d200d4e#d200d4eb20cdad42ed30a77f9c1690f43361d9e8" dependencies = [ "embedded-nal", "heapless 0.6.1", diff --git a/Cargo.toml b/Cargo.toml index 63ea340..dcdffea 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -60,7 +60,7 @@ rev = "314fa5587d" [dependencies.smoltcp-nal] git = "https://github.com/quartiq/smoltcp-nal.git" -rev = "db2d6c6" +rev = "d200d4e" [patch.crates-io.minimq] git = "https://github.com/quartiq/minimq.git" From c24eb17d1eb469a03a3538638d1fa660b3180fde Mon Sep 17 00:00:00 2001 From: Ryan Summers Date: Thu, 8 Apr 2021 14:02:56 +0200 Subject: [PATCH 6/7] Using main branch commit --- Cargo.lock | 2 +- Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6224d53..f77e0bd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -710,7 +710,7 @@ dependencies = [ [[package]] name = "smoltcp-nal" version = "0.1.0" -source = "git+https://github.com/quartiq/smoltcp-nal.git?rev=d200d4e#d200d4eb20cdad42ed30a77f9c1690f43361d9e8" +source = "git+https://github.com/quartiq/smoltcp-nal.git?rev=7572183#757218316620e074405bc38ff5502ef17a8a3499" dependencies = [ "embedded-nal", "heapless 0.6.1", diff --git a/Cargo.toml b/Cargo.toml index dcdffea..0c4ab0d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -60,7 +60,7 @@ rev = "314fa5587d" [dependencies.smoltcp-nal] git = "https://github.com/quartiq/smoltcp-nal.git" -rev = "d200d4e" +rev = "7572183" [patch.crates-io.minimq] git = "https://github.com/quartiq/minimq.git" From 1a08634dcb90634141c5f2bb966174b7905423fe Mon Sep 17 00:00:00 2001 From: Ryan Summers Date: Mon, 19 Apr 2021 12:17:41 +0200 Subject: [PATCH 7/7] Renaming interface to avoid confusion --- src/bin/dual-iir.rs | 20 ++++++++++++-------- src/bin/lockin-external.rs | 20 ++++++++++++-------- src/net/mod.rs | 11 ++++++----- 3 files changed, 30 insertions(+), 21 deletions(-) diff --git a/src/bin/dual-iir.rs b/src/bin/dual-iir.rs index cac6f45..8f07cf1 100644 --- a/src/bin/dual-iir.rs +++ b/src/bin/dual-iir.rs @@ -13,7 +13,7 @@ use hardware::{ InputPin, AFE0, AFE1, }; -use net::{Action, MqttSettings}; +use net::{Action, MiniconfInterface}; const SCALE: f32 = i16::MAX as _; @@ -46,7 +46,7 @@ const APP: () = { digital_input1: DigitalInput1, adcs: (Adc0Input, Adc1Input), dacs: (Dac0Output, Dac1Output), - mqtt_settings: MqttSettings, + mqtt_config: MiniconfInterface, // Format: iir_state[ch][cascade-no][coeff] #[init([[[0.; 5]; IIR_CASCADE_LENGTH]; 2])] @@ -59,7 +59,7 @@ const APP: () = { // Configure the microcontroller let (mut stabilizer, _pounder) = hardware::setup(c.core, c.device); - let mqtt_settings = MqttSettings::new( + let mqtt_config = MiniconfInterface::new( stabilizer.net.stack, "", "dt/sinara/stabilizer", @@ -83,7 +83,7 @@ const APP: () = { afes: stabilizer.afes, adcs: stabilizer.adcs, dacs: stabilizer.dacs, - mqtt_settings, + mqtt_config, digital_input1: stabilizer.digital_inputs.1, settings: Settings::default(), } @@ -140,10 +140,14 @@ const APP: () = { } } - #[idle(resources=[mqtt_settings], spawn=[settings_update])] + #[idle(resources=[mqtt_config], spawn=[settings_update])] fn idle(mut c: idle::Context) -> ! { loop { - match c.resources.mqtt_settings.lock(|settings| settings.update()) { + match c + .resources + .mqtt_config + .lock(|config_interface| config_interface.update()) + { Some(Action::Sleep) => cortex_m::asm::wfi(), Some(Action::UpdateSettings) => { c.spawn.settings_update().unwrap() @@ -153,9 +157,9 @@ const APP: () = { } } - #[task(priority = 1, resources=[mqtt_settings, afes, settings])] + #[task(priority = 1, resources=[mqtt_config, afes, settings])] fn settings_update(mut c: settings_update::Context) { - let settings = &c.resources.mqtt_settings.mqtt.settings; + let settings = &c.resources.mqtt_config.mqtt.settings; // Update the IIR channels. c.resources.settings.lock(|current| *current = *settings); diff --git a/src/bin/lockin-external.rs b/src/bin/lockin-external.rs index b62ea42..36bd882 100644 --- a/src/bin/lockin-external.rs +++ b/src/bin/lockin-external.rs @@ -14,7 +14,7 @@ use stabilizer::hardware::{ }; use miniconf::Miniconf; -use stabilizer::net::{Action, MqttSettings}; +use stabilizer::net::{Action, MiniconfInterface}; #[derive(Copy, Clone, Debug, Deserialize, Miniconf)] enum Conf { @@ -58,7 +58,7 @@ const APP: () = { afes: (AFE0, AFE1), adcs: (Adc0Input, Adc1Input), dacs: (Dac0Output, Dac1Output), - mqtt_settings: MqttSettings, + mqtt_config: MiniconfInterface, settings: Settings, timestamper: InputStamper, @@ -71,7 +71,7 @@ const APP: () = { // Configure the microcontroller let (mut stabilizer, _pounder) = setup(c.core, c.device); - let mqtt_settings = MqttSettings::new( + let mqtt_config = MiniconfInterface::new( stabilizer.net.stack, "", "dt/sinara/lockin", @@ -108,7 +108,7 @@ const APP: () = { afes: stabilizer.afes, adcs: stabilizer.adcs, dacs: stabilizer.dacs, - mqtt_settings, + mqtt_config, timestamper: stabilizer.timestamper, settings, @@ -190,10 +190,14 @@ const APP: () = { } } - #[idle(resources=[mqtt_settings], spawn=[settings_update])] + #[idle(resources=[mqtt_config], spawn=[settings_update])] fn idle(mut c: idle::Context) -> ! { loop { - match c.resources.mqtt_settings.lock(|settings| settings.update()) { + match c + .resources + .mqtt_config + .lock(|config_interface| config_interface.update()) + { Some(Action::Sleep) => cortex_m::asm::wfi(), Some(Action::UpdateSettings) => { c.spawn.settings_update().unwrap() @@ -203,9 +207,9 @@ const APP: () = { } } - #[task(priority = 1, resources=[mqtt_settings, settings, afes])] + #[task(priority = 1, resources=[mqtt_config, settings, afes])] fn settings_update(mut c: settings_update::Context) { - let settings = &c.resources.mqtt_settings.mqtt.settings; + let settings = &c.resources.mqtt_config.mqtt.settings; c.resources.afes.0.set_gain(settings.afe[0]); c.resources.afes.1.set_gain(settings.afe[1]); diff --git a/src/net/mod.rs b/src/net/mod.rs index f38f3d9..23d712d 100644 --- a/src/net/mod.rs +++ b/src/net/mod.rs @@ -2,7 +2,7 @@ use crate::hardware::{ design_parameters::MQTT_BROKER, CycleCounter, EthernetPhy, NetworkStack, }; -use miniconf::{minimq, MqttInterface}; +use miniconf::minimq; /// Potential actions for firmware to take. pub enum Action { @@ -14,17 +14,17 @@ pub enum Action { } /// MQTT settings interface. -pub struct MqttSettings +pub struct MiniconfInterface where S: miniconf::Miniconf + Default, { - pub mqtt: MqttInterface, + pub mqtt: miniconf::MqttInterface, clock: CycleCounter, phy: EthernetPhy, network_was_reset: bool, } -impl MqttSettings +impl MiniconfInterface where S: miniconf::Miniconf + Default, { @@ -49,7 +49,8 @@ where .unwrap() }; - MqttInterface::new(mqtt_client, prefix, S::default()).unwrap() + miniconf::MqttInterface::new(mqtt_client, prefix, S::default()) + .unwrap() }; Self {