stabilizer: don't flatten namespace, renames

master
Robert Jördens 2021-06-04 17:02:01 +02:00
parent f60827e59a
commit f514205f8d
9 changed files with 85 additions and 80 deletions

View File

@ -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,

View File

@ -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,

View File

@ -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<hal::ethernet::EthernetMAC>;
pub use configuration::{setup, PounderDevices, StabilizerDevices};
#[inline(never)]
#[panic_handler]
fn panic(info: &core::panic::PanicInfo) -> ! {

View File

@ -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:

View File

@ -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,
);

View File

@ -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)]

View File

@ -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 {

View File

@ -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::<f32>::into(self.adcs[0]) / afe0.as_multiplier();
let in1_volts = Into::<f32>::into(self.adcs[1]) / afe1.as_multiplier();