Expanding miniconf to lockin
This commit is contained in:
parent
411a847a88
commit
096f786795
|
@ -9,10 +9,9 @@ use rtic::cyccnt::{Instant, U32Ext};
|
||||||
|
|
||||||
use stabilizer::hardware;
|
use stabilizer::hardware;
|
||||||
|
|
||||||
use miniconf::StringSet;
|
|
||||||
use miniconf::{
|
use miniconf::{
|
||||||
embedded_nal::{IpAddr, Ipv4Addr},
|
embedded_nal::{IpAddr, Ipv4Addr},
|
||||||
MqttInterface,
|
MqttInterface, StringSet,
|
||||||
};
|
};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
|
||||||
|
@ -59,6 +58,15 @@ const APP: () = {
|
||||||
// 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);
|
||||||
|
|
||||||
|
let broker = IpAddr::V4(Ipv4Addr::new(10, 0, 0, 2));
|
||||||
|
let mqtt_interface = MqttInterface::new(
|
||||||
|
stabilizer.net.stack,
|
||||||
|
"stabilizer/iir/dual",
|
||||||
|
broker,
|
||||||
|
Settings::new(),
|
||||||
|
)
|
||||||
|
.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();
|
||||||
|
@ -68,16 +76,8 @@ const APP: () = {
|
||||||
// Start sampling ADCs.
|
// Start sampling ADCs.
|
||||||
stabilizer.adc_dac_timer.start();
|
stabilizer.adc_dac_timer.start();
|
||||||
|
|
||||||
let broker = IpAddr::V4(Ipv4Addr::new(10, 0, 0, 2));
|
|
||||||
|
|
||||||
init::LateResources {
|
init::LateResources {
|
||||||
mqtt_interface: MqttInterface::new(
|
mqtt_interface,
|
||||||
stabilizer.net.stack,
|
|
||||||
"stabilizer",
|
|
||||||
broker,
|
|
||||||
Settings::new(),
|
|
||||||
)
|
|
||||||
.unwrap(),
|
|
||||||
afes: stabilizer.afes,
|
afes: stabilizer.afes,
|
||||||
adcs: stabilizer.adcs,
|
adcs: stabilizer.adcs,
|
||||||
dacs: stabilizer.dacs,
|
dacs: stabilizer.dacs,
|
||||||
|
|
|
@ -9,6 +9,12 @@ use rtic::cyccnt::{Instant, U32Ext};
|
||||||
|
|
||||||
use stabilizer::{hardware, ADC_SAMPLE_TICKS_LOG2, SAMPLE_BUFFER_SIZE_LOG2};
|
use stabilizer::{hardware, ADC_SAMPLE_TICKS_LOG2, SAMPLE_BUFFER_SIZE_LOG2};
|
||||||
|
|
||||||
|
use miniconf::{
|
||||||
|
embedded_nal::{IpAddr, Ipv4Addr},
|
||||||
|
MqttInterface, StringSet,
|
||||||
|
};
|
||||||
|
use serde::Deserialize;
|
||||||
|
|
||||||
use dsp::{iir, iir_int, lockin::Lockin, rpll::RPLL};
|
use dsp::{iir, iir_int, lockin::Lockin, rpll::RPLL};
|
||||||
use hardware::{
|
use hardware::{
|
||||||
Adc0Input, Adc1Input, Dac0Output, Dac1Output, InputStamper, AFE0, AFE1,
|
Adc0Input, Adc1Input, Dac0Output, Dac1Output, InputStamper, AFE0, AFE1,
|
||||||
|
@ -19,13 +25,26 @@ const SCALE: f32 = ((1 << 15) - 1) as f32;
|
||||||
// The number of cascaded IIR biquads per channel. Select 1 or 2!
|
// The number of cascaded IIR biquads per channel. Select 1 or 2!
|
||||||
const IIR_CASCADE_LENGTH: usize = 1;
|
const IIR_CASCADE_LENGTH: usize = 1;
|
||||||
|
|
||||||
|
#[derive(Debug, Deserialize, StringSet)]
|
||||||
|
pub struct Settings {
|
||||||
|
iir: [[iir::IIR; IIR_CASCADE_LENGTH]; 2],
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Settings {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Self {
|
||||||
|
iir: [[iir::IIR::default(); IIR_CASCADE_LENGTH]; 2],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[rtic::app(device = stm32h7xx_hal::stm32, peripherals = true, monotonic = rtic::cyccnt::CYCCNT)]
|
#[rtic::app(device = stm32h7xx_hal::stm32, peripherals = true, monotonic = rtic::cyccnt::CYCCNT)]
|
||||||
const APP: () = {
|
const APP: () = {
|
||||||
struct Resources {
|
struct Resources {
|
||||||
afes: (AFE0, AFE1),
|
afes: (AFE0, AFE1),
|
||||||
adcs: (Adc0Input, Adc1Input),
|
adcs: (Adc0Input, Adc1Input),
|
||||||
dacs: (Dac0Output, Dac1Output),
|
dacs: (Dac0Output, Dac1Output),
|
||||||
stack: hardware::NetworkStack,
|
mqtt_interface: MqttInterface<Settings, hardware::NetworkStack>,
|
||||||
|
|
||||||
// Format: iir_state[ch][cascade-no][coeff]
|
// Format: iir_state[ch][cascade-no][coeff]
|
||||||
#[init([[[0.; 5]; IIR_CASCADE_LENGTH]; 2])]
|
#[init([[[0.; 5]; IIR_CASCADE_LENGTH]; 2])]
|
||||||
|
@ -43,6 +62,15 @@ const APP: () = {
|
||||||
// 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);
|
||||||
|
|
||||||
|
let broker = IpAddr::V4(Ipv4Addr::new(10, 0, 0, 2));
|
||||||
|
let mqtt_interface = MqttInterface::new(
|
||||||
|
stabilizer.net.stack,
|
||||||
|
"stabilizer/lockin",
|
||||||
|
broker,
|
||||||
|
Settings::new(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let pll = RPLL::new(ADC_SAMPLE_TICKS_LOG2 + SAMPLE_BUFFER_SIZE_LOG2, 0);
|
let pll = RPLL::new(ADC_SAMPLE_TICKS_LOG2 + SAMPLE_BUFFER_SIZE_LOG2, 0);
|
||||||
|
|
||||||
let lockin = Lockin::new(
|
let lockin = Lockin::new(
|
||||||
|
@ -62,10 +90,10 @@ const APP: () = {
|
||||||
stabilizer.adc_dac_timer.start();
|
stabilizer.adc_dac_timer.start();
|
||||||
|
|
||||||
init::LateResources {
|
init::LateResources {
|
||||||
|
mqtt_interface,
|
||||||
afes: stabilizer.afes,
|
afes: stabilizer.afes,
|
||||||
adcs: stabilizer.adcs,
|
adcs: stabilizer.adcs,
|
||||||
dacs: stabilizer.dacs,
|
dacs: stabilizer.dacs,
|
||||||
stack: stabilizer.net.stack,
|
|
||||||
timestamper: stabilizer.timestamper,
|
timestamper: stabilizer.timestamper,
|
||||||
|
|
||||||
pll,
|
pll,
|
||||||
|
@ -152,8 +180,8 @@ const APP: () = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[idle(resources=[stack, iir_state, iir_ch, afes])]
|
#[idle(resources=[mqtt_interface], spawn=[settings_update])]
|
||||||
fn idle(c: idle::Context) -> ! {
|
fn idle(mut c: idle::Context) -> ! {
|
||||||
let mut time = 0u32;
|
let mut time = 0u32;
|
||||||
let mut next_ms = Instant::now();
|
let mut next_ms = Instant::now();
|
||||||
|
|
||||||
|
@ -168,14 +196,35 @@ const APP: () = {
|
||||||
time += 1;
|
time += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
let sleep = !c.resources.stack.poll(time);
|
let sleep = c
|
||||||
|
.resources
|
||||||
|
.mqtt_interface
|
||||||
|
.lock(|interface| !interface.network_stack().poll(time));
|
||||||
|
|
||||||
if sleep {
|
match c
|
||||||
cortex_m::asm::wfi();
|
.resources
|
||||||
|
.mqtt_interface
|
||||||
|
.lock(|interface| interface.update().unwrap())
|
||||||
|
{
|
||||||
|
miniconf::Action::Continue => {
|
||||||
|
if sleep {
|
||||||
|
cortex_m::asm::wfi();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
miniconf::Action::CommitSettings => {
|
||||||
|
c.spawn.settings_update().unwrap()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[task(priority = 1, resources=[mqtt_interface, afes, iir_ch])]
|
||||||
|
fn settings_update(mut c: settings_update::Context) {
|
||||||
|
let settings = &c.resources.mqtt_interface.settings;
|
||||||
|
c.resources.iir_ch.lock(|iir| *iir = settings.iir);
|
||||||
|
// TODO: Update AFEs
|
||||||
|
}
|
||||||
|
|
||||||
#[task(binds = ETH, priority = 1)]
|
#[task(binds = ETH, priority = 1)]
|
||||||
fn eth(_: eth::Context) {
|
fn eth(_: eth::Context) {
|
||||||
unsafe { hal::ethernet::interrupt_handler() }
|
unsafe { hal::ethernet::interrupt_handler() }
|
||||||
|
|
Loading…
Reference in New Issue