From 261ed127983fb2a280c602b8b473409612e35da8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20J=C3=B6rdens?= Date: Mon, 17 May 2021 12:32:20 +0200 Subject: [PATCH 1/5] dsp: reduce num dependency --- dsp/Cargo.toml | 2 +- dsp/src/complex.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dsp/Cargo.toml b/dsp/Cargo.toml index 0f82bd2..e3be45b 100644 --- a/dsp/Cargo.toml +++ b/dsp/Cargo.toml @@ -6,7 +6,7 @@ edition = "2018" [dependencies] serde = { version = "1.0", features = ["derive"], default-features = false } -num = { version = "0.4.0", default-features = false } +num-complex = { version = "0.4.0", features = ["serde"], default-features = false } miniconf = "0.1" [dev-dependencies] diff --git a/dsp/src/complex.rs b/dsp/src/complex.rs index 1eb003f..bf3e76d 100644 --- a/dsp/src/complex.rs +++ b/dsp/src/complex.rs @@ -1,4 +1,4 @@ -pub use num::Complex; +pub use num_complex::Complex; use super::{atan2, cossin}; From e58e7f179e728e8e77f47890c58e1c36d60b21c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20J=C3=B6rdens?= Date: Mon, 17 May 2021 13:01:45 +0200 Subject: [PATCH 2/5] clean up item visibility * There isn't much API that would only be used accross modules within stabilizer/dsp but should not be pub beyond stabilizer/dsp. * Therefore it's easier to let the definition determine visibility and the mod.rs/lib.rs determine location in the namesapce. * Blanket use pub items in mod and lib. --- Cargo.lock | 38 ++--------------------------------- src/bin/dual-iir.rs | 23 ++++++++++----------- src/bin/lockin.rs | 25 +++++++++-------------- src/hardware/configuration.rs | 4 ++-- src/hardware/mod.rs | 16 +++++++-------- src/hardware/pounder/mod.rs | 18 ++++++++--------- src/net/mod.rs | 15 +++++++------- 7 files changed, 48 insertions(+), 91 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 274b2bb..388ce16 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -208,7 +208,7 @@ dependencies = [ "easybench", "miniconf", "ndarray", - "num", + "num-complex", "rand", "serde", ] @@ -458,19 +458,6 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2178127478ae4ee9be7180bc9c3bffb6354dd7238400db567102f98c413a9f35" -[[package]] -name = "num" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43db66d1170d347f9a065114077f7dccb00c1b9478c89384490a3425279a4606" -dependencies = [ - "num-complex", - "num-integer", - "num-iter", - "num-rational", - "num-traits", -] - [[package]] name = "num-complex" version = "0.4.0" @@ -478,6 +465,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "26873667bbbb7c5182d4a37c1add32cdf09f841af72da53318fdb81543c15085" dependencies = [ "num-traits", + "serde", ] [[package]] @@ -490,28 +478,6 @@ dependencies = [ "num-traits", ] -[[package]] -name = "num-iter" -version = "0.1.42" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2021c8337a54d21aca0d59a92577a029af9431cb59b909b03252b9c164fad59" -dependencies = [ - "autocfg", - "num-integer", - "num-traits", -] - -[[package]] -name = "num-rational" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d41702bd167c2df5520b384281bc111a4b5efcf7fbc4c9c222c815b07e0a6a6a" -dependencies = [ - "autocfg", - "num-integer", - "num-traits", -] - [[package]] name = "num-traits" version = "0.2.14" diff --git a/src/bin/dual-iir.rs b/src/bin/dual-iir.rs index 29eb474..9b1511e 100644 --- a/src/bin/dual-iir.rs +++ b/src/bin/dual-iir.rs @@ -2,19 +2,18 @@ #![no_std] #![no_main] -use stabilizer::{hardware, net}; - -use miniconf::Miniconf; use serde::Deserialize; use dsp::iir; -use hardware::{ - Adc0Input, Adc1Input, AdcCode, AfeGain, Dac0Output, Dac1Output, DacCode, - DigitalInput0, DigitalInput1, InputPin, SystemTimer, AFE0, AFE1, +use stabilizer::{ + hardware::{ + hal, setup, Adc0Input, Adc1Input, AdcCode, AfeGain, Dac0Output, + Dac1Output, DacCode, DigitalInput0, DigitalInput1, InputPin, + SystemTimer, AFE0, AFE1, + }, + net::{Miniconf, NetworkUsers, Telemetry, TelemetryBuffer, UpdateState}, }; -use net::{NetworkUsers, Telemetry, TelemetryBuffer, UpdateState}; - const SCALE: f32 = i16::MAX as _; // The number of cascaded IIR biquads per channel. Select 1 or 2! @@ -50,7 +49,7 @@ impl Default for Settings { } } -#[rtic::app(device = stm32h7xx_hal::stm32, peripherals = true, monotonic = stabilizer::hardware::SystemTimer)] +#[rtic::app(device = stabilizer::hardware::hal::stm32, peripherals = true, monotonic = stabilizer::hardware::SystemTimer)] const APP: () = { struct Resources { afes: (AFE0, AFE1), @@ -69,7 +68,7 @@ const APP: () = { #[init(spawn=[telemetry, settings_update])] fn init(c: init::Context) -> init::LateResources { // Configure the microcontroller - let (mut stabilizer, _pounder) = hardware::setup(c.core, c.device); + let (mut stabilizer, _pounder) = setup(c.core, c.device); let network = NetworkUsers::new( stabilizer.net.stack, @@ -98,7 +97,7 @@ const APP: () = { dacs: stabilizer.dacs, network, digital_inputs: stabilizer.digital_inputs, - telemetry: net::TelemetryBuffer::default(), + telemetry: TelemetryBuffer::default(), settings: Settings::default(), } } @@ -214,7 +213,7 @@ const APP: () = { #[task(binds = ETH, priority = 1)] fn eth(_: eth::Context) { - unsafe { stm32h7xx_hal::ethernet::interrupt_handler() } + unsafe { hal::ethernet::interrupt_handler() } } #[task(binds = SPI2, priority = 3)] diff --git a/src/bin/lockin.rs b/src/bin/lockin.rs index a187767..d8a4a74 100644 --- a/src/bin/lockin.rs +++ b/src/bin/lockin.rs @@ -2,23 +2,18 @@ #![no_std] #![no_main] -use embedded_hal::digital::v2::InputPin; - use serde::Deserialize; use dsp::{Accu, Complex, ComplexExt, Lockin, RPLL}; - -use stabilizer::net; - -use stabilizer::hardware::{ - design_parameters, setup, Adc0Input, Adc1Input, AdcCode, AfeGain, - Dac0Output, Dac1Output, DacCode, DigitalInput0, DigitalInput1, - InputStamper, SystemTimer, AFE0, AFE1, +use stabilizer::{ + hardware::{ + design_parameters, hal, setup, Adc0Input, Adc1Input, AdcCode, AfeGain, + Dac0Output, Dac1Output, DacCode, DigitalInput0, DigitalInput1, + InputPin, InputStamper, SystemTimer, AFE0, AFE1, + }, + net::{Miniconf, NetworkUsers, Telemetry, TelemetryBuffer, UpdateState}, }; -use miniconf::Miniconf; -use net::{NetworkUsers, Telemetry, TelemetryBuffer, UpdateState}; - // A constant sinusoid to send on the DAC output. // Full-scale gives a +/- 10.24V amplitude waveform. Scale it down to give +/- 1V. const ONE: i16 = ((1.0 / 10.24) * i16::MAX as f32) as _; @@ -78,7 +73,7 @@ impl Default for Settings { } } -#[rtic::app(device = stm32h7xx_hal::stm32, peripherals = true, monotonic = stabilizer::hardware::SystemTimer)] +#[rtic::app(device = stabilizer::hardware::hal::stm32, peripherals = true, monotonic = stabilizer::hardware::SystemTimer)] const APP: () = { struct Resources { afes: (AFE0, AFE1), @@ -140,7 +135,7 @@ const APP: () = { network, digital_inputs: stabilizer.digital_inputs, timestamper: stabilizer.timestamper, - telemetry: net::TelemetryBuffer::default(), + telemetry: TelemetryBuffer::default(), settings, @@ -295,7 +290,7 @@ const APP: () = { #[task(binds = ETH, priority = 1)] fn eth(_: eth::Context) { - unsafe { stm32h7xx_hal::ethernet::interrupt_handler() } + unsafe { hal::ethernet::interrupt_handler() } } #[task(binds = SPI2, priority = 3)] diff --git a/src/hardware/configuration.rs b/src/hardware/configuration.rs index f48b3d2..da0503e 100644 --- a/src/hardware/configuration.rs +++ b/src/hardware/configuration.rs @@ -833,7 +833,7 @@ pub fn setup( .set_speed(hal::gpio::Speed::VeryHigh); // Configure the IO_Update signal for the DDS. - let mut hrtimer = pounder::hrtimer::HighResTimerE::new( + let mut hrtimer = pounder::HighResTimerE::new( device.HRTIM_TIME, device.HRTIM_MASTER, device.HRTIM_COMMON, @@ -845,7 +845,7 @@ pub fn setup( // is triggered after the QSPI write, which can take approximately 120nS, so // there is additional margin. hrtimer.configure_single_shot( - pounder::hrtimer::Channel::Two, + pounder::HRTimerChannel::Two, design_parameters::POUNDER_IO_UPDATE_DURATION, design_parameters::POUNDER_IO_UPDATE_DELAY, ); diff --git a/src/hardware/mod.rs b/src/hardware/mod.rs index 66152e0..4f65f94 100644 --- a/src/hardware/mod.rs +++ b/src/hardware/mod.rs @@ -1,5 +1,5 @@ ///! Module for all hardware-specific setup of Stabilizer -use stm32h7xx_hal as hal; +pub use stm32h7xx_hal as hal; // Re-export for the DigitalInputs below: pub use embedded_hal::digital::v2::InputPin; @@ -16,13 +16,13 @@ pub mod pounder; mod system_timer; mod timers; -pub use adc::{Adc0Input, Adc1Input, AdcCode}; -pub use afe::Gain as AfeGain; -pub use cycle_counter::CycleCounter; -pub use dac::{Dac0Output, Dac1Output, DacCode}; -pub use digital_input_stamper::InputStamper; -pub use pounder::DdsOutput; -pub use system_timer::SystemTimer; +pub use adc::*; +pub use afe::{Gain as AfeGain, *}; +pub use cycle_counter::*; +pub use dac::*; +pub use digital_input_stamper::*; +pub use pounder::*; +pub use system_timer::*; // Type alias for the analog front-end (AFE) for ADC0. pub type AFE0 = afe::ProgrammableGainAmplifier< diff --git a/src/hardware/pounder/mod.rs b/src/hardware/pounder/mod.rs index 32a8e80..1eb60c0 100644 --- a/src/hardware/pounder/mod.rs +++ b/src/hardware/pounder/mod.rs @@ -1,21 +1,19 @@ +use super::hal; +use embedded_hal::{adc::OneShot, blocking::spi::Transfer}; use serde::{Deserialize, Serialize}; -pub mod attenuators; +mod attenuators; mod dds_output; -pub mod hrtimer; +mod hrtimer; mod rf_power; #[cfg(feature = "pounder_v1_1")] pub mod timestamp; -pub use dds_output::DdsOutput; - -use super::hal; - -use attenuators::AttenuatorInterface; -use rf_power::PowerMeasurementInterface; - -use embedded_hal::{adc::OneShot, blocking::spi::Transfer}; +pub use attenuators::*; +pub use dds_output::*; +pub use hrtimer::{Channel as HRTimerChannel, *}; +pub use rf_power::*; const EXT_CLK_SEL_PIN: u8 = 8 + 7; #[allow(dead_code)] diff --git a/src/net/mod.rs b/src/net/mod.rs index 38499ca..9843e46 100644 --- a/src/net/mod.rs +++ b/src/net/mod.rs @@ -5,11 +5,10 @@ ///! telemetry (via MQTT), configuration of run-time settings (via MQTT + Miniconf), and live data ///! streaming over raw UDP/TCP sockets. This module encompasses the main processing routines ///! related to Stabilizer networking operations. -use heapless::{consts, String}; -use miniconf::Miniconf; -use serde::Serialize; - use core::fmt::Write; +use heapless::{consts, String}; +pub use miniconf::Miniconf; +use serde::Serialize; mod messages; mod miniconf_client; @@ -20,10 +19,10 @@ mod telemetry; use crate::hardware::{CycleCounter, EthernetPhy, NetworkStack}; use messages::{MqttMessage, SettingsResponse}; -pub use miniconf_client::MiniconfClient; -pub use network_processor::NetworkProcessor; -pub use shared::NetworkManager; -pub use telemetry::{Telemetry, TelemetryBuffer, TelemetryClient}; +pub use miniconf_client::*; +pub use network_processor::*; +pub use shared::*; +pub use telemetry::*; pub type NetworkReference = shared::NetworkStackProxy<'static, NetworkStack>; From 316dbb3d2e8860781c703c766fed4a8c770f10cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20J=C3=B6rdens?= Date: Wed, 26 May 2021 17:59:30 +0200 Subject: [PATCH 3/5] dual-iir: fmt --- src/bin/dual-iir.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/bin/dual-iir.rs b/src/bin/dual-iir.rs index 65704ea..e434e66 100644 --- a/src/bin/dual-iir.rs +++ b/src/bin/dual-iir.rs @@ -14,7 +14,6 @@ use stabilizer::{ net::{Miniconf, NetworkState, NetworkUsers, Telemetry, TelemetryBuffer}, }; - const SCALE: f32 = i16::MAX as _; // The number of cascaded IIR biquads per channel. Select 1 or 2! From f60827e59a3bdf1b376c1634995687becd5bf3b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20J=C3=B6rdens?= Date: Fri, 4 Jun 2021 12:00:15 +0200 Subject: [PATCH 4/5] lockin: remove SPI error ISR Let them be handled by HardFault here. Keep them in dual-iir for debugging and show-casing their usage. --- src/bin/lockin.rs | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/src/bin/lockin.rs b/src/bin/lockin.rs index 270c94a..b2447e5 100644 --- a/src/bin/lockin.rs +++ b/src/bin/lockin.rs @@ -307,26 +307,6 @@ const APP: () = { unsafe { hal::ethernet::interrupt_handler() } } - #[task(binds = SPI2, priority = 3)] - fn spi2(_: spi2::Context) { - panic!("ADC0 SPI error"); - } - - #[task(binds = SPI3, priority = 3)] - fn spi3(_: spi3::Context) { - panic!("ADC1 SPI error"); - } - - #[task(binds = SPI4, priority = 3)] - fn spi4(_: spi4::Context) { - panic!("DAC0 SPI error"); - } - - #[task(binds = SPI5, priority = 3)] - fn spi5(_: spi5::Context) { - panic!("DAC1 SPI error"); - } - extern "C" { // hw interrupt handlers for RTIC to use for scheduling tasks // one per priority From f514205f8d5f56f46f627a5ca39abbd55cecc4c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20J=C3=B6rdens?= Date: Fri, 4 Jun 2021 17:02:01 +0200 Subject: [PATCH 5/5] stabilizer: don't flatten namespace, renames --- src/bin/dual-iir.rs | 29 ++++++++++------ src/bin/lockin.rs | 31 +++++++++++------ ...ital_input_stamper.rs => input_stamper.rs} | 0 src/hardware/mod.rs | 31 ++++++----------- src/hardware/pounder/mod.rs | 17 ++++------ src/hardware/{configuration.rs => setup.rs} | 18 +++++----- src/net/mod.rs | 33 ++++++++++--------- src/net/network_processor.rs | 2 +- src/net/telemetry.rs | 4 +-- 9 files changed, 85 insertions(+), 80 deletions(-) rename src/hardware/{digital_input_stamper.rs => input_stamper.rs} (100%) rename src/hardware/{configuration.rs => setup.rs} (98%) diff --git a/src/bin/dual-iir.rs b/src/bin/dual-iir.rs index e41ef05..d511ce1 100644 --- a/src/bin/dual-iir.rs +++ b/src/bin/dual-iir.rs @@ -3,18 +3,26 @@ #![no_main] use core::sync::atomic::{fence, Ordering}; -use miniconf::Miniconf; -use serde::Deserialize; use dsp::iir; use stabilizer::{ flatten_closures, hardware::{ - hal, setup, Adc0Input, Adc1Input, AdcCode, AfeGain, Dac0Output, - Dac1Output, DacCode, DigitalInput0, DigitalInput1, InputPin, - SystemTimer, AFE0, AFE1, + self, + adc::{Adc0Input, Adc1Input, AdcCode}, + afe::Gain, + dac::{Dac0Output, Dac1Output, DacCode}, + embedded_hal::digital::v2::InputPin, + hal, + system_timer::SystemTimer, + DigitalInput0, DigitalInput1, AFE0, AFE1, + }, + net::{ + miniconf::Miniconf, + serde::Deserialize, + telemetry::{Telemetry, TelemetryBuffer}, + NetworkState, NetworkUsers, }, - net::{NetworkState, NetworkUsers, Telemetry, TelemetryBuffer}, }; const SCALE: f32 = i16::MAX as _; @@ -24,7 +32,7 @@ const IIR_CASCADE_LENGTH: usize = 1; #[derive(Clone, Copy, Debug, Deserialize, Miniconf)] pub struct Settings { - afe: [AfeGain; 2], + afe: [Gain; 2], iir_ch: [[iir::IIR; IIR_CASCADE_LENGTH]; 2], allow_hold: bool, force_hold: bool, @@ -35,7 +43,7 @@ impl Default for Settings { fn default() -> Self { Self { // Analog frontend programmable gain amplifier gains (G1, G2, G5, G10) - afe: [AfeGain::G1, AfeGain::G1], + afe: [Gain::G1, Gain::G1], // IIR filter tap gains are an array `[b0, b1, b2, a1, a2]` such that the // new output is computed as `y0 = a1*y1 + a2*y2 + b0*x0 + b1*x1 + b2*x2`. // The array is `iir_state[channel-index][cascade-index][coeff-index]`. @@ -52,7 +60,7 @@ impl Default for Settings { } } -#[rtic::app(device = stabilizer::hardware::hal::stm32, peripherals = true, monotonic = stabilizer::hardware::SystemTimer)] +#[rtic::app(device = stabilizer::hardware::hal::stm32, peripherals = true, monotonic = stabilizer::hardware::system_timer::SystemTimer)] const APP: () = { struct Resources { afes: (AFE0, AFE1), @@ -71,7 +79,8 @@ const APP: () = { #[init(spawn=[telemetry, settings_update])] fn init(c: init::Context) -> init::LateResources { // Configure the microcontroller - let (mut stabilizer, _pounder) = setup(c.core, c.device); + let (mut stabilizer, _pounder) = + hardware::setup::setup(c.core, c.device); let network = NetworkUsers::new( stabilizer.net.stack, diff --git a/src/bin/lockin.rs b/src/bin/lockin.rs index b2447e5..46ffdc0 100644 --- a/src/bin/lockin.rs +++ b/src/bin/lockin.rs @@ -3,18 +3,28 @@ #![no_main] use core::sync::atomic::{fence, Ordering}; -use miniconf::Miniconf; -use serde::Deserialize; use dsp::{Accu, Complex, ComplexExt, Lockin, RPLL}; use stabilizer::{ flatten_closures, hardware::{ - design_parameters, hal, setup, Adc0Input, Adc1Input, AdcCode, AfeGain, - Dac0Output, Dac1Output, DacCode, DigitalInput0, DigitalInput1, - InputPin, InputStamper, SystemTimer, AFE0, AFE1, + self, + adc::{Adc0Input, Adc1Input, AdcCode}, + afe::Gain, + dac::{Dac0Output, Dac1Output, DacCode}, + design_parameters, + embedded_hal::digital::v2::InputPin, + hal, + input_stamper::InputStamper, + system_timer::SystemTimer, + DigitalInput0, DigitalInput1, AFE0, AFE1, + }, + net::{ + miniconf::Miniconf, + serde::Deserialize, + telemetry::{Telemetry, TelemetryBuffer}, + NetworkState, NetworkUsers, }, - net::{NetworkState, NetworkUsers, Telemetry, TelemetryBuffer}, }; // A constant sinusoid to send on the DAC output. @@ -43,7 +53,7 @@ enum LockinMode { #[derive(Copy, Clone, Debug, Deserialize, Miniconf)] pub struct Settings { - afe: [AfeGain; 2], + afe: [Gain; 2], lockin_mode: LockinMode, pll_tc: [u8; 2], @@ -59,7 +69,7 @@ pub struct Settings { impl Default for Settings { fn default() -> Self { Self { - afe: [AfeGain::G1; 2], + afe: [Gain::G1; 2], lockin_mode: LockinMode::External, @@ -76,7 +86,7 @@ impl Default for Settings { } } -#[rtic::app(device = stabilizer::hardware::hal::stm32, peripherals = true, monotonic = stabilizer::hardware::SystemTimer)] +#[rtic::app(device = stabilizer::hardware::hal::stm32, peripherals = true, monotonic = stabilizer::hardware::system_timer::SystemTimer)] const APP: () = { struct Resources { afes: (AFE0, AFE1), @@ -95,7 +105,8 @@ const APP: () = { #[init(spawn=[settings_update, telemetry])] fn init(c: init::Context) -> init::LateResources { // Configure the microcontroller - let (mut stabilizer, _pounder) = setup(c.core, c.device); + let (mut stabilizer, _pounder) = + hardware::setup::setup(c.core, c.device); let network = NetworkUsers::new( stabilizer.net.stack, diff --git a/src/hardware/digital_input_stamper.rs b/src/hardware/input_stamper.rs similarity index 100% rename from src/hardware/digital_input_stamper.rs rename to src/hardware/input_stamper.rs diff --git a/src/hardware/mod.rs b/src/hardware/mod.rs index 2e4cd46..422f7b9 100644 --- a/src/hardware/mod.rs +++ b/src/hardware/mod.rs @@ -1,28 +1,19 @@ +pub use embedded_hal; ///! Module for all hardware-specific setup of Stabilizer pub use stm32h7xx_hal as hal; -// Re-export for the DigitalInputs below: -pub use embedded_hal::digital::v2::InputPin; - -mod adc; -mod afe; -mod configuration; -mod cycle_counter; -mod dac; +pub mod adc; +pub mod afe; +pub mod cycle_counter; +pub mod dac; pub mod design_parameters; -mod digital_input_stamper; -mod eeprom; +pub mod input_stamper; pub mod pounder; -mod system_timer; -mod timers; +pub mod setup; +pub mod system_timer; -pub use adc::*; -pub use afe::{Gain as AfeGain, *}; -pub use cycle_counter::*; -pub use dac::*; -pub use digital_input_stamper::*; -pub use pounder::*; -pub use system_timer::*; +mod eeprom; +mod timers; // Type alias for the analog front-end (AFE) for ADC0. pub type AFE0 = afe::ProgrammableGainAmplifier< @@ -52,8 +43,6 @@ pub type NetworkStack = smoltcp_nal::NetworkStack< pub type EthernetPhy = hal::ethernet::phy::LAN8742A; -pub use configuration::{setup, PounderDevices, StabilizerDevices}; - #[inline(never)] #[panic_handler] fn panic(info: &core::panic::PanicInfo) -> ! { diff --git a/src/hardware/pounder/mod.rs b/src/hardware/pounder/mod.rs index a69e5b0..a56446e 100644 --- a/src/hardware/pounder/mod.rs +++ b/src/hardware/pounder/mod.rs @@ -2,19 +2,14 @@ use super::hal; use embedded_hal::{adc::OneShot, blocking::spi::Transfer}; use serde::{Deserialize, Serialize}; -mod attenuators; -mod dds_output; -mod hrtimer; -mod rf_power; +pub mod attenuators; +pub mod dds_output; +pub mod hrtimer; +pub mod rf_power; #[cfg(feature = "pounder_v1_1")] pub mod timestamp; -pub use attenuators::*; -pub use dds_output::*; -pub use hrtimer::{Channel as HRTimerChannel, *}; -pub use rf_power::*; - pub enum GpioPin { Led4Green = 0, Led5Red = 1, @@ -327,7 +322,7 @@ impl PounderDevices { } } -impl AttenuatorInterface for PounderDevices { +impl attenuators::AttenuatorInterface for PounderDevices { /// Reset all of the attenuators to a power-on default state. fn reset_attenuators(&mut self) -> Result<(), Error> { self.mcp23017 @@ -374,7 +369,7 @@ impl AttenuatorInterface for PounderDevices { } } -impl PowerMeasurementInterface for PounderDevices { +impl rf_power::PowerMeasurementInterface for PounderDevices { /// Sample an ADC channel. /// /// Args: diff --git a/src/hardware/configuration.rs b/src/hardware/setup.rs similarity index 98% rename from src/hardware/configuration.rs rename to src/hardware/setup.rs index 57e7361..515dd51 100644 --- a/src/hardware/configuration.rs +++ b/src/hardware/setup.rs @@ -15,9 +15,10 @@ use smoltcp_nal::smoltcp; use embedded_hal::digital::v2::{InputPin, OutputPin}; use super::{ - adc, afe, cycle_counter::CycleCounter, dac, design_parameters, - digital_input_stamper, eeprom, pounder, system_timer, timers, DdsOutput, - DigitalInput0, DigitalInput1, EthernetPhy, NetworkStack, AFE0, AFE1, + adc, afe, cycle_counter::CycleCounter, dac, design_parameters, eeprom, + input_stamper::InputStamper, pounder, pounder::dds_output::DdsOutput, + system_timer, timers, DigitalInput0, DigitalInput1, EthernetPhy, + NetworkStack, AFE0, AFE1, }; pub struct NetStorage { @@ -84,7 +85,7 @@ pub struct StabilizerDevices { pub afes: (AFE0, AFE1), pub adcs: (adc::Adc0Input, adc::Adc1Input), pub dacs: (dac::Dac0Output, dac::Dac1Output), - pub timestamper: digital_input_stamper::InputStamper, + pub timestamper: InputStamper, pub adc_dac_timer: timers::SamplingTimer, pub timestamp_timer: timers::TimestampTimer, pub net: NetworkDevices, @@ -509,10 +510,7 @@ pub fn setup( let input_stamper = { let trigger = gpioa.pa3.into_alternate_af2(); - digital_input_stamper::InputStamper::new( - trigger, - timestamp_timer_channels.ch4, - ) + InputStamper::new(trigger, timestamp_timer_channels.ch4) }; let digital_inputs = { @@ -877,7 +875,7 @@ pub fn setup( .set_speed(hal::gpio::Speed::VeryHigh); // Configure the IO_Update signal for the DDS. - let mut hrtimer = pounder::HighResTimerE::new( + let mut hrtimer = pounder::hrtimer::HighResTimerE::new( device.HRTIM_TIME, device.HRTIM_MASTER, device.HRTIM_COMMON, @@ -889,7 +887,7 @@ pub fn setup( // is triggered after the QSPI write, which can take approximately 120nS, so // there is additional margin. hrtimer.configure_single_shot( - pounder::HRTimerChannel::Two, + pounder::hrtimer::Channel::Two, design_parameters::POUNDER_IO_UPDATE_DURATION, design_parameters::POUNDER_IO_UPDATE_DELAY, ); diff --git a/src/net/mod.rs b/src/net/mod.rs index fb12ea7..e9a2538 100644 --- a/src/net/mod.rs +++ b/src/net/mod.rs @@ -5,25 +5,28 @@ ///! telemetry (via MQTT), configuration of run-time settings (via MQTT + Miniconf), and live data ///! streaming over raw UDP/TCP sockets. This module encompasses the main processing routines ///! related to Stabilizer networking operations. +pub use heapless; +pub use miniconf; +pub use serde; + +pub mod messages; +pub mod miniconf_client; +pub mod network_processor; +pub mod shared; +pub mod telemetry; + +use crate::hardware::{cycle_counter::CycleCounter, EthernetPhy, NetworkStack}; +use messages::{MqttMessage, SettingsResponse}; +use miniconf_client::MiniconfClient; +use network_processor::NetworkProcessor; +use shared::NetworkManager; +use telemetry::TelemetryClient; + use core::fmt::Write; use heapless::String; -pub use miniconf::Miniconf; +use miniconf::Miniconf; use serde::Serialize; -mod messages; -mod miniconf_client; -mod network_processor; -mod shared; -mod telemetry; - -use crate::hardware::{CycleCounter, EthernetPhy, NetworkStack}; -use messages::{MqttMessage, SettingsResponse}; - -pub use miniconf_client::*; -pub use network_processor::*; -pub use shared::*; -pub use telemetry::*; - pub type NetworkReference = shared::NetworkStackProxy<'static, NetworkStack>; #[derive(Copy, Clone, PartialEq)] diff --git a/src/net/network_processor.rs b/src/net/network_processor.rs index a64d6e7..a8168d3 100644 --- a/src/net/network_processor.rs +++ b/src/net/network_processor.rs @@ -4,7 +4,7 @@ ///! The network processir is a small taks to regularly process incoming data over ethernet, handle ///! the ethernet PHY state, and reset the network as appropriate. use super::{NetworkReference, UpdateState}; -use crate::hardware::{CycleCounter, EthernetPhy}; +use crate::hardware::{cycle_counter::CycleCounter, EthernetPhy}; /// Processor for managing network hardware. pub struct NetworkProcessor { diff --git a/src/net/telemetry.rs b/src/net/telemetry.rs index d976fee..40a5ce3 100644 --- a/src/net/telemetry.rs +++ b/src/net/telemetry.rs @@ -16,7 +16,7 @@ use serde::Serialize; use super::NetworkReference; use crate::hardware::{ - design_parameters::MQTT_BROKER, AdcCode, AfeGain, DacCode, + adc::AdcCode, afe::Gain, dac::DacCode, design_parameters::MQTT_BROKER, }; /// The telemetry client for reporting telemetry data over MQTT. @@ -73,7 +73,7 @@ impl TelemetryBuffer { /// /// # Returns /// The finalized telemetry structure that can be serialized and reported. - pub fn finalize(self, afe0: AfeGain, afe1: AfeGain) -> Telemetry { + pub fn finalize(self, afe0: Gain, afe1: Gain) -> Telemetry { let in0_volts = Into::::into(self.adcs[0]) / afe0.as_multiplier(); let in1_volts = Into::::into(self.adcs[1]) / afe1.as_multiplier();