Adding streaming to lockin app

This commit is contained in:
Ryan Summers 2021-06-15 13:22:38 +02:00
parent 2815d6d9e9
commit 9e083842ee

View File

@ -20,6 +20,7 @@ use stabilizer::{
DigitalInput0, DigitalInput1, AFE0, AFE1,
},
net::{
data_stream::{BlockGenerator, StreamTarget},
miniconf::Miniconf,
serde::Deserialize,
telemetry::{Telemetry, TelemetryBuffer},
@ -64,6 +65,8 @@ pub struct Settings {
output_conf: [Conf; 2],
telemetry_period: u16,
stream_target: StreamTarget,
}
impl Default for Settings {
@ -82,6 +85,8 @@ impl Default for Settings {
output_conf: [Conf::InPhase, Conf::Quadrature],
// The default telemetry period in seconds.
telemetry_period: 10,
stream_target: StreamTarget::default(),
}
}
}
@ -96,6 +101,7 @@ const APP: () = {
settings: Settings,
telemetry: TelemetryBuffer,
digital_inputs: (DigitalInput0, DigitalInput1),
generator: BlockGenerator,
timestamper: InputStamper,
pll: RPLL,
@ -108,7 +114,7 @@ const APP: () = {
let (mut stabilizer, _pounder) =
hardware::setup::setup(c.core, c.device);
let network = NetworkUsers::new(
let mut network = NetworkUsers::new(
stabilizer.net.stack,
stabilizer.net.phy,
stabilizer.cycle_counter,
@ -116,6 +122,8 @@ const APP: () = {
stabilizer.net.mac_address,
);
let generator = network.enable_streaming();
let settings = Settings::default();
let pll = RPLL::new(
@ -155,6 +163,7 @@ const APP: () = {
telemetry: TelemetryBuffer::default(),
settings,
generator,
pll,
lockin: Lockin::default(),
@ -168,7 +177,7 @@ const APP: () = {
/// This is an implementation of a externally (DI0) referenced PLL lockin on the ADC0 signal.
/// It outputs either I/Q or power/phase on DAC0/DAC1. Data is normalized to full scale.
/// PLL bandwidth, filter bandwidth, slope, and x/y or power/phase post-filters are available.
#[task(binds=DMA1_STR4, resources=[adcs, dacs, lockin, timestamper, pll, settings, telemetry], priority=2)]
#[task(binds=DMA1_STR4, resources=[adcs, dacs, lockin, timestamper, pll, settings, telemetry, generator], priority=2)]
#[inline(never)]
#[link_section = ".itcm.process"]
fn process(mut c: process::Context) {
@ -180,6 +189,7 @@ const APP: () = {
ref mut lockin,
ref mut pll,
ref mut timestamper,
ref mut generator,
} = c.resources;
let (reference_phase, reference_frequency) = match settings.lockin_mode
@ -252,6 +262,10 @@ const APP: () = {
*sample = DacCode::from(value as i16).0;
}
}
// Stream data
generator.send(&adc_samples, &dac_samples);
// Update telemetry measurements.
telemetry.adcs =
[AdcCode(adc_samples[0][0]), AdcCode(adc_samples[1][0])];
@ -285,6 +299,9 @@ const APP: () = {
c.resources.afes.1.set_gain(settings.afe[1]);
c.resources.settings.lock(|current| *current = *settings);
let target = settings.stream_target.into();
c.resources.network.direct_stream(target);
}
#[task(priority = 1, resources=[network, digital_inputs, settings, telemetry], schedule=[telemetry])]